Skip to content

Commit

Permalink
Update to latest wwobjloader2 and fix PotentiallyInfiniteExample
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Oct 22, 2023
1 parent 50a93f6 commit 3f3f2ef
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions packages/examples/src/infinite/PotentiallyInfiniteExample.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AmbientLight,
BufferGeometry,
Color,
DirectionalLight,
FileLoader,
Expand Down Expand Up @@ -35,9 +36,9 @@ import {
MeshPayload,
MaterialsPayload
} from 'wtd-three-ext';
// import {
// OBJLoader2
// } from 'wwobjloader2';
import {
OBJLoader2
} from 'wwobjloader2';

export type CameraDefaults = {
posCamera: Vector3;
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 10 additions & 13 deletions packages/examples/src/worker/InfiniteWorkerExternalGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +62,6 @@ class InfiniteWorkerExternalGeometry extends WorkerTaskDefaultWorker {
self.postMessage(execComplete, transferables);
}
}

}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"exclude": [
"dist",
"node_modules",
"src/infinite/**/*.ts",
"node_modules"
]
}

0 comments on commit 3f3f2ef

Please sign in to comment.