()
| 7 | import SceneInit from './lib/SceneInit'; |
| 8 | |
| 9 | function App() { |
| 10 | useEffect(() => { |
| 11 | // ============ |
| 12 | // part 0 |
| 13 | // set up Three.js scene with axis helper |
| 14 | // ============ |
| 15 | const test = new SceneInit('myThreeJsCanvas'); |
| 16 | test.initialize(); |
| 17 | test.animate(); |
| 18 | const axesHelper = new THREE.AxesHelper(8); |
| 19 | test.scene.add(axesHelper); |
| 20 | |
| 21 | // ============ |
| 22 | // part 1 |
| 23 | // set up world physics with gravity |
| 24 | // ============ |
| 25 | const physicsWorld = new CANNON.World({ |
| 26 | gravity: new CANNON.Vec3(0, -9.82, 0), |
| 27 | }); |
| 28 | |
| 29 | // create a ground body with a static plane |
| 30 | const groundBody = new CANNON.Body({ |
| 31 | type: CANNON.Body.STATIC, |
| 32 | // infinte geometric plane |
| 33 | shape: new CANNON.Plane(), |
| 34 | }); |
| 35 | // rotate ground body by 90 degrees |
| 36 | groundBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0); |
| 37 | // groundBody.quaternion.setFromEuler(-Math.PI / 2, Math.PI / 24, 0); |
| 38 | physicsWorld.addBody(groundBody); |
| 39 | |
| 40 | // add a green wireframe to each object and visualize the physics world |
| 41 | const cannonDebugger = new CannonDebugger(test.scene, physicsWorld); |
| 42 | |
| 43 | // const animate = () => { |
| 44 | // physicsWorld.fixedStep(); |
| 45 | // cannonDebugger.update(); |
| 46 | // window.requestAnimationFrame(animate); |
| 47 | // }; |
| 48 | // animate(); |
| 49 | |
| 50 | // ============ |
| 51 | // part 2 |
| 52 | // add base vehicle body |
| 53 | // reference: https://github.com/pmndrs/cannon-es/blob/master/examples/rigid_vehicle.html |
| 54 | // ============ |
| 55 | const carBody = new CANNON.Body({ |
| 56 | mass: 5, |
| 57 | position: new CANNON.Vec3(0, 6, 0), |
| 58 | shape: new CANNON.Box(new CANNON.Vec3(4, 0.5, 2)), |
| 59 | }); |
| 60 | |
| 61 | const vehicle = new CANNON.RigidVehicle({ |
| 62 | chassisBody: carBody, |
| 63 | }); |
| 64 | |
| 65 | // vehicle.addToWorld(physicsWorld); |
| 66 |
nothing calls this directly
no test coverage detected