@needle-tools/engine 3.5.9-alpha.1 → 3.5.9-beta
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 +8 -0
- package/dist/needle-engine.js +1734 -1722
- package/dist/needle-engine.light.js +1680 -1668
- package/dist/needle-engine.light.min.js +74 -74
- package/dist/needle-engine.light.umd.cjs +72 -72
- package/dist/needle-engine.min.js +79 -79
- package/dist/needle-engine.umd.cjs +73 -73
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_element.d.ts +4 -1
- package/lib/engine/engine_element.js +17 -13
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_attributes.d.ts +37 -0
- package/lib/engine/engine_element_attributes.js +2 -0
- package/lib/engine/engine_element_attributes.js.map +1 -0
- package/lib/engine/engine_gltf_builtin_components.js +7 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_progressive.d.ts +1 -0
- package/lib/engine/extensions/NEEDLE_progressive.js +41 -24
- package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
- package/package.json +1 -1
- package/plugins/next/next.js +1 -1
- package/src/engine/api.ts +1 -0
- package/src/engine/engine_element.ts +22 -14
- package/src/engine/engine_element_attributes.ts +42 -0
- package/src/engine/engine_gltf_builtin_components.ts +9 -1
- package/src/engine/extensions/NEEDLE_progressive.ts +43 -24
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Material, Texture, TextureLoader } from "three";
|
|
1
|
+
import { Material, RawShaderMaterial, Texture, TextureLoader } from "three";
|
|
2
2
|
import { GLTF, GLTFLoader, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
|
|
3
3
|
import { SourceIdentifier } from "../engine_types";
|
|
4
4
|
import { Context } from "../engine_setup";
|
|
@@ -36,42 +36,55 @@ if (debug) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
39
|
export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
41
40
|
|
|
42
41
|
static assignTextureLOD(context: Context, source: SourceIdentifier | undefined, material: Material, level: number = 0) {
|
|
43
42
|
if (!material) return;
|
|
43
|
+
|
|
44
44
|
for (let slot of Object.keys(material)) {
|
|
45
45
|
const val = material[slot];
|
|
46
|
-
if (val?.isTexture
|
|
46
|
+
if (val?.isTexture)
|
|
47
|
+
this.assignTextureLODForSlot(context, source, material, level, slot, val);
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
if (material instanceof RawShaderMaterial) {
|
|
51
|
+
// iterate uniforms
|
|
52
|
+
for (let slot of Object.keys(material.uniforms)) {
|
|
53
|
+
const val = material.uniforms[slot].value;
|
|
54
|
+
if (val?.isTexture)
|
|
55
|
+
this.assignTextureLODForSlot(context, source, material, level, slot, val);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
private static assignTextureLODForSlot(context: Context, source: SourceIdentifier | undefined, material: Material, level: number, slot: string, val: any) {
|
|
61
|
+
if (val?.isTexture !== true) return;
|
|
52
62
|
|
|
53
|
-
|
|
63
|
+
if (debug) console.log("-----------\n", "FIND", material.name, slot, val?.name, val?.userData, val, material);
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
material.needsUpdate = true;
|
|
65
|
+
NEEDLE_progressive.getOrLoadTexture(context, source, material, slot, val, level).then(t => {
|
|
66
|
+
if (t?.isTexture === true) {
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
68
|
+
if (debug) console.log("Assign LOD", material.name, slot, t.name, t["guid"], material, "Prev:", val, "Now:", t, "\n--------------");
|
|
69
|
+
|
|
70
|
+
material[slot] = t;
|
|
71
|
+
t.needsUpdate = true;
|
|
72
|
+
material.needsUpdate = true;
|
|
73
|
+
|
|
74
|
+
if (debug) {
|
|
75
|
+
let debug_map = debug_toggle_maps.get(material);
|
|
76
|
+
if (!debug_map) {
|
|
77
|
+
debug_map = {};
|
|
78
|
+
debug_toggle_maps.set(material, debug_map);
|
|
71
79
|
}
|
|
72
|
-
|
|
80
|
+
let entry = debug_map[slot];
|
|
81
|
+
if (!entry) {
|
|
82
|
+
entry = debug_map[slot] = { original: val, lod0: t };
|
|
83
|
+
}
|
|
84
|
+
entry.lod0 = t;
|
|
85
|
+
}
|
|
73
86
|
}
|
|
74
|
-
}
|
|
87
|
+
});
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
get name(): string {
|
|
@@ -176,6 +189,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
176
189
|
if (debug) console.log("Loading finished " + uri, material.name, slot, ext.guid);
|
|
177
190
|
let index = -1;
|
|
178
191
|
let found = false;
|
|
192
|
+
|
|
193
|
+
if (!gltf.parser.json?.textures) {
|
|
194
|
+
if (debug) console.warn("No textures in glTF " + uri + " - may be a bug", material.name, slot, ext.guid);
|
|
195
|
+
return resolve(null);
|
|
196
|
+
}
|
|
197
|
+
|
|
179
198
|
for (const tex of gltf.parser.json.textures) {
|
|
180
199
|
index++;
|
|
181
200
|
if (tex?.extensions) {
|