From 73a5ecb8149afdae0b3096542a779b392ee9fde2 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 5 Jan 2024 08:18:55 -0600 Subject: [PATCH] feat(model): load sequence information when loading models --- src/lib/model/M2Model.ts | 27 ++++++++++++++ src/lib/model/M2Sequence.ts | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/lib/model/M2Sequence.ts diff --git a/src/lib/model/M2Model.ts b/src/lib/model/M2Model.ts index 642b10a..1d7bd0e 100644 --- a/src/lib/model/M2Model.ts +++ b/src/lib/model/M2Model.ts @@ -7,6 +7,7 @@ import M2TextureWeight from './M2TextureWeight.js'; import M2TextureTransform from './M2TextureTransform.js'; import { m2typedArray } from './io/common.js'; import * as io from '@wowserhq/io'; +import M2Sequence from './M2Sequence.js'; class M2Model { #name: string; @@ -25,6 +26,8 @@ class M2Model { #materials: M2Material[] = []; #skinProfileCount: number; + #sequences: M2Sequence[] = []; + get flags() { return this.#flags; } @@ -37,6 +40,10 @@ class M2Model { return this.#name; } + get sequences() { + return this.#sequences; + } + get textures() { return this.#textures; } @@ -106,6 +113,8 @@ class M2Model { this.#loadMaterials(data); + this.#loadSequences(data); + return this; } @@ -115,6 +124,24 @@ class M2Model { } } + #loadSequences(data: any) { + for (const sequenceData of data.sequences) { + this.#sequences.push( + new M2Sequence( + sequenceData.id, + sequenceData.variationIndex, + sequenceData.duration, + sequenceData.moveSpeed, + sequenceData.flags, + sequenceData.frequency, + sequenceData.blendTime, + sequenceData.variationNext, + sequenceData.aliasNext, + ), + ); + } + } + #loadTextures(data: any) { for (const textureData of data.textures) { this.#textures.push( diff --git a/src/lib/model/M2Sequence.ts b/src/lib/model/M2Sequence.ts new file mode 100644 index 0000000..5d32fe0 --- /dev/null +++ b/src/lib/model/M2Sequence.ts @@ -0,0 +1,71 @@ +class M2Sequence { + #id: number; + #variationIndex: number; + #duration: number; + #moveSpeed: number; + #flags: number; + #frequency: number; + #blendTime: number; + #variationNext: number; + #aliasNext: number; + + constructor( + id: number, + variationIndex: number, + duration: number, + moveSpeed: number, + flags: number, + frequency: number, + blendTime: number, + variationNext: number, + aliasNext: number, + ) { + this.#id = id; + this.#variationIndex = variationIndex; + this.#duration = duration; + this.#moveSpeed = moveSpeed; + this.#flags = flags; + this.#frequency = frequency; + this.#blendTime = blendTime; + this.#variationNext = variationNext; + this.#aliasNext = aliasNext; + } + + get aliasNext() { + return this.#aliasNext; + } + + get blendTime() { + return this.#blendTime; + } + + get duration() { + return this.#duration; + } + + get flags() { + return this.#flags; + } + + get frequency() { + return this.#frequency; + } + + get id() { + return this.#id; + } + + get moveSpeed() { + return this.#moveSpeed; + } + + get variationIndex() { + return this.#variationIndex; + } + + get variationNext() { + return this.#variationNext; + } +} + +export default M2Sequence;