Import a 3D Model and automatically assign and export animations
TypeScript
Constrain the preview generator size so aspect ratio is correct. Add documentation for preview generator
Scott Petrovic2e91fce5d66b
diff --git a/src/preview-generator/README.md b/src/preview-generator/README.mdindex b396f9c..a0173df 100644--- a/src/preview-generator/README.md+++ b/src/preview-generator/README.md@@ -1,19 +1,20 @@# Preview Generator-The goal of this preview generator is to create small animated clip previews to use in the animation listing.-+The goal of this preview generator is to create small animated clip previews to use in the animation listing. It is fully done in the web browser. So that is the only "tool" needed.## Workflow-1. Background: Create a 3d setup scene that resembles what is in the application. Maybe we can reuse the Generator-2. Background: Load the human mesh skinned that includes all the animations and add to scene-2a. Background: specify video parameters like screen size, bitrate, and FPS-3. Use the MediaRecorder API to record the 3d canvas- -- Loop through each animation and record each animation.- a Start recording- b Play animation clip- c when animation clip ends, stop recording- d save recording as animation_clip_x.webm to array somewhere- e repeat to step a for each animation- f when all the animations are done being recorded, save everything to a zip file and download\ No newline at end of file+1. Go to the URL manually for the preview generator once the web server is started (command: npm run dev): http://localhost:5173/preview-generator/index.html+2. Select a 3d model that you want to generate animations from the drop-down.+3. Rotate and position the 3d model+4. Press the record button+5. Wait for all the animations to finish playing/recording. A ZIP file will be downloaded when they are all done+6. Place the animation preview webm files in the static/animpreviews folder. Each skeleton type has its own folder.++## Tech talk+In step 1 of the workflow, the model/animation selection pulls the GLB files from the static/animations folder. These files have all the animations as well as a skinned mesh, so we can focus on recording and not skinning.++The recording is all done with the "MediaRecorder API" that is a vanilla javascript API. The JSZIP javascript package does the zipping behavior.++The canvas size on the preview-generator is hard-coded in the preview-generator.ts file. The display on the preview generator is larger than the result will be, but it is easier to position when the canvas size is larger. The UI in the application expects a certain size the previews will be in. This helps with the lazy loading and the preview sizes are hard-coded in the Mesh2Motion app itself in CSS.\ No newline at end of filediff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.tsindex efd619a..2cdf0a5 100644--- a/src/preview-generator/preview-generator.ts+++ b/src/preview-generator/preview-generator.ts@@ -30,11 +30,14 @@ class PreviewGenerator {private selected_file_to_load: string = ''+ private readonly preview_height: number = 120+ private readonly preview_width: number = 100+constructor () {// Setup renderer, scene, camerathis.renderer_ = new THREE.WebGLRenderer({ antialias: true, alpha: true })- this.renderer_.setSize(window.innerWidth, window.innerHeight)this.renderer_.shadowMap.enabled = true // Enable shadows+ this.recorder = new WebMRecorder(this.renderer_, this.preview_width, this.preview_height)// Set Filmic tone mapping for less saturated, more cinematic lookthis.renderer_.toneMapping = THREE.ACESFilmicToneMapping // a bit softer of a look@@ -44,7 +47,6 @@ class PreviewGenerator {this.theme_manager = new ThemeManager()this.zip = new JSZip()- this.recorder = new WebMRecorder(this.renderer_)this.environment_container = new THREE.Group()this.scene_ = new THREE.Scene()@@ -52,6 +54,14 @@ class PreviewGenerator {this.regenerate_floor_grid()+ // set the canvas size and aspect ratio, otherwise distortion happens for models+ // we are adding a multiplier so the preview is higher resolution and easier to position+ const preview_multiplier: number = 4+ this.renderer_.setSize(this.preview_width * preview_multiplier, this.preview_height * preview_multiplier)+ this.camera_.aspect = (this.preview_width * preview_multiplier) / (this.preview_height * preview_multiplier)+ this.camera_.updateProjectionMatrix()++// Add orbit controlsthis.controls_ = new OrbitControls(this.camera_, this.renderer_.domElement)this.controls_.target.set(0, 0.4, 0)diff --git a/src/preview-generator/webm-recorder.ts b/src/preview-generator/webm-recorder.tsindex 863b50b..dce3b07 100644--- a/src/preview-generator/webm-recorder.ts+++ b/src/preview-generator/webm-recorder.ts@@ -1,8 +1,8 @@import * as THREE from 'three'export class WebMRecorder {- public width: number = 100- public height: number = 120+ public width: number+ public height: numberpublic fps: number = 24public kbps: number = 2600@@ -17,8 +17,12 @@ export class WebMRecorder {private stopped_resolve: (() => void) | null = nullprivate file_name: string = ''- constructor (renderer: THREE.WebGLRenderer) {+ constructor (renderer: THREE.WebGLRenderer, preview_width: number, preview_height: number) {this.renderer_ref = renderer+ this.width = preview_width+ this.height = preview_height++ console.log(this.renderer_ref.domElement.height, this.renderer_ref.domElement.width)}public start (saved_name: string): void {