@needle-tools/three-mesh-effects 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/build/box-impostor-runtime.js +14 -2
- package/build/box-impostor-runtime.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display.js +10 -2
- package/build/internal/box-impostor/box-impostor-display.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-faces.js.map +1 -1
- package/build/internal/box-impostor/box-impostor-geometry.js +4 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-material.js +10 -2
- package/build/internal/box-impostor/box-impostor-material.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-metadata.js +4 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-projection.js.map +1 -1
- package/build/internal/box-impostor/box-impostor-runtime.js +14 -2
- package/build/internal/box-impostor/box-impostor-runtime.js.map +2 -2
- package/build/types/box-impostor/box-impostor-metadata.d.ts +3 -1
- package/package.json +1 -1
- package/src/box-impostor/box-impostor-material.js +10 -2
- package/src/box-impostor/box-impostor-metadata.js +5 -1
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
attribute,
|
|
22
22
|
varying,
|
|
23
23
|
positionLocal,
|
|
24
|
+
positionViewDirection,
|
|
24
25
|
modelWorldMatrixInverse,
|
|
25
26
|
cameraPosition,
|
|
26
27
|
cameraWorldMatrix,
|
|
@@ -758,8 +759,15 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
758
759
|
material.roughnessNode = surfaceOrm.g;
|
|
759
760
|
material.metalnessNode = surfaceOrm.b;
|
|
760
761
|
material.aoNode = surfaceOrm.r;
|
|
761
|
-
material.emissiveNode = emission;
|
|
762
|
-
if (transparency !== "cutout")
|
|
762
|
+
material.emissiveNode = emission.mul(descriptor.emissiveStrength ?? 1);
|
|
763
|
+
if (transparency !== "cutout") {
|
|
764
|
+
let opacity = color.a.clamp(0, 1);
|
|
765
|
+
if (descriptor.fresnelOpacity) {
|
|
766
|
+
const cosine = material.normalNode.dot(positionViewDirection).abs().clamp(0, 1);
|
|
767
|
+
opacity = opacity.add(opacity.oneMinus().mul(cosine.oneMinus().pow(5)));
|
|
768
|
+
}
|
|
769
|
+
material.opacityNode = opacity;
|
|
770
|
+
}
|
|
763
771
|
material.maskNode = hit.get("valid").greaterThan(0.5);
|
|
764
772
|
material.maskShadowNode = material.maskNode;
|
|
765
773
|
material.depthNode = capturedSurfaceDepth(hit.get("position"));
|
|
@@ -5,7 +5,7 @@ export const BOX_OCCUPANCY_RESOLUTION = 8;
|
|
|
5
5
|
export const BOX_OCCUPANCY_WORDS = BOX_OCCUPANCY_RESOLUTION ** 3 / 32;
|
|
6
6
|
export { BOX_FACE_AXES } from "./box-impostor-face-axes.js";
|
|
7
7
|
/** @typedef {{center:number[],axes:number[][],halfSize:number[],views:number[][],planes?:number[],planeErrors?:number[],depthBounds?:number[],occupancy?:number[]}} ImpostorBox */
|
|
8
|
-
/** @typedef {{version:1,depthMode?:'auto'|'projection'|'depth',alphaMode?:'opaque'|'mask'|'blend',interpolation?:'none'|'linear'|'smooth',transparency?:'auto'|'cutout'|'dithered'|'blended',mode:'basic'|'cards'|'fitted',atlasResolution:number,padding:number,raySteps:8|16|32,alphaCutoff:number,boxes:ImpostorBox[]}} BoxImpostorDescriptor */
|
|
8
|
+
/** @typedef {{version:1,fresnelOpacity?:boolean,emissiveStrength?:number,depthMode?:'auto'|'projection'|'depth',alphaMode?:'opaque'|'mask'|'blend',interpolation?:'none'|'linear'|'smooth',transparency?:'auto'|'cutout'|'dithered'|'blended',mode:'basic'|'cards'|'fitted',atlasResolution:number,padding:number,raySteps:8|16|32,alphaCutoff:number,boxes:ImpostorBox[]}} BoxImpostorDescriptor */
|
|
9
9
|
/** @param {unknown} raw @returns {BoxImpostorDescriptor} */
|
|
10
10
|
export function parseBoxImpostorDescriptor(raw) {
|
|
11
11
|
const d = /** @type {BoxImpostorDescriptor} */ (raw);
|
|
@@ -38,6 +38,8 @@ export function parseBoxImpostorDescriptor(raw) {
|
|
|
38
38
|
!["opaque", "mask", "blend"].includes(d.alphaMode)
|
|
39
39
|
)
|
|
40
40
|
fail();
|
|
41
|
+
if (d.fresnelOpacity !== undefined && typeof d.fresnelOpacity !== 'boolean') fail();
|
|
42
|
+
if (d.emissiveStrength !== undefined && (!Number.isFinite(d.emissiveStrength) || d.emissiveStrength < 1)) fail();
|
|
41
43
|
if (d.mode === "basic" && d.boxes.length !== 1) fail();
|
|
42
44
|
for (const b of d.boxes) {
|
|
43
45
|
if (
|
|
@@ -116,6 +118,8 @@ export function parseBoxImpostorDescriptor(raw) {
|
|
|
116
118
|
atlasResolution: d.atlasResolution,
|
|
117
119
|
padding: d.padding,
|
|
118
120
|
boxes: d.boxes,
|
|
121
|
+
...(d.fresnelOpacity !== undefined ? {fresnelOpacity: d.fresnelOpacity} : {}),
|
|
122
|
+
...(d.emissiveStrength !== undefined ? {emissiveStrength: d.emissiveStrength} : {}),
|
|
119
123
|
...(d.alphaMode ? { alphaMode: d.alphaMode } : {}),
|
|
120
124
|
...normalizeBoxImpostorDisplay(d),
|
|
121
125
|
};
|