@@ -6,7 +6,7 @@
|
|
6
6
|
import { RegisteredAnimationInfo, UsdzAnimation } from "../Animation.js";
|
7
7
|
import { getWorldPosition, getWorldQuaternion, getWorldScale, setWorldPosition, setWorldQuaternion, setWorldScale } from "../../../../../engine/engine_three_utils.js";
|
8
8
|
|
9
|
-
import { Object3D, Material, Vector3, Quaternion } from "three";
|
9
|
+
import { Object3D, Material, Vector3, Quaternion, Mesh, Group } from "three";
|
10
10
|
import { USDDocument, USDObject } from "../../ThreeUSDZExporter.js";
|
11
11
|
|
12
12
|
import { BehaviorExtension, UsdzBehaviour } from "./Behaviour.js";
|
@@ -154,14 +154,27 @@
|
|
154
154
|
@serializable()
|
155
155
|
fadeDuration : number = 0;
|
156
156
|
|
157
|
-
private _objectsWithThisMaterial:
|
157
|
+
private _objectsWithThisMaterial: Mesh[] = [];
|
158
158
|
|
159
159
|
awake() {
|
160
160
|
if (this.variantMaterial && this.materialToSwitch) {
|
161
161
|
const renderer = GameObject.findObjectsOfType(Renderer);
|
162
162
|
for (const rend of renderer) {
|
163
|
-
|
164
|
-
|
163
|
+
for (let i = 0; i < rend.sharedMaterials.length; i++) {
|
164
|
+
const mat = rend.sharedMaterials[i];
|
165
|
+
if (mat === this.materialToSwitch) {
|
166
|
+
if (rend.gameObject instanceof Mesh) {
|
167
|
+
this._objectsWithThisMaterial.push(rend.gameObject);
|
168
|
+
}
|
169
|
+
else if (rend.gameObject instanceof Group) {
|
170
|
+
for (const child of rend.gameObject.children) {
|
171
|
+
if (child instanceof Mesh && child.material === mat) {
|
172
|
+
this._objectsWithThisMaterial.push(child);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
break;
|
177
|
+
}
|
165
178
|
}
|
166
179
|
}
|
167
180
|
}
|
@@ -169,8 +182,9 @@
|
|
169
182
|
|
170
183
|
onPointerClick() {
|
171
184
|
if (!this.variantMaterial) return;
|
172
|
-
for (
|
173
|
-
|
185
|
+
for (let i = 0; i < this._objectsWithThisMaterial.length; i++) {
|
186
|
+
const obj = this._objectsWithThisMaterial[i];
|
187
|
+
obj.material = this.variantMaterial;
|
174
188
|
}
|
175
189
|
}
|
176
190
|
|
@@ -196,7 +210,7 @@
|
|
196
210
|
|
197
211
|
createBehaviours(_ext: BehaviorExtension, model: USDObject, _context) {
|
198
212
|
|
199
|
-
const shouldExport = this._objectsWithThisMaterial.find(o => o.
|
213
|
+
const shouldExport = this._objectsWithThisMaterial.find(o => o.uuid === model.uuid);
|
200
214
|
if (shouldExport) {
|
201
215
|
this.targetModels.push(model);
|
202
216
|
}
|
@@ -58,7 +58,8 @@
|
|
58
58
|
|
59
59
|
// TODO: we probably want to turn this into a symbol to prevent anyone from overriding it
|
60
60
|
// But when we need to store the symbol per prototype to allow e.g. material disposing to iterate those and dispose all
|
61
|
-
|
61
|
+
// TODO: making symbols here breaks e.g. progressive textures because they iterate on the property keys
|
62
|
+
const backingField = fieldName + "___needle";// Symbol(fieldName);// + " (patched)";
|
62
63
|
|
63
64
|
internalAddPatch(prototype, fieldName, beforeCallback, afterCallback);
|
64
65
|
|
@@ -45,7 +45,7 @@
|
|
45
45
|
|
46
46
|
for (const slot of Object.keys(material)) {
|
47
47
|
const val = material[slot];
|
48
|
-
if (val
|
48
|
+
if (val instanceof Texture) {
|
49
49
|
const task = this.assignTextureLODForSlot(context, source, material, level, slot, val);
|
50
50
|
promises.push(task);
|
51
51
|
}
|
@@ -55,7 +55,7 @@
|
|
55
55
|
// iterate uniforms
|
56
56
|
for (const slot of Object.keys(material.uniforms)) {
|
57
57
|
const val = material.uniforms[slot].value;
|
58
|
-
if (val
|
58
|
+
if (val instanceof Texture) {
|
59
59
|
const task = this.assignTextureLODForSlot(context, source, material, level, slot, val);
|
60
60
|
promises.push(task);
|
61
61
|
}
|