@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
package/build/hull-effects.js
CHANGED
|
@@ -4871,7 +4871,7 @@ function createWrapSkin(original, copy, asset, animate) {
|
|
|
4871
4871
|
// src/rendering/wireframe.js
|
|
4872
4872
|
import * as THREE2 from "three";
|
|
4873
4873
|
import { MeshBasicNodeMaterial } from "three/webgpu";
|
|
4874
|
-
import { attribute, fwidth, min, vec3, uniform, float } from "three/tsl";
|
|
4874
|
+
import { attribute, fwidth, min, vec3, uniform, float, mix } from "three/tsl";
|
|
4875
4875
|
function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, blendMode) {
|
|
4876
4876
|
const thicknessNode = uniform(thickness);
|
|
4877
4877
|
const barycentric = attribute(
|
|
@@ -4892,11 +4892,13 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4892
4892
|
edgeDistanceVector.z
|
|
4893
4893
|
);
|
|
4894
4894
|
const halfWidth = thicknessNode.mul(0.5);
|
|
4895
|
-
const coverage =
|
|
4896
|
-
|
|
4897
|
-
);
|
|
4895
|
+
const coverage = lineCoverage(edgeDistance, halfWidth);
|
|
4896
|
+
const contrastCore = lineCoverage(edgeDistance, halfWidth.max(1));
|
|
4897
|
+
const contrastCoverage = lineCoverage(edgeDistance, halfWidth.max(1).add(0.125));
|
|
4898
|
+
const contrast = uniform(0);
|
|
4899
|
+
const opacity = mix(coverage, contrastCoverage, contrast);
|
|
4898
4900
|
const material = new MeshBasicNodeMaterial({
|
|
4899
|
-
name: isImpostor ? "
|
|
4901
|
+
name: isImpostor ? "Impostor quad overlay" : "Mesh wireframe overlay",
|
|
4900
4902
|
color: 0,
|
|
4901
4903
|
side: isImpostor ? THREE2.DoubleSide : sourceMaterial.side,
|
|
4902
4904
|
depthTest: !isImpostor,
|
|
@@ -4908,8 +4910,14 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4908
4910
|
});
|
|
4909
4911
|
material.transparent = true;
|
|
4910
4912
|
material.premultipliedAlpha = true;
|
|
4911
|
-
material.opacityNode =
|
|
4912
|
-
|
|
4913
|
+
material.opacityNode = opacity;
|
|
4914
|
+
const lineColor = uniform(new THREE2.Vector3());
|
|
4915
|
+
material.colorNode = mix(
|
|
4916
|
+
lineColor,
|
|
4917
|
+
vec3(float(1).sub(contrastCore.div(contrastCoverage.max(1e-4)))).mul(0.45),
|
|
4918
|
+
contrast
|
|
4919
|
+
);
|
|
4920
|
+
material.maskNode = opacity.greaterThan(1 / 1024);
|
|
4913
4921
|
if ("positionNode" in sourceMaterial) {
|
|
4914
4922
|
const sourceNodeMaterial = (
|
|
4915
4923
|
/** @type {import('three/webgpu').NodeMaterial} */
|
|
@@ -4918,18 +4926,31 @@ function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, b
|
|
|
4918
4926
|
material.positionNode = sourceNodeMaterial.positionNode ?? null;
|
|
4919
4927
|
}
|
|
4920
4928
|
material.userData.previewWireframeThickness = thicknessNode;
|
|
4929
|
+
material.userData.previewWireframeContrast = contrast;
|
|
4930
|
+
material.userData.previewWireframeColor = lineColor;
|
|
4921
4931
|
applyPreviewWireframeBlendMode(material, blendMode);
|
|
4922
4932
|
return material;
|
|
4923
4933
|
}
|
|
4934
|
+
function lineCoverage(distance, halfWidth) {
|
|
4935
|
+
return halfWidth.add(0.5).sub(distance).clamp(0, 1).sub(
|
|
4936
|
+
float(0.5).sub(halfWidth).sub(distance).clamp(0, 1)
|
|
4937
|
+
);
|
|
4938
|
+
}
|
|
4924
4939
|
function parseWireframeBlendMode(value) {
|
|
4925
|
-
return value === "white" || value === "invert" ? value : "
|
|
4940
|
+
return value === "black" || value === "white" || value === "invert" || value === "cyan" || value === "lime" || value === "magenta" ? value : "high-contrast";
|
|
4926
4941
|
}
|
|
4927
4942
|
function applyPreviewWireframeBlendMode(material, mode) {
|
|
4928
4943
|
const basic = (
|
|
4929
4944
|
/** @type {import('three/webgpu').MeshBasicNodeMaterial} */
|
|
4930
4945
|
material
|
|
4931
4946
|
);
|
|
4932
|
-
|
|
4947
|
+
const colors = { black: 0, cyan: 65535, lime: 3800852, magenta: 16711935 };
|
|
4948
|
+
basic.color.set(mode in colors ? colors[
|
|
4949
|
+
/** @type {keyof typeof colors} */
|
|
4950
|
+
mode
|
|
4951
|
+
] : 16777215);
|
|
4952
|
+
basic.userData.previewWireframeColor.value.set(basic.color.r, basic.color.g, basic.color.b);
|
|
4953
|
+
basic.userData.previewWireframeContrast.value = mode === "high-contrast" ? 1 : 0;
|
|
4933
4954
|
if (mode === "invert") {
|
|
4934
4955
|
basic.blending = THREE2.CustomBlending;
|
|
4935
4956
|
basic.blendEquation = THREE2.AddEquation;
|
|
@@ -4969,6 +4990,17 @@ function createBarycentricWireframeGeometry(source) {
|
|
|
4969
4990
|
"previewWireframeEdgeMask",
|
|
4970
4991
|
new THREE2.BufferAttribute(edgeMask, 3)
|
|
4971
4992
|
);
|
|
4993
|
+
const floats = Object.entries(geometry.attributes).filter(([, value]) => value.array instanceof Float32Array);
|
|
4994
|
+
const stride = floats.reduce((sum, [, value]) => sum + value.itemSize, 0);
|
|
4995
|
+
const packed = new THREE2.InterleavedBuffer(new Float32Array(vertexCount * stride), stride);
|
|
4996
|
+
let offset = 0;
|
|
4997
|
+
for (const [name, value] of floats) {
|
|
4998
|
+
for (let vertex = 0; vertex < vertexCount; vertex++)
|
|
4999
|
+
for (let component = 0; component < value.itemSize; component++)
|
|
5000
|
+
packed.array[vertex * stride + offset + component] = value.getComponent(vertex, component);
|
|
5001
|
+
geometry.setAttribute(name, new THREE2.InterleavedBufferAttribute(packed, value.itemSize, offset, value.normalized));
|
|
5002
|
+
offset += value.itemSize;
|
|
5003
|
+
}
|
|
4972
5004
|
return geometry;
|
|
4973
5005
|
}
|
|
4974
5006
|
|
|
@@ -4978,7 +5010,7 @@ import {
|
|
|
4978
5010
|
atan,
|
|
4979
5011
|
color,
|
|
4980
5012
|
float as float2,
|
|
4981
|
-
mix,
|
|
5013
|
+
mix as mix2,
|
|
4982
5014
|
mx_fractal_noise_float,
|
|
4983
5015
|
mx_noise_vec3,
|
|
4984
5016
|
mx_worley_noise_vec2,
|
|
@@ -5228,10 +5260,10 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5228
5260
|
const grain = mx_fractal_noise_float(q.mul(9), 3).mul(0.5).add(0.5).clamp(0, 1);
|
|
5229
5261
|
const flow = q.y.mul(3).sub(clock.mul(4)).add(mx_fractal_noise_float(q.mul(1.5), 2).mul(5));
|
|
5230
5262
|
const heat = flow.sin().mul(0.5).add(0.5).pow(2).mul(1.4).add(0.2);
|
|
5231
|
-
const molten =
|
|
5232
|
-
material.colorNode =
|
|
5263
|
+
const molten = mix2(effectColor, color("#fff4a0"), core.mul(heat).clamp(0, 1));
|
|
5264
|
+
material.colorNode = mix2(mix2(color("#100c0b"), color("#42312a"), grain), effectColor.mul(0.4), seam);
|
|
5233
5265
|
material.emissiveNode = molten.mul(seam).mul(heat).mul(uniforms.glow);
|
|
5234
|
-
material.roughnessNode =
|
|
5266
|
+
material.roughnessNode = mix2(grain.mul(0.2).add(0.8), 0.32, seam);
|
|
5235
5267
|
const level = rest.y.sub(bounds.min.y).div(Math.max(bounds.max.y - bounds.min.y, 1e-5));
|
|
5236
5268
|
const fill = uniforms.fill.mul(uniforms.transition.add(1).add(uniforms.noise.mul(0.6))).sub(uniforms.noise.mul(0.3));
|
|
5237
5269
|
const irregularity = growthNoiseEnabled ? mx_fractal_noise_float(q.mul(0.45), 3).clamp(-1, 1).mul(uniforms.noise).mul(0.3) : float2(0);
|
|
@@ -5300,8 +5332,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5300
5332
|
const leaf = pattern.y;
|
|
5301
5333
|
const mottling = mx_fractal_noise_float(q.mul(18), 2).mul(0.12).add(0.88);
|
|
5302
5334
|
const green = effectColor.mul(mottling).mul(pattern.w);
|
|
5303
|
-
material.colorNode =
|
|
5304
|
-
material.roughnessNode =
|
|
5335
|
+
material.colorNode = mix2(color("#344519"), mix2(green, color("#9fae59"), pattern.z.mul(0.5)), leaf);
|
|
5336
|
+
material.roughnessNode = mix2(0.95, 0.58, leaf);
|
|
5305
5337
|
material.opacityNode = pattern.x.mul(uniforms.growth.smoothstep(0, 1e-3));
|
|
5306
5338
|
} else if (mode === "ice") {
|
|
5307
5339
|
geometry = prepareIceNormalAttributes(shell);
|
|
@@ -5310,11 +5342,11 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5310
5342
|
if (dispersionEnabled) material.dispersionNode = uniforms.dispersion;
|
|
5311
5343
|
const noise = mx_fractal_noise_float(normalized.mul(5), 3).mul(0.5).add(0.5);
|
|
5312
5344
|
const frost = smoothstep(0.4, 0.68, noise).mul(uniforms.frost);
|
|
5313
|
-
material.roughnessNode =
|
|
5314
|
-
material.transmissionNode =
|
|
5315
|
-
material.thicknessNode = uniforms.thickness.mul(size).mul(
|
|
5316
|
-
material.colorNode =
|
|
5317
|
-
material.normalNode = skin ? transformNormalToView(normalLocal) :
|
|
5345
|
+
material.roughnessNode = mix2(0.015, 0.92, frost);
|
|
5346
|
+
material.transmissionNode = mix2(0.995, 0.86, frost);
|
|
5347
|
+
material.thicknessNode = uniforms.thickness.mul(size).mul(mix2(0.65, 1.3, frost));
|
|
5348
|
+
material.colorNode = mix2(color("#ffffff"), color("#eefcff"), frost.mul(0.35));
|
|
5349
|
+
material.normalNode = skin ? transformNormalToView(normalLocal) : mix2(transformNormalToView(attribute2(
|
|
5318
5350
|
"iceSmoothNormal",
|
|
5319
5351
|
/** @type {const} */
|
|
5320
5352
|
"vec3"
|
|
@@ -5411,11 +5443,11 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5411
5443
|
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);
|
|
5412
5444
|
return vec32(smoothstep(0.405, 0.475, edge), pulse2, patch);
|
|
5413
5445
|
};
|
|
5414
|
-
const cells =
|
|
5446
|
+
const cells = mix2(hex(first), hex(second), blend);
|
|
5415
5447
|
const lines = cells.x, pulse = cells.y;
|
|
5416
5448
|
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))));
|
|
5417
5449
|
const rim = float2(1).sub(normalWorld.dot(cameraPosition.sub(positionWorld).normalize()).abs()).clamp(0, 1).pow(uniforms.fresnel);
|
|
5418
|
-
field.colorNode =
|
|
5450
|
+
field.colorNode = mix2(effectColor, color("#ffffff"), pulse.mul(0.35)).mul(uniforms.glow);
|
|
5419
5451
|
const energy = lines.mul(pulse.mul(0.65).add(0.14)).add(pulse.mul(0.045)).add(rim.mul(0.12));
|
|
5420
5452
|
field.opacityNode = energy.mul(layer ? cells.z.mul(0.85) : float2(1)).clamp(0, 1);
|
|
5421
5453
|
return field;
|
|
@@ -5494,8 +5526,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5494
5526
|
/** @type {const} */
|
|
5495
5527
|
"vec3"
|
|
5496
5528
|
).mul(windward).mul(uniforms.normalOffset).mul(size));
|
|
5497
|
-
material.colorNode =
|
|
5498
|
-
material.roughnessNode =
|
|
5529
|
+
material.colorNode = mix2(color("#cceeff"), color("#ffffff"), frost);
|
|
5530
|
+
material.roughnessNode = mix2(0.035, 0.95, frost);
|
|
5499
5531
|
material.transmissionNode = float2(1).sub(frost);
|
|
5500
5532
|
}
|
|
5501
5533
|
} else if (mode === "outline") {
|
|
@@ -5527,7 +5559,7 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5527
5559
|
floorPoint.y = worldBounds.min.y;
|
|
5528
5560
|
const fromFloor = positionWorld.sub(uniform2(floorPoint));
|
|
5529
5561
|
const radialUp = vec32(fromFloor.x, fromFloor.y.max(size * 1e-6), fromFloor.z).normalize();
|
|
5530
|
-
const direction =
|
|
5562
|
+
const direction = mix2(vec32(0, 1, 0), radialUp, uniforms.radialUp).normalize();
|
|
5531
5563
|
const up = smoothstep(uniforms.upThreshold, uniforms.upThreshold.add(0.25), normalWorldGeometry.dot(direction));
|
|
5532
5564
|
const localUp = modelWorldMatrixInverse.mul(vec4(direction, 0)).xyz;
|
|
5533
5565
|
if (mode === "aura") {
|
|
@@ -5569,7 +5601,7 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5569
5601
|
material.positionNode = positionLocal.add(localUp.mul(flame).mul(uniforms.height).mul(size));
|
|
5570
5602
|
const travel = varying(flame.div(up.max(1e-3)).clamp(0, 1), "flameTravel");
|
|
5571
5603
|
const emitter = varying(up, "flameEmitter");
|
|
5572
|
-
const ignition =
|
|
5604
|
+
const ignition = mix2(0.6, 1, smoothstep(0, 0.12, travel));
|
|
5573
5605
|
const cooling = float2(1).sub(smoothstep(0.15, 0.95, travel));
|
|
5574
5606
|
const sourcePosition = varying(attribute2(
|
|
5575
5607
|
"position",
|
|
@@ -5578,8 +5610,8 @@ function createHullEffect(asset, original, effect, options = {}) {
|
|
|
5578
5610
|
), "flameSourcePosition");
|
|
5579
5611
|
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);
|
|
5580
5612
|
const temperature = ignition.mul(cooling).mul(density.mul(0.2).add(0.8)).mul(emitter.smoothstep(0, 0.35)).clamp(0, 1);
|
|
5581
|
-
const coolToWarm =
|
|
5582
|
-
material.colorNode =
|
|
5613
|
+
const coolToWarm = mix2(effectColor, warmColor, temperature.mul(2).clamp(0, 1));
|
|
5614
|
+
material.colorNode = mix2(coolToWarm, hotColor, temperature.mul(2).sub(1).clamp(0, 1)).mul(2);
|
|
5583
5615
|
material.opacityNode = noise.smoothstep(0.25, 0.7).mul(up.mul(0.65).add(0.2));
|
|
5584
5616
|
}
|
|
5585
5617
|
} else throw new Error(`Unknown wrap preview: ${mode}`);
|