@pmndrs/viverse 0.2.23 → 0.2.24

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.
@@ -31,6 +31,17 @@ export type CharacterModel = {
31
31
  scene: Object3D;
32
32
  currentAnimations: Map<string | undefined, AnimationAction>;
33
33
  boneRotationOffset?: Quaternion;
34
+ /**
35
+ * The character's real height in world units, measured once from the loaded mesh in its
36
+ * bind pose. Use this to size things to the character (nameplates, hitboxes, scale
37
+ * normalization) instead of `new Box3().setFromObject(scene)` — that includes the skeleton
38
+ * bones and the internal rest-pose reference copy and changes as the animation plays, so it
39
+ * returns a height several times the visible body.
40
+ *
41
+ * Always set by `loadCharacterModel`; optional only so hand-built `CharacterModel` objects
42
+ * (e.g. cloned NPC instances) stay valid — copy it across when you clone.
43
+ */
44
+ height?: number;
34
45
  };
35
46
  export declare function loadCharacterModel(url?: string, type?: Exclude<CharacterModelOptions, boolean>['type'], boneRotationOffset?: Quaternion, castShadow?: boolean, receiveShadow?: boolean, boneMap?: BoneMap, useDraco?: boolean): Promise<CharacterModel>;
36
47
  export declare function getBone(model: CharacterModel, name: VRMHumanBoneName): Object3D | undefined;
@@ -1,5 +1,5 @@
1
1
  import { VRM } from '@pixiv/three-vrm';
2
- import { AnimationMixer, Euler, Quaternion } from 'three';
2
+ import { AnimationMixer, Box3, Euler, Quaternion, Vector3 } from 'three';
3
3
  import { loadGltfCharacterModel } from './gltf.js';
4
4
  import { loadVrmCharacterModel } from './vrm.js';
5
5
  export { VRMHumanBoneName } from '@pixiv/three-vrm';
@@ -56,11 +56,15 @@ export async function loadCharacterModel(url, type, boneRotationOffset, castShad
56
56
  obj.receiveShadow = true;
57
57
  }
58
58
  });
59
+ // Measure the real height here: the scene is still in its bind pose, the mixer has not run,
60
+ // and the rest-pose clone below has not been added yet — so the bounding box is just the
61
+ // visible mesh and is stable. Measuring later (after the clone, once animating) inflates it.
62
+ const height = new Box3().setFromObject(result.scene).getSize(new Vector3()).y;
59
63
  const restPose = result.scene.clone();
60
64
  restPose.visible = false;
61
65
  restPose.traverse((object) => (object.name = `rest_${object.name}`));
62
66
  result.scene.add(restPose);
63
- return Object.assign(result, { mixer: new AnimationMixer(result.scene), currentAnimations: new Map() });
67
+ return Object.assign(result, { mixer: new AnimationMixer(result.scene), currentAnimations: new Map(), height });
64
68
  }
65
69
  export function getBone(model, name) {
66
70
  return model instanceof VRM ? (model.humanoid.getRawBoneNode(name) ?? undefined) : model.scene.getObjectByName(name);
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.2.23",
24
+ "version": "0.2.24",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",