@needle-tools/three-mesh-effects 0.2.2 → 0.3.1
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 +28 -6
- package/README.md +76 -1
- package/SKILL.md +9 -1
- package/build/box-impostor-runtime.js +1298 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +85 -31
- package/build/deformation-runtime.js.map +4 -4
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +235 -116
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
- package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-display.js +1005 -0
- package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-faces.js +125 -0
- package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-material.js +964 -0
- package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-projection.js +256 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1252 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +23 -17
- package/build/internal/deformation/cloth-surface.js.map +3 -3
- package/build/internal/deformation/fur-surface.js +55 -12
- package/build/internal/deformation/fur-surface.js.map +3 -3
- package/build/internal/deformation/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +85 -31
- package/build/internal/deformation/rig-runtime.js.map +4 -4
- package/build/internal/impostor/impostor-node-material.js +235 -116
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/rendering/hull-effect-runtime.js +59 -27
- package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
- package/build/internal/rendering/texture-slot.js +26 -0
- package/build/internal/rendering/texture-slot.js.map +7 -0
- package/build/internal/rendering/wireframe.js +41 -9
- package/build/internal/rendering/wireframe.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +59 -27
- package/build/internal/rendering/wrap-preview.js.map +3 -3
- package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
- package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
- package/build/types/box-impostor/box-impostor-display.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-display.js +1 -0
- package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
- package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
- package/build/types/box-impostor/box-impostor-faces.js +1 -0
- package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-geometry.js +1 -0
- package/build/types/box-impostor/box-impostor-material.d.ts +10 -0
- package/build/types/box-impostor/box-impostor-material.js +1 -0
- package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
- package/build/types/box-impostor/box-impostor-metadata.js +1 -0
- package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-projection.js +1 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +25 -0
- package/build/types/box-impostor/box-impostor-runtime.js +1 -0
- package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
- package/build/types/deformation/cloth-surface.d.ts +1 -0
- package/build/types/deformation/pin-cloth.d.ts +1 -0
- package/build/types/public/box-impostor-runtime.d.ts +6 -0
- package/build/types/public/box-impostor-runtime.js +1 -0
- package/build/types/public/hull-effects.d.ts +1 -0
- package/build/types/public/index.d.ts +1 -1
- package/build/types/rendering/texture-slot.d.ts +10 -0
- package/build/types/rendering/texture-slot.js +1 -0
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +27 -6
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +38 -0
- package/src/box-impostor/box-impostor-face-axes.js +11 -0
- package/src/box-impostor/box-impostor-faces.js +118 -0
- package/src/box-impostor/box-impostor-geometry.js +140 -0
- package/src/box-impostor/box-impostor-material.js +721 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +287 -0
- package/src/box-impostor/box-impostor-runtime.js +122 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/fur-surface.ts +22 -12
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +238 -150
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +5 -1
- package/src/rendering/texture-slot.js +27 -0
- package/src/rendering/wireframe.js +51 -13
|
@@ -4849,7 +4849,7 @@ function createWrapSkin(original, copy, asset, animate) {
|
|
|
4849
4849
|
// src/rendering/wireframe.js
|
|
4850
4850
|
import * as THREE2 from "three";
|
|
4851
4851
|
import { MeshBasicNodeMaterial } from "three/webgpu";
|
|
4852
|
-
import { attribute, fwidth, min, vec3, uniform, float } from "three/tsl";
|
|
4852
|
+
import { attribute, fwidth, min, vec3, uniform, float, mix } from "three/tsl";
|
|
4853
4853
|
function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, blendMode) {
|
|
4854
4854
|
const thicknessNode = uniform(thickness);
|
|
4855
4855
|
const barycentric = attribute(
|
|
@@ -4870,11 +4870,13 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4870
4870
|
edgeDistanceVector.z
|
|
4871
4871
|
);
|
|
4872
4872
|
const halfWidth = thicknessNode.mul(0.5);
|
|
4873
|
-
const coverage =
|
|
4874
|
-
|
|
4875
|
-
);
|
|
4873
|
+
const coverage = lineCoverage(edgeDistance, halfWidth);
|
|
4874
|
+
const contrastCore = lineCoverage(edgeDistance, halfWidth.max(1));
|
|
4875
|
+
const contrastCoverage = lineCoverage(edgeDistance, halfWidth.max(1).add(0.125));
|
|
4876
|
+
const contrast = uniform(0);
|
|
4877
|
+
const opacity = mix(coverage, contrastCoverage, contrast);
|
|
4876
4878
|
const material = new MeshBasicNodeMaterial({
|
|
4877
|
-
name: isImpostor ? "
|
|
4879
|
+
name: isImpostor ? "Impostor quad overlay" : "Mesh wireframe overlay",
|
|
4878
4880
|
color: 0,
|
|
4879
4881
|
side: isImpostor ? THREE2.DoubleSide : sourceMaterial.side,
|
|
4880
4882
|
depthTest: !isImpostor,
|
|
@@ -4886,8 +4888,14 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4886
4888
|
});
|
|
4887
4889
|
material.transparent = true;
|
|
4888
4890
|
material.premultipliedAlpha = true;
|
|
4889
|
-
material.opacityNode =
|
|
4890
|
-
|
|
4891
|
+
material.opacityNode = opacity;
|
|
4892
|
+
const lineColor = uniform(new THREE2.Vector3());
|
|
4893
|
+
material.colorNode = mix(
|
|
4894
|
+
lineColor,
|
|
4895
|
+
vec3(float(1).sub(contrastCore.div(contrastCoverage.max(1e-4)))).mul(0.45),
|
|
4896
|
+
contrast
|
|
4897
|
+
);
|
|
4898
|
+
material.maskNode = opacity.greaterThan(1 / 1024);
|
|
4891
4899
|
if ("positionNode" in sourceMaterial) {
|
|
4892
4900
|
const sourceNodeMaterial = (
|
|
4893
4901
|
/** @type {import('three/webgpu').NodeMaterial} */
|
|
@@ -4896,15 +4904,28 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4896
4904
|
material.positionNode = sourceNodeMaterial.positionNode ?? null;
|
|
4897
4905
|
}
|
|
4898
4906
|
material.userData.previewWireframeThickness = thicknessNode;
|
|
4907
|
+
material.userData.previewWireframeContrast = contrast;
|
|
4908
|
+
material.userData.previewWireframeColor = lineColor;
|
|
4899
4909
|
applyPreviewWireframeBlendMode(material, blendMode);
|
|
4900
4910
|
return material;
|
|
4901
4911
|
}
|
|
4912
|
+
function lineCoverage(distance, halfWidth) {
|
|
4913
|
+
return halfWidth.add(0.5).sub(distance).clamp(0, 1).sub(
|
|
4914
|
+
float(0.5).sub(halfWidth).sub(distance).clamp(0, 1)
|
|
4915
|
+
);
|
|
4916
|
+
}
|
|
4902
4917
|
function applyPreviewWireframeBlendMode(material, mode) {
|
|
4903
4918
|
const basic = (
|
|
4904
4919
|
/** @type {import('three/webgpu').MeshBasicNodeMaterial} */
|
|
4905
4920
|
material
|
|
4906
4921
|
);
|
|
4907
|
-
|
|
4922
|
+
const colors = { black: 0, cyan: 65535, lime: 3800852, magenta: 16711935 };
|
|
4923
|
+
basic.color.set(mode in colors ? colors[
|
|
4924
|
+
/** @type {keyof typeof colors} */
|
|
4925
|
+
mode
|
|
4926
|
+
] : 16777215);
|
|
4927
|
+
basic.userData.previewWireframeColor.value.set(basic.color.r, basic.color.g, basic.color.b);
|
|
4928
|
+
basic.userData.previewWireframeContrast.value = mode === "high-contrast" ? 1 : 0;
|
|
4908
4929
|
if (mode === "invert") {
|
|
4909
4930
|
basic.blending = THREE2.CustomBlending;
|
|
4910
4931
|
basic.blendEquation = THREE2.AddEquation;
|
|
@@ -4944,6 +4965,17 @@ function createBarycentricWireframeGeometry(source) {
|
|
|
4944
4965
|
"previewWireframeEdgeMask",
|
|
4945
4966
|
new THREE2.BufferAttribute(edgeMask, 3)
|
|
4946
4967
|
);
|
|
4968
|
+
const floats = Object.entries(geometry.attributes).filter(([, value]) => value.array instanceof Float32Array);
|
|
4969
|
+
const stride = floats.reduce((sum, [, value]) => sum + value.itemSize, 0);
|
|
4970
|
+
const packed = new THREE2.InterleavedBuffer(new Float32Array(vertexCount * stride), stride);
|
|
4971
|
+
let offset = 0;
|
|
4972
|
+
for (const [name, value] of floats) {
|
|
4973
|
+
for (let vertex = 0; vertex < vertexCount; vertex++)
|
|
4974
|
+
for (let component = 0; component < value.itemSize; component++)
|
|
4975
|
+
packed.array[vertex * stride + offset + component] = value.getComponent(vertex, component);
|
|
4976
|
+
geometry.setAttribute(name, new THREE2.InterleavedBufferAttribute(packed, value.itemSize, offset, value.normalized));
|
|
4977
|
+
offset += value.itemSize;
|
|
4978
|
+
}
|
|
4947
4979
|
return geometry;
|
|
4948
4980
|
}
|
|
4949
4981
|
|
|
@@ -4953,7 +4985,7 @@ import {
|
|
|
4953
4985
|
atan,
|
|
4954
4986
|
color,
|
|
4955
4987
|
float as float2,
|
|
4956
|
-
mix,
|
|
4988
|
+
mix as mix2,
|
|
4957
4989
|
mx_fractal_noise_float,
|
|
4958
4990
|
mx_noise_vec3,
|
|
4959
4991
|
mx_worley_noise_vec2,
|
|
@@ -5203,10 +5235,10 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5203
5235
|
const grain = mx_fractal_noise_float(q.mul(9), 3).mul(0.5).add(0.5).clamp(0, 1);
|
|
5204
5236
|
const flow = q.y.mul(3).sub(clock.mul(4)).add(mx_fractal_noise_float(q.mul(1.5), 2).mul(5));
|
|
5205
5237
|
const heat = flow.sin().mul(0.5).add(0.5).pow(2).mul(1.4).add(0.2);
|
|
5206
|
-
const molten =
|
|
5207
|
-
material.colorNode =
|
|
5238
|
+
const molten = mix2(effectColor, color("#fff4a0"), core.mul(heat).clamp(0, 1));
|
|
5239
|
+
material.colorNode = mix2(mix2(color("#100c0b"), color("#42312a"), grain), effectColor.mul(0.4), seam);
|
|
5208
5240
|
material.emissiveNode = molten.mul(seam).mul(heat).mul(uniforms.glow);
|
|
5209
|
-
material.roughnessNode =
|
|
5241
|
+
material.roughnessNode = mix2(grain.mul(0.2).add(0.8), 0.32, seam);
|
|
5210
5242
|
const level = rest.y.sub(bounds.min.y).div(Math.max(bounds.max.y - bounds.min.y, 1e-5));
|
|
5211
5243
|
const fill = uniforms.fill.mul(uniforms.transition.add(1).add(uniforms.noise.mul(0.6))).sub(uniforms.noise.mul(0.3));
|
|
5212
5244
|
const irregularity = growthNoiseEnabled ? mx_fractal_noise_float(q.mul(0.45), 3).clamp(-1, 1).mul(uniforms.noise).mul(0.3) : float2(0);
|
|
@@ -5275,8 +5307,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5275
5307
|
const leaf = pattern.y;
|
|
5276
5308
|
const mottling = mx_fractal_noise_float(q.mul(18), 2).mul(0.12).add(0.88);
|
|
5277
5309
|
const green = effectColor.mul(mottling).mul(pattern.w);
|
|
5278
|
-
material.colorNode =
|
|
5279
|
-
material.roughnessNode =
|
|
5310
|
+
material.colorNode = mix2(color("#344519"), mix2(green, color("#9fae59"), pattern.z.mul(0.5)), leaf);
|
|
5311
|
+
material.roughnessNode = mix2(0.95, 0.58, leaf);
|
|
5280
5312
|
material.opacityNode = pattern.x.mul(uniforms.growth.smoothstep(0, 1e-3));
|
|
5281
5313
|
} else if (mode === "ice") {
|
|
5282
5314
|
geometry = prepareIceNormalAttributes(shell);
|
|
@@ -5285,11 +5317,11 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5285
5317
|
if (dispersionEnabled) material.dispersionNode = uniforms.dispersion;
|
|
5286
5318
|
const noise = mx_fractal_noise_float(normalized.mul(5), 3).mul(0.5).add(0.5);
|
|
5287
5319
|
const frost = smoothstep(0.4, 0.68, noise).mul(uniforms.frost);
|
|
5288
|
-
material.roughnessNode =
|
|
5289
|
-
material.transmissionNode =
|
|
5290
|
-
material.thicknessNode = uniforms.thickness.mul(size).mul(
|
|
5291
|
-
material.colorNode =
|
|
5292
|
-
material.normalNode = skin ? transformNormalToView(normalLocal) :
|
|
5320
|
+
material.roughnessNode = mix2(0.015, 0.92, frost);
|
|
5321
|
+
material.transmissionNode = mix2(0.995, 0.86, frost);
|
|
5322
|
+
material.thicknessNode = uniforms.thickness.mul(size).mul(mix2(0.65, 1.3, frost));
|
|
5323
|
+
material.colorNode = mix2(color("#ffffff"), color("#eefcff"), frost.mul(0.35));
|
|
5324
|
+
material.normalNode = skin ? transformNormalToView(normalLocal) : mix2(transformNormalToView(attribute2(
|
|
5293
5325
|
"iceSmoothNormal",
|
|
5294
5326
|
/** @type {const} */
|
|
5295
5327
|
"vec3"
|
|
@@ -5386,11 +5418,11 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5386
5418
|
const patch = fieldNoiseEnabled ? mx_fractal_noise_float(vec32(cellCenter.mul(uniforms.detail).mul(0.07), clock.mul(0.35).add(layer * 4)), 2).mul(uniforms.noise).mul(0.5).add(0.5).smoothstep(0.52, 0.68) : seed.smoothstep(0.55, 0.7);
|
|
5387
5419
|
return vec32(smoothstep(0.405, 0.475, edge), pulse2, patch);
|
|
5388
5420
|
};
|
|
5389
|
-
const cells =
|
|
5421
|
+
const cells = mix2(hex(first), hex(second), blend);
|
|
5390
5422
|
const lines = cells.x, pulse = cells.y;
|
|
5391
5423
|
field.positionNode = positionLocal.add(n.mul(displacement.mul(pulse.mul(0.7).add(0.3)).add(pulse.mul(size * 6e-3)).add(size * (8e-3 + layer * 0.018))));
|
|
5392
5424
|
const rim = float2(1).sub(normalWorld.dot(cameraPosition.sub(positionWorld).normalize()).abs()).clamp(0, 1).pow(uniforms.fresnel);
|
|
5393
|
-
field.colorNode =
|
|
5425
|
+
field.colorNode = mix2(effectColor, color("#ffffff"), pulse.mul(0.35)).mul(uniforms.glow);
|
|
5394
5426
|
const energy = lines.mul(pulse.mul(0.65).add(0.14)).add(pulse.mul(0.045)).add(rim.mul(0.12));
|
|
5395
5427
|
field.opacityNode = energy.mul(layer ? cells.z.mul(0.85) : float2(1)).clamp(0, 1);
|
|
5396
5428
|
return field;
|
|
@@ -5469,8 +5501,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5469
5501
|
/** @type {const} */
|
|
5470
5502
|
"vec3"
|
|
5471
5503
|
).mul(windward).mul(uniforms.normalOffset).mul(size));
|
|
5472
|
-
material.colorNode =
|
|
5473
|
-
material.roughnessNode =
|
|
5504
|
+
material.colorNode = mix2(color("#cceeff"), color("#ffffff"), frost);
|
|
5505
|
+
material.roughnessNode = mix2(0.035, 0.95, frost);
|
|
5474
5506
|
material.transmissionNode = float2(1).sub(frost);
|
|
5475
5507
|
}
|
|
5476
5508
|
} else if (mode === "outline") {
|
|
@@ -5502,7 +5534,7 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5502
5534
|
floorPoint.y = worldBounds.min.y;
|
|
5503
5535
|
const fromFloor = positionWorld.sub(uniform2(floorPoint));
|
|
5504
5536
|
const radialUp = vec32(fromFloor.x, fromFloor.y.max(size * 1e-6), fromFloor.z).normalize();
|
|
5505
|
-
const direction =
|
|
5537
|
+
const direction = mix2(vec32(0, 1, 0), radialUp, uniforms.radialUp).normalize();
|
|
5506
5538
|
const up = smoothstep(uniforms.upThreshold, uniforms.upThreshold.add(0.25), normalWorldGeometry.dot(direction));
|
|
5507
5539
|
const localUp = modelWorldMatrixInverse.mul(vec4(direction, 0)).xyz;
|
|
5508
5540
|
if (mode === "aura") {
|
|
@@ -5544,7 +5576,7 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5544
5576
|
material.positionNode = positionLocal.add(localUp.mul(flame).mul(uniforms.height).mul(size));
|
|
5545
5577
|
const travel = varying(flame.div(up.max(1e-3)).clamp(0, 1), "flameTravel");
|
|
5546
5578
|
const emitter = varying(up, "flameEmitter");
|
|
5547
|
-
const ignition =
|
|
5579
|
+
const ignition = mix2(0.6, 1, smoothstep(0, 0.12, travel));
|
|
5548
5580
|
const cooling = float2(1).sub(smoothstep(0.15, 0.95, travel));
|
|
5549
5581
|
const sourcePosition = varying(attribute2(
|
|
5550
5582
|
"position",
|
|
@@ -5553,8 +5585,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5553
5585
|
), "flameSourcePosition");
|
|
5554
5586
|
const density = mx_fractal_noise_float(sourcePosition.sub(center).div(size).mul(uniforms.scale).mul(3).sub(vec32(0, clock, 0)).add(vec32(8.1, 2.7, 4.3)), 2).mul(0.5).add(0.5).clamp(0, 1);
|
|
5555
5587
|
const temperature = ignition.mul(cooling).mul(density.mul(0.2).add(0.8)).mul(emitter.smoothstep(0, 0.35)).clamp(0, 1);
|
|
5556
|
-
const coolToWarm =
|
|
5557
|
-
material.colorNode =
|
|
5588
|
+
const coolToWarm = mix2(effectColor, warmColor, temperature.mul(2).clamp(0, 1));
|
|
5589
|
+
material.colorNode = mix2(coolToWarm, hotColor, temperature.mul(2).sub(1).clamp(0, 1)).mul(2);
|
|
5558
5590
|
material.opacityNode = noise.smoothstep(0.25, 0.7).mul(up.mul(0.65).add(0.2));
|
|
5559
5591
|
}
|
|
5560
5592
|
} else throw new Error(`Unknown wrap preview: ${mode}`);
|