Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Style update for preview. Add theme prefix for webm previews to help with theme switching

Scott Petrovica3e9e220e9b2
diff --git a/src/index.html b/src/index.html
index 39a672e..23adf07 100644
--- a/src/index.html
+++ b/src/index.html
@@ -324,7 +324,7 @@
<button id="export-button" title="Export animations. Make sure to select the animations you want to export first.">
<span class="button-icon-group">
<span class="material-symbols-outlined">save_alt</span>
- <span>Download GLB</span>
+ <span>Download</span>
</span>
</button>
<a id="download-hidden-link" href="#" style="display:none"></a>
diff --git a/src/lib/AnimationSearch.ts b/src/lib/AnimationSearch.ts
index 900704a..b6223bd 100644
--- a/src/lib/AnimationSearch.ts
+++ b/src/lib/AnimationSearch.ts
@@ -103,9 +103,9 @@ export class AnimationSearch {
// Use a placeholder for the video preview, to be replaced by IntersectionObserver
this.animation_list_container.innerHTML +=
`<div class="anim-item">
- <div class="anim-preview-placeholder" data-src="../animpreviews/sample.webm" style="width:80px;height:80px;background:#222;"></div>
- <button class="secondary-button play" data-index="${original_index}">
- ${this.animation_name_clean(animation_clip.name)}
+ <button class="secondary-button play" data-index="${original_index}" style="display: flex; flex-direction:column">
+ <div class="anim-preview-placeholder" data-src="../animpreviews/sample.webm" style="pointer-events: none;"></div>
+ <span class="anim-preview-label">${this.animation_name_clean(animation_clip.name)}</span>
</button>
<div class="styled-checkbox">
<input type="checkbox" name="${animation_clip.name}" value="${original_index}" ${checked_attribute}>
diff --git a/src/preview-generator/preview-generator.ts b/src/preview-generator/preview-generator.ts
index 687a4cf..69da6c9 100644
--- a/src/preview-generator/preview-generator.ts
+++ b/src/preview-generator/preview-generator.ts
@@ -6,7 +6,6 @@ import { WebMRecorder } from './webm-recorder.ts'
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
-import { Utility } from '../lib/Utilities.ts'
import { Generators } from '../lib/Generators.ts'
import { ThemeManager } from '../lib/ThemeManager.ts'
@@ -142,14 +141,18 @@ class PreviewGenerator {
this.mixer_.removeEventListener('finished', handler)
// Stop recording after animation ends
const file = await this.recorder.stop()
- this.zip.file(`${clip.name}.webm`, file)
+
+ console.log('file name saved ', file.name)
+
+ // Start recording before playing the animation
+ this.zip.file(file.name, file)
resolve()
}
this.mixer_.removeEventListener('finished', handler)
this.mixer_.addEventListener('finished', handler)
- // Start recording before playing the animation
- this.recorder.start(`${clip.name}.webm`)
+ const theme_name: string = this.theme_manager.get_current_theme()
+ this.recorder.start(`${theme_name}_${clip.name}.webm`)
action.play()
})
@@ -158,8 +161,10 @@ class PreviewGenerator {
this.current_animation_index_processing += 1
- const temp_limit = 6 // this.animation_clips.length
- if (this.current_animation_index_processing <= temp_limit) {
+ // for testing a few, change to something small like 5
+ const temp_limit = 5 // this.animation_clips.length
+
+ if (this.current_animation_index_processing < temp_limit) {
await this.process_animation_clip()
} else {
console.log('finished processing')
diff --git a/src/preview-generator/webm-recorder.ts b/src/preview-generator/webm-recorder.ts
index 54a0a13..4c7a7fa 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 = 160
- public height: number = 140
+ public width: number = 120
+ public height: number = 80
public fps: number = 24
public kbps: number = 1000
@@ -13,20 +13,20 @@ export class WebMRecorder {
private old_pr: number | null = null
private recorder: MediaRecorder | null = null
private chunks: Blob[] = []
- private file_name: string = ''
private stopped_promise: Promise<void> | null = null
private stopped_resolve: (() => void) | null = null
+ private file_name: string = ''
constructor (renderer: THREE.WebGLRenderer) {
this.renderer_ref = renderer
}
- public start(fileName: string): void {
- this.file_name = fileName
+ public start (saved_name: string): void {
this.old_size = this.renderer_ref.getSize(new THREE.Vector2())
this.old_pr = this.renderer_ref.getPixelRatio()
this.renderer_ref.setPixelRatio(1)
this.renderer_ref.setSize(this.width, this.height, false)
+ this.file_name = saved_name
const stream: MediaStream = this.renderer_ref.domElement.captureStream(this.fps)
this.recorder = new MediaRecorder(stream, {
@@ -37,12 +37,12 @@ export class WebMRecorder {
this.recorder.ondataavailable = e => (e.data.size !== 0) && this.chunks.push(e.data)
this.stopped_promise = new Promise<void>(resolve => {
this.stopped_resolve = resolve
- this.recorder!.onstop = () => resolve()
+ this.recorder!.onstop = () => { resolve() }
})
this.recorder.start()
}
- public async stop(): Promise<File> {
+ public async stop (): Promise<File> {
if (!this.recorder) throw new Error('Recorder not started')
this.recorder.stop()
if (this.stopped_promise) {
diff --git a/src/styles.css b/src/styles.css
index d5e3eb8..064c412 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -58,9 +58,6 @@ h1, h2, h3, h4, h5, h6, input, button, select {
}
-#skinned-step-animation-export-options {
- width: 18rem;
-}
#skinned-step-tools
{
@@ -317,6 +314,11 @@ option {
.anim-item {
display: flex;
justify-content: space-between;
+ padding: 0;
+}
+
+.anim-preview-label {
+ font-size: 75%;
}