Import a 3D Model and automatically assign and export animations
TypeScript
use a pole and staff variation
Scott Petrovic7e083fe16a32
diff --git a/src/lib/processes/animations-listing/props/ProceduralPropBuilder.ts b/src/lib/processes/animations-listing/props/ProceduralPropBuilder.tsindex 73ba707..3c3d985 100644--- a/src/lib/processes/animations-listing/props/ProceduralPropBuilder.ts+++ b/src/lib/processes/animations-listing/props/ProceduralPropBuilder.ts@@ -3,13 +3,24 @@ import { CylinderGeometry, Group, Mesh, MeshStandardMaterial } from 'three'export class ProceduralPropBuilder {// sized in meters for a rig at skeleton scale 1.0public static create_pole (): Group {+ return this.create_rod('pole', true)+ }++ public static create_staff (): Group {+ return this.create_rod('staff', false)+ }++ private static create_rod (name: string, origin_at_base: boolean): Group {const pole_group = new Group()const geometry = new CylinderGeometry(0.018, 0.018, 1.7, 12)const material = new MeshStandardMaterial({ color: 0x8b5a2b, roughness: 0.8, metalness: 0.0 })const pole_mesh = new Mesh(geometry, material)- pole_mesh.name = 'prop_pole_mesh'+ pole_mesh.name = `prop_${name}_mesh`pole_mesh.castShadow = true+ if (origin_at_base) {+ pole_mesh.position.y = 0.75+ }pole_group.add(pole_mesh)return pole_groupdiff --git a/src/lib/processes/animations-listing/props/PropCatalog.ts b/src/lib/processes/animations-listing/props/PropCatalog.tsindex 16ee774..3858e36 100644--- a/src/lib/processes/animations-listing/props/PropCatalog.ts+++ b/src/lib/processes/animations-listing/props/PropCatalog.ts@@ -34,6 +34,16 @@ export class PropCatalog {[PropSide.Right]: { along_hand: 0.09, below_palm: 0.035, rotation: new Euler() }},rig_mount_offsets: {}+ },+ {+ type: PropType.Staff,+ display_name: 'Staff',+ create_object: () => ProceduralPropBuilder.create_staff(),+ default_mount_offsets: {+ [PropSide.Left]: { along_hand: 0.09, below_palm: 0.035, rotation: new Euler() },+ [PropSide.Right]: { along_hand: 0.09, below_palm: 0.035, rotation: new Euler() }+ },+ rig_mount_offsets: {}}]diff --git a/src/lib/processes/animations-listing/props/PropType.ts b/src/lib/processes/animations-listing/props/PropType.tsindex 3512946..0002590 100644--- a/src/lib/processes/animations-listing/props/PropType.ts+++ b/src/lib/processes/animations-listing/props/PropType.ts@@ -1,4 +1,5 @@export enum PropType {None = 'none',- Pole = 'pole'+ Pole = 'pole',+ Staff = 'staff'}diff --git a/src/lib/processes/animations-listing/props/Props.test.ts b/src/lib/processes/animations-listing/props/Props.test.tsindex 22e5b40..9efe921 100644--- a/src/lib/processes/animations-listing/props/Props.test.ts+++ b/src/lib/processes/animations-listing/props/Props.test.ts@@ -1,6 +1,9 @@import { describe, it, expect } from 'vitest'import { Bone, Group, Mesh, Skeleton } from 'three'import { HandBoneResolver } from './HandBoneResolver'+import { PropCatalog } from './PropCatalog'+import { ProceduralPropBuilder } from './ProceduralPropBuilder'+import { PropType } from './PropType'import { PropsExportFilter, PROP_USER_DATA_KEY } from './PropsExportFilter'import { PropSide } from './PropSide'@@ -12,6 +15,17 @@ function make_skeleton (names: string[]): Skeleton {}))}+describe('Procedural props', () => {+ it('keeps the staff centered and places the pole origin at its base', () => {+ const staff_mesh = ProceduralPropBuilder.create_staff().children[0] as Mesh+ const pole_mesh = ProceduralPropBuilder.create_pole().children[0] as Mesh++ expect(staff_mesh.position.y).toBe(0)+ expect(pole_mesh.position.y).toBe(0.75)+ expect(PropCatalog.all().map((definition) => definition.type)).toEqual([PropType.Pole, PropType.Staff])+ })+})+describe('HandBoneResolver', () => {it('finds exact hand bone names', () => {const skeleton = make_skeleton(['pelvis', 'hand_l', 'index_01_l', 'hand_r'])diff --git a/static/images/icons/props.svg b/static/images/icons/props.svgindex 736e2b2..8539427 100644--- a/static/images/icons/props.svg+++ b/static/images/icons/props.svg@@ -1,12 +1,32 @@-<svg width="100%" height="100%" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">- <defs>- <g id="sword" style="fill:rgb(212,212,212);">- <path d="M12,1.5L13.1,3.6L13.1,15L10.9,15L10.9,3.6Z"/>- <rect x="8.6" y="15" width="6.8" height="1.5" rx="0.5"/>- <rect x="11.35" y="16.5" width="1.3" height="3.6"/>- <circle cx="12" cy="21" r="1.3"/>- </g>- </defs>- <use href="#sword" transform="rotate(45 12 12)"/>- <use href="#sword" transform="rotate(-45 12 12)"/>+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g id="sword" transform="matrix(0.707107,0.707107,-0.707107,0.707107,13.5,-4.970563)">+ <g transform="matrix(1.101068,0,0,1.398909,-3.307338,-2.293416)">+ <path d="M12,2.5L13.7,4.8L13.7,14.5L10.3,14.5L10.3,4.8L12,2.5Z" style="fill:rgb(212,212,212);fill-rule:nonzero;"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,-3.307338,1.66698)">+ <path d="M16,15.136L16,15.864C16,16.215 15.715,16.5 15.364,16.5L8.636,16.5C8.285,16.5 8,16.215 8,15.864L8,15.136C8,14.785 8.285,14.5 8.636,14.5L15.364,14.5C15.715,14.5 16,14.785 16,15.136Z" style="fill:rgb(212,212,212);"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,-3.307338,0.68809)">+ <rect x="11" y="16.5" width="2" height="3" style="fill:rgb(212,212,212);"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,-3.307338,0.68809)">+ <circle cx="12" cy="20.5" r="1.7" style="fill:rgb(212,212,212);"/>+ </g>+ </g>+ <g id="sword1" serif:id="sword" transform="matrix(0.707107,-0.707107,0.707107,0.707107,-6.470563,12)">+ <g transform="matrix(1.101068,-0,0,1.398909,0.881703,-2.293416)">+ <path d="M12,2.5L13.7,4.8L13.7,14.5L10.3,14.5L10.3,4.8L12,2.5Z" style="fill:rgb(212,212,212);fill-rule:nonzero;"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,0.881703,1.828638)">+ <path d="M16,15.136L16,15.864C16,16.215 15.715,16.5 15.364,16.5L8.636,16.5C8.285,16.5 8,16.215 8,15.864L8,15.136C8,14.785 8.285,14.5 8.636,14.5L15.364,14.5C15.715,14.5 16,14.785 16,15.136Z" style="fill:rgb(212,212,212);"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,0.881703,0.68809)">+ <rect x="11" y="16.5" width="2" height="3" style="fill:rgb(212,212,212);"/>+ </g>+ <g transform="matrix(1.101068,0,0,1.101068,0.881703,0.68809)">+ <circle cx="12" cy="20.5" r="1.7" style="fill:rgb(212,212,212);"/>+ </g>+ </g></svg>