Import a 3D Model and automatically assign and export animations
TypeScript
merge and squash all the dragon branch stuff to main for new development work
Scott Petroviceaf2d1c82e9c
diff --git a/LICENSE b/LICENSEindex 8395d3a..e794755 100644--- a/LICENSE+++ b/LICENSE@@ -1,6 +1,6 @@MIT License-Copyright (c) 2023 Scott Petrovic+Copyright (c) 2025 Scott PetrovicPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealdiff --git a/src/index.html b/src/index.htmlindex 922d535..b9d8ec3 100644--- a/src/index.html+++ b/src/index.html@@ -65,7 +65,7 @@</label><input id="model-upload" type="file" name="file-upload" accept=".glb, .zip, .fbx" />- <span class="material-symbols-outlined" data-tippy-content="GLB and FBX preferred. ZIP is for GLTF that includes BIN and textures separately.">help</span>+ <span class="material-symbols-outlined" data-tippy-content="GLB and FBX preferred. ZIP is for GLTF+BIN and textures separately. DAE+textures is also supported in ZIP format.">help</span><div style="text-align: center; font-size: 1.5rem">or</div>@@ -73,9 +73,10 @@<div class="alternate-background-section"><p style="margin: 0">Reference model:</p><select id="model-selection">- <option value="models/human-mannequin.glb">Human</option>- <option value="models/fox.glb">Fox</option>- <option value="models/seagull.glb">Bird</option>+ <option value="models/model-human.glb">Human</option>+ <option value="models/model-fox.glb">Fox</option>+ <option value="models/model-bird.glb">Bird</option>+ <option value="models/model-dragon.glb">Dragon</option></select><button id="load-model-button">Load</button></div>@@ -123,6 +124,7 @@<option value="human">Human</option><option value="quadraped">4 Leg Creature</option><option value="bird">Bird</option>+ <option value="dragon">Dragon</option></select></div>diff --git a/src/lib/enums/SkeletonType.ts b/src/lib/enums/SkeletonType.tsindex 4a271a7..6fb5737 100644--- a/src/lib/enums/SkeletonType.ts+++ b/src/lib/enums/SkeletonType.ts@@ -1,9 +1,10 @@// Supported skeleton types// the file names for the skeleton types are associated with the constexport enum SkeletonType {- Quadraped = 'skeletons/skeleton-quadraped.glb',- Human = 'skeletons/human-skeleton.glb',- Bird = 'skeletons/skeleton-bird.glb',+ Quadraped = 'rigs/rig-fox.glb',+ Human = 'rigs/rig-human.glb',+ Bird = 'rigs/rig-bird.glb',+ Dragon = 'rigs/rig-dragon.glb',Error = 'ERROR',None = 'NONE'}diff --git a/src/lib/processes/animations-listing/AnimationSearch.ts b/src/lib/processes/animations-listing/AnimationSearch.tsindex 960b511..3c52b61 100644--- a/src/lib/processes/animations-listing/AnimationSearch.ts+++ b/src/lib/processes/animations-listing/AnimationSearch.ts@@ -149,6 +149,13 @@ export class AnimationSearch extends EventTarget {case SkeletonType.Bird:preview_folder = 'bird'break+ case SkeletonType.Dragon:+ preview_folder = 'dragon'+ break+ default:+ preview_folder = 'error'+ console.error('Unknown skeleton type for animation previews. Update AnimationSearch.ts switch statement.')+ break}const anim_name: string = animation_clip.namediff --git a/src/lib/processes/animations-listing/StepAnimationsListing.ts b/src/lib/processes/animations-listing/StepAnimationsListing.tsindex 75109ef..089bbff 100644--- a/src/lib/processes/animations-listing/StepAnimationsListing.ts+++ b/src/lib/processes/animations-listing/StepAnimationsListing.ts@@ -5,7 +5,8 @@ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import {type AnimationClip, AnimationMixer, Quaternion, Vector3, type SkinnedMesh, type QuaternionKeyframeTrack,- type KeyframeTrack, type AnimationAction, type Object3D, Bone+ type KeyframeTrack, type AnimationAction, type Object3D, Bone,+ Skeleton} from 'three'import { SkeletonType } from '../../enums/SkeletonType.ts'@@ -125,6 +126,11 @@ export class StepAnimationsListing extends EventTarget {case SkeletonType.Bird:animations_to_load_filepaths = ['animations/bird-animations.glb']break+ case SkeletonType.Dragon:+ animations_to_load_filepaths = ['animations/dragon-animations.glb']+ break+ default:+ console.error('Unknown skeleton type for loading animations. Add GLB file to animation listing process')}this.gltf_animation_loader = new GLTFLoader()diff --git a/src/lib/processes/load-model/CustomDAELoader.ts b/src/lib/processes/load-model/CustomDAELoader.tsnew file mode 100644index 0000000..81678da--- /dev/null+++ b/src/lib/processes/load-model/CustomDAELoader.ts@@ -0,0 +1,147 @@+import JSZip from 'jszip'+import { EventDispatcher } from 'three'+import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader.js'+import { ModalDialog } from '../../ModalDialog'++/**+ * Loads a DAE (with textures) from a ZIP file buffer, using in-memory URLs for all assets.+ * Usage: new CustomDAELoader(colladaLoaderInstance).loadFromZip(zipBuffer, (scene) => { ... })+ */+export class CustomDAELoader extends EventDispatcher {+ private readonly loader: ColladaLoader++ constructor (loader: ColladaLoader) {+ super()+ this.loader = loader+ }++ /**+ * Main entry: Loads a DAE (with textures) from a ZIP file buffer, using in-memory URLs for all assets.+ */+ public async load_from_zip (+ zip_data: ArrayBuffer,+ onLoad: (scene: any) => void,+ onError?: (err: any) => void+ ): Promise<void> {+ try {+ // 1. Load and scan the ZIP for DAE file+ const zip_file: JSZip = await JSZip.loadAsync(zip_data)+ const dae_file = this.find_dae_file(zip_file)+ if (!dae_file) throw new Error('No DAE file found in ZIP')++ // 2. Build a map of all relevant files (textures, dae) by filename+ const file_map: Record<string, Uint8Array> = await this.build_file_map(zip_file)++ // 3. Patch loader to use in-memory blobs for all referenced files+ this.loader.manager.setURLModifier(this.make_url_modifier(file_map))++ // Add error listener for texture/resource loading+ this.loader.manager.itemError = (url: string) => {+ new ModalDialog('Could not find file in ZIP', `${this.get_last_segment_of_url(url)}`).show()+ }++ // 4. Load the DAE from the in-memory XML blob+ const dae_text = await dae_file.async('text')+ const dae_blob = new Blob([dae_text], { type: 'model/vnd.collada+xml' })+ const dae_url = URL.createObjectURL(dae_blob)++ this.loader.load(+ dae_url,+ (collada) => {+ const loaded_scene = collada.scene++ console.log('DAE model loaded from ZIP:', loaded_scene)++ onLoad(loaded_scene)+ URL.revokeObjectURL(dae_url)+ },+ undefined,+ (err) => {+ if (onError != null) {+ onError(err)+ }+ }+ )+ } catch (err) {+ if (onError != null) {+ onError(err)+ }+ }+ // cleanup error handler+ this.loader.manager.onError = null+ }++ /**+ * Scans the ZIP for .dae file and returns its file object.+ */+ private find_dae_file (zip: JSZip): any {+ let dae_file: any = null+ zip.forEach((relativePath, file) => {+ if (relativePath.toLowerCase().endsWith('.dae')) {+ dae_file = file+ }+ })+ return dae_file+ }++ /**+ * Builds a map of all relevant files (textures, dae) by filename (case-insensitive, handles spaces).+ */+ private async build_file_map (zip: JSZip): Promise<Record<string, Uint8Array>> {+ const fileMap: Record<string, Uint8Array> = {}+ const filePromises = Object.keys(zip.files).map(async (filename) => {+ const file = zip.files[filename]+ if (!file.dir) {+ const nameOnly = filename.split('/').pop() ?? filename+ if (/\.(dae|png|jpg|jpeg|webp)$/i.test(nameOnly)) {+ const buffer = new Uint8Array(await file.async('arraybuffer'))+ fileMap[nameOnly] = buffer+ fileMap[nameOnly.toLowerCase()] = buffer+ try {+ const decoded = decodeURIComponent(nameOnly)+ fileMap[decoded] = buffer+ fileMap[decoded.toLowerCase()] = buffer+ } catch {}+ }+ }+ })+ await Promise.all(filePromises)+ return fileMap+ }++ /**+ * Returns a URL modifier function for the loader, serving in-memory blobs for referenced files.+ */+ private make_url_modifier (file_map: Record<string, Uint8Array>): (url: string) => string {+ return (url: string) => {+ const clean_url = url.split(/[?#]/)[0]+ const name_only: string = clean_url.split('/').pop() ?? clean_url+ let buffer: Uint8Array | undefined = file_map[name_only]+ if (!buffer) buffer = file_map[name_only.toLowerCase()]+ if (!buffer) {+ try {+ const decoded = decodeURIComponent(name_only)+ buffer = file_map[decoded] || file_map[decoded.toLowerCase()]+ } catch {}+ }+ if (buffer) {+ let mime = 'application/octet-stream'+ if (/\.png$/i.test(name_only)) mime = 'image/png'+ else if (/\.jpe?g$/i.test(name_only)) mime = 'image/jpeg'+ else if (/\.webp$/i.test(name_only)) mime = 'image/webp'+ else if (/\.dae$/i.test(name_only)) mime = 'model/vnd.collada+xml'+ const blob = new Blob([buffer], { type: mime })+ return URL.createObjectURL(blob)+ }+ return url+ }+ }++ /**+ * Gets the last segment of a URL path.+ */+ private get_last_segment_of_url (path: string): string {+ const segments = path.split('/')+ return segments[segments.length - 1]+ }+}diff --git a/src/lib/processes/load-model/ZipGLTFLoader.ts b/src/lib/processes/load-model/CustomGLTFLoader.tssimilarity index 97%rename from src/lib/processes/load-model/ZipGLTFLoader.tsrename to src/lib/processes/load-model/CustomGLTFLoader.tsindex ed3cbce..c7f29ca 100644--- a/src/lib/processes/load-model/ZipGLTFLoader.ts+++ b/src/lib/processes/load-model/CustomGLTFLoader.ts@@ -6,9 +6,9 @@ import { ModalDialog } from '../../ModalDialog'/*** Loads a GLTF (with BIN and textures) from a ZIP file buffer, using in-memory URLs for all assets.- * Usage: new ZipGLTFLoader(gltfLoaderInstance).loadFromZip(zipBuffer, (scene) => { ... })+ * Usage: new CustomGLTFLoader(gltfLoaderInstance).loadFromZip(zipBuffer, (scene) => { ... })*/-export class ZipGLTFLoader extends EventDispatcher {+export class CustomGLTFLoader extends EventDispatcher {private readonly loader: GLTFLoaderconstructor (loader: GLTFLoader) {diff --git a/src/lib/processes/load-model/ModelZipLoader.ts b/src/lib/processes/load-model/ModelZipLoader.tsnew file mode 100644index 0000000..1a16e9f--- /dev/null+++ b/src/lib/processes/load-model/ModelZipLoader.ts@@ -0,0 +1,94 @@+import JSZip from 'jszip'++import { CustomGLTFLoader } from './CustomGLTFLoader'+import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'+import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader.js'+import { CustomDAELoader } from './CustomDAELoader'++// things that might be in the ZIP file+export type ModelFormat = 'gltf' | 'dae' | 'unknown'++export interface ZipModelInfo {+ format: ModelFormat+ fileName: string+ fileData: ArrayBuffer+}++export class ModelZipLoader {+ /**+ * Unzips and analyzes a ZIP file buffer, returning model file info and format.+ * @param buffer - ZIP file as ArrayBuffer+ * @returns ZipModelInfo or throws error if not found+ */+ public async analyzeZip (buffer: ArrayBuffer): Promise<ZipModelInfo> {+ const zip = await JSZip.loadAsync(buffer)+ const file_names = Object.keys(zip.files)+ const model_file = this.findModelFile(file_names)+ if (model_file == null || model_file === '') {+ throw new Error('No supported model file found in ZIP')+ }+ const format = this.detectFormat(model_file)+ const file_data = await zip.files[model_file].async('arraybuffer')+ return { format, fileName: model_file, fileData: file_data }+ }++ /**+ * Loads a model from a ZIP buffer using the appropriate loader and returns the loaded object.+ * @param buffer - ZIP file as ArrayBuffer+ * @returns Promise<Object3D> - The loaded model object+ */+ public async loadModelFromZip (buffer: ArrayBuffer): Promise<any> {+ const info = await this.analyzeZip(buffer)+ switch (info.format) {+ case 'gltf': {+ const gltf_loader_instance = new GLTFLoader()+ const custom_gltf_loader = new CustomGLTFLoader(gltf_loader_instance)+ // Wrap callback in a Promise to return the loaded scene+ return await new Promise((resolve, reject) => {+ custom_gltf_loader.load_from_zip(+ buffer,+ (scene) => { resolve(scene) },+ (err) => { reject(err) }+ )+ })+ }+ // TODO: OBJ can use this too. They have external texture files+ // case 'obj': {+ // console.log('Using OBJ loader since OBJ file detected in ZIP')+ // const obj_loader = new CustomOBJLoader()+ // return await obj_loader.load_from_zip(buffer)+ // }+ case 'dae': {+ console.log('Using DAE loader since DAE file detected in ZIP')+ // use custom dae loader+ const collada_loader_instance = new CustomDAELoader(new ColladaLoader())+ return await new Promise((resolve, reject) => {+ collada_loader_instance.load_from_zip(+ buffer,+ (scene) => { resolve(scene) },+ (err) => { reject(err) }+ )+ })+ }+ default:+ throw new Error('Unsupported model format')+ }+ }++ private findModelFile (file_names: string[]): string | null {+ // Prioritize GLTF, then DAE+ const priorities = [/\.gltf$/i, /\.dae$/i]+ for (const regex of priorities) {+ const found = file_names.find(name => regex.test(name))+ if (found != null && found !== '') return found+ }+ return null+ }++ private detectFormat (file_name: string): ModelFormat {+ if (/\.gltf$/i.test(file_name)) return 'gltf'+ if (/\.dae$/i.test(file_name)) return 'dae'+ // if (/\.obj$/i.test(file_name)) return 'obj'+ return 'unknown'+ }+}diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex 655711a..c82415d 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -1,5 +1,5 @@import { UI } from '../../UI.ts'-import { ZipGLTFLoader } from './ZipGLTFLoader.ts'+import { ModelZipLoader } from './ModelZipLoader.ts'import { Box3 } from 'three/src/math/Box3.js'import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'@@ -162,6 +162,7 @@ export class StepLoadModel extends EventTarget {this.process_loaded_scene(loaded_scene)})} else if (file_extension === 'zip') {+ console.log('ZIP file can contain GLTF+BIN model data')this.handle_zip_file(model_file_path)} else {console.error('Unsupported file format to load. Only acccepts FBX, (ZIP)GLTF+BIN, GLB:', model_file_path)@@ -173,32 +174,37 @@ export class StepLoadModel extends EventTarget {* supporting both data URLs and ArrayBuffer input.*/private handle_zip_file (model_file_path: string | ArrayBuffer | null): void {- // Handle loading a ZIP file with GLTF data inside it- const handle_zip = (buffer: ArrayBuffer): void => {- const zip_loader = new ZipGLTFLoader(this.gltf_loader)- zip_loader.load_from_zip(buffer, (scene) => {- this.process_loaded_scene(scene) // loaded successfully...continue- }, (err: Error) => {- console.error('Failed to load GLTF from ZIP:', err)- new ModalDialog('Failed to load GLTF from ZIP: ', err?.message || err).show()- }).catch((err: Error) => {- console.error('Error loading ZIP:', err)- new ModalDialog('Error loading ZIP: ', err?.message || err).show()- })+ const zip_loader = new ModelZipLoader()++ // internal async function that loads the ZIP from an ArrayBuffer+ const handle_zip = async (buffer: ArrayBuffer): Promise<void> => {+ try {+ const scene = await zip_loader.loadModelFromZip(buffer)+ console.log('Model loaded from ZIP:', scene)+ this.process_loaded_scene(scene)+ } catch (err) {+ // if no GLTF file found, or other error, show dialog+ console.error('Failed to load model from ZIP:', err)+ new ModalDialog('Failed to load model from ZIP: ', err?.message || err).show()+ }}- // support both data URLs+ // load in the zip and send the array buffer data to the loaderif (typeof model_file_path === 'string' && model_file_path.startsWith('data:')) {fetch(model_file_path)- .then(async res => await res.arrayBuffer())- .then(buffer => { handle_zip(buffer) })- .catch((err: Error) => {+ .then(async res => await res.arrayBuffer()) // convert to ArrayBuffer for processing+ .then(buffer => handle_zip(buffer).catch((err) => {+ const msg = (err && typeof err === 'object' && 'message' in err) ? err.message : String(err)+ console.error('Failed to load model from ZIP:', err)+ new ModalDialog('Failed to load model from ZIP: ', msg).show()+ }))+ .catch((err) => {+ const msg = (err && typeof err === 'object' && 'message' in err) ? err.message : String(err)console.error('Failed to fetch ZIP data:', err)- new ModalDialog('Failed to fetch ZIP data: ', err?.message || err).show()+ new ModalDialog('Failed to fetch ZIP data: ', msg).show()})- } else if (model_file_path instanceof ArrayBuffer) {- handle_zip(model_file_path)} else {+ // ZIP file is corrupted??const msg = 'ZIP file data is not in a supported format'console.error(msg)new ModalDialog('ZIP file error decompressing: ', msg).show()diff --git a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts b/src/lib/processes/load-skeleton/PreviewSkeletonManager.tsindex 10a5036..5aa477a 100644--- a/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts+++ b/src/lib/processes/load-skeleton/PreviewSkeletonManager.ts@@ -9,39 +9,48 @@ const skeleton_group_name: string = 'preview_skeleton_group'// need a function that will add a preview skeleton to the scene// this will remove any existing preview skeleton first// and then add the new one based on the selected type-export async function add_preview_skeleton (root: Scene, skeleton_file_path: SkeletonType,- hand_skeleton_type: HandSkeletonType, skeleton_scale: number = 1.0): Promise<Object3D<Object3DEventMap>> {- remove_preview_skeleton(root)+export async function add_preview_skeleton (+ root: Scene,+ skeleton_file_path: SkeletonType,+ hand_skeleton_type: HandSkeletonType,+ skeleton_scale: number = 1.0+): Promise<Object3D<Object3DEventMap>> {+ let preview_skeleton_group = root.getObjectByName(skeleton_group_name) as Group | undefined- // always create a new group for the preview skeleton- // checking if a preview skeleton exist before occasionally- // caused duplicate skeletons to appear on the scene- const preview_skeleton_group = new Group()+ // Check if preview skeleton group exists and matches requested skeleton+ if (preview_skeleton_group !== undefined) {+ // Read previous skeleton info from userData+ const previous_file_path = preview_skeleton_group.userData.skeleton_file_path+ const previous_hand_type = preview_skeleton_group.userData.hand_skeleton_type+ if (previous_file_path === skeleton_file_path && previous_hand_type === hand_skeleton_type) {+ // Only update scale+ preview_skeleton_group.scale.set(skeleton_scale, skeleton_scale, skeleton_scale)+ // Return the first child (should be loaded_scene)+ return preview_skeleton_group.children[0]+ } else {+ // Remove old skeleton group+ remove_preview_skeleton(root)+ }+ }++ // Create new preview skeleton group+ preview_skeleton_group = new Group()preview_skeleton_group.name = skeleton_group_name+ // Store current skeleton info for future comparison+ preview_skeleton_group.userData.skeleton_file_path = skeleton_file_path+ preview_skeleton_group.userData.hand_skeleton_type = hand_skeleton_typeroot.add(preview_skeleton_group)- // need some logic to load the actual skeleton based on the type- // we can only see the skeleton helper, so jwe will add that to the group+ // Load and customize skeletonconst loaded_scene: Object3D<Object3DEventMap> = await load_skeleton(skeleton_file_path)-- // console.log('loaded skeleton file path: ', loaded_scene, hand_skeleton_type)-- // skeleton customization options here. Right now only for humans and handsif (skeleton_file_path === SkeletonType.Human) {- // apply hand skeleton modifications for human skeletonsconst helper = new HandHelper()helper.modify_hand_skeleton(loaded_scene, hand_skeleton_type)}-- // need to convert the loaded scene into a custom skeleton helperconst skeleton_helper = new SkeletonHelper(loaded_scene.children[0])skeleton_helper.name = 'preview_skeleton'preview_skeleton_group.add(skeleton_helper)-- // apply skeleton scalingpreview_skeleton_group.scale.set(skeleton_scale, skeleton_scale, skeleton_scale)-- // finally add the preview skeleton group to the final sceneroot.add(preview_skeleton_group)return loaded_scene}@@ -56,7 +65,7 @@ async function load_skeleton (file_path: string): Promise<Object3D<Object3DEvent// need a function that will remove the preview skeleton from the sceneexport function remove_preview_skeleton (root: Scene): void {const skeleton_group = root.getObjectByName(skeleton_group_name)- if (skeleton_group !== undefined && skeleton_group.parent) {+ if ((skeleton_group?.parent) != null) {skeleton_group.parent.remove(skeleton_group)}}diff --git a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts b/src/lib/processes/load-skeleton/StepLoadSkeleton.tsindex ba64532..5d08804 100644--- a/src/lib/processes/load-skeleton/StepLoadSkeleton.ts+++ b/src/lib/processes/load-skeleton/StepLoadSkeleton.ts@@ -104,6 +104,8 @@ export class StepLoadSkeleton extends EventTarget {return SkeletonType.Birdcase 'select-skeleton':return SkeletonType.None+ case 'dragon':+ return SkeletonType.Dragondefault:console.error('unknown skeleton type selected: ', skeleton_file)return SkeletonType.Errordiff --git a/src/lib/solvers/SolverDistanceChildTargeting.ts b/src/lib/solvers/SolverDistanceChildTargeting.tsindex f6d0807..2fc831a 100644--- a/src/lib/solvers/SolverDistanceChildTargeting.ts+++ b/src/lib/solvers/SolverDistanceChildTargeting.ts@@ -1,6 +1,7 @@import {Vector3, Group, Raycaster, type Bone, Mesh,- MeshBasicMaterial, DoubleSide+ MeshBasicMaterial, DoubleSide,+ BufferAttribute} from 'three'import { Utility } from '../Utilities.js'@@ -14,10 +15,27 @@ import { Generators } from '../Generators.js'* This adds extra logic to target ares in the arms and hips to help with assigning weights*/export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver {+ /**+ * Returns an array of vertex indices whose weights do not sum to 1.0 (within a small epsilon).+ */+ public find_vertices_with_incorrect_weight_sum (skin_weights: number[]): number[] {+ const epsilon: number = 1e-4 // very small number to signify close enough to 0+ const incorrect_vertices: number[] = []+ const vertex_count = this.geometry_vertex_count()+ for (let i = 0; i < vertex_count; i++) {+ const offset = i * 4+ const sum = skin_weights[offset] + skin_weights[offset + 1] + skin_weights[offset + 2] + skin_weights[offset + 3]+ if (Math.abs(sum - 1.0) > epsilon) {+ incorrect_vertices.push(i)+ }+ }+ return incorrect_vertices+ }+private readonly points_to_show_for_debugging: Vector3[] = []// cache objects to help speed up calculations- private cached_bone_positions: Vector3[] = [] // bone positions don't change+ // private cached_bone_positions: Vector3[] = [] // bone positions don't changeprivate cached_median_child_bone_positions: Vector3[] = [] // position between bone and its childprivate readonly bone_object_to_index = new Map<Bone, number>() // map to get the index of the bone object@@ -26,6 +44,108 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver// each index will be a bone index. the value will be a list of vertex indices that belong to that boneprivate readonly bones_vertex_segmentation: number[][] = []+ /**+ * Builds a spatial adjacency map for the mesh vertices using geometry's index (faces).+ * Returns an array of Sets, where each Set contains the indices of neighboring vertices.+ * This is important for operations like smoothing+ */+ private build_vertex_adjacency (): Array<Set<number>> {+ const vertex_count = this.geometry_vertex_count()++ // Initialize adjacency list+ // Each vertex will have a set of neighboring vertices+ const adjacency: Array<Set<number>> = Array.from({ length: vertex_count }, () => new Set<number>())++ const index_attribute: BufferAttribute | null = this.geometry.index // This contains list of a faces+ if (index_attribute === null) return adjacency // No faces, fallback to empty adjacency++ const indices = index_attribute.array+ for (let i = 0; i < indices.length; i += 3) {+ const a = indices[i]; const b = indices[i + 1]; const c = indices[i + 2]+ adjacency[a].add(b); adjacency[a].add(c)+ adjacency[b].add(a); adjacency[b].add(c)+ adjacency[c].add(a); adjacency[c].add(b)+ }+ return adjacency+ }++ /**+ * Smooths skin weights at the boundary between bone influences using spatial adjacency.+ * When a joint change occurs, it is a sharp transition since first skinning pass only assigns 100% to one bone.+ * For each vertex, if a (spatial) neighbor has a different primary bone and both have 100% influence,+ * blend their weights to 50/50 between the two bones.+ */+ private smooth_bone_weight_boundaries (skin_indices: number[], skin_weights: number[]): void {+ const vertex_count = this.geometry_vertex_count()+ const adjacency = this.build_vertex_adjacency()+ const visited = new Set<string>()++ // Build a map of shared vertices (those with identical positions)+ const position_to_indices = new Map<string, number[]>()+ for (let i = 0; i < vertex_count; i++) {+ const pos = this.geometry.attributes.position+ const x = pos.getX(i); const y = pos.getY(i); const z = pos.getZ(i)+ const key = `${x.toFixed(6)},${y.toFixed(6)},${z.toFixed(6)}`+ if (!position_to_indices.has(key)) position_to_indices.set(key, [])+ position_to_indices.get(key)!.push(i)+ }++ // Iterate through each vertex and its neighbors+ // looking for rigid 100% weight vertices that are next to other rigid 100% weight vertices+ // and blend their weights to 50/50 between the two bones+ // poor man's blending by the joint areas so it is less rigid+ for (let i = 0; i < vertex_count; i++) {+ const offsetA = i * 4+ const boneA = skin_indices[offsetA]+ const weightA = skin_weights[offsetA]+ if (weightA !== 1.0) continue+ for (const j of adjacency[i]) {+ const offsetB = j * 4+ const boneB = skin_indices[offsetB]+ const weightB = skin_weights[offsetB]+ if (boneA === boneB || weightB !== 1.0) continue+ // Only blend once per pair+ const key = i < j ? `${i},${j}` : `${j},${i}`+ if (visited.has(key)) continue+ visited.add(key)++ // Find all shared vertices for i and j+ const posA = this.geometry.attributes.position+ const xA = posA.getX(i); const yA = posA.getY(i); const zA = posA.getZ(i)+ const shared_keyA = `${xA.toFixed(6)},${yA.toFixed(6)},${zA.toFixed(6)}`+ const sharedA = position_to_indices.get(shared_keyA) || [i]++ const xB = posA.getX(j); const yB = posA.getY(j); const zB = posA.getZ(j)+ const shared_keyB = `${xB.toFixed(6)},${yB.toFixed(6)},${zB.toFixed(6)}`+ const sharedB = position_to_indices.get(shared_keyB) || [j]++ // Blend all shared vertices for i and j+ for (const idx of sharedA) {+ const off = idx * 4+ skin_indices[off + 0] = boneA+ skin_indices[off + 1] = boneB+ skin_weights[off + 0] = 0.5+ skin_weights[off + 1] = 0.5+ skin_indices[off + 2] = 0+ skin_indices[off + 3] = 0+ skin_weights[off + 2] = 0+ skin_weights[off + 3] = 0+ }+ for (const idx of sharedB) {+ const off = idx * 4+ skin_indices[off + 0] = boneB+ skin_indices[off + 1] = boneA+ skin_weights[off + 0] = 0.5+ skin_weights[off + 1] = 0.5+ skin_indices[off + 2] = 0+ skin_indices[off + 3] = 0+ skin_weights[off + 2] = 0+ skin_weights[off + 3] = 0+ }+ }+ }+ }+public calculate_indexes_and_weights (): number[][] {// There can be multiple objects that need skinning, so// this will make sure we have a clean slate by putting it in function@@ -33,20 +153,15 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolverconst skin_weights: number[] = []// create cached items for all the vertex calculations later- this.cached_bone_positions = this.get_bone_master_data().map(b => Utility.world_position_from_object(b))+ // this.cached_bone_positions = this.get_bone_master_data().map(b => Utility.world_position_from_object(b))this.cached_median_child_bone_positions = this.get_bone_master_data().map(b => this.midpoint_to_child(b))this.get_bone_master_data().forEach((b, idx) => this.bone_object_to_index.set(b, idx))this.distance_to_bottom_of_hip = this.calculate_distance_to_bottom_of_hip()console.time('calculate_closest_bone_weights')- // add more blended weighting for non-human meshes for better deformation- if (this.skeleton_type === SkeletonType.Human || this.skeleton_type === SkeletonType.Quadraped) {- // mutates (assigns) skin_indices and skin_weights- this.calculate_median_bone_weights(skin_indices, skin_weights)- } else {- this.calculate_bone_segment_weights(skin_indices, skin_weights)- }+ this.calculate_median_bone_weights(skin_indices, skin_weights)+ this.smooth_bone_weight_boundaries(skin_indices, skin_weights)console.timeEnd('calculate_closest_bone_weights')if (this.show_debug) {@@ -54,103 +169,36 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolverthis.points_to_show_for_debugging.length = 0 // Clear the points after adding to the scene}- return [skin_indices, skin_weights]- }-- private calculate_bone_segment_weights (skin_indices: number[], skin_weights: number[]): void {- const bone_count: number = this.get_bone_master_data().length- const number_influence_bones: number = 4 // number of bones to blend-- for (let i = 0; i < this.geometry_vertex_count(); i++) {- const vertex_position = new Vector3().fromBufferAttribute(this.geometry.attributes.position, i)-- // store influence for each bone- const influences: Array<{ bone: number, distance: number }> = []-- // loop through each bone and calculate distance to the vertex- // if the bone has no children, treat it as a point- // if the bone has children, treat it as a segment and project the vertex onto the segment- // this will help with assigning weights to the bones that are closer to the vertex- for (let bone_index = 0; bone_index < bone_count; bone_index++) {- const bone = this.get_bone_master_data()[bone_index]- const bone_position = this.cached_bone_positions[bone_index]--- // abort if the bone is the root. we don't want to assign weights to the root bone- if (bone.name === 'root') {- continue // skip the root bone and continue to the next bone- }-- // skip right-side bones for left side vertices- // good for close fittings like feet that are close together- if (bone.name.toLowerCase().includes('_r') === true && vertex_position.x > 0) continue- if (bone.name.toLowerCase().includes('_l') === true && vertex_position.x < 0) continue-- // End bone: treat as a point- if (bone.children.length === 0) {- const dist = vertex_position.distanceTo(bone_position)- influences.push({ bone: bone_index, distance: dist })- continue- }-- const child = bone.children[0] as Bone- const child_idx = this.bone_object_to_index.get(child)- if (child_idx === undefined) {- continue // Skip if child bone is not in the map- }+ // find out if any weights aren't adding up to 1.0+ // go through each incorrect weight influence. Fill in the 0.00 weight with the remaining weght so+ // all the weights add up to 1.0+ this.normalize_weights_with_incorrect_vertices(skin_weights)- // Child bone: treat as a segment- const child_position = this.cached_bone_positions[child_idx]-- // Project vertex onto bone segment- // Projects the vertex onto the bone segment direction (scalar projection).- const seg_vec: Vector3 = child_position.clone().sub(bone_position)- const seg_len: number = seg_vec.length()- const seg_dir: Vector3 = seg_vec.clone().normalize()- const v_vec: Vector3 = vertex_position.clone().sub(bone_position)- let proj: number = v_vec.dot(seg_dir)- proj = Math.max(0, Math.min(seg_len, proj))- const closest_point = bone_position.clone().add(seg_dir.multiplyScalar(proj))- const dist = vertex_position.distanceTo(closest_point)- influences.push({ bone: bone_index, distance: dist })- }+ console.log('do we have any leftover incorrect weights ', this.find_vertices_with_incorrect_weight_sum(skin_weights))- // Sort by distance and pick N closest- influences.sort((a, b) => a.distance - b.distance)-- // some areas like feet get weird if too many bones influence them- // this target them based on the skeleton's bone name- const closest_bone: Bone = this.bones_master_data[influences[0].bone]- // closest_bone.name.toLowerCase().includes('leg') === true ||- const bone_requires_one_influence = closest_bone.name.toLowerCase().includes('foot') === true ||- closest_bone.name.toLowerCase().includes('toes') === true- if (bone_requires_one_influence) {- const offset = i * 4- skin_indices[offset + 0] = influences[0].bone- skin_weights[offset + 0] = 1.0- // Zero out the other influences- skin_indices[offset + 1] = 0- skin_indices[offset + 2] = 0- skin_indices[offset + 3] = 0- skin_weights[offset + 1] = 0- skin_weights[offset + 2] = 0- skin_weights[offset + 3] = 0- continue- }+ return [skin_indices, skin_weights]+ }- // do weight assigning- let selected: Array< { bone: number, distance: number } > = influences.slice(0, number_influence_bones)- const weights = selected.map(inf => 1 / (inf.distance + 1e-4)) // avoid div by zero+ private normalize_weights_with_incorrect_vertices (all_skin_weights: number[]): void {+ const vertices_that_do_not_have_influences_adding_to_one: number[] = this.find_vertices_with_incorrect_weight_sum(all_skin_weights)+ for (const vertex_index of vertices_that_do_not_have_influences_adding_to_one) {+ const offset = vertex_index * 4++ // if the weight is 0.00, then we can assign the remaining weights to the other bones+ const weights = [+ all_skin_weights[offset],+ all_skin_weights[offset + 1],+ all_skin_weights[offset + 2],+ all_skin_weights[offset + 3]+ ]const weight_sum = weights.reduce((a, b) => a + b, 0)+ const weight_per_index: number = (1 - weight_sum) / 3.0+ console.log(weight_per_index)- // Assign to skin_indices/skin_weights- for (let j = 0; j < 4; j++) {- if (selected[j]) {- skin_indices[i * 4 + j] = selected[j].bone- skin_weights[i * 4 + j] = weights[j] / weight_sum- } else {- skin_indices[i * 4 + j] = 0- skin_weights[i * 4 + j] = 0+ // assign the weights all at once+ for (let i = 0; i < 4; i++) {+ if (weights[i] !== 0) {+ all_skin_weights[offset + i] += weight_per_index}}}@@ -207,7 +255,7 @@ export default class SolverDistanceChildTargeting extends AbstractAutoSkinSolver// hip bones should have custom logic for distance. If the distance is too far away we should ignore it// This will help with hips when left/right legs could be closer than knee bones- if (this.skeleton_type === SkeletonType.Human && bone.name.includes('hips') === true) {+ if (this.skeleton_type === SkeletonType.Human && bone.name.includes('hips')) {// if the intersection point is lower than the vertex position, that means the vertex is below// the hips area, and is part of the left or right leg...ignore that resultif (this.distance_to_bottom_of_hip !== null && this.distance_to_bottom_of_hip < vertex_position.y) {diff --git a/src/preview-generator/index.html b/src/preview-generator/index.htmlindex 56c82bf..c5c9a4a 100644--- a/src/preview-generator/index.html+++ b/src/preview-generator/index.html@@ -19,6 +19,7 @@<option value="../animations/human-addon-animations.glb">Human Addon Animations</option><option value="../animations/quad-creature-animations.glb">Quad Creature Animations</option><option value="../animations/bird-animations.glb">Bird Animations</option>+ <option value="../animations/dragon-animations.glb">Dragon Animations</option></select></body>diff --git a/static/ANIMATOR-README.md b/static/ANIMATOR-README.mdnew file mode 100644index 0000000..ff8ef8c--- /dev/null+++ b/static/ANIMATOR-README.md@@ -0,0 +1,82 @@+# Animator Guide++This is a general guide for working with Blender and how this web application expects animations to be. There are some things to consider to make rigs work with a variation of mesh sizes.++## Blender Source files++I am using Blender 4.5. All the source files are in the "blender" folder at the location of this readme. There are two variations of the blender files for each rig+ - **RIG**-model.blend - Contains no animations. This has things like mirror modifiers applied to help with modeling+ - **RIG**.blend - Has the skeleton + model + animations.++When you make changes or create a new 3d model, export to GLB and place it in the "models" folder. This models folder is what the web app will use when loading the reference models.++## Rigs and animations++The rig files are in the "blender" folder with the name <RIG>.blend. If I am making a new one, I create **RIG**.blend file with the new rig type. I import the associated GLB file from the "models" folder. I then proceed to build out the armature.++### Things to consider++### Naming bones++The Three.js framework that Mesh2Motion uses does "sanitation" on object names. this means that bone names with things like "." symbols will get completely removed when it enters Mesh2Motion. This can create issues when we use those symbols for parsing to determine what might be a left or right bone. Avoid using characters like that. Models are using the _ character in places where periods are used.++Reference: https://discourse.threejs.org/t/avoid-dots-and-colons-being-deleted-from-models-name/15304++#### Rotation keyframes++When creating animations, we generally only want to make rotation keyframes. This is because people import 3d models in Mesh2Motion that have different sized limbs. We want to make sure their limbs don't get shortened or elongated. If we make position keyframes, this can affect the results. This also makes for a smaller size animations.++When starting a new rig file, one of the first things to do is change the "Keying" type to help with this. This is set in the timeline here.++<img src="./ANIMATOR-README/defaut-keying.png" alt="Default keying section" />++Make sure to set this to "Rotation". When we are animating bones around later and want to make a keyframe, we can press the "I" shortcut. Pressing this shortcut will not only create a keyframe for the rotation property.++### Hip bone positions++In general we only use rotation keyframes. The hip bone is the only exception. This is needed to help with things like jumping or falling where we really need the hip bone to move the entire model.++The easiest way I have found to do this is position the hip bone where you want, then hover over the location transform area and press the "I" shortcut key. The keyframe should change colors indicating there is a keyframe there. YOu can remove the position keyframe with "Shift + Alt + I".++<img src="./ANIMATOR-README/insert-location-keyframe.png" alt="Insert location keyframe" />+++### No root motion++For each rig, there is a root bone that should be at the origin (0,0,0). This is the parent of all the bones. Currently Mesh2Motion doesn't support root motion, so don't keyframes to that for now. Any root motion will be stripped out when Mesh2Motion loads an animation.++## Final skeleton and animation files for rig++When the animations are ready, you can export out the skeleton by itself in the "skeletons" folder as a GLB if you made changes to that. I usually remove all the animations from the skeleton to make the skeleton size smaller.++The final animations go in the "animations" folder. It is a GLB with everything exported: mesh, skeleton, and animations. The reason we put everything in the file is that it will be used for animation previews.+++# New Rig setup+There will need to be programming work to actually see and test a new rig in Mesh2Motion. Before the programming work can start you can export the following into the directories++- models - put the GLB of the mesh only+- skeletons - put the GLB of the skeleton only+- animations - put the GLB of the mesh + skeleton + animations++There needs to be a few places in code to add a new rig+- index.html: Add an option for the model. Add an option for the skeleton+- script.js - TODO: add references to whatever this is when I do it next+++## Blender usage notes++For editing and creating animation keyframes, I use the Dope sheet. There is a sub-view to the right where you can change to the "Action Editor". This is where animating all the keyframes happen.++When creating new animation actions, make sure to click the shield icon to save the action. If you don't do this, the action will disappear the next time you start Blender. Blender calls these "Fake users" under the hood. There should be an "F" at the start of every action name in the actions drop-down to denote this property is set.++<img src="./ANIMATOR-README/save-action-dummy.png" alt="save fake user" />+++++++++diff --git a/static/ANIMATOR-README/defaut-keying.png b/static/ANIMATOR-README/defaut-keying.pngnew file mode 100644index 0000000..8e493dbBinary files /dev/null and b/static/ANIMATOR-README/defaut-keying.png differdiff --git a/static/ANIMATOR-README/insert-location-keyframe.png b/static/ANIMATOR-README/insert-location-keyframe.pngnew file mode 100644index 0000000..2ecafd3Binary files /dev/null and b/static/ANIMATOR-README/insert-location-keyframe.png differdiff --git a/static/ANIMATOR-README/save-action-dummy.png b/static/ANIMATOR-README/save-action-dummy.pngnew file mode 100644index 0000000..a4e6262Binary files /dev/null and b/static/ANIMATOR-README/save-action-dummy.png differdiff --git a/static/MODELER-README.md b/static/MODELER-README.mdnew file mode 100644index 0000000..fa6be1f--- /dev/null+++ b/static/MODELER-README.md@@ -0,0 +1,11 @@+# 3D modeling considerations when using Mesh2Motion++## Try to have one material per mesh+There is a quirk with how the web technology (three.js) deals with materials and meshes. The 3d library only supports one material per mesh. If you import a mesh with more than one material, the mesh will be broken apart into multiple meshes when you export it. This may, or may not, be an issue for the end animations.++We will just need to keep that in mind for future reference when building out samples or instructions.++Reference:+https://discourse.threejs.org/t/some-issues-when-export-a-single-mesh-with-multiple-materials-using-gltf-exporter/50395/4++diff --git a/static/animations/bird-animations.glb b/static/animations/bird-animations.glbindex c61a6f4..4edac40 100644Binary files a/static/animations/bird-animations.glb and b/static/animations/bird-animations.glb differdiff --git a/static/animations/dragon-animations.glb b/static/animations/dragon-animations.glbnew file mode 100644index 0000000..809e201Binary files /dev/null and b/static/animations/dragon-animations.glb differdiff --git a/static/animations/quad-creature-animations.glb b/static/animations/quad-creature-animations.glbindex bd9b8c9..2a5b477 100644Binary files a/static/animations/quad-creature-animations.glb and b/static/animations/quad-creature-animations.glb differdiff --git a/static/animpreviews/bird/dark_Death.webm b/static/animpreviews/bird/dark_Death.webmnew file mode 100644index 0000000..97e9f9dBinary files /dev/null and b/static/animpreviews/bird/dark_Death.webm differdiff --git a/static/animpreviews/bird/dark_Flap.webm b/static/animpreviews/bird/dark_Flap.webmnew file mode 100644index 0000000..3893aa6Binary files /dev/null and b/static/animpreviews/bird/dark_Flap.webm differdiff --git a/static/animpreviews/bird/dark_Glide.webm b/static/animpreviews/bird/dark_Glide.webmnew file mode 100644index 0000000..1b56155Binary files /dev/null and b/static/animpreviews/bird/dark_Glide.webm differdiff --git a/static/animpreviews/bird/dark_Idle.webm b/static/animpreviews/bird/dark_Idle.webmnew file mode 100644index 0000000..a19e658Binary files /dev/null and b/static/animpreviews/bird/dark_Idle.webm differdiff --git a/static/animpreviews/bird/dark_Keow.webm b/static/animpreviews/bird/dark_Keow.webmnew file mode 100644index 0000000..c33e5c1Binary files /dev/null and b/static/animpreviews/bird/dark_Keow.webm differdiff --git a/static/animpreviews/bird/dark_Walk.webm b/static/animpreviews/bird/dark_Walk.webmnew file mode 100644index 0000000..80490b4Binary files /dev/null and b/static/animpreviews/bird/dark_Walk.webm differdiff --git a/static/animpreviews/bird/light_Death.webm b/static/animpreviews/bird/light_Death.webmnew file mode 100644index 0000000..8c3444bBinary files /dev/null and b/static/animpreviews/bird/light_Death.webm differdiff --git a/static/animpreviews/bird/light_Flap.webm b/static/animpreviews/bird/light_Flap.webmnew file mode 100644index 0000000..a4c558fBinary files /dev/null and b/static/animpreviews/bird/light_Flap.webm differdiff --git a/static/animpreviews/bird/light_Glide.webm b/static/animpreviews/bird/light_Glide.webmnew file mode 100644index 0000000..c67abd6Binary files /dev/null and b/static/animpreviews/bird/light_Glide.webm differdiff --git a/static/animpreviews/bird/light_Idle.webm b/static/animpreviews/bird/light_Idle.webmnew file mode 100644index 0000000..dbb2780Binary files /dev/null and b/static/animpreviews/bird/light_Idle.webm differdiff --git a/static/animpreviews/bird/light_Keow.webm b/static/animpreviews/bird/light_Keow.webmnew file mode 100644index 0000000..a426f8eBinary files /dev/null and b/static/animpreviews/bird/light_Keow.webm differdiff --git a/static/animpreviews/bird/light_Walk.webm b/static/animpreviews/bird/light_Walk.webmnew file mode 100644index 0000000..83751b4Binary files /dev/null and b/static/animpreviews/bird/light_Walk.webm differdiff --git a/static/animpreviews/dragon/dark_Flap.webm b/static/animpreviews/dragon/dark_Flap.webmnew file mode 100644index 0000000..dfbcbe6Binary files /dev/null and b/static/animpreviews/dragon/dark_Flap.webm differdiff --git a/static/animpreviews/dragon/dark_Idle.webm b/static/animpreviews/dragon/dark_Idle.webmnew file mode 100644index 0000000..81c5303Binary files /dev/null and b/static/animpreviews/dragon/dark_Idle.webm differdiff --git a/static/animpreviews/dragon/dark_T-Pose.webm b/static/animpreviews/dragon/dark_T-Pose.webmnew file mode 100644index 0000000..21d6dd4Binary files /dev/null and b/static/animpreviews/dragon/dark_T-Pose.webm differdiff --git a/static/animpreviews/dragon/dark_Walk.webm b/static/animpreviews/dragon/dark_Walk.webmnew file mode 100644index 0000000..95ba6bfBinary files /dev/null and b/static/animpreviews/dragon/dark_Walk.webm differdiff --git a/static/animpreviews/dragon/light_Flap.webm b/static/animpreviews/dragon/light_Flap.webmnew file mode 100644index 0000000..ba452a7Binary files /dev/null and b/static/animpreviews/dragon/light_Flap.webm differdiff --git a/static/animpreviews/dragon/light_Idle.webm b/static/animpreviews/dragon/light_Idle.webmnew file mode 100644index 0000000..471a150Binary files /dev/null and b/static/animpreviews/dragon/light_Idle.webm differdiff --git a/static/animpreviews/dragon/light_T-Pose.webm b/static/animpreviews/dragon/light_T-Pose.webmnew file mode 100644index 0000000..48e91bfBinary files /dev/null and b/static/animpreviews/dragon/light_T-Pose.webm differdiff --git a/static/animpreviews/dragon/light_Walk.webm b/static/animpreviews/dragon/light_Walk.webmnew file mode 100644index 0000000..fa515cfBinary files /dev/null and b/static/animpreviews/dragon/light_Walk.webm differdiff --git a/static/blender/bird-model.blend b/static/blender/bird-model.blenddeleted file mode 100644index c24c2e8..0000000Binary files a/static/blender/bird-model.blend and /dev/null differdiff --git a/static/blender/bird.blend b/static/blender/bird.blenddeleted file mode 100644index aa7d228..0000000Binary files a/static/blender/bird.blend and /dev/null differdiff --git a/static/blender/fox-model.blend b/static/blender/fox-model.blenddeleted file mode 100644index 3589e9f..0000000Binary files a/static/blender/fox-model.blend and /dev/null differdiff --git a/static/blender/fox.blend b/static/blender/fox.blenddeleted file mode 100644index a16e941..0000000Binary files a/static/blender/fox.blend and /dev/null differdiff --git a/static/blender/human-mannequin-model.blend b/static/blender/human-mannequin-model.blenddeleted file mode 100644index 50e0c3c..0000000Binary files a/static/blender/human-mannequin-model.blend and /dev/null differdiff --git a/static/blender/human-quaternius-animations.blend b/static/blender/human-quaternius-animations.blenddeleted file mode 100644index 1f76999..0000000Binary files a/static/blender/human-quaternius-animations.blend and /dev/null differdiff --git a/static/blender/models/DragonTexture.png b/static/blender/models/DragonTexture.pngnew file mode 100644index 0000000..ca97218Binary files /dev/null and b/static/blender/models/DragonTexture.png differdiff --git a/static/blender/color-palette.png b/static/blender/models/color-palette.pngsimilarity index 100%rename from static/blender/color-palette.pngrename to static/blender/models/color-palette.pngdiff --git a/static/blender/models/model-bird.blend b/static/blender/models/model-bird.blendnew file mode 100644index 0000000..972b3b1Binary files /dev/null and b/static/blender/models/model-bird.blend differdiff --git a/static/blender/models/model-dragon.blend b/static/blender/models/model-dragon.blendnew file mode 100644index 0000000..70d2811Binary files /dev/null and b/static/blender/models/model-dragon.blend differdiff --git a/static/blender/models/model-fox.blend b/static/blender/models/model-fox.blendnew file mode 100644index 0000000..ed6d2f2Binary files /dev/null and b/static/blender/models/model-fox.blend differdiff --git a/static/blender/models/model-human.blend b/static/blender/models/model-human.blendnew file mode 100644index 0000000..e27cb5bBinary files /dev/null and b/static/blender/models/model-human.blend differdiff --git a/static/blender/rigs/bird/animation-bird-death.blend b/static/blender/rigs/bird/animation-bird-death.blendnew file mode 100644index 0000000..283878eBinary files /dev/null and b/static/blender/rigs/bird/animation-bird-death.blend differdiff --git a/static/blender/rigs/bird/animation-bird-flap.blend b/static/blender/rigs/bird/animation-bird-flap.blendnew file mode 100644index 0000000..5e6acd0Binary files /dev/null and b/static/blender/rigs/bird/animation-bird-flap.blend differdiff --git a/static/blender/rigs/bird/animation-bird-glide.blend b/static/blender/rigs/bird/animation-bird-glide.blendnew file mode 100644index 0000000..dbb14beBinary files /dev/null and b/static/blender/rigs/bird/animation-bird-glide.blend differdiff --git a/static/blender/rigs/bird/animation-bird-idle.blend b/static/blender/rigs/bird/animation-bird-idle.blendnew file mode 100644index 0000000..e0066f2Binary files /dev/null and b/static/blender/rigs/bird/animation-bird-idle.blend differdiff --git a/static/blender/rigs/bird/animation-bird-keow.blend b/static/blender/rigs/bird/animation-bird-keow.blendnew file mode 100644index 0000000..c3490c9Binary files /dev/null and b/static/blender/rigs/bird/animation-bird-keow.blend differdiff --git a/static/blender/rigs/bird/animation-bird-walk.blend b/static/blender/rigs/bird/animation-bird-walk.blendnew file mode 100644index 0000000..ac3c48dBinary files /dev/null and b/static/blender/rigs/bird/animation-bird-walk.blend differdiff --git a/static/blender/rigs/bird/combine-and-export.py b/static/blender/rigs/bird/combine-and-export.pynew file mode 100644index 0000000..b29f04d--- /dev/null+++ b/static/blender/rigs/bird/combine-and-export.py@@ -0,0 +1,55 @@+import bpy+import os++## WHAT IS THIS SCRIPT FOR?+# Each BLEND file only has one animation action. This script consolidates all these actions and+# creates one GLB file that the Mesh2Motion tool can load.+# This will make loading faster since it will be one HTTP request+# if there gets to be a ton of animations, we can revisit this to split things apart.++## INSTRUCTIONS ON HOW TO RUN+# 1. Open the rig-bird.blend file in Blender. This process should work for all the rig files+# 2. Open a "Text Editor" view and click New to create a new text area+# 3. Copy and paste this script into the text area+# 4. Update the path below to point to the rig you want to create a GLB for+# 5. Click the "Run Script" (play) button+# 6. You can put the GLB file in the static > animations folder overwriting the old rig one+++# Define the directory containing the Blender RIG files+base_dir = r"C:\git\ModelMotionizer\static\blender\rigs"++# Define the rig type/folder+rig_type = "bird"+++# DO NOT NEED TO CHANGE BELOW THIS LINE+#----------------------------------------------------++# Define the output file path. It will be saved in the same directory as the input files+blend_dir = os.path.join(base_dir, rig_type)+output_file = os.path.join(blend_dir, f"{rig_type}-animations.glb")+++# Iterate over each Blender file+for file in os.listdir(blend_dir):+ if file.endswith(".blend") and "animation" in file.lower():+ # Append actions from the file+ filepath = os.path.join(blend_dir, file)+ with bpy.data.libraries.load(filepath) as (data_from, data_to):+ data_to.actions = data_from.actions++# Export the combined actions to a GLB file+# select just the armature and mesh objects we want to export+export_objects = [obj for obj in bpy.context.scene.objects if obj.type in ['ARMATURE', 'MESH']]+for obj in export_objects:+ obj.select_set(True)+++bpy.ops.export_scene.gltf(+ filepath=output_file,+ export_format="GLB",+ export_animations=True,+ export_nla_strips=False, # Export actions instead of NLA strips+ use_selection=True+)\ No newline at end of filediff --git a/static/blender/rigs/bird/rig-bird.blend b/static/blender/rigs/bird/rig-bird.blendnew file mode 100644index 0000000..719487aBinary files /dev/null and b/static/blender/rigs/bird/rig-bird.blend differdiff --git a/static/blender/rigs/dragon/animation-dragon-flap.blend b/static/blender/rigs/dragon/animation-dragon-flap.blendnew file mode 100644index 0000000..32023a3Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-flap.blend differdiff --git a/static/blender/rigs/dragon/animation-dragon-idle.blend b/static/blender/rigs/dragon/animation-dragon-idle.blendnew file mode 100644index 0000000..528ad72Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-idle.blend differdiff --git a/static/blender/rigs/dragon/animation-dragon-walk.blend b/static/blender/rigs/dragon/animation-dragon-walk.blendnew file mode 100644index 0000000..b67c905Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-walk.blend differdiff --git a/static/blender/rigs/dragon/rig-dragon.blend b/static/blender/rigs/dragon/rig-dragon.blendnew file mode 100644index 0000000..0afe806Binary files /dev/null and b/static/blender/rigs/dragon/rig-dragon.blend differdiff --git a/static/blender/rigs/fox/animation-fox-idle.blend b/static/blender/rigs/fox/animation-fox-idle.blendnew file mode 100644index 0000000..75ec40fBinary files /dev/null and b/static/blender/rigs/fox/animation-fox-idle.blend differdiff --git a/static/blender/rigs/fox/rig-fox.blend b/static/blender/rigs/fox/rig-fox.blendnew file mode 100644index 0000000..cf57799Binary files /dev/null and b/static/blender/rigs/fox/rig-fox.blend differdiff --git a/static/blender/rigs/human/animation-human-ymca.blend b/static/blender/rigs/human/animation-human-ymca.blendnew file mode 100644index 0000000..06d9c94Binary files /dev/null and b/static/blender/rigs/human/animation-human-ymca.blend differdiff --git a/static/blender/human.blend b/static/blender/rigs/human/rig-human.blendsimilarity index 66%rename from static/blender/human.blendrename to static/blender/rigs/human/rig-human.blendindex 4f2fb54..ed5d227 100644Binary files a/static/blender/human.blend and b/static/blender/rigs/human/rig-human.blend differdiff --git a/static/models/fox.glb b/static/models/fox.glbdeleted file mode 100644index 3d20db6..0000000Binary files a/static/models/fox.glb and /dev/null differdiff --git a/static/models/human-mannequin.glb b/static/models/human-mannequin.glbdeleted file mode 100644index 6248015..0000000Binary files a/static/models/human-mannequin.glb and /dev/null differdiff --git a/static/models/model-bird.glb b/static/models/model-bird.glbnew file mode 100644index 0000000..0d93ed7Binary files /dev/null and b/static/models/model-bird.glb differdiff --git a/static/models/model-dragon.glb b/static/models/model-dragon.glbnew file mode 100644index 0000000..a455d70Binary files /dev/null and b/static/models/model-dragon.glb differdiff --git a/static/models/model-fox.glb b/static/models/model-fox.glbnew file mode 100644index 0000000..bce3073Binary files /dev/null and b/static/models/model-fox.glb differdiff --git a/static/models/model-human.glb b/static/models/model-human.glbnew file mode 100644index 0000000..1b4937dBinary files /dev/null and b/static/models/model-human.glb differdiff --git a/static/models/seagull.glb b/static/models/seagull.glbdeleted file mode 100644index 71432fc..0000000Binary files a/static/models/seagull.glb and /dev/null differdiff --git a/static/rigs/rig-bird.glb b/static/rigs/rig-bird.glbnew file mode 100644index 0000000..d0d2751Binary files /dev/null and b/static/rigs/rig-bird.glb differdiff --git a/static/rigs/rig-dragon.glb b/static/rigs/rig-dragon.glbnew file mode 100644index 0000000..26705cbBinary files /dev/null and b/static/rigs/rig-dragon.glb differdiff --git a/static/rigs/rig-fox.glb b/static/rigs/rig-fox.glbnew file mode 100644index 0000000..fe7360cBinary files /dev/null and b/static/rigs/rig-fox.glb differdiff --git a/static/rigs/rig-human.glb b/static/rigs/rig-human.glbnew file mode 100644index 0000000..e46d4d9Binary files /dev/null and b/static/rigs/rig-human.glb differdiff --git a/static/skeletons/human-skeleton.glb b/static/skeletons/human-skeleton.glbdeleted file mode 100644index e7ed800..0000000Binary files a/static/skeletons/human-skeleton.glb and /dev/null differdiff --git a/static/skeletons/skeleton-bird.glb b/static/skeletons/skeleton-bird.glbdeleted file mode 100644index 71930fe..0000000Binary files a/static/skeletons/skeleton-bird.glb and /dev/null differdiff --git a/static/skeletons/skeleton-quadraped.glb b/static/skeletons/skeleton-quadraped.glbdeleted file mode 100644index 8ad4238..0000000Binary files a/static/skeletons/skeleton-quadraped.glb and /dev/null differ