Introduce node types. GroupNode is a node that contains child nodes and optionally some meshes. MeshNode is a node that contains only one mesh. MeshNodes are not visible in the tree.

This commit is contained in:
kovacsv 2021-11-13 20:56:35 +01:00
parent 79cd5189dc
commit ca3fd182b0
5 changed files with 33 additions and 10 deletions

View File

@ -541,6 +541,7 @@ OV.Importer3ds = class extends OV.ImporterBase
let isMeshNode = this.meshNameToIndex.has (node3ds.name); let isMeshNode = this.meshNameToIndex.has (node3ds.name);
node.SetTransformation (GetNodeTransformation (node3ds, isMeshNode)); node.SetTransformation (GetNodeTransformation (node3ds, isMeshNode));
if (isMeshNode) { if (isMeshNode) {
node.SetType (OV.NodeType.MeshNode);
node.AddMeshIndex (this.meshNameToIndex.get (node3ds.name)); node.AddMeshIndex (this.meshNameToIndex.get (node3ds.name));
} }
} }

View File

@ -943,16 +943,15 @@ OV.ImporterGltf = class extends OV.ImporterBase
node.SetTransformation (GetNodeTransformation (gltfNode)); node.SetTransformation (GetNodeTransformation (gltfNode));
parentNode.AddChildNode (node); parentNode.AddChildNode (node);
if (gltfNode.children !== undefined) { if (gltfNode.mesh !== undefined) {
node.SetType (OV.NodeType.MeshNode);
node.AddMeshIndex (gltfNode.mesh);
} else if (gltfNode.children !== undefined) {
for (let childIndex of gltfNode.children) { for (let childIndex of gltfNode.children) {
let childGltfNode = gltf.nodes[childIndex]; let childGltfNode = gltf.nodes[childIndex];
this.ImportNode (gltf, childGltfNode, node); this.ImportNode (gltf, childGltfNode, node);
} }
} }
if (gltfNode.mesh !== undefined) {
node.AddMeshIndex (gltfNode.mesh);
}
} }
GetReaderFromBufferView (bufferView) GetReaderFromBufferView (bufferView)

View File

@ -139,6 +139,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
AddObject (importer, model, childObject, node); AddObject (importer, model, childObject, node);
} }
if (threeObject.isMesh && importer.IsMeshVisible (threeObject)) { if (threeObject.isMesh && importer.IsMeshVisible (threeObject)) {
node.SetType (OV.NodeType.MeshNode);
let mesh = importer.ConvertThreeMesh (threeObject); let mesh = importer.ConvertThreeMesh (threeObject);
let meshIndex = model.AddMesh (mesh); let meshIndex = model.AddMesh (mesh);
node.AddMeshIndex (meshIndex); node.AddMeshIndex (meshIndex);

View File

@ -1,4 +1,8 @@
OV.InvalidNodeId = -1; OV.NodeType =
{
GroupNode : 0,
MeshNode : 1
};
OV.NodeIdGenerator = class OV.NodeIdGenerator = class
{ {
@ -19,6 +23,7 @@ OV.Node = class
{ {
constructor () constructor ()
{ {
this.type = OV.NodeType.GroupNode;
this.name = ''; this.name = '';
this.parent = null; this.parent = null;
this.transformation = new OV.Transformation (); this.transformation = new OV.Transformation ();
@ -35,6 +40,16 @@ OV.Node = class
return this.childNodes.length === 0 && this.meshIndices.length === 0; return this.childNodes.length === 0 && this.meshIndices.length === 0;
} }
GetType ()
{
return this.type;
}
SetType (type)
{
this.type = type;
}
GetId () GetId ()
{ {
return this.id; return this.id;

View File

@ -591,16 +591,23 @@ OV.NavigatorMeshesPanel = class extends OV.NavigatorPanel
function AddModelNodeToTree (panel, model, node, parentItem, showTree) function AddModelNodeToTree (panel, model, node, parentItem, showTree)
{ {
let meshNodes = [];
for (let childNode of node.GetChildNodes ()) { for (let childNode of node.GetChildNodes ()) {
if (showTree) { if (showTree) {
let nodeItem = CreateNodeItem (panel, childNode); if (childNode.GetType () === OV.NodeType.GroupNode) {
parentItem.AddChild (nodeItem); let nodeItem = CreateNodeItem (panel, childNode);
AddModelNodeToTree (panel, model, childNode, nodeItem, showTree); parentItem.AddChild (nodeItem);
AddModelNodeToTree (panel, model, childNode, nodeItem, showTree);
} else if (childNode.GetType () === OV.NodeType.MeshNode) {
meshNodes.push (childNode);
}
} else { } else {
AddModelNodeToTree (panel, model, childNode, parentItem, showTree); AddModelNodeToTree (panel, model, childNode, parentItem, showTree);
} }
} }
for (let meshNode of meshNodes) {
AddModelNodeToTree (panel, model, meshNode, parentItem, showTree);
}
for (let meshIndex of node.GetMeshIndices ()) { for (let meshIndex of node.GetMeshIndices ()) {
AddMeshToNodeTree (panel, model, node, meshIndex, parentItem, showTree); AddMeshToNodeTree (panel, model, node, meshIndex, parentItem, showTree);
} }