Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Convert classes to enums

Scott Petrovicd6d4a3f0f484
diff --git a/.eslintrc.json b/.eslintrc.json
index 8491e50..553f7f8 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -12,9 +12,10 @@
"@typescript-eslint/naming-convention": [
"error",
{
- "selector": "default",
+ "selector": "variable",
"format": ["snake_case"]
},
+
{
"selector": "class",
"format": ["PascalCase"]
@@ -22,7 +23,11 @@
{
"selector": "import",
"format": ["PascalCase", "snake_case"]
- }
+ },
+ {
+ "selector": "enumMember",
+ "format": ["PascalCase"]
+ }
],
"indent": "off",
"brace-style": "off",
diff --git a/src/lib/enums/ProcessStep.js b/src/lib/enums/ProcessStep.js
deleted file mode 100644
index ad2ec64..0000000
--- a/src/lib/enums/ProcessStep.js
+++ /dev/null
@@ -1,8 +0,0 @@
-export const ProcessStep = {
- LoadModel: 'load-model',
- LoadSkeleton: 'load-skeleton',
- EditSkeleton: 'edit-skeleton',
- WeightSkin: 'weight-skin',
- AnimationsListing: 'animations-export',
- StepExportToFile: 'export-to-file'
-}
diff --git a/src/lib/enums/ProcessStep.ts b/src/lib/enums/ProcessStep.ts
new file mode 100644
index 0000000..ed416b3
--- /dev/null
+++ b/src/lib/enums/ProcessStep.ts
@@ -0,0 +1,8 @@
+export enum ProcessStep {
+ LoadModel = 'load-model',
+ LoadSkeleton = 'load-skeleton',
+ EditSkeleton = 'edit-skeleton',
+ WeightSkin = 'weight-skin',
+ AnimationsListing = 'animations-export',
+ StepExportToFile = 'export-to-file'
+}
diff --git a/src/lib/enums/SkeletonType.js b/src/lib/enums/SkeletonType.js
deleted file mode 100644
index a7728c4..0000000
--- a/src/lib/enums/SkeletonType.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// Supported skeleton types
-// the file names for the skeleton types are associated with the const
-export const SkeletonType = {
- Quadraped: 'skeletons/skeleton-quadraped.glb',
- BipedalSimple: 'skeletons/skeleton-bipedal-simple.glb',
- BipedalFull: 'skeletons/skeleton-mecanim-full.glb',
-}
diff --git a/src/lib/enums/SkeletonType.ts b/src/lib/enums/SkeletonType.ts
new file mode 100644
index 0000000..9e7d75e
--- /dev/null
+++ b/src/lib/enums/SkeletonType.ts
@@ -0,0 +1,7 @@
+// Supported skeleton types
+// the file names for the skeleton types are associated with the const
+export enum SkeletonType {
+ Quadraped = 'skeletons/skeleton-quadraped.glb',
+ BipedalSimple = 'skeletons/skeleton-bipedal-simple.glb',
+ BipedalFull = 'skeletons/skeleton-mecanim-full.glb'
+}
diff --git a/src/lib/enums/SkinningFormula.js b/src/lib/enums/SkinningFormula.js
deleted file mode 100644
index a92c081..0000000
--- a/src/lib/enums/SkinningFormula.js
+++ /dev/null
@@ -1,5 +0,0 @@
-export const SkinningFormula = {
- Distance: 'distance',
- MedianDistance: 'median-distance',
- Envelope: 'envelope'
-}
diff --git a/src/lib/enums/SkinningFormula.ts b/src/lib/enums/SkinningFormula.ts
new file mode 100644
index 0000000..8090f41
--- /dev/null
+++ b/src/lib/enums/SkinningFormula.ts
@@ -0,0 +1,5 @@
+export enum SkinningFormula {
+ Distance = 'distance',
+ MedianDistance = 'median-distance',
+ Envelope = 'envelope'
+}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 41b51d1..cccf75c 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -5,7 +5,7 @@ import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
import { AnimationClip, AnimationMixer, Quaternion, Vector3, type SkinnedMesh, type QuaternionKeyframeTrack, type KeyframeTrack, type AnimationAction } from 'three'
-import { SkeletonType } from '../enums/SkeletonType.js'
+import { SkeletonType } from '../enums/SkeletonType.ts'
import { MixamoToSimpleMapping } from '../mapping/MixamoToSimple.js'
// Note: EventTarget is a built-ininterface and do not need to import it
diff --git a/src/lib/processes/StepEditSkeleton.ts b/src/lib/processes/StepEditSkeleton.ts
index c8111b5..6db48ef 100644
--- a/src/lib/processes/StepEditSkeleton.ts
+++ b/src/lib/processes/StepEditSkeleton.ts
@@ -1,8 +1,8 @@
import { UI } from '../UI.ts'
import { Generators } from '../Generators.ts'
import { Utility } from '../Utilities.ts'
-import { Vector3, Euler, Object3D, Skeleton, Bone } from 'three'
-import { SkinningFormula } from '../enums/SkinningFormula.js'
+import { Vector3, Euler, Object3D, Skeleton, type Bone } from 'three'
+import { SkinningFormula } from '../enums/SkinningFormula.ts'
export class StepEditSkeleton extends EventTarget {
private readonly ui: UI
diff --git a/src/lib/processes/StepExportToFile.ts b/src/lib/processes/StepExportToFile.ts
index 2d4cfea..058e485 100644
--- a/src/lib/processes/StepExportToFile.ts
+++ b/src/lib/processes/StepExportToFile.ts
@@ -54,7 +54,9 @@ export class StepExportToFile extends EventTarget {
}
gltf_exporter.parse(exported_scene, (result) => {
- if (result instanceof ArrayBuffer) {
+ // I have tried casting this as an ArrayBuffer...but there are problems for some reason
+ // doing this. Maybe come back later to see what is going on
+ if (result) {
this.save_array_buffer(result, `${file_name}.glb`)
} else {
console.log('ERROR: result is not an instance of ArrayBuffer')
diff --git a/src/lib/processes/StepWeightSkin.ts b/src/lib/processes/StepWeightSkin.ts
index cd86eb6..5c5bcbd 100644
--- a/src/lib/processes/StepWeightSkin.ts
+++ b/src/lib/processes/StepWeightSkin.ts
@@ -4,7 +4,7 @@ import { BoneWeightsByEnvelope } from '../solvers/BoneWeightsByEnvelope.ts'
import BoneWeightsByDistance from '../solvers/BoneWeightsByDistance.ts'
import BoneWeightsByMedianDistance from '../solvers/BoneWeightsByMedianDistance.ts'
-import { SkinningFormula } from '../enums/SkinningFormula.js'
+import { SkinningFormula } from '../enums/SkinningFormula.ts'
import { Generators } from '../Generators.ts'
diff --git a/src/script.js b/src/script.js
index 932be87..f1542d7 100644
--- a/src/script.js
+++ b/src/script.js
@@ -15,7 +15,7 @@ import { StepAnimationsListing } from './lib/processes/StepAnimationsListing.ts'
import { StepExportToFile } from './lib/processes/StepExportToFile.ts'
import { StepWeightSkin } from './lib/processes/StepWeightSkin.ts'
-import { ProcessStep } from './lib/enums/ProcessStep.js'
+import { ProcessStep } from './lib/enums/ProcessStep.ts'
// Initialize basic sene things that are not related to the main work that is being tested
const camera = Generators.create_camera()