1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| import * as THREE from "three/build/three.module";
import modelDataUrl from "./public/model/model.glb?url";
import Part from "./src/part"; import Body from "./src/body";
let camera, scene, renderer; let object, axis, light; let body;
let set = { body: [ { file: modelDataUrl, position: { x: 0, y: 0, z: 0 } }, { file: modelDataUrl, position: { x: 0, y: 0.38, z: 0 } }, { file: modelDataUrl, position: { x: 0, y: 0.38, z: 0 } }, ], connects: [-1, 0, 1], poses: [ { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, ], }, { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: 0.5, y: 0, z: 0 }, ], }, { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }, ], }, { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: 0.5, y: 0, z: 0 }, { x: 0.5, y: 0, z: 0 }, ], }, { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: 0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, ], }, { time: 1000, radians: [ { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }, ], }, ], };
init();
async function init() { camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 ); camera.position.set(1, 1.5, 1); camera.lookAt(new THREE.Vector3(0, 0.5, 0));
scene = new THREE.Scene();
light = new THREE.AmbientLight(0xffffff, 1.0); scene.add(light);
body = new Body(set); object = await body.load(); scene.add(object);
axis = THREE.AxisHelper(2000); axis.position.set(0, 0, 0); scene.add(axis);
renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setAnimationLoop(animation); document.body.appendChild(renderer.domElement); }
function animation(time) { body.update(time);
renderer.render(scene, camera); }
|