Skip to content

Commit

Permalink
feat(model): include sequence bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Jan 31, 2024
1 parent 702aa69 commit 027f7d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 94 deletions.
41 changes: 19 additions & 22 deletions src/lib/model/M2Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { IoMode, IoSource, openStream } from '@wowserhq/io';
import * as io from '@wowserhq/io';
import * as m2Io from './io/m2.js';
import { M2_MODEL_FLAG } from './const.js';
import { M2Track, M2TextureTransform, M2TextureWeight, M2Color, M2Bone } from './types.js';
import {
M2Sequence,
M2Track,
M2TextureTransform,
M2TextureWeight,
M2Color,
M2Bone,
} from './types.js';
import M2Texture, { M2_TEXTURE_COMBINER, M2_TEXTURE_COORD } from './M2Texture.js';
import M2Material from './M2Material.js';
import { m2typedArray } from './io/common.js';
import M2Sequence from './M2Sequence.js';
import M2Bounds from './M2Bounds.js';

class M2Model {
Expand Down Expand Up @@ -156,7 +162,7 @@ class M2Model {

this.#loadMaterials(data);

this.#loadSequences(data);
this.#sequences = data.sequences;

return this;
}
Expand All @@ -167,24 +173,6 @@ 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(
Expand All @@ -195,4 +183,13 @@ class M2Model {
}

export default M2Model;
export { M2Model, M2Track, M2Bone, M2Color, M2TextureWeight, M2TextureTransform, M2_MODEL_FLAG };
export {
M2Model,
M2Track,
M2Bone,
M2Color,
M2Sequence,
M2TextureWeight,
M2TextureTransform,
M2_MODEL_FLAG,
};
71 changes: 0 additions & 71 deletions src/lib/model/M2Sequence.ts

This file was deleted.

20 changes: 19 additions & 1 deletion src/lib/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ type M2Track<T> = {
sequenceKeys: T[];
};

type M2Bounds = {
extent: Float32Array;
radius: number;
};

type M2Bone = {
boneId: number;
flags: number;
Expand All @@ -22,6 +27,19 @@ type M2Color = {
alphaTrack: M2Track<Int16Array>;
};

type M2Sequence = {
id: number;
variationIndex: number;
duration: number;
moveSpeed: number;
flags: number;
frequency: number;
blendTime: number;
bounds: M2Bounds;
variationNext: number;
aliasNext: number;
};

type M2TextureTransform = {
translationTrack: M2Track<Float32Array>;
rotationTrack: M2Track<Float32Array>;
Expand All @@ -32,4 +50,4 @@ type M2TextureWeight = {
weightTrack: M2Track<Int16Array>;
};

export { M2Track, M2Bone, M2Color, M2TextureTransform, M2TextureWeight };
export { M2Bone, M2Color, M2Sequence, M2TextureTransform, M2TextureWeight, M2Track };

0 comments on commit 027f7d8

Please sign in to comment.