From ede91f6cec2bbd9c10837f680b83f369f83d0c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:02:32 +0200 Subject: [PATCH] making use of mesh rather than aggregate for global repositioning in playground --- src/ts/playground.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ts/playground.ts b/src/ts/playground.ts index f83f36a89..4d42194f8 100644 --- a/src/ts/playground.ts +++ b/src/ts/playground.ts @@ -108,6 +108,7 @@ const aggregates = [sphereAggregate, boxAggregate, capsuleAggregate, spaceship.g for(const aggregate of aggregates) { aggregate.body.disablePreStep = false; } +const meshes = [sphere, box, capsule, spaceship.instanceRoot, newton.transform.node]; const fallingAggregates = [sphereAggregate, boxAggregate, capsuleAggregate, spaceship.getAggregate()]; //viewer.showBody(spaceship.getAggregate().body); @@ -117,11 +118,7 @@ const gravity = -9.81; let clockSeconds = 0; function updateScene() { - // move back everything to the origin - const spaceshipPosition = spaceship.getAbsolutePosition(); - for(const aggregate of aggregates) { - aggregate.transformNode.position.subtractInPlace(spaceshipPosition); - } + const deltaTime = engine.getDeltaTime() / 1000; clockSeconds += deltaTime; @@ -144,6 +141,13 @@ function updateScene() { newton.updateLOD(camera.globalPosition); newton.material.update(camera.globalPosition, [light.getAbsolutePosition()]); Assets.ChunkForge.update(); + + // move back everything to the origin + const spaceshipPosition = spaceship.getAbsolutePosition(); + + for(const mesh of meshes) { + mesh.position.subtractInPlace(spaceshipPosition); + } } scene.executeWhenReady(() => {