Import a 3D Model and automatically assign and export animations
TypeScript
Add model drop zone and A-pose tips for human rig
Scott Petrovica265120f8a50
diff --git a/src/create.html b/src/create.htmlindex dbc33d7..7e0dd9e 100644--- a/src/create.html+++ b/src/create.html@@ -53,15 +53,16 @@<div id="load-model-tools"><!-- <p class="step-instructions">Supports GLB, GLTF, FBX</p> -->- <label- for="model-upload"- class="button"- data-tippy-content="GLB and FBX preferred. ZIP is for GLTF+BIN and textures separately. DAE+textures is also supported in ZIP format."- >- <span class="button-icon-group">- <img src="images/icons/upload.svg" alt="Upload" width="16" height="16" />- <span>Upload</span>- <img src="images/icons/help.svg" alt="Help" width="20" height="20" />+ <!-- drop area for the model file. clicking anywhere in it also opens the file picker -->+ <label id="model-drop-zone" for="model-upload">+ <img src="images/icons/upload.svg" alt="" width="32" height="32" />+ <span class="model-drop-zone-title">Drop your 3D model here</span>+ <span class="model-drop-zone-subtext">or click to browse</span>+ <span class="model-drop-zone-subtext">+ GLB, FBX, or ZIP+ <img+ data-tippy-content="GLB and FBX preferred. ZIP is for GLTF+BIN and textures separately. DAE+textures is also supported in ZIP format."+ src="images/icons/help.svg" alt="Help" width="16" height="16" /></span></label><input@@ -208,6 +209,18 @@<img class="skeleton-template-image-preview ignore-filters" src="images/icons/zoom.svg" alt="Preview image" width="20" height="20" /></div>+ <!-- posing tips. only shown for the human skeleton -->+ <div id="model-pose-instructions">+ <p class="model-pose-instructions-heading">Tips</p>+ <p>The 3d models work best with a <strong>T-pose</strong> by default (arms straight out to the sides).</p>+ <p>Using an <strong>A-pose</strong> model (arms angled down)?</p>+ <ol>+ <li>Set Positioning to <strong>Transform Widget</strong></li>+ <li>Choose the <strong>Rotation</strong> transform</li>+ <li>Select each shoulder / upper arm bone and rotate it down to line up with the arm</li>+ </ol>+ </div>+<div style="display: flex; flex-direction: column;"><div class="pill-switch-group" aria-label="Positioning mode">diff --git a/src/lib/UI.ts b/src/lib/UI.tsindex 4d4e019..d2b2978 100644--- a/src/lib/UI.ts+++ b/src/lib/UI.ts@@ -61,6 +61,8 @@ export class UI {dom_preview_plane_height_label: HTMLElement | null = nulldom_preview_plane_setting_container: HTMLElement | null = null+ dom_model_pose_instructions: HTMLElement | null = null+// arm plane controlsdom_use_arm_plane_container: HTMLElement | null = nulldom_arm_plane_checkbox: HTMLInputElement | null = null@@ -196,6 +198,8 @@ export class UI {this.dom_preview_plane_height_label = document.querySelector('#preview-plane-height-label')this.dom_preview_plane_setting_container = document.querySelector('#preview-plane-setting-container')+ this.dom_model_pose_instructions = document.querySelector('#model-pose-instructions')+// arm plane controlsthis.dom_use_arm_plane_container = document.querySelector('#use-arm-plane-container')this.dom_arm_plane_checkbox = document.querySelector('#arm-plane-checkbox')diff --git a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts b/src/lib/processes/edit-skeleton/StepEditSkeleton.tsindex c5f60ad..76bb7ff 100644--- a/src/lib/processes/edit-skeleton/StepEditSkeleton.ts+++ b/src/lib/processes/edit-skeleton/StepEditSkeleton.ts@@ -125,6 +125,11 @@ export class StepEditSkeleton extends EventTarget {}}+ // T-pose / A-pose tips only apply to the human skeleton+ if (this.ui.dom_model_pose_instructions != null) {+ this.ui.dom_model_pose_instructions.style.display = skeleton_type === SkeletonType.Human ? 'block' : 'none'+ }+// only human skeletons have the arm plane correction optionif (this.ui.dom_use_arm_plane_container != null) {if (skeleton_type === SkeletonType.Human) {diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex 88574f8..d764f06 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -124,15 +124,8 @@ export class StepLoadModel extends EventTarget {// handle file uploadthis.ui.dom_upload_model_button.addEventListener('change', (event: Event) => {const file = event.target.files[0]- const file_extension: string = Utility.get_file_extension(file.name)- this.source_file_name = file.name-- const reader = new FileReader()- reader.readAsDataURL(file)- reader.onload = () => {- console.log('File reader loaded', reader)- this.load_model_file(reader.result, file_extension)- }+ if (file === undefined) return+ this.load_uploaded_file(file)})// iOS has a weird issue with accepted file extensions, so we need to just@@ -142,6 +135,8 @@ export class StepLoadModel extends EventTarget {}}+ this.add_drop_zone_event_listeners()+if (this.ui.dom_load_model_debug_checkbox !== null) {this.ui.dom_load_model_debug_checkbox.addEventListener('change', (event: Event) => {const debug_mode = event.target.checked@@ -164,6 +159,51 @@ export class StepLoadModel extends EventTarget {}}+ private add_drop_zone_event_listeners (): void {+ const drop_zone = document.querySelector<HTMLElement>('#model-drop-zone')+ if (drop_zone === null) return++ drop_zone.addEventListener('dragover', (event: DragEvent) => {+ event.preventDefault()+ drop_zone.classList.add('drag-over')+ })++ drop_zone.addEventListener('dragleave', () => {+ drop_zone.classList.remove('drag-over')+ })++ drop_zone.addEventListener('drop', (event: DragEvent) => {+ event.preventDefault()+ drop_zone.classList.remove('drag-over')++ const file = event.dataTransfer?.files[0]+ if (file === undefined) return+ this.load_uploaded_file(file)+ })++ // a file dropped outside the drop zone would make the browser navigate away+ // and open it, which loses all progress. swallow those drops instead+ window.addEventListener('dragover', (event: DragEvent) => { event.preventDefault() })+ window.addEventListener('drop', (event: DragEvent) => { event.preventDefault() })+ }++ private load_uploaded_file (file: File): void {+ const file_extension: string = Utility.get_file_extension(file.name).toLowerCase()+ if (!['glb', 'fbx', 'zip'].includes(file_extension)) {+ new ModalDialog('Unsupported file type', 'Please use a GLB, FBX, or ZIP (GLTF+BIN) file.').show()+ return+ }++ this.source_file_name = file.name++ const reader = new FileReader()+ reader.readAsDataURL(file)+ reader.onload = () => {+ console.log('File reader loaded', reader)+ this.load_model_file(reader.result, file_extension)+ }+ }+public clear_loaded_model_data (): void {this.original_model_data = new Scene()this.final_mesh_data = new Scene()diff --git a/src/styles.css b/src/styles.cssindex 1876711..819daa3 100644--- a/src/styles.css+++ b/src/styles.css@@ -503,6 +503,71 @@ option {row-gap: 0.4rem;}+#model-drop-zone {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 0.4rem;+ padding: 1.5rem 1rem;+ border: 2px dashed var(--text-alternate);+ border-radius: 8px;+ background: color-mix(in srgb, var(--bg-alternate) 60%, transparent);+ cursor: pointer;+ text-align: center;+ transition: background-color 0.2s ease, border-color 0.2s ease;+}++#model-drop-zone:hover,+#model-drop-zone.drag-over {+ border-color: var(--button-primary-bg);+ background: var(--bg-alternate);+}++/* keep child elements from firing their own dragleave events while hovering over the zone */+#model-drop-zone.drag-over * {+ pointer-events: none;+}++#model-drop-zone .model-drop-zone-title {+ font-size: 1.15rem;+}++#model-drop-zone .model-drop-zone-subtext {+ display: inline-flex;+ align-items: center;+ gap: 0.3rem;+ color: var(--text-alternate);+}++#model-pose-instructions {+ background-color: var(--bg-alternate);+ border-left: 4px solid var(--button-primary-bg);+ padding: 0.75rem 1rem;+ margin-top: 0.5rem;++ /* keep the panel at its normal width. the undo/redo buttons are positioned against it */+ max-width: 260px;+ box-sizing: border-box;+}++#model-pose-instructions p {+ margin: 0 0 0.5rem 0;+}++#model-pose-instructions .model-pose-instructions-heading {+ font-size: 1.1rem;+}++#model-pose-instructions ol {+ margin: 0;+ padding-left: 1.25rem;+}++#model-pose-instructions li {+ display: list-item;+ margin-bottom: 0.25rem;+}+#tool-panel {position: fixed;height: fit-content;