Import a 3D Model and automatically assign and export animations
TypeScript
fix mirroring props and fix some of the weapons so they line up correctly
Scott Petrovice057db947ff1
diff --git a/.vscode/settings.json b/.vscode/settings.jsonnew file mode 100644index 0000000..7b9ce27--- /dev/null+++ b/.vscode/settings.json@@ -0,0 +1,8 @@+{+ "chat.tools.terminal.autoApprove": {+ "/^npx vitest run src/lib/processes/animations-listing/props/Props\\.test\\.ts$/": {+ "approve": true,+ "matchCommandLine": true+ }+ }+}\ No newline at end of filediff --git a/src/lib/processes/animations-listing/props/PropCatalog.ts b/src/lib/processes/animations-listing/props/PropCatalog.tsindex 99a6c94..7bf9507 100644--- a/src/lib/processes/animations-listing/props/PropCatalog.ts+++ b/src/lib/processes/animations-listing/props/PropCatalog.ts@@ -53,7 +53,7 @@ export class PropCatalog {private static readonly model_cache = new Map<string, Promise<Group>>()private static readonly definitions: PropDefinition[] = [- create_definition(PropType.Pole, 'Pole', 'Polearms', 'spear_A.glb', 0.93),+ create_definition(PropType.Pole, 'Pole', 'Polearms', 'spear_A.glb'),create_definition(PropType.Halberd, 'Halberd', 'Polearms', 'halberd.glb'),create_definition(PropType.Staff, 'Staff', 'Staves', 'staff_A.glb'),create_definition(PropType.StaffB, 'Staff B', 'Staves', 'staff_B.glb'),@@ -69,9 +69,8 @@ export class PropCatalog {create_definition(PropType.DaggerA, 'Dagger A', 'Daggers', 'dagger_A.glb'),create_definition(PropType.DaggerB, 'Dagger B', 'Daggers', 'dagger_B.glb'),create_definition(PropType.FistWeaponA, 'Fist Weapon A', 'Fist Weapons', 'fistweapon_A.glb'),- create_definition(PropType.FistWeaponAStacked, 'Fist Weapon A (Stacked)', 'Fist Weapons', 'fistweapon_A_stacked.glb'),+ // this is having a weird rotation offset between the right and left hand. need to do more research latercreate_definition(PropType.FistWeaponB, 'Fist Weapon B', 'Fist Weapons', 'fistweapon_B.glb'),- create_definition(PropType.FistWeaponBStacked, 'Fist Weapon B (Stacked)', 'Fist Weapons', 'fistweapon_B_stacked.glb'),create_definition(PropType.HammerA, 'Hammer A', 'Hammers', 'hammer_A.glb'),create_definition(PropType.HammerB, 'Hammer B', 'Hammers', 'hammer_B.glb'),create_definition(PropType.HammerC, 'Hammer C', 'Hammers', 'hammer_C.glb'),diff --git a/src/lib/processes/animations-listing/props/Props.test.ts b/src/lib/processes/animations-listing/props/Props.test.tsindex b075724..fad0da8 100644--- a/src/lib/processes/animations-listing/props/Props.test.ts+++ b/src/lib/processes/animations-listing/props/Props.test.ts@@ -1,10 +1,11 @@import { describe, it, expect } from 'vitest'-import { Bone, Group, Mesh, Skeleton } from 'three'+import { Bone, Euler, Group, Mesh, Quaternion, Skeleton, Vector3 } from 'three'import { HandBoneResolver } from './HandBoneResolver'import { PropCatalog } from './PropCatalog'import { PropType } from './PropType'import { PropsExportFilter, PROP_USER_DATA_KEY } from './PropsExportFilter'import { PropSide } from './PropSide'+import { mount_quaternion, mount_scale } from './PropsManager'function make_skeleton (names: string[]): Skeleton {return new Skeleton(names.map((name) => {@@ -45,6 +46,23 @@ describe('HandBoneResolver', () => {})})+describe('mount_quaternion', () => {+ it('mirrors the prop geometry while preserving the grip and face directions', () => {+ for (const [side, hand_rotation] of [[PropSide.Left, new Euler(0, 0, Math.PI / 2)], [PropSide.Right, new Euler(0, 0, -Math.PI / 2)]] as const) {+ const hand_quaternion = new Quaternion().setFromEuler(hand_rotation)+ const world_to_local = hand_quaternion.clone().invert()+ const local_forward = new Vector3(0, 0, 1).applyQuaternion(world_to_local)+ const local_down = new Vector3(0, -1, 0).applyQuaternion(world_to_local)+ const prop_world_quaternion = hand_quaternion.multiply(mount_quaternion(local_forward, local_down, new Euler()))+ const prop_scale = mount_scale(side, 2)++ expect(new Vector3(0, 1, 0).applyQuaternion(prop_world_quaternion).distanceTo(new Vector3(0, 0, 1))).toBeLessThan(1e-6)+ expect(new Vector3(0, 0, 1).applyQuaternion(prop_world_quaternion).distanceTo(new Vector3(0, 1, 0))).toBeLessThan(1e-6)+ expect(new Vector3(1, 0, 0).multiply(prop_scale).applyQuaternion(prop_world_quaternion).x).toBe(side === PropSide.Left ? 2 : -2)+ }+ })+})+describe('PropsExportFilter', () => {it('detaches props and restores them to their original parents', () => {const root = new Bone()diff --git a/src/lib/processes/animations-listing/props/PropsManager.ts b/src/lib/processes/animations-listing/props/PropsManager.tsindex 0f5a061..d3feae2 100644--- a/src/lib/processes/animations-listing/props/PropsManager.ts+++ b/src/lib/processes/animations-listing/props/PropsManager.ts@@ -1,4 +1,4 @@-import { Mesh, Quaternion, type Bone, type Object3D, type Skeleton, type SkinnedMesh, Vector3 } from 'three'+import { type Euler, Matrix4, Mesh, Quaternion, type Bone, type Object3D, type Skeleton, type SkinnedMesh, Vector3 } from 'three'import { SkeletonType } from '../../../enums/SkeletonType.ts'import { PropCatalog } from './PropCatalog.ts'import { PropSide } from './PropSide.ts'@@ -13,6 +13,18 @@ interface HandGripFrame {local_forward: Vector3}+export function mount_quaternion (local_forward: Vector3, local_down: Vector3, rotation: Euler): Quaternion {+ const local_up = local_down.clone().negate()+ const local_right = new Vector3().crossVectors(local_forward, local_up)+ return new Quaternion()+ .setFromRotationMatrix(new Matrix4().makeBasis(local_right, local_forward, local_up))+ .multiply(new Quaternion().setFromEuler(rotation))+}++export function mount_scale (side: PropSide, size_factor: number): Vector3 {+ return new Vector3(side === PropSide.Left ? -size_factor : size_factor, size_factor, size_factor)+}+/*** Attaches the user's chosen props to the hand bones of the animated skinned meshes.* Props are children of the bones, so they follow every animation and are exported with the rig.@@ -152,16 +164,14 @@ export class PropsManager extends EventTarget {const { local_down, local_forward } = this.grip_frames.get(hand_bone) ?? this.compute_grip_frame(hand_bone)- prop_object.quaternion- .setFromUnitVectors(new Vector3(0, 1, 0), local_forward)- .multiply(new Quaternion().setFromEuler(mount_offset.rotation))+ prop_object.quaternion.copy(mount_quaternion(local_forward, local_down, mount_offset.rotation))prop_object.position.set(0, mount_offset.along_hand, 0).addScaledVector(local_down, mount_offset.below_palm).multiplyScalar(size_factor)- prop_object.scale.setScalar(size_factor)+ prop_object.scale.copy(mount_scale(side, size_factor))hand_bone.add(prop_object)this.attached_props.push(prop_object)diff --git a/static/props/arrow_A.glb b/static/props/arrow_A.glbindex bb3f394..eaeb1cd 100644Binary files a/static/props/arrow_A.glb and b/static/props/arrow_A.glb differdiff --git a/static/props/arrow_B.glb b/static/props/arrow_B.glbindex 4584d69..d1a315a 100644Binary files a/static/props/arrow_B.glb and b/static/props/arrow_B.glb differdiff --git a/static/props/axe_A.glb b/static/props/axe_A.glbindex d19d37d..6700eb6 100644Binary files a/static/props/axe_A.glb and b/static/props/axe_A.glb differdiff --git a/static/props/axe_B.glb b/static/props/axe_B.glbindex d2c708c..0ad796c 100644Binary files a/static/props/axe_B.glb and b/static/props/axe_B.glb differdiff --git a/static/props/axe_C.glb b/static/props/axe_C.glbindex 302abed..b38ed81 100644Binary files a/static/props/axe_C.glb and b/static/props/axe_C.glb differdiff --git a/static/props/bow_A.glb b/static/props/bow_A.glbindex b4043f2..8defe6f 100644Binary files a/static/props/bow_A.glb and b/static/props/bow_A.glb differdiff --git a/static/props/bow_A_withString.glb b/static/props/bow_A_withString.glbindex adf1279..0904b6f 100644Binary files a/static/props/bow_A_withString.glb and b/static/props/bow_A_withString.glb differdiff --git a/static/props/bow_B.glb b/static/props/bow_B.glbindex 3b42e29..f9972fe 100644Binary files a/static/props/bow_B.glb and b/static/props/bow_B.glb differdiff --git a/static/props/bow_B_withString.glb b/static/props/bow_B_withString.glbindex ac51dda..73ac131 100644Binary files a/static/props/bow_B_withString.glb and b/static/props/bow_B_withString.glb differdiff --git a/static/props/dagger_A.glb b/static/props/dagger_A.glbindex 1d2e420..1228c68 100644Binary files a/static/props/dagger_A.glb and b/static/props/dagger_A.glb differdiff --git a/static/props/dagger_B.glb b/static/props/dagger_B.glbindex 2bced7e..13e5007 100644Binary files a/static/props/dagger_B.glb and b/static/props/dagger_B.glb differdiff --git a/static/props/fistweapon_A.glb b/static/props/fistweapon_A.glbindex a8f596c..1f44acc 100644Binary files a/static/props/fistweapon_A.glb and b/static/props/fistweapon_A.glb differdiff --git a/static/props/fistweapon_A_stacked.glb b/static/props/fistweapon_A_stacked.glbindex 27a0de5..14e5dc7 100644Binary files a/static/props/fistweapon_A_stacked.glb and b/static/props/fistweapon_A_stacked.glb differdiff --git a/static/props/fistweapon_B.glb b/static/props/fistweapon_B.glbindex 38c98ae..1db0e37 100644Binary files a/static/props/fistweapon_B.glb and b/static/props/fistweapon_B.glb differdiff --git a/static/props/fistweapon_B_stacked.glb b/static/props/fistweapon_B_stacked.glbindex 47f86c1..a453778 100644Binary files a/static/props/fistweapon_B_stacked.glb and b/static/props/fistweapon_B_stacked.glb differdiff --git a/static/props/halberd.glb b/static/props/halberd.glbindex f890cad..62447f9 100644Binary files a/static/props/halberd.glb and b/static/props/halberd.glb differdiff --git a/static/props/hammer_A.glb b/static/props/hammer_A.glbindex 0f6f52c..50ae974 100644Binary files a/static/props/hammer_A.glb and b/static/props/hammer_A.glb differdiff --git a/static/props/hammer_B.glb b/static/props/hammer_B.glbindex 39c3e29..5440693 100644Binary files a/static/props/hammer_B.glb and b/static/props/hammer_B.glb differdiff --git a/static/props/hammer_C.glb b/static/props/hammer_C.glbindex 17d3411..525a864 100644Binary files a/static/props/hammer_C.glb and b/static/props/hammer_C.glb differdiff --git a/static/props/shield_A.glb b/static/props/shield_A.glbindex a8a6450..d11afb3 100644Binary files a/static/props/shield_A.glb and b/static/props/shield_A.glb differdiff --git a/static/props/shield_B.glb b/static/props/shield_B.glbindex a03310f..463b7ba 100644Binary files a/static/props/shield_B.glb and b/static/props/shield_B.glb differdiff --git a/static/props/shield_C.glb b/static/props/shield_C.glbindex 9d6450f..03be016 100644Binary files a/static/props/shield_C.glb and b/static/props/shield_C.glb differdiff --git a/static/props/spear_A.glb b/static/props/spear_A.glbindex 0febc14..2f432db 100644Binary files a/static/props/spear_A.glb and b/static/props/spear_A.glb differdiff --git a/static/props/staff_A.glb b/static/props/staff_A.glbindex 0c66ce8..d96c952 100644Binary files a/static/props/staff_A.glb and b/static/props/staff_A.glb differdiff --git a/static/props/staff_B.glb b/static/props/staff_B.glbindex 24d2076..6fc2dae 100644Binary files a/static/props/staff_B.glb and b/static/props/staff_B.glb differdiff --git a/static/props/sword_A.glb b/static/props/sword_A.glbindex 7e1c2b0..7044d02 100644Binary files a/static/props/sword_A.glb and b/static/props/sword_A.glb differdiff --git a/static/props/sword_B.glb b/static/props/sword_B.glbindex 2b0397f..9dbd6a6 100644Binary files a/static/props/sword_B.glb and b/static/props/sword_B.glb differdiff --git a/static/props/sword_C.glb b/static/props/sword_C.glbindex bc113f1..30cae66 100644Binary files a/static/props/sword_C.glb and b/static/props/sword_C.glb differdiff --git a/static/props/sword_D.glb b/static/props/sword_D.glbindex f93fef4..d3c8b79 100644Binary files a/static/props/sword_D.glb and b/static/props/sword_D.glb differdiff --git a/static/props/sword_E.glb b/static/props/sword_E.glbindex e81a8ff..ac14414 100644Binary files a/static/props/sword_E.glb and b/static/props/sword_E.glb differdiff --git a/static/props/wand_A.glb b/static/props/wand_A.glbindex 3802185..80ac69d 100644Binary files a/static/props/wand_A.glb and b/static/props/wand_A.glb differ