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);
node.SetTransformation (GetNodeTransformation (node3ds, isMeshNode));
if (isMeshNode) {
node.SetType (OV.NodeType.MeshNode);
node.AddMeshIndex (this.meshNameToIndex.get (node3ds.name));
}
}

View File

@ -943,16 +943,15 @@ OV.ImporterGltf = class extends OV.ImporterBase
node.SetTransformation (GetNodeTransformation (gltfNode));
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) {
let childGltfNode = gltf.nodes[childIndex];
this.ImportNode (gltf, childGltfNode, node);
}
}
if (gltfNode.mesh !== undefined) {
node.AddMeshIndex (gltfNode.mesh);
}
}
GetReaderFromBufferView (bufferView)

View File

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

View File

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

View File

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