Import a 3D Model and automatically assign and export animations
TypeScript
add default camera to video previews by rig
Scott Petrovic8a55c3b1e5f1
diff --git a/src/lib/RigConfig.ts b/src/lib/RigConfig.tsindex dd840ab..fe1d5b0 100644--- a/src/lib/RigConfig.ts+++ b/src/lib/RigConfig.ts@@ -28,10 +28,18 @@ interface RigSettings {// The bone used for position tracking (e.g., 'hips' or 'head').// we only have one bone per rig that we allow position keyframes (besides root)position_tracking_bone_name: string+ // Camera used by the preview generator for this rig's animation preview videos. Set by hand from the+ // camera position readout on the preview generator page. Without it, the camera is fit to the animations+ preview_camera?: PreviewCamera// keyed by the variation name in the asset manifest. Variations listed here are shown first, in this ordervariations?: Record<string, VariationSettings>}+export interface PreviewCamera {+ position: [number, number, number] // where the camera sits+ target: [number, number, number] // the point the camera looks at+}+export interface ModelVariation {name: string // variation name in the asset manifest, e.g. 'psx-05'model_file: string // Model file path relative to the static root, e.g. 'assets/human/variations/psx-05.glb'@@ -69,6 +77,7 @@ const rig_settings: RigSettings[] = [animation_preview_folder: 'human',position_tracking_bone_name: 'pelvis',skeleton_template_image_url: 'rig-reference/human.png',+ preview_camera: { position: [5.367, 3.298, 13.687], target: [-0.12, 1.104, -0.197] },variations: {base: { display_name: 'Male', attribution: 'Quaternius' },zombie: { display_name: 'Zombie', attribution: 'Kenney.nl' },@@ -107,6 +116,7 @@ const rig_settings: RigSettings[] = [animation_preview_folder: 'fox',position_tracking_bone_name: 'hips',skeleton_template_image_url: 'rig-reference/fox.png',+ preview_camera: { position: [7.395, 5.274, 14.832], target: [-0.279, 1.112, -0.187] },variations: {base: { display_name: 'Fox' },dog: { display_name: 'Dog' },@@ -132,7 +142,8 @@ const rig_settings: RigSettings[] = [rig_display_name: 'Dragon',animation_preview_folder: 'dragon',position_tracking_bone_name: 'hips',- skeleton_template_image_url: 'rig-reference/dragon.png'+ skeleton_template_image_url: 'rig-reference/dragon.png',+ preview_camera: { position: [17.216, 7.122, 23.386], target: [-0.452, 1.362, -0.873] }},{skeleton_type: SkeletonType.Kaiju,@@ -239,6 +250,7 @@ function create_entry (settings: RigSettings): RigConfigEntry | undefined {animation_preview_folder: settings.animation_preview_folder,skeleton_template_image_url: settings.skeleton_template_image_url,position_tracking_bone_name: settings.position_tracking_bone_name,+ preview_camera: settings.preview_camera,model_file: asset_path(manifest_rig.model.file),rig_file: asset_path(manifest_rig.skeleton.file),fps: manifest_rig.fps,diff --git a/src/preview-generator/index.html b/src/preview-generator/index.htmlindex ab63b11..3de0813 100644--- a/src/preview-generator/index.html+++ b/src/preview-generator/index.html@@ -16,6 +16,12 @@<button id="record-button">Record</button></div>+ <div style="position: absolute; top: 60px; right: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px;">+ <span>Camera position</span>+ <pre id="camera-position-output" style="margin: 0; padding: 8px; font-size: 13px; user-select: all; background: rgba(0, 0, 0, 0.25); border-radius: 4px;"></pre>+ <button id="copy-camera-position-button">Copy camera position</button>+ </div>+<div id="record-status" style="position: absolute; bottom: 20px; left: 20px; right: 20px;"></div><select id="animation-file-dropdown" style="position: absolute; top: 20px; left: 20px;">diff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.tsindex 9ef1c4e..8af5c3d 100644--- a/src/preview-generator/preview-generator.ts+++ b/src/preview-generator/preview-generator.ts@@ -14,7 +14,7 @@ import { ThemeManager } from '../lib/ThemeManager.ts'import { AnimationUtility } from '../lib/processes/animations-listing/AnimationUtility.ts'import { DOMUtilities } from '../lib/DOMUtilities.ts'import { SkeletonType } from '../lib/enums/SkeletonType.ts'-import { RigConfig, type RigAnimation } from '../lib/RigConfig.ts'+import { RigConfig, type PreviewCamera, type RigAnimation } from '../lib/RigConfig.ts'type ThemeName = 'light' | 'dark'@@ -88,9 +88,36 @@ class PreviewGenerator {this.controls_.maxDistance = 100this.controls_.update()+ // show the camera position while orbiting so it can be copied into a per-rig setting+ this.controls_.addEventListener('change', () => { this.update_camera_position_output() })+ this.update_camera_position_output()+ document.getElementById('copy-camera-position-button')?.addEventListener('click', () => {+ void navigator.clipboard.writeText(this.camera_position_text())+ })+this.clock_ = new THREE.Clock()}+ private apply_camera (camera: PreviewCamera): void {+ this.camera_.position.fromArray(camera.position)+ this.controls_.target.fromArray(camera.target)+ this.controls_.update()+ this.update_camera_position_output()+ }++ private camera_position_text (): string {+ const format = (vector: THREE.Vector3): string =>+ `[${vector.toArray().map((value) => Number(value.toFixed(3))).join(', ')}]`+ return `position: ${format(this.camera_.position)}\ntarget: ${format(this.controls_.target)}`+ }++ private update_camera_position_output (): void {+ const output = document.getElementById('camera-position-output')+ if (output !== null) {+ output.textContent = this.camera_position_text()+ }+ }+private create_theme_environment (theme: ThemeName): ThemeEnvironment {let grid_color = 0x4b6368let floor_color = 0x2d4353@@ -174,10 +201,16 @@ class PreviewGenerator {AnimationUtility.clean_track_data(this.preview_clips.map(entry => entry.clip), rig.position_tracking_bone_name)}- this.fit_camera_to_animations()+ // use the rig's saved camera so previews stay consistent between runs. Rigs without one get fit automatically+ const camera_source = rig.preview_camera !== undefined ? 'saved camera from RigConfig' : 'auto-fit camera'+ if (rig.preview_camera !== undefined) {+ this.apply_camera(rig.preview_camera)+ } else {+ this.fit_camera_to_animations()+ }this.play_display_clip()this.animate_()- this.set_status(`${this.preview_clips.length} animations loaded. Adjust the camera, then press Record.`)+ this.set_status(`${this.preview_clips.length} animations loaded, using the ${camera_source}. Adjust the camera if needed, then press Record.`)})()})@@ -233,6 +266,7 @@ class PreviewGenerator {this.controls_.target.copy(bounding_sphere.center)this.camera_.position.copy(bounding_sphere.center).addScaledVector(view_direction, distance)this.controls_.update()+ this.update_camera_position_output()}private async start_recording (): Promise<void> {