npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aframe-shadow-casting

v1.0.1

Published

AFRAME components & primitives for real-time shadow casting on a transparent ground plane using custom lighting components and THREE.js ShadowMaterial

Downloads

3

Readme

aframe-shadow-casting

AFRAME components & primitives for real-time shadow casting on a transparent ground plane using custom lighting components and THREE.js ShadowMaterial

Inspiration

I was working on a project using AFRAME and 8th Wall to create a mobile webAR experience, and wanted to add real-time shadows to my scene. AFRAME documentation includes a section on real-time shadows, but that method only works if the receiving plane is opaque, which isn't ideal for AR applications. So I wrote this.

It includes two components - shadow-light and shadow-plane - and two primitives - <a-shadow-light> and <a-shadow-plane> - for use in your AFRAME and/or 8th Wall projects.

Installation

Working on it - for now, just copy and paste.

How to Use

Once installed in your project, you can either add the custom element tags directly or use the components on other AFRAME entities:

<a-shadow-light
    id="spot-light-primitive"
    type="spot"
    mapsize="2048 2048"
    far="20">
</a-shadow-light>
<a-entity
  id="directional-light-entity"
  shadow-light="type: directional; intensity: 0.8; helper: true">
</a-entity>
    
<a-shadow-plane
    id="shadow-plane-primitive
    dimensions="20 20">
</a-shadow-plane>
<a-entity
  id="shadow-plane-entity"
  shadow-plane="opacity: 0.4">
</a-entity>

The shadow-light component creates a directional or spot light in the scene that casts shadows with a configurable shadow camera. The shadow-plane component creates a ground plane that receives shadows. Make sure you add the shadow component to any objects in your scene that you want to cast shadows:

<a-entity gltf-model="#myModel" shadow="receive: false"></a-entity>

Configuration

shadow-light

| Property | type | default | constraints | description | |-----------|---------|------------------------------|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------| | type | string | directional | "directional" or "spot" | Determines the type of THREE.js light that is added to the scene | | intensity | float | 0.5 | > 0 | Intensity of light | | color | color | 'white' | a valid THREE Color | Color of light | | target | vec3 | { x: 0, y: 0, z: 0} | | Light will rotate to face target point | | near | float | 1 | > 0 | 'near' property of shadow camera | | far | float | 5 | > near | 'far' property of shadow camera | | tlrb | vec4 | { x: 5, y: -5, z: 5, w: -5 } | | 'top', 'left', 'right', 'bottom' properties of shadow camera | | mapSize | vec2 | { x: 1024, y: 1024 } | powers of 2 | determines resolution of shadow (width, height) - higher resolution means smoother shadows at the cost of computing time | | bias | float | -0.000222 | | see THREE documentation | | helper | boolean | false | | adds/removes a visualizer to help debug / configure the shadow camera |

You also have the ability to access the light directly through its element using the shadowLight property. This can be helpful for setting other attributes of the light that aren't included in the component - like the angle of a spotlight

var spotlight = document.querySelector('a-shadow-light');
spotlight.shadowLight.angle = Math.PI/2;

You can find all properties of Directional and Spot Lights in the THREEjs documentation.

shadow-plane

| Property | type | default | constraints | description | |------------|---------|------------------------------|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------| | dimensions | vec2 | { x: 10, y: 10 } | > 0 | Defines dimensions (width, height) of ground plane | | opacity | float | 0.2 | 0-1 | Opacity of shadow |

Example

In this repo, you'll find an example webpage (creatively named 'example.html') that you can reference. It creates a simple scene with a levitating ball casting a shadow on the ground.

example gif

It's not all that impressive considering you can't tell if the shadow-plane is actually transparent or not, so if you'd like to see an AR application, you can check out a video of an 8th Wall WebAR experience I created here

Enjoy