Skip to content

Commit

Permalink
feat(model): expose all skin section attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 10, 2024
1 parent 4476ea7 commit f459180
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/lib/model/M2Batch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import M2Material from './M2Material.js';
import M2SkinSection from './M2SkinSection.js';
import M2Texture from './M2Texture.js';
import { M2_FRAGMENT_SHADER, M2_VERTEX_SHADER } from './const.js';
import { M2SkinSection } from './types.js';

class M2Batch {
#flags: number;
Expand Down
23 changes: 15 additions & 8 deletions src/lib/model/M2SkinProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { IoMode, IoSource, openStream } from '@wowserhq/io';
import * as m2Io from './io/m2.js';
import M2Batch from './M2Batch.js';
import M2Model from './M2Model.js';
import M2SkinSection from './M2SkinSection.js';
import { M2_FRAGMENT_SHADER, M2_VERTEX_SHADER } from './const.js';
import { M2SkinSection } from './types.js';
import { getBatchShaders, normalizeBatches } from './batch.js';

class M2SkinProfile {
Expand Down Expand Up @@ -53,13 +53,20 @@ class M2SkinProfile {

#loadSkinSections(data: any) {
for (const skinSectionData of data.skinSections) {
const skinSection = new M2SkinSection(
skinSectionData.skinSectionId,
skinSectionData.vertexStart | (skinSectionData.level << 16),
skinSectionData.vertexCount,
skinSectionData.indexStart | (skinSectionData.level << 16),
skinSectionData.indexCount,
);
const skinSection = {
id: skinSectionData.id,
vertexStart: skinSectionData.vertexStart | (skinSectionData.level << 16),
vertexCount: skinSectionData.vertexCount,
indexStart: skinSectionData.indexStart | (skinSectionData.level << 16),
indexCount: skinSectionData.indexCount,
boneCount: skinSectionData.boneCount,
boneComboIndex: skinSectionData.boneComboIndex,
boneInfluences: skinSectionData.boneInfluences,
centerBoneIndex: skinSectionData.centerBoneIndex,
centerPosition: skinSectionData.centerPosition,
sortCenterPosition: skinSectionData.sortCenterPosition,
sortRadius: skinSectionData.sortRadius,
};

this.#skinSections.push(skinSection);
}
Expand Down
45 changes: 0 additions & 45 deletions src/lib/model/M2SkinSection.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/lib/model/io/m2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const m2particle = io.struct({
});

const m2skinSection = io.struct({
skinSectionId: io.uint16le,
id: io.uint16le,
level: io.uint16le,
vertexStart: io.uint16le,
vertexCount: io.uint16le,
Expand All @@ -126,8 +126,8 @@ const m2skinSection = io.struct({
boneComboIndex: io.uint16le,
boneInfluences: io.uint16le,
centerBoneIndex: io.uint16le,
centerPosition: io.typedArray(io.float32le, { size: 3 }),
sortCenterPosition: io.typedArray(io.float32le, { size: 3 }),
centerPosition: io.array(io.float32le, { size: 3 }),
sortCenterPosition: io.array(io.float32le, { size: 3 }),
sortRadius: io.float32le,
});

Expand Down
17 changes: 16 additions & 1 deletion src/lib/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ type M2Sequence = {
aliasNext: number;
};

type M2SkinSection = {
id: number;
vertexStart: number;
vertexCount: number;
indexStart: number;
indexCount: number;
boneCount: number;
boneComboIndex: number;
boneInfluences: number;
centerBoneIndex: number;
centerPosition: number[];
sortCenterPosition: number[];
sortRadius: number;
};

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

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

0 comments on commit f459180

Please sign in to comment.