Spaces:
Running
Running
Keep objects standing on the floor as their parts move
Browse filesFiles changed (3)
- app.js+1-1
- index.html+1-1
- viewer.js+28-7
239 unmodified lines240241242243244245246239 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=31"));viewer = createViewer();} catch (e) {console.error("3D viewer failed to start", e);239 unmodified lines240241242243244245246239 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=32"));viewer = createViewer();} catch (e) {console.error("3D viewer failed to start", e);
82 unmodified lines83848586878882 unmodified lines</aside></div><script src="app.js?v=33"></script></body></html>82 unmodified lines83848586878882 unmodified lines</aside></div><script src="app.js?v=34"></script></body></html>
183 unmodified lines184185186187188189129 unmodified lines31932032132232332432523 unmodified lines34935035135235335435535696 unmodified lines45345445545645745840 unmodified lines4995005015025035045055065075088 unmodified lines51751851952052152252352452552652752852953053153245 unmodified lines578579580581582583183 unmodified linesloader.setDRACOLoader(draco);let model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1, interior = false;let onJoint = () => {};function setTheme(t) { theme = t === "light" ? "light" : "dark"; } // the studio is the same grey in both129 unmodified lines}});}model = null; rig = []; grabMeshes = []; drag = null;placeGrid();}23 unmodified linesif (r.type === "hinge") r.group.quaternion.setFromAxisAngle(r.axis, THREE.MathUtils.degToRad(v));else r.group.position.copy(r.base).addScaledVector(r.axis, v);onJoint(r.index, v);if (depth < 8) for (const f of r.followers || []) place(f, -(f.mimic.gearing * v + f.mimic.offset), depth + 1);}function setJoint(r, v) {for (let n = 0; r.mimic && n < 8; n++) { v = -(v + r.mimic.offset) / r.mimic.gearing; r = r.mimic.ref; }place(r, Math.min(r.hi, Math.max(r.lo, v)));96 unmodified lines}linkJoints(data.joints || []);leaders().forEach((r) => setJoint(r, rest(r)));const box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());40 unmodified lines// a part centred on its own axis (wheel, knob): turn it by horizontal pointer movementdrag = v0.lengthSq() < 1e-10 * sizeM * sizeM? { r, kind: "spin", x0: e.clientX, start: r.val }: { r, kind: "hinge", pivot, axis, v0: v0.normalize(), start: r.val };} else {const n = camera.getWorldDirection(new THREE.Vector3());drag = { r, kind: "slider", axis, start: r.val, p0: point.clone(),plane: new THREE.Plane().setFromNormalAndCoplanarPoint(n, point) };}setHot(r);8 unmodified linesif (drag.kind === "spin") { setJoint(drag.r, drag.start + (e.clientX - drag.x0) * 0.8); return; }aim(e);const p = new THREE.Vector3();if (drag.kind === "hinge") {if (!ray.ray.intersectPlane(new THREE.Plane().setFromNormalAndCoplanarPoint(drag.axis, drag.pivot), p)) return;const v1 = p.sub(drag.pivot).projectOnPlane(drag.axis);if (v1.lengthSq() < 1e-12) return;v1.normalize();const delta = Math.atan2(new THREE.Vector3().crossVectors(drag.v0, v1).dot(drag.axis), drag.v0.dot(v1));setJoint(drag.r, drag.start + THREE.MathUtils.radToDeg(delta));} else {if (!ray.ray.intersectPlane(drag.plane, p)) return;setJoint(drag.r, drag.start + p.sub(drag.p0).dot(drag.axis));}}function endDrag() {45 unmodified lines(function tick() {if (!running) return;requestAnimationFrame(tick);controls.update();renderer.render(scene, camera);placeDots();183 unmodified lines184185186187188189190129 unmodified lines32032132232332432532623 unmodified lines35035135235335435535635735835936036136236336436536636736836937037137296 unmodified lines46947047147247347447547640 unmodified lines5175185195205215225235245255268 unmodified lines53553653753853954054154254354454554654754854955055155245 unmodified lines598599600601602603604183 unmodified linesloader.setDRACOLoader(draco);let model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1, interior = false;let groundY = null, settleDirty = false; // see settle()let onJoint = () => {};function setTheme(t) { theme = t === "light" ? "light" : "dark"; } // the studio is the same grey in both129 unmodified lines}});}model = null; rig = []; grabMeshes = []; drag = null; groundY = null;placeGrid();}23 unmodified linesif (r.type === "hinge") r.group.quaternion.setFromAxisAngle(r.axis, THREE.MathUtils.degToRad(v));else r.group.position.copy(r.base).addScaledVector(r.axis, v);onJoint(r.index, v);settleDirty = true;if (depth < 8) for (const f of r.followers || []) place(f, -(f.mimic.gearing * v + f.mimic.offset), depth + 1);}// Objects stand on the floor the way a free-standing one would: when a moving part swings// below the base the object lifts, and when a low part folds up it settles back down, so// nothing passes through the floor. groundY is the lowest point in the rest pose.function lowest() {model.position.y = 0;model.updateMatrixWorld(true);return new THREE.Box3().setFromObject(model, true).min.y;}function settle() {settleDirty = false;if (!model || interior || groundY === null) return;model.position.y = groundY - lowest();model.updateMatrixWorld(true);}function setJoint(r, v) {for (let n = 0; r.mimic && n < 8; n++) { v = -(v + r.mimic.offset) / r.mimic.gearing; r = r.mimic.ref; }place(r, Math.min(r.hi, Math.max(r.lo, v)));96 unmodified lines}linkJoints(data.joints || []);leaders().forEach((r) => setJoint(r, rest(r)));groundY = rig.length && !opts.interior ? lowest() : null;settleDirty = false;const box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());40 unmodified lines// a part centred on its own axis (wheel, knob): turn it by horizontal pointer movementdrag = v0.lengthSq() < 1e-10 * sizeM * sizeM? { r, kind: "spin", x0: e.clientX, start: r.val }: { r, kind: "hinge", pivot, axis, v0: v0.normalize(), start: r.val, lift0: model.position.y };} else {const n = camera.getWorldDirection(new THREE.Vector3());drag = { r, kind: "slider", axis, start: r.val, p0: point.clone(), lift0: model.position.y,plane: new THREE.Plane().setFromNormalAndCoplanarPoint(n, point) };}setHot(r);8 unmodified linesif (drag.kind === "spin") { setJoint(drag.r, drag.start + (e.clientX - drag.x0) * 0.8); return; }aim(e);const p = new THREE.Vector3();const lift = new THREE.Vector3(0, model.position.y - drag.lift0, 0); // the object rose or settled since the drag beganif (drag.kind === "hinge") {const pivot = drag.pivot.clone().add(lift);if (!ray.ray.intersectPlane(new THREE.Plane().setFromNormalAndCoplanarPoint(drag.axis, pivot), p)) return;const v1 = p.sub(pivot).projectOnPlane(drag.axis);if (v1.lengthSq() < 1e-12) return;v1.normalize();const delta = Math.atan2(new THREE.Vector3().crossVectors(drag.v0, v1).dot(drag.axis), drag.v0.dot(v1));setJoint(drag.r, drag.start + THREE.MathUtils.radToDeg(delta));} else {if (!ray.ray.intersectPlane(drag.plane.clone().translate(lift), p)) return;setJoint(drag.r, drag.start + p.sub(drag.p0).sub(lift).dot(drag.axis));}}function endDrag() {45 unmodified lines(function tick() {if (!running) return;requestAnimationFrame(tick);if (settleDirty) settle();controls.update();renderer.render(scene, camera);placeDots();
app.js+1-1
index.html+1-1
viewer.js+28-7