Skip to content

Commit

Permalink
adjust test (passes test)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsErdkamp committed May 30, 2024
1 parent 4cf2aa7 commit 8f3210f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
33 changes: 22 additions & 11 deletions src/gltf/gltf-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export class glTFParser {
* Creates a new parser using the specified asset.
* @param asset The asset to parse.
* @param materialFactory The material factory to use.
* @param meshoptDecoder optionally provide meshoptDecoder to parse meshopt meshes.
* @param meshoptDecoder provide meshoptimizer's meshoptDecoder to parse meshopt meshes.
*/
constructor(asset: glTFAsset, materialFactory?: MaterialFactory, meshoptDecoder?: any) {
constructor(
asset: glTFAsset,
materialFactory?: MaterialFactory,
meshoptDecoder?: any
) {
this._asset = asset;
this._materialFactory = materialFactory || new StandardMaterialFactory();
this._descriptor = this._asset.descriptor;
Expand All @@ -52,7 +56,11 @@ export class glTFParser {
* @param asset The asset to create the model from.
* @param materialFactory The material factory to use.
*/
static createModel(asset: glTFAsset, materialFactory?: MaterialFactory, meshoptDecoder ?: any) {
static createModel(
asset: glTFAsset,
materialFactory?: MaterialFactory,
meshoptDecoder?: any
) {
return new glTFParser(asset, materialFactory, meshoptDecoder).parseModel();
}

Expand Down Expand Up @@ -100,15 +108,18 @@ export class glTFParser {
let buffer = this._asset.buffers[bufferView.buffer];

if (bufferView.extensions?.EXT_meshopt_compression != undefined) {

if (this._meshoptDecoder == undefined) {
console.error('Buffer uses EXT_meshopt_compression but meshoptDecoder is not provided.');
return;
if (this._meshoptDecoder != undefined) {
const meshoptExtension = bufferView.extensions.EXT_meshopt_compression;
buffer = this.decodeMeshoptBuffer(
meshoptExtension,
accessor.bufferView
);
offset = accessor.byteOffset || 0;
} else {
console.error(
"Buffer uses EXT_meshopt_compression but meshoptDecoder is not provided."
);
}

const meshoptExtension = bufferView.extensions.EXT_meshopt_compression;
buffer = this.decodeMeshoptBuffer(meshoptExtension, accessor.bufferView);
offset = accessor.byteOffset || 0;
}

return glTFAttribute.from(
Expand Down
5 changes: 4 additions & 1 deletion test/gltf.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import { MeshoptDecoder } from "meshoptimizer";

describe("glTF", () => {
it("should render separate correctly using pixi *.*.*", async () => {
Expand Down Expand Up @@ -52,7 +53,9 @@ describe("glTF", () => {
it("should render meshopt correctly using pixi *.*.*", async () => {
let render = (renderer, resources) => {
let model = PIXI3D.Model.from(
resources["assets/teapot/teapot-binary-meshopt.glb"].gltf
resources["assets/teapot/teapot-binary-meshopt.glb"].gltf,
undefined,
MeshoptDecoder
);
model.y = -0.8;
model.meshes.forEach((mesh) => {
Expand Down

0 comments on commit 8f3210f

Please sign in to comment.