Skip to content

Commit db15d9f

Browse files
authored
r170 (#4928)
* updated deps - need to fix TS * model-viewer compiles * everything builds, removed cruft * fixed variant exporter plugin
1 parent 976796f commit db15d9f

File tree

138 files changed

+241
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+241
-237
lines changed

package-lock.json

Lines changed: 167 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/model-viewer-effects/README.md

Lines changed: 1 addition & 1 deletion

packages/model-viewer-effects/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
],
7474
"dependencies": {
7575
"lit": "^3.2.1",
76-
"postprocessing": "^6.35.3"
76+
"postprocessing": "^6.36.4"
7777
},
7878
"peerDependencies": {
7979
"@google/model-viewer": "^4.0.0"
@@ -85,7 +85,7 @@
8585
"@rollup/plugin-replace": "^6.0.1",
8686
"@types/mocha": "^10.0.9",
8787
"@types/pngjs": "^6.0.1",
88-
"@types/three": "^0.164.0",
88+
"@types/three": "^0.169.0",
8989
"@ungap/event-target": "^0.2.3",
9090
"@web/test-runner": "^0.19.0",
9191
"@web/test-runner-playwright": "^0.11.0",
@@ -99,7 +99,7 @@
9999
"rollup-plugin-dts": "^6.1.1",
100100
"rollup-plugin-polyfill": "^3.0.0",
101101
"@rollup/plugin-terser": "^0.4.4",
102-
"three": "^0.169.0",
102+
"three": "^0.170.0",
103103
"typescript": "5.6.3"
104104
},
105105
"publishConfig": {

packages/model-viewer-effects/src/test/utilities.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import {ModelViewerElement} from '@google/model-viewer';
1717
import {Renderer} from '@google/model-viewer/lib/three-components/Renderer.js';
18-
import {EventDispatcher, HSL} from 'three';
18+
import {HSL} from 'three';
1919

2020
import {getOwnPropertySymbolValue} from '../utilities.js';
2121

@@ -168,32 +168,26 @@ export const createModelViewerElement =
168168
return element;
169169
};
170170

171-
/**
172-
* Three.js EventDispatcher and DOM EventTarget use different event patterns,
173-
* so AnyEvent covers the shape of both event types.
174-
*/
175-
export type AnyEvent = Event|CustomEvent<any>|{[index: string]: string};
176-
177171
export type PredicateFunction<T = void> = (value: T) => boolean;
178172

179173
/**
180174
* @param {EventTarget|EventDispatcher} target
181175
* @param {string} eventName
182176
* @param {?Function} predicate
183177
*/
184-
export const waitForEvent = <T extends AnyEvent = Event>(
185-
target: EventTarget|EventDispatcher,
186-
eventName: string,
187-
predicate: PredicateFunction<T>|null = null): Promise<T> =>
188-
new Promise((resolve) => {
189-
function handler(event: AnyEvent) {
190-
if (!predicate || predicate(event as T)) {
191-
resolve(event as T);
192-
target.removeEventListener(eventName, handler as any);
193-
}
194-
}
195-
target.addEventListener(eventName, handler as any);
196-
});
178+
export const waitForEvent =
179+
<T>(target: any,
180+
eventName: string,
181+
predicate: PredicateFunction<T>|null = null): Promise<T> =>
182+
new Promise((resolve) => {
183+
function handler(event: T) {
184+
if (!predicate || predicate(event)) {
185+
resolve(event);
186+
target.removeEventListener(eventName, handler);
187+
}
188+
}
189+
target.addEventListener(eventName, handler);
190+
});
197191

198192
export interface TypedArray<T = unknown> {
199193
readonly BYTES_PER_ELEMENT: number;

packages/model-viewer-effects/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "es2017",
44
"module": "es2015",
5-
"moduleResolution": "node",
5+
"moduleResolution": "bundler",
66
"lib": [
77
"es2017",
88
"dom"

packages/model-viewer/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@
8787
"@monogrid/gainmap-js": "^3.0.1"
8888
},
8989
"peerDependencies": {
90-
"three": "^0.169.0"
90+
"three": "^0.170.0"
9191
},
9292
"devDependencies": {
9393
"@rollup/plugin-commonjs": "^28.0.1",
9494
"@rollup/plugin-node-resolve": "^15.3.0",
9595
"@rollup/plugin-replace": "^6.0.1",
9696
"@types/mocha": "^10.0.9",
9797
"@types/pngjs": "^6.0.1",
98-
"@types/three": "^0.164.0",
98+
"@types/three": "^0.169.0",
9999
"@ungap/event-target": "^0.2.3",
100100
"@web/test-runner": "^0.19.0",
101101
"@web/test-runner-playwright": "^0.11.0",
@@ -109,7 +109,7 @@
109109
"rollup-plugin-polyfill": "^3.0.0",
110110
"@rollup/plugin-terser": "^0.4.4",
111111
"typescript": "5.6.3",
112-
"three": "^0.169.0"
112+
"three": "^0.170.0"
113113
},
114114
"publishConfig": {
115115
"access": "public"

packages/model-viewer/src/three-components/CachingGLTFLoader.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import {EventDispatcher, Texture, WebGLRenderer} from 'three';
17+
import {MeshoptDecoder} from 'three/examples/jsm/libs/meshopt_decoder.module.js';
1718
import {DRACOLoader} from 'three/examples/jsm/loaders/DRACOLoader.js';
1819
import {GLTF, GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';
1920
import {KTX2Loader} from 'three/examples/jsm/loaders/KTX2Loader.js';
@@ -69,15 +70,6 @@ const ktx2Loader = new KTX2Loader();
6970
let meshoptDecoderLocation: string;
7071
let meshoptDecoder: Promise<typeof MeshoptDecoder>|undefined;
7172

72-
interface MeshoptDecoder {
73-
ready: Promise<void>;
74-
supported: boolean;
75-
}
76-
77-
declare global {
78-
const MeshoptDecoder: MeshoptDecoder;
79-
}
80-
8173
export const $loader = Symbol('loader');
8274
export const $evictionPolicy = Symbol('evictionPolicy');
8375
const $GLTFInstance = Symbol('GLTFInstance');

packages/model-viewer/src/three-components/ModelScene.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {ACESFilmicToneMapping, AnimationAction, AnimationActionLoopStyles, AnimationClip, AnimationMixer, Box3, Camera, Euler, Event as ThreeEvent, LoopPingPong, LoopRepeat, Material, Matrix3, Mesh, Object3D, PerspectiveCamera, Raycaster, Scene, Sphere, Texture, ToneMapping, Triangle, Vector2, Vector3, WebGLRenderer, XRTargetRaySpace} from 'three';
16+
import {ACESFilmicToneMapping, AnimationAction, AnimationActionLoopStyles, AnimationClip, AnimationMixer, AnimationMixerEventMap, Box3, Camera, Euler, Event as ThreeEvent, LoopPingPong, LoopRepeat, Material, Matrix3, Mesh, Object3D, PerspectiveCamera, Raycaster, Scene, Sphere, Texture, ToneMapping, Triangle, Vector2, Vector3, WebGLRenderer, XRTargetRaySpace} from 'three';
1717
import {CSS2DRenderer} from 'three/examples/jsm/renderers/CSS2DRenderer.js';
1818
import {reduceVertices} from 'three/examples/jsm/utils/SceneUtils.js';
1919

@@ -783,7 +783,8 @@ export class ModelScene extends Scene {
783783
this.queueShadowRender();
784784
}
785785

786-
subscribeMixerEvent(event: string, callback: (...args: any[]) => void) {
786+
subscribeMixerEvent(
787+
event: keyof AnimationMixerEventMap, callback: (...args: any[]) => void) {
787788
this.mixer.addEventListener(event, callback);
788789
}
789790

packages/model-viewer/src/three-components/gltf-instance/VariantMaterialExporterPlugin.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
import {Material, Mesh, Object3D} from 'three';
29+
import {GLTFExporterPlugin} from 'three/examples/jsm/Addons.js';
2930

3031
import {VariantData} from '../../features/scene-graph/model.js';
3132

@@ -61,7 +62,8 @@ const compatibleMaterial = (material: Material|null) => {
6162
return material && material.isMaterial && !Array.isArray(material);
6263
};
6364

64-
export default class GLTFExporterMaterialsVariantsExtension {
65+
export default class GLTFExporterMaterialsVariantsExtension implements
66+
GLTFExporterPlugin {
6567
writer: any; // @TODO: Replace with GLTFWriter when GLTFExporter plugin TS
6668
// declaration is ready
6769
name: string;
@@ -73,32 +75,38 @@ export default class GLTFExporterMaterialsVariantsExtension {
7375
this.variantNames = [];
7476
}
7577

76-
beforeParse(objects: Object3D[]) {
78+
beforeParse(objects: Object3D|Object3D[]) {
7779
// Find all variant names and store them to the table
7880
const variantNameSet = new Set<string>();
79-
for (const object of objects) {
80-
object.traverse(o => {
81-
if (!compatibleObject(o)) {
82-
return;
83-
}
84-
const variantMaterials =
85-
o.userData.variantMaterials as Map<number, UserDataVariantMapping>;
86-
const variantDataMap =
87-
o.userData.variantData as Map<string, VariantData>;
88-
for (const [variantName, variantData] of variantDataMap) {
89-
const variantMaterial = variantMaterials.get(variantData.index);
90-
// Ignore unloaded variant materials
91-
if (variantMaterial && compatibleMaterial(variantMaterial.material)) {
92-
variantNameSet.add(variantName);
93-
}
81+
82+
const addVariantNames = (o: Object3D) => {
83+
if (!compatibleObject(o)) {
84+
return;
85+
}
86+
const variantMaterials =
87+
o.userData.variantMaterials as Map<number, UserDataVariantMapping>;
88+
const variantDataMap = o.userData.variantData as Map<string, VariantData>;
89+
for (const [variantName, variantData] of variantDataMap) {
90+
const variantMaterial = variantMaterials.get(variantData.index);
91+
// Ignore unloaded variant materials
92+
if (variantMaterial && compatibleMaterial(variantMaterial.material)) {
93+
variantNameSet.add(variantName);
9494
}
95-
});
95+
}
96+
};
97+
98+
if (Array.isArray(objects)) {
99+
for (const object of objects) {
100+
object.traverse(addVariantNames);
101+
}
102+
} else {
103+
objects.traverse(addVariantNames);
96104
}
97105
// We may want to sort?
98106
variantNameSet.forEach(name => this.variantNames.push(name));
99107
}
100108

101-
writeMesh(mesh: Mesh, meshDef: any) {
109+
async writeMesh(mesh: Mesh, meshDef: any) {
102110
if (!compatibleObject(mesh)) {
103111
return;
104112
}
@@ -126,7 +134,7 @@ export default class GLTFExporterMaterialsVariantsExtension {
126134
}
127135

128136
const materialIndex =
129-
this.writer.processMaterial(variantInstance.material);
137+
await this.writer.processMaterialAsync(variantInstance.material);
130138
if (!mappingTable.has(materialIndex)) {
131139
mappingTable.set(
132140
materialIndex, {material: materialIndex, variants: []});
@@ -146,7 +154,7 @@ export default class GLTFExporterMaterialsVariantsExtension {
146154

147155
const originalMaterialIndex =
148156
compatibleMaterial(userData.originalMaterial) ?
149-
this.writer.processMaterial(userData.originalMaterial) :
157+
await this.writer.processMaterialAsync(userData.originalMaterial) :
150158
-1;
151159

152160
for (const primitiveDef of meshDef.primitives) {

packages/model-viewer/src/utilities.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {EventDispatcher} from 'three';
17-
1816
import {HAS_WEBXR_DEVICE_API, HAS_WEBXR_HIT_TEST_API, IS_WEBXR_AR_CANDIDATE} from './constants.js';
1917

2018
export type Constructor<T = object, U = object> = {
@@ -143,13 +141,6 @@ export const isDebugMode = (() => {
143141
self.location.search.match(debugQueryParameter));
144142
})();
145143

146-
147-
/**
148-
* Three.js EventDispatcher and DOM EventTarget use different event patterns,
149-
* so AnyEvent covers the shape of both event types.
150-
*/
151-
export type AnyEvent = Event|CustomEvent<any>|{[index: string]: string};
152-
153144
export type PredicateFunction<T = void> = (value: T) => boolean;
154145

155146
export const timePasses = (ms: number = 0): Promise<void> =>
@@ -160,16 +151,16 @@ export const timePasses = (ms: number = 0): Promise<void> =>
160151
* @param {string} eventName
161152
* @param {?Function} predicate
162153
*/
163-
export const waitForEvent = <T extends AnyEvent = Event>(
164-
target: EventTarget|EventDispatcher,
165-
eventName: string,
166-
predicate: PredicateFunction<T>|null = null): Promise<T> =>
167-
new Promise(resolve => {
168-
function handler(event: AnyEvent) {
169-
if (!predicate || predicate(event as T)) {
170-
resolve(event as T);
171-
target.removeEventListener(eventName, handler as any);
172-
}
173-
}
174-
target.addEventListener(eventName, handler as any);
175-
});
154+
export const waitForEvent =
155+
<T>(target: any,
156+
eventName: string,
157+
predicate: PredicateFunction<T>|null = null): Promise<T> =>
158+
new Promise(resolve => {
159+
function handler(event: T) {
160+
if (!predicate || predicate(event)) {
161+
resolve(event);
162+
target.removeEventListener(eventName, handler);
163+
}
164+
}
165+
target.addEventListener(eventName, handler);
166+
});

0 commit comments

Comments
 (0)