From 3f3f2ef6bc36d38f8c2efcf51fa19857594bdd18 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Sun, 22 Oct 2023 17:51:24 +0200 Subject: [PATCH] Update to latest wwobjloader2 and fix PotentiallyInfiniteExample --- package-lock.json | 16 ++++++++++++- packages/examples/package.json | 6 ++--- .../infinite/PotentiallyInfiniteExample.ts | 9 ++++---- .../worker/InfiniteWorkerExternalGeometry.ts | 23 ++++++++----------- packages/examples/tsconfig.json | 3 +-- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53ef992..944d531 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3584,6 +3584,19 @@ "resolved": "packages/wtd-three-ext", "link": true }, + "node_modules/wwobjloader2": { + "version": "6.2.0-next.0", + "resolved": "https://registry.npmjs.org/wwobjloader2/-/wwobjloader2-6.2.0-next.0.tgz", + "integrity": "sha512-nJ+3x/KWCC3FEN/3AqKIGb24d+vEXgM9FQFaEPUwKUqCVIEwifXHDqLPbDG8qDIWVYc3eJ2plxEubvDMZRugKQ==", + "dependencies": { + "three": "~0.157.0", + "wtd-core": "~2.4.0-next.0", + "wtd-three-ext": "~2.4.0-next.0" + }, + "peerDependencies": { + "three": ">= 0.137.5 < 1" + } + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -3608,7 +3621,8 @@ "dependencies": { "lil-gui": "~0.18.2", "wtd-core": "~2.4.0-next.0", - "wtd-three-ext": "~2.4.0-next.0" + "wtd-three-ext": "~2.4.0-next.0", + "wwobjloader2": "6.2.0-next.0" }, "devDependencies": { "http-server": "~14.1.1" diff --git a/packages/examples/package.json b/packages/examples/package.json index 07e0b52..4984fe1 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -20,8 +20,7 @@ "build:worker:TransferableWorkerTest3": "shx rm -f ./src/worker/generated/TransferableWorkerTest3*.js && vite -c build/vite.config.TransferableWorkerTest3.ts build", "build:worker:TransferableWorkerTest4": "shx rm -f ./src/worker/generated/TransferableWorkerTest4*.js && vite -c build/vite.config.TransferableWorkerTest4.ts build", "build:worker": "npm run build:worker:HelloWorldWorker && npm run build:worker:Com1Worker && npm run build:worker:Com2Worker && npm run build:worker:HelloWorldThreeWorker && npm run build:worker:InfiniteWorkerExternalGeometry && npm run build:worker:InfiniteWorkerInternalGeometry && npm run build:worker:OBJLoaderWorker && npm run build:worker:TransferableWorkerTest1 && npm run build:worker:TransferableWorkerTest2 && npm run build:worker:TransferableWorkerTest3 && npm run build:worker:TransferableWorkerTest4", - "_build": "npm run clean && npm run copy:worker:OBJLoader2Worker && npm run compile", - "build": "npm run clean && npm run compile", + "build": "npm run clean && npm run copy:worker:OBJLoader2Worker && npm run compile", "clean:production": "shx rm -fr preview", "copy:assets:production": "shx mkdir -p ./preview/worker/generated && shx cp -f ./src/worker/generated/*.js ./preview/worker/generated && shx cp -f ./models/obj/female02/*.jpg ./preview/assets", "build:production": "npm run build && npm run build:worker && npm run build:production:vite", @@ -31,7 +30,8 @@ "dependencies": { "lil-gui": "~0.18.2", "wtd-core": "~2.4.0-next.0", - "wtd-three-ext": "~2.4.0-next.0" + "wtd-three-ext": "~2.4.0-next.0", + "wwobjloader2": "6.2.0-next.0" }, "devDependencies": { "http-server": "~14.1.1" diff --git a/packages/examples/src/infinite/PotentiallyInfiniteExample.ts b/packages/examples/src/infinite/PotentiallyInfiniteExample.ts index a07c783..dcacb6a 100644 --- a/packages/examples/src/infinite/PotentiallyInfiniteExample.ts +++ b/packages/examples/src/infinite/PotentiallyInfiniteExample.ts @@ -1,5 +1,6 @@ import { AmbientLight, + BufferGeometry, Color, DirectionalLight, FileLoader, @@ -35,9 +36,9 @@ import { MeshPayload, MaterialsPayload } from 'wtd-three-ext'; -// import { -// OBJLoader2 -// } from 'wwobjloader2'; +import { + OBJLoader2 +} from 'wwobjloader2'; export type CameraDefaults = { posCamera: Vector3; @@ -514,7 +515,7 @@ class PotentiallyInfiniteExample { color.b = randArray[2] / 255; material = new MeshPhongMaterial({ color: color }); } - mesh = new Mesh(meshPayload.message.bufferGeometry, material); + mesh = new Mesh(meshPayload.message.bufferGeometry as BufferGeometry, material); } this.addMesh(mesh, wtm.id); } diff --git a/packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts b/packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts index 03ab789..f5f2662 100644 --- a/packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts +++ b/packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts @@ -6,35 +6,33 @@ import { WorkerTaskMessage, WorkerTaskMessageType, createFromExisting, - pack + pack, + unpack } from 'wtd-core'; import { - MeshPayload, MeshPayloadHandler + MeshPayload } from 'wtd-three-ext'; declare const self: DedicatedWorkerGlobalScope; class InfiniteWorkerExternalGeometry extends WorkerTaskDefaultWorker { - private localData = { - meshPayloadRaw: undefined as MeshPayload | undefined - }; + private bufferGeometry?: BufferGeometry = undefined; init(message: WorkerTaskMessage) { - this.localData.meshPayloadRaw = message.payloads[0] as MeshPayload; + const wtm = unpack(message, true); + this.bufferGeometry = (wtm.payloads[0] as MeshPayload).message.bufferGeometry as BufferGeometry; const initComplete = createFromExisting(message, 'initComplete'); self.postMessage(initComplete); } execute(message: WorkerTaskMessageType) { - if (!this.localData.meshPayloadRaw) { + if (!this.bufferGeometry) { self.postMessage(new Error('No initial payload available')); - } - else { - // unpack for every usage to ensure Transferables are not re-used - const meshPayload = new MeshPayloadHandler().unpack(this.localData.meshPayloadRaw, true) as MeshPayload; - const geometry = meshPayload.message.bufferGeometry as BufferGeometry; + } else { + // clone before re-using as othewise transferables can not be obtained + const geometry = this.bufferGeometry.clone(); if (geometry) { geometry.name = 'tmProto' + message.id; @@ -64,7 +62,6 @@ class InfiniteWorkerExternalGeometry extends WorkerTaskDefaultWorker { self.postMessage(execComplete, transferables); } } - } } diff --git a/packages/examples/tsconfig.json b/packages/examples/tsconfig.json index 381fcbd..df8439e 100644 --- a/packages/examples/tsconfig.json +++ b/packages/examples/tsconfig.json @@ -17,7 +17,6 @@ ], "exclude": [ "dist", - "node_modules", - "src/infinite/**/*.ts", + "node_modules" ] }