0.2.0 • Published 2 months ago

@fern-solutions/aframe-highlight v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Highlight component

npm version npm version github twitter mastodon ko-fi

This component adds a highlight to objects. The highlight can be drawn on either the occluded parts (default) or the visible parts (mode: visible). This allows the user to easily and quickly spot them. The highlight consists of accentuating the rim of the object.

Checkout the example: Online Demo | Source

Usage

Load the script from npm or add the following script tag:

<script src="https://unpkg.com/@fern-solutions/aframe-highlight/dist/highlight.umd.min.js"></script>

The highlight component can be attached to any object:

<a-sphere highlight="rimColor: #FF0000; coreColor: #FF0000; coreOpacity: 0.5"></a-sphere>

To ensure certain objects or entities are rendered on top of any highlight (e.g. hands), you can use the above-highlight component:

<a-entity hand-controls="hand: left" above-highlight></a-entity>

Properties

NameTypeDefaultDescription
rimColorcolor#FF0000The color at the rim of the object
rimOpacityfloat1.0The opacity of the rim between 0.0 and 1.0
coreColorcolor#000000The color at the core of the object
coreOpacityfloat0.0The opacity of the core between 0.0 and 1.0
mode'occlusion' or 'visibleocclusionWhether to show the highlight on occluded or visible parts of the object

Caveats

This component tries to be a relatively lightweight and does not introduce any post-processing. Instead it renders the highlighted objects one (or two) more times to achieve the effect. There are however a couple of caveats associated with this: 1. If the object is expensive to draw, the highlight rendering can be expensive as well 2. The component uses an Object3D directly attached to the scene with renderOrder set to 1000. If you make use of renderOrder make sure there is no conflict. 3. When rendering the highlight on occluded parts, the object itself is rendered without proper depth testing, meaning for concave objects the highlight won't always match the outer surface. 4. Multiple objects with highlights when occluded can render in arbitrary order. It's recommended to limit the amount of entities this effect is used on and try to make sure these entities don't overlap each other.