From 4ab88bda6d1bb837625e561a087ee7bf0acfe657 Mon Sep 17 00:00:00 2001 From: 1AlbertChen <2218685507@qq.com> Date: Wed, 8 Dec 2021 14:28:16 +0800 Subject: [PATCH] added imesh initial velocities --- src/components/physics/useCannon.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/physics/useCannon.js b/src/components/physics/useCannon.js index 02d3a43..d69002f 100644 --- a/src/components/physics/useCannon.js +++ b/src/components/physics/useCannon.js @@ -159,7 +159,17 @@ export default function useCannon(options) { if (mesh.userData.dampings?.[i]) damping = mesh.userData.dampings?.[i] else if (mesh.userData.damping) damping = mesh.userData.damping - const body = new Body({ shape, position, mass, linearDamping: damping, angularDamping: damping }) + let velocity = new Vec3(0, 0, 0) + if (mesh.userData.velocities?.[i]) velocity = new Vec3( + mesh.userData.velocities?.[i].x, + mesh.userData.velocities?.[i].y, + mesh.userData.velocities?.[i].z) + else if (mesh.userData.velocities) velocity = new Vec3( + mesh.userData.velocities.x, + mesh.userData.velocities.y, + mesh.userData.velocities.z) + + const body = new Body({ shape, position, velocity, mass, linearDamping: damping, angularDamping: damping }) world.addBody(body) bodies.push(body) }