Skip to content

Commit

Permalink
Merge pull request #14565 from carolhmj/fixOBJImport
Browse files Browse the repository at this point in the history
Parent group entities to object entities on the OBJ loader
  • Loading branch information
sebavan committed Nov 30, 2023
2 parents 239f833 + 4709063 commit 7d2c9ee
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/dev/loaders/src/OBJ/solidParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type MeshObject = {
uvs?: Array<number>;
materialName: string;
directMaterial?: Nullable<Material>;
isObject: boolean; // If the entity is defined as an object ("o"), or group ("g")
_babylonMesh?: AbstractMesh; // The corresponding Babylon mesh
};

/**
Expand Down Expand Up @@ -655,6 +657,7 @@ export class SolidParser {
uvs: undefined,
colors: undefined,
materialName: this._materialNameFromObj,
isObject: SolidParser.ObjectDescriptor.test(line),
};
this._addPreviousObjMesh();

Expand Down Expand Up @@ -686,6 +689,7 @@ export class SolidParser {
uvs: undefined,
colors: undefined,
materialName: this._materialNameFromObj,
isObject: false,
};
this._increment++;
//If meshes are already defined
Expand Down Expand Up @@ -792,6 +796,7 @@ export class SolidParser {
uvs: this._unwrappedUVForBabylon,
materialName: this._materialNameFromObj,
directMaterial: newMaterial,
isObject: true,
});
}

Expand Down Expand Up @@ -819,6 +824,16 @@ export class SolidParser {
const babylonMesh = new Mesh(this._meshesFromObj[j].name, scene);
babylonMesh._parentContainer = assetContainer;
scene._blockEntityCollection = false;
this._handledMesh._babylonMesh = babylonMesh;
// If this is a group mesh, it should have an object mesh as a parent. So look for the first object mesh that appears before it.
if (!this._handledMesh.isObject) {
for (let k = j - 1; k >= 0; --k) {
if (this._meshesFromObj[k].isObject && this._meshesFromObj[k]._babylonMesh) {
babylonMesh.parent = this._meshesFromObj[k]._babylonMesh!;
break;
}
}
}

//Push the name of the material to an array
//This is indispensable for the importMesh function
Expand Down

0 comments on commit 7d2c9ee

Please sign in to comment.