Skip to content

Commit

Permalink
feat(model): load color animations
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Jan 24, 2024
1 parent b5d698e commit a2b6750
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/lib/model/M2Batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class M2Batch {
#textures: M2Texture[];
#textureWeightIndex: number;
#textureTransformIndices: number[];
#colorIndex: number;
#vertexShader: M2_VERTEX_SHADER;
#fragmentShader: M2_FRAGMENT_SHADER;

Expand All @@ -24,6 +25,7 @@ class M2Batch {
textures: M2Texture[],
textureWeightIndex: number,
textureTransformIndices: number[],
colorIndex: number,
vertexShader: M2_VERTEX_SHADER,
fragmentShader: M2_FRAGMENT_SHADER,
) {
Expand All @@ -35,10 +37,15 @@ class M2Batch {
this.#textures = textures;
this.#textureWeightIndex = textureWeightIndex;
this.#textureTransformIndices = textureTransformIndices;
this.#colorIndex = colorIndex;
this.#vertexShader = vertexShader;
this.#fragmentShader = fragmentShader;
}

get colorIndex() {
return this.#colorIndex;
}

get flags() {
return this.#flags;
}
Expand Down
12 changes: 10 additions & 2 deletions src/lib/model/M2Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 } from './types.js';
import { M2Track, M2TextureTransform, M2TextureWeight, M2Color } 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';
Expand All @@ -25,6 +25,8 @@ class M2Model {
#textureTransformCombos: number[] = [];
#textureCombinerCombos: M2_TEXTURE_COMBINER[] = [];

#colors: M2Color[] = [];

#materials: M2Material[] = [];
#skinProfileCount: number;

Expand All @@ -39,6 +41,10 @@ class M2Model {
return this.#collisionBounds;
}

get colors() {
return this.#colors;
}

get flags() {
return this.#flags;
}
Expand Down Expand Up @@ -130,6 +136,8 @@ class M2Model {
this.#textureTransforms = data.textureTransforms;
this.#textureWeights = data.textureWeights;

this.#colors = data.colors;

this.#loadMaterials(data);

this.#loadSequences(data);
Expand Down Expand Up @@ -171,4 +179,4 @@ class M2Model {
}

export default M2Model;
export { M2Model, M2Track, M2TextureWeight, M2TextureTransform, M2_MODEL_FLAG };
export { M2Model, M2Track, M2Color, M2TextureWeight, M2TextureTransform, M2_MODEL_FLAG };
1 change: 1 addition & 0 deletions src/lib/model/M2SkinProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class M2SkinProfile {
textures,
textureWeightIndex,
textureTransformIndices,
batchData.colorIndex,
vertexShader,
fragmentShader,
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model/io/m2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const m2vertex = io.struct({

const m2color = io.struct({
colorTrack: m2track(io.float32le, 3),
alphaTrack: m2track(io.uint16le),
alphaTrack: m2track(io.int16le),
});

const m2texture = io.struct({
Expand Down
7 changes: 6 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 M2Color = {
colorTrack: M2Track<Float32Array>;
alphaTrack: M2Track<Int16Array>;
};

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

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

0 comments on commit a2b6750

Please sign in to comment.