Skip to content

Commit

Permalink
feat(mapobj): load group colors
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 25, 2024
1 parent 78d776f commit b2957fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Binary file added fixture/mapobj/inn_003.wmo
Binary file not shown.
10 changes: 10 additions & 0 deletions src/lib/mapobj/MapObjGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ class MapObjGroup {
#indices: Uint16Array;
#normals: Float32Array;
#textureCoords: Float32Array;
#colors: Uint8Array;
#vertices: Float32Array;

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

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

get indices() {
return this.#indices;
}
Expand Down Expand Up @@ -77,6 +82,11 @@ class MapObjGroup {
this.#textureCoords = textureCoordsChunk;
}

const colorsChunk = groupData.get('MOCV');
if (colorsChunk) {
this.#colors = colorsChunk;
}

const verticesChunk = groupData.get('MOVT');
if (verticesChunk) {
this.#vertices = verticesChunk;
Expand Down
23 changes: 22 additions & 1 deletion src/spec/mapobj/MapObjGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MapObjGroup from '../../lib/mapobj/MapObjGroup.js';
describe('MapObjGroup', () => {
describe('load', () => {
describe('inn', () => {
test('should load mapobj group from valid file', () => {
test('should load exterior mapobj group from valid file', () => {
const mapObjGroup = new MapObjGroup().load('./fixture/mapobj/inn_000.wmo');

expect(mapObjGroup.version).toBe(17);
Expand All @@ -17,6 +17,27 @@ describe('MapObjGroup', () => {
expect(mapObjGroup.batches[0].vertexStart).toBe(0);
expect(mapObjGroup.batches[0].vertexCount).toBe(69);
expect(mapObjGroup.batches[0].materialIndex).toBe(6);

expect(mapObjGroup.vertices.length).toBe(8277);
expect(mapObjGroup.colors).toBeUndefined();
});

test('should load interior mapobj group from valid file', () => {
const mapObjGroup = new MapObjGroup().load('./fixture/mapobj/inn_003.wmo');

expect(mapObjGroup.version).toBe(17);

expect(mapObjGroup.batches.length).toBe(13);
expect(mapObjGroup.batches[0].flags).toBe(0);
expect(mapObjGroup.batches[0].boundingBox).toStrictEqual([-34, -1, +0, -28, 5, 7]);
expect(mapObjGroup.batches[0].indexStart).toBe(0);
expect(mapObjGroup.batches[0].indexCount).toBe(453);
expect(mapObjGroup.batches[0].vertexStart).toBe(0);
expect(mapObjGroup.batches[0].vertexCount).toBe(122);
expect(mapObjGroup.batches[0].materialIndex).toBe(6);

expect(mapObjGroup.vertices.length).toBe(6930);
expect(mapObjGroup.colors.length).toBe((6930 / 3) * 4);
});
});
});
Expand Down

0 comments on commit b2957fa

Please sign in to comment.