Fix order of nodes in glTF export.
This commit is contained in:
parent
7a6cdaee68
commit
8cb4bd284b
@ -273,31 +273,46 @@ export class ExporterGltf extends ExporterBase
|
||||
}
|
||||
}
|
||||
|
||||
function NodeHasVisibleChildren (model, node)
|
||||
{
|
||||
for (let meshIndex of node.GetMeshIndices ()) {
|
||||
let meshInstanceId = new MeshInstanceId (node.GetId (), meshIndex);
|
||||
if (model.IsMeshInstanceVisible (meshInstanceId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (let childNode of node.GetChildNodes ()) {
|
||||
if (NodeHasVisibleChildren (model, childNode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function AddNode (model, jsonParent, jsonNodes, node)
|
||||
{
|
||||
if (node.IsMeshNode ()) {
|
||||
for (let meshIndex of node.GetMeshIndices ()) {
|
||||
AddMeshNode (model, jsonParent, jsonNodes, node, meshIndex, true);
|
||||
}
|
||||
} else {
|
||||
} else if (NodeHasVisibleChildren (model, node)) {
|
||||
let nodeJson = {};
|
||||
|
||||
let nodeName = node.GetName ();
|
||||
if (nodeName.length > 0) {
|
||||
nodeJson.name = node.GetName ();
|
||||
nodeJson.name = nodeName;
|
||||
}
|
||||
|
||||
let transformation = node.GetTransformation ();
|
||||
if (!transformation.IsIdentity ()) {
|
||||
nodeJson.matrix = node.GetTransformation ().GetMatrix ().Get ();
|
||||
}
|
||||
|
||||
if (node.ChildNodeCount () > 0 || node.MeshIndexCount () > 0) {
|
||||
nodeJson.children = [];
|
||||
AddChildNodes (model, nodeJson.children, jsonNodes, node);
|
||||
if (nodeJson.children.length > 0) {
|
||||
jsonNodes.push (nodeJson);
|
||||
jsonParent.push (jsonNodes.length - 1);
|
||||
}
|
||||
}
|
||||
jsonNodes.push (nodeJson);
|
||||
jsonParent.push (jsonNodes.length - 1);
|
||||
|
||||
nodeJson.children = [];
|
||||
AddChildNodes (model, nodeJson.children, jsonNodes, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,15 @@ export class Model extends ModelObject3D
|
||||
return this.root;
|
||||
}
|
||||
|
||||
NodeCount ()
|
||||
{
|
||||
let count = 0;
|
||||
this.root.Enumerate ((node) => {
|
||||
count += 1;
|
||||
});
|
||||
return count - 1;
|
||||
}
|
||||
|
||||
MaterialCount ()
|
||||
{
|
||||
return this.materials.length;
|
||||
|
||||
@ -425,6 +425,7 @@ describe ('Exporter', function () {
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
assert.ok (OV.CheckModel (importedModel));
|
||||
assert.strictEqual (importedModel.NodeCount (), 5);
|
||||
assert.strictEqual (importedModel.MaterialCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshInstanceCount (), 4);
|
||||
@ -459,6 +460,7 @@ describe ('Exporter', function () {
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
assert.ok (OV.CheckModel (importedModel));
|
||||
assert.strictEqual (importedModel.NodeCount (), 4);
|
||||
assert.strictEqual (importedModel.MaterialCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshInstanceCount (), 3);
|
||||
@ -493,6 +495,7 @@ describe ('Exporter', function () {
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
assert.ok (OV.CheckModel (importedModel));
|
||||
assert.strictEqual (importedModel.NodeCount (), 3);
|
||||
assert.strictEqual (importedModel.MaterialCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshCount (), 2);
|
||||
assert.strictEqual (importedModel.MeshInstanceCount (), 2);
|
||||
@ -501,6 +504,41 @@ describe ('Exporter', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it ('Gltf Hierarchical Export Filter 2', function (done) {
|
||||
let model = CreateHierarchicalTestModelForExport ();
|
||||
let settings = new OV.ExporterSettings ({
|
||||
isMeshVisible : (meshInstanceId) => {
|
||||
return meshInstanceId.IsEqual (new OV.MeshInstanceId (1, 0));
|
||||
}
|
||||
});
|
||||
Export (model, settings, OV.FileFormat.Binary, 'glb', function (result) {
|
||||
assert.strictEqual (result.length, 1);
|
||||
|
||||
let glbFile = result[0];
|
||||
assert.strictEqual (glbFile.GetName (), 'model.glb');
|
||||
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getFileBuffer (filePath) {
|
||||
return null;
|
||||
},
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
assert.ok (OV.CheckModel (importedModel));
|
||||
assert.strictEqual (importedModel.NodeCount (), 2);
|
||||
assert.strictEqual (importedModel.MaterialCount (), 3);
|
||||
assert.strictEqual (importedModel.MeshCount (), 1);
|
||||
assert.strictEqual (importedModel.MeshInstanceCount (), 1);
|
||||
done ();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -421,7 +421,7 @@ export function CreateHierarchicalTestModelForExport ()
|
||||
|
||||
let material2 = new OV.PhongMaterial ();
|
||||
material2.name = 'Material 2';
|
||||
material1.color = new OV.RGBColor (0, 255, 0);
|
||||
material2.color = new OV.RGBColor (0, 255, 0);
|
||||
model.AddMaterial (material2);
|
||||
|
||||
let material3 = new OV.PhongMaterial ();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user