@adatechnology/game-interactables-three 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.global.js +21 -19
- package/dist/index.global.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -3254,38 +3254,40 @@ void main() {
|
|
|
3254
3254
|
function poseOf(motion, t) {
|
|
3255
3255
|
const tt = Math.max(0, Math.min(1, t));
|
|
3256
3256
|
const axis = motion.axis ?? DEFAULT_AXIS;
|
|
3257
|
-
const
|
|
3257
|
+
const pose3 = { position: [0, 0, 0], rotation: { axis: [axis[0], axis[1], axis[2]], angle: 0 }, scale: [1, 1, 1] };
|
|
3258
3258
|
switch (motion.kind) {
|
|
3259
3259
|
case "hinge":
|
|
3260
3260
|
case "rocker":
|
|
3261
3261
|
case "knob":
|
|
3262
|
-
|
|
3262
|
+
pose3.rotation.angle = (motion.angle ?? Math.PI / 2) * tt;
|
|
3263
3263
|
break;
|
|
3264
3264
|
case "slide": {
|
|
3265
3265
|
const d = (motion.distance ?? 0.4) * tt;
|
|
3266
|
-
|
|
3266
|
+
pose3.position = [axis[0] * d, axis[1] * d, axis[2] * d];
|
|
3267
3267
|
break;
|
|
3268
3268
|
}
|
|
3269
3269
|
case "scale": {
|
|
3270
3270
|
const k = 1 + ((motion.scale ?? 0.2) - 1) * tt;
|
|
3271
|
-
|
|
3271
|
+
pose3.scale = [axis[0] !== 0 ? k : 1, axis[1] !== 0 ? k : 1, axis[2] !== 0 ? k : 1];
|
|
3272
3272
|
break;
|
|
3273
3273
|
}
|
|
3274
3274
|
}
|
|
3275
|
-
return
|
|
3275
|
+
return pose3;
|
|
3276
3276
|
}
|
|
3277
|
+
var pose = new Float64Array(7);
|
|
3278
|
+
var pose2 = new Float64Array(7);
|
|
3277
3279
|
|
|
3278
3280
|
// src/pose.ts
|
|
3279
3281
|
function poseOf2(motion, t) {
|
|
3280
3282
|
const k = Math.min(1, Math.max(0, Number.isFinite(t) ? t : 0));
|
|
3281
|
-
const
|
|
3282
|
-
const [x, y, z] =
|
|
3283
|
+
const pose3 = poseOf(motion, k);
|
|
3284
|
+
const [x, y, z] = pose3.rotation.axis;
|
|
3283
3285
|
const l = Math.hypot(x, y, z) || 1;
|
|
3284
|
-
const s = Math.sin(
|
|
3286
|
+
const s = Math.sin(pose3.rotation.angle / 2);
|
|
3285
3287
|
return {
|
|
3286
|
-
position: [
|
|
3287
|
-
quaternion: [x / l * s, y / l * s, z / l * s, Math.cos(
|
|
3288
|
-
scale: [
|
|
3288
|
+
position: [pose3.position[0], pose3.position[1], pose3.position[2]],
|
|
3289
|
+
quaternion: [x / l * s, y / l * s, z / l * s, Math.cos(pose3.rotation.angle / 2)],
|
|
3290
|
+
scale: [pose3.scale[0], pose3.scale[1], pose3.scale[2]]
|
|
3289
3291
|
};
|
|
3290
3292
|
}
|
|
3291
3293
|
function rememberRest(group) {
|
|
@@ -3301,13 +3303,13 @@ void main() {
|
|
|
3301
3303
|
}
|
|
3302
3304
|
function applyPose(THREE, group, motion, t) {
|
|
3303
3305
|
const rest = rememberRest(group);
|
|
3304
|
-
const
|
|
3306
|
+
const pose3 = poseOf2(motion, t);
|
|
3305
3307
|
const restQ = new THREE.Quaternion(rest.quaternion[0], rest.quaternion[1], rest.quaternion[2], rest.quaternion[3]);
|
|
3306
|
-
const delta = new THREE.Quaternion(
|
|
3308
|
+
const delta = new THREE.Quaternion(pose3.quaternion[0], pose3.quaternion[1], pose3.quaternion[2], pose3.quaternion[3]);
|
|
3307
3309
|
group.quaternion.copy(restQ).multiply(delta);
|
|
3308
|
-
const offset = new THREE.Vector3(
|
|
3310
|
+
const offset = new THREE.Vector3(pose3.position[0], pose3.position[1], pose3.position[2]).applyQuaternion(restQ);
|
|
3309
3311
|
group.position.set(rest.position[0] + offset.x, rest.position[1] + offset.y, rest.position[2] + offset.z);
|
|
3310
|
-
group.scale.set(rest.scale[0] *
|
|
3312
|
+
group.scale.set(rest.scale[0] * pose3.scale[0], rest.scale[1] * pose3.scale[1], rest.scale[2] * pose3.scale[2]);
|
|
3311
3313
|
group.updateMatrix();
|
|
3312
3314
|
return group;
|
|
3313
3315
|
}
|
|
@@ -3592,10 +3594,10 @@ ${QROT}${shader.vertexShader}`;
|
|
|
3592
3594
|
kind: "pose",
|
|
3593
3595
|
ids,
|
|
3594
3596
|
apply(m, t) {
|
|
3595
|
-
const
|
|
3596
|
-
uniforms.q.value.set(
|
|
3597
|
-
uniforms.pos.value.set(
|
|
3598
|
-
uniforms.scale.value.set(
|
|
3597
|
+
const pose3 = poseOf2(m, t);
|
|
3598
|
+
uniforms.q.value.set(pose3.quaternion[0], pose3.quaternion[1], pose3.quaternion[2], pose3.quaternion[3]);
|
|
3599
|
+
uniforms.pos.value.set(pose3.position[0], pose3.position[1], pose3.position[2]);
|
|
3600
|
+
uniforms.scale.value.set(pose3.scale[0], pose3.scale[1], pose3.scale[2]);
|
|
3599
3601
|
}
|
|
3600
3602
|
};
|
|
3601
3603
|
batch.apply(motion, 0);
|