@pmndrs/viverse 0.1.15 → 0.1.17

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.
@@ -5,10 +5,8 @@ import { loadVrmModelMixamoAnimations as loadModelMixamoAnimations } from './mix
5
5
  import { scaleAnimationClipTime, trimAnimationClip } from './utils.js';
6
6
  import { loadVrmModelVrmaAnimations } from './vrma.js';
7
7
  import { cached } from '../utils.js';
8
- const parentWorldVector = new Vector3();
9
8
  const restRotationInverse = new Quaternion();
10
9
  const parentRestWorldRotation = new Quaternion();
11
- const parentRestWorldRotationInverse = new Quaternion();
12
10
  const quaternion = new Quaternion();
13
11
  const vector = new Vector3();
14
12
  const nonVrmRotationOffset = new Quaternion().setFromEuler(new Euler(0, Math.PI, 0));
@@ -18,7 +16,9 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement,
18
16
  throw new Error('Failed to determine hips bone name for VRM animation. Please check the bone map or animation file.');
19
17
  }
20
18
  const clipSceneHips = clipScene.getObjectByName(hipsBoneName);
21
- const vrmHipsPosition = model instanceof VRM ? model.humanoid.normalizedRestPose.hips?.position : clipSceneHips?.position;
19
+ const vrmHipsPosition = model instanceof VRM
20
+ ? model.humanoid.normalizedRestPose.hips?.position
21
+ : model.scene.getObjectByName('hips')?.position.toArray();
22
22
  if (clipSceneHips == null || vrmHipsPosition == null) {
23
23
  throw new Error('Failed to load VRM animation: missing animation hips object or VRM hips position.');
24
24
  }
@@ -32,14 +32,18 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement,
32
32
  const vrmBoneName = boneMap?.[boneName] ?? boneName;
33
33
  const vrmNodeName = model instanceof VRM ? model.humanoid.getNormalizedBoneNode(vrmBoneName)?.name : vrmBoneName;
34
34
  const bone = clipScene.getObjectByName(boneName);
35
- if (vrmNodeName == null || bone == null || bone.parent == null) {
35
+ if (vrmNodeName == null || bone == null) {
36
36
  continue;
37
37
  }
38
- bone.getWorldQuaternion(restRotationInverse).invert();
39
- bone.parent.getWorldQuaternion(parentRestWorldRotation);
40
- parentRestWorldRotationInverse.copy(parentRestWorldRotation).invert();
41
- bone.parent.getWorldPosition(parentWorldVector);
42
38
  if (track instanceof QuaternionKeyframeTrack) {
39
+ if (bone.parent != null) {
40
+ bone.getWorldQuaternion(restRotationInverse).invert();
41
+ bone.parent.getWorldQuaternion(parentRestWorldRotation);
42
+ }
43
+ else {
44
+ restRotationInverse.identity();
45
+ parentRestWorldRotation.identity();
46
+ }
43
47
  // Store rotations of rest-pose.
44
48
  for (let i = 0; i < track.values.length; i += 4) {
45
49
  quaternion.fromArray(track.values, i);
@@ -2,6 +2,7 @@ import { Box3, Line3, Matrix4, Vector3 } from 'three';
2
2
  //for this is a kinematic character controller
3
3
  const triPoint = new Vector3();
4
4
  const capsulePoint = new Vector3();
5
+ const centerHelper = new Vector3();
5
6
  const collisionFreePosition = new Vector3();
6
7
  const position = new Vector3();
7
8
  const invertedParentMatrix = new Matrix4();
@@ -83,7 +84,8 @@ export class BvhCharacterPhysics {
83
84
  }
84
85
  }
85
86
  this.updateBoundingShapes(options);
86
- this.world.updateSensors((bounds) => bounds.intersectsBox(this.aabbox), (triangle) => triangle.closestPointToSegment(this.segment) < this.radius);
87
+ centerHelper.addVectors(this.segment.start, this.segment.end).multiplyScalar(0.5);
88
+ this.world.updateSensors(centerHelper, (bounds) => bounds.intersectsBox(this.aabbox), (triangle) => triangle.closestPointToSegment(this.segment) < this.radius);
87
89
  }
88
90
  updateBoundingShapes(options) {
89
91
  //compute the bounding capsule and bounding box
@@ -1,4 +1,4 @@
1
- import { Box3, Object3D, Ray } from 'three';
1
+ import { Box3, Object3D, Ray, Vector3 } from 'three';
2
2
  import { ExtendedTriangle } from 'three-mesh-bvh';
3
3
  export declare class BvhPhysicsWorld {
4
4
  private bodies;
@@ -13,7 +13,7 @@ export declare class BvhPhysicsWorld {
13
13
  private computeBvhEntries;
14
14
  removeBody(object: Object3D): void;
15
15
  private computeMatrix;
16
- updateSensors(intersectsBounds: (box: Box3) => boolean, intersectsTriangle: (triangle: ExtendedTriangle) => boolean): void;
16
+ updateSensors(playerCenter: Vector3, intersectsBounds: (box: Box3) => boolean, intersectsTriangle: (triangle: ExtendedTriangle) => boolean): void;
17
17
  shapecast(intersectsBounds: (box: Box3) => boolean, intersectsTriangle: (triangle: ExtendedTriangle) => void): void;
18
18
  private shapecastEntry;
19
19
  raycast(ray: Ray, far: number): number | undefined;
@@ -1,4 +1,4 @@
1
- import { Box3, InstancedMesh, Matrix4, Ray, Vector3 } from 'three';
1
+ import { Box3, DoubleSide, InstancedMesh, Matrix4, Ray, Vector3 } from 'three';
2
2
  import { computeBoundsTree, StaticGeometryGenerator, ExtendedTriangle } from 'three-mesh-bvh';
3
3
  const rayHelper = new Ray();
4
4
  const farPointHelper = new Vector3();
@@ -70,11 +70,20 @@ export class BvhPhysicsWorld {
70
70
  target.premultiply(object.matrixWorld);
71
71
  return true;
72
72
  }
73
- updateSensors(intersectsBounds, intersectsTriangle) {
74
- console.log('update sensors', this.sensors.length);
73
+ updateSensors(playerCenter, intersectsBounds, intersectsTriangle) {
75
74
  for (const entry of this.sensors) {
76
- const intersected = this.shapecastEntry(entry, intersectsBounds, intersectsTriangle);
77
- console.log(intersected);
75
+ //check surface intersection
76
+ let intersected = this.shapecastEntry(entry, intersectsBounds, intersectsTriangle);
77
+ if (!intersected) {
78
+ //check if we are entirely inside
79
+ rayHelper.origin.copy(playerCenter);
80
+ rayHelper.direction.set(0, -1, 0);
81
+ if (this.computeMatrix(entry, matrixHelper)) {
82
+ matrixHelper.invert();
83
+ rayHelper.applyMatrix4(matrixHelper);
84
+ }
85
+ intersected = entry.bvh.raycast(rayHelper, DoubleSide).length % 2 == 1;
86
+ }
78
87
  if (entry.intersected === intersected) {
79
88
  continue;
80
89
  }
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.1.15",
24
+ "version": "0.1.17",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",