Import a 3D Model and automatically assign and export animations
TypeScript
Turn main app file into engine that can be instantiated and controlled from outside class file for reuse
Scott Petrovic89228dd22b3f
diff --git a/src/CustomModelUploadBootstrap.ts b/src/CustomModelUploadBootstrap.tsnew file mode 100644index 0000000..f5f9e30--- /dev/null+++ b/src/CustomModelUploadBootstrap.ts@@ -0,0 +1,12 @@+import { Mesh2MotionEngine } from './Mesh2MotionEngine'++export class CustomModelUploadBootstrap {+ private readonly mesh2motion_engine: Mesh2MotionEngine++ constructor () {+ this.mesh2motion_engine = new Mesh2MotionEngine()+ }+}++// instantiate the class to setup event listeners+const app = new CustomModelUploadBootstrap()diff --git a/src/script.ts b/src/Mesh2MotionEngine.tssimilarity index 99%rename from src/script.tsrename to src/Mesh2MotionEngine.tsindex 711a429..825f533 100644--- a/src/script.ts+++ b/src/Mesh2MotionEngine.ts@@ -32,7 +32,7 @@ import { TransformControlType } from './lib/enums/TransformControlType.ts'import { ThemeManager } from './lib/ThemeManager.ts'import { ModalDialog } from './lib/ModalDialog.ts'-export class Bootstrap {+export class Mesh2MotionEngine {public readonly camera = Generators.create_camera()public readonly renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })public controls: OrbitControls | undefined = undefined@@ -530,7 +530,4 @@ export class Bootstrap {public show_contributors_dialog (): void {new ModalDialog('Contributors', Generators.get_contributors_list()).show()}-} // end Bootstrap class--// Create an instance of the Bootstrap class when the script is loaded-const app = new Bootstrap()+} // end Mesh2Motion Enginediff --git a/src/index.html b/src/index.htmlindex a4a6806..a1d9af7 100644--- a/src/index.html+++ b/src/index.html@@ -8,7 +8,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body style="margin: 0">- <script type="module" src="./script.ts"></script>+ <script type="module" src="./CustomModelUploadBootstrap.ts"></script><link href="./styles.css" rel="stylesheet" crossorigin="anonymous" /><link rel="stylesheet" href="./radio-button-group.css" crossorigin="anonymous" /><link rel="stylesheet" href="./animation-player.css" crossorigin="anonymous" />diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.tsindex c82415d..96ae15b 100644--- a/src/lib/processes/load-model/StepLoadModel.ts+++ b/src/lib/processes/load-model/StepLoadModel.ts@@ -148,7 +148,7 @@ export class StepLoadModel extends EventTarget {return file_extension}- private load_model_file (model_file_path: string | ArrayBuffer | null, file_extension: string): void {+ public load_model_file (model_file_path: string | ArrayBuffer | null, file_extension: string): void {if (file_extension === 'fbx') {console.log('Loading FBX model:', model_file_path)this.fbx_loader.load(model_file_path as string, (fbx) => {diff --git a/src/marketing/MarketingBootstrap.ts b/src/marketing/MarketingBootstrap.tsindex 544dad8..fac60c1 100644--- a/src/marketing/MarketingBootstrap.ts+++ b/src/marketing/MarketingBootstrap.ts@@ -1,6 +1,13 @@+import { SkeletonType } from '../lib/enums/SkeletonType'+import { Mesh2MotionEngine } from '../Mesh2MotionEngine'+export class MarketingBootstrap {+ private readonly mesh2motion_engine: Mesh2MotionEngine+ private skeleton_type: SkeletonType = SkeletonType.None+constructor () {- this.add_event_listners()+ this.mesh2motion_engine = new Mesh2MotionEngine()+ this.add_event_listeners()}public setup_model_buttons (): void {@@ -10,34 +17,40 @@ export class MarketingBootstrap {const bird_button = document.getElementById('load-bird-model-button')const dragon_button = document.getElementById('load-dragon-model-button')- // <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>-- if (human_button != null) {- human_button?.addEventListener('click', () => {- console.log('Human model button clicked')- })- }+ human_button?.addEventListener('click', () => {+ this.mesh2motion_engine.load_model_step.load_model_file('../models/model-human.glb', 'glb')+ this.skeleton_type = SkeletonType.Human+ })fox_button?.addEventListener('click', () => {- console.log('Fox model button clicked')+ this.mesh2motion_engine.load_model_step.load_model_file('../models/model-fox.glb', 'glb')+ this.skeleton_type = SkeletonType.Quadraped})bird_button?.addEventListener('click', () => {- console.log('Bird model button clicked')+ this.mesh2motion_engine.load_model_step.load_model_file('../models/model-bird.glb', 'glb')+ this.skeleton_type = SkeletonType.Bird})dragon_button?.addEventListener('click', () => {- console.log('Dragon model button clicked')+ this.mesh2motion_engine.load_model_step.load_model_file('../models/model-dragon.glb', 'glb')+ this.skeleton_type = SkeletonType.Dragon})}- public add_event_listners (): void {+ public add_event_listeners (): void {// event after the DOM is fully loaded for HTML elementsdocument.addEventListener('DOMContentLoaded', () => {this.setup_model_buttons()++ this.mesh2motion_engine.load_model_step.addEventListener('modelLoaded', () => {+ console.log('model has been loaded')++ // load associated skeleton+ // ths (this.skeleton_type) value contains the filename for the skeleton rig+ // this.mesh2motion_engine.load_skeleton_step.load++ })})}}diff --git a/src/marketing/index.html b/src/marketing/index.htmlindex c10e13c..237ae6f 100644--- a/src/marketing/index.html+++ b/src/marketing/index.html@@ -9,7 +9,6 @@</head><body style="margin: 0"><!-- Script files-->- <script type="module" src="../script.ts"></script><script type="module" src="./MarketingBootstrap.ts"></script><!-- Stylesheets-->