Node list instead of hierarchy in o3dv files.

This commit is contained in:
kovacsv 2021-11-22 16:52:45 +01:00
parent 583ab14e34
commit e8e6108dfe
5 changed files with 194 additions and 224 deletions

View File

@ -29,6 +29,11 @@ OV.ImporterO3dv = class extends OV.ImporterBase
{
let textContent = OV.ArrayBufferToUtf8String (fileContent);
let content = JSON.parse (textContent);
if (content.root === undefined) {
onFinish ();
return;
}
if (content.materials !== undefined) {
for (let i = 0; i < content.materials.length; i++) {
const materialContent = content.materials[i];
@ -41,10 +46,11 @@ OV.ImporterO3dv = class extends OV.ImporterBase
this.ImportMesh (meshContent);
}
}
if (content.root !== undefined) {
this.ImportNode (content, content.root, this.model.GetRootNode ());
}
let rootNode = content.nodes[content.root];
this.ImportNode (content, rootNode, this.model.GetRootNode ());
this.ImportProperties (this.model, content);
onFinish ();
}
@ -121,24 +127,18 @@ OV.ImporterO3dv = class extends OV.ImporterBase
node.SetTransformation (nodeTransformation);
}
if (nodeContent.children !== undefined) {
for (const child of nodeContent.children) {
for (const childIndex of nodeContent.children) {
let childContent = content.nodes[childIndex];
let childNode = new OV.Node ();
node.AddChildNode (childNode);
this.ImportNode (content, child, childNode);
this.ImportNode (content, childContent, childNode);
}
}
if (nodeContent.meshes !== undefined) {
for (const meshIndex of nodeContent.meshes) {
let meshNode = new OV.Node ();
meshNode.SetType (OV.NodeType.MeshNode);
let meshContent = content.meshes[meshIndex];
if (meshContent.transformation !== undefined) {
let meshTransformation = this.GetTransformation (meshContent.transformation);
meshNode.SetTransformation (meshTransformation);
}
meshNode.AddMeshIndex (meshIndex);
node.AddChildNode (meshNode);
if (nodeContent.mesh !== undefined) {
if (nodeContent.children === undefined || nodeContent.children.length === 0) {
node.SetType (OV.NodeType.MeshNode);
}
node.AddMeshIndex (nodeContent.mesh);
}
}

View File

@ -1,50 +0,0 @@
{
"root" : {
"children" : [
{
"name" : "Translated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [0]
},
{
"name" : "Rotated",
"transformation" : {
"rotation" : [0.0, 0.0, 0.7071067811865475, 0.7071067811865476]
},
"children" : [
{
"name" : "Translated and Rotated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [0]
}
]
}
],
"meshes" : [0]
},
"materials" : [
{
"name" : "Green",
"color" : [0, 200, 0]
}
],
"meshes" : [
{
"name" : "Cube",
"type" : "cuboid",
"material" : 0,
"transformation" : {
"scale" : [1.5, 0.2, 0.2]
},
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
}
]
}

View File

@ -1,105 +1,106 @@
{
"root" : {
"children" : [
{
"name" : "Cubes",
"transformation" : {
"translation" : [0.0, 0.0, 2.0]
},
"children" : [
{
"name" : "Cube 01",
"transformation" : {
"translation" : [0.0, 0.0, 0.0]
},
"meshes" : [0]
},
{
"name" : "Cube 02",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [0]
},
{
"name" : "Cube 03",
"transformation" : {
"translation" : [2.0, 2.0, 0.0]
},
"meshes" : [0]
},
{
"name" : "Cube 04",
"transformation" : {
"translation" : [0.0, 2.0, 0.0]
},
"meshes" : [0]
}
]
"root" : 0,
"nodes" : [
{
"children" : [1, 2, 3, 4, 15, 16]
},
{
"name" : "Cubes",
"transformation" : {
"translation" : [0.0, 0.0, 2.0]
},
{
"name" : "Spheres",
"transformation" : {
"translation" : [0.0, 0.0, 4.0]
},
"children" : [
{
"name" : "Spheres 01",
"transformation" : {
"translation" : [0.0, 0.0, 0.0]
},
"meshes" : [1]
},
{
"name" : "Spheres 02",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [1]
},
{
"name" : "Spheres 03",
"transformation" : {
"translation" : [2.0, 2.0, 0.0]
},
"meshes" : [1]
},
{
"name" : "Spheres 04",
"transformation" : {
"translation" : [0.0, 2.0, 0.0]
},
"meshes" : [1]
}
]
"children" : [5, 6, 7, 8]
},
{
"name" : "Cubes 2",
"transformation" : {
"translation" : [0.0, 0.0, 4.0]
},
{
"name" : "Cube and Sphere",
"transformation" : {
"translation" : [0.0, 0.0, 6.0]
},
"children" : [
{
"name" : "Cube 01",
"transformation" : {
"translation" : [0.0, 0.0, 0.0],
"scale" : [0.8, 0.8, 0.8]
},
"meshes" : [0]
},
{
"name" : "Sphere 01",
"transformation" : {
"translation" : [2.0, 0.0, 0.0],
"scale" : [0.8, 0.8, 0.8]
},
"meshes" : [1]
}
]
}
],
"meshes" : [0, 1]
},
"children" : [5, 6, 7, 8]
},
{
"name" : "Spheres",
"transformation" : {
"translation" : [0.0, 0.0, 6.0]
},
"children" : [9, 10, 11, 12]
},
{
"name" : "Cube and Sphere",
"transformation" : {
"translation" : [0.0, 0.0, 8.0]
},
"children" : [13, 14]
},
{
"transformation" : {
"translation" : [0.0, 0.0, 0.0]
},
"mesh" : 0
},
{
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"mesh" : 0
},
{
"transformation" : {
"translation" : [2.0, 2.0, 0.0]
},
"mesh" : 0
},
{
"transformation" : {
"translation" : [0.0, 2.0, 0.0]
},
"mesh" : 0
},
{
"transformation" : {
"translation" : [0.0, 0.0, 0.0]
},
"mesh" : 1
},
{
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"mesh" : 1
},
{
"transformation" : {
"translation" : [2.0, 2.0, 0.0]
},
"mesh" : 1
},
{
"transformation" : {
"translation" : [0.0, 2.0, 0.0]
},
"mesh" : 1
},
{
"transformation" : {
"translation" : [0.0, 0.0, 0.0],
"scale" : [0.8, 0.8, 0.8]
},
"mesh" : 0
},
{
"transformation" : {
"translation" : [2.0, 0.0, 0.0],
"scale" : [0.8, 0.8, 0.8]
},
"mesh" : 1
},
{
"mesh" : 0
},
{
"mesh" : 1
}
],
"materials" : [
{
"name" : "Green",
@ -109,7 +110,7 @@
"name" : "Blue",
"color" : [0, 0, 200]
}
],
],
"meshes" : [
{
"name" : "Cube",

View File

@ -3,25 +3,54 @@
{ "name" : "Author", "value" : "Viktor Kovács" },
{ "name" : "License", "value" : "MIT" }
],
"root" : {
"children" : [
{
"name" : "Tetrahedral",
"meshes" : [0]
},
{
"name" : "Octahedral",
"meshes" : [1, 2]
},
{
"name" : "Icosahedral",
"meshes" : [3, 4]
"root" : 0,
"nodes" : [
{
"children" : [1, 2, 3],
"transformation" : {
"rotation" : [0.7071067811865475, 0.0, 0.0, 0.7071067811865476]
}
},
{
"name" : "Tetrahedral",
"children" : [4]
},
{
"name" : "Octahedral",
"children" : [5, 6]
},
{
"name" : "Icosahedral",
"children" : [7, 8]
},
{
"mesh" : 0
},
{
"mesh" : 1,
"transformation" : {
"translation" : [0.0, 3.0, 0.0]
}
},
{
"mesh" : 2,
"transformation" : {
"translation" : [3.0, 0.0, 0.0]
}
},
{
"mesh" : 3,
"transformation" : {
"translation" : [3.0, 3.0, 0.0]
}
},
{
"mesh" : 4,
"transformation" : {
"translation" : [6.0, 1.5, 0.0]
}
],
"transformation" : {
"rotation" : [0.7071067811865475, 0.0, 0.0, 0.7071067811865476]
}
},
],
"materials" : [
{
"name" : "Red",
@ -65,9 +94,6 @@
"name" : "Hexahedron",
"type" : "platonic",
"material" : 1,
"transformation" : {
"translation" : [0.0, 3.0, 0.0]
},
"parameters" : {
"solid_type" : "hexahedron",
"radius" : 1.0
@ -84,9 +110,6 @@
"name" : "Octahedron",
"type" : "platonic",
"material" : 2,
"transformation" : {
"translation" : [3.0, 0.0, 0.0]
},
"parameters" : {
"solid_type" : "octahedron",
"radius" : 1.0
@ -103,9 +126,6 @@
"name" : "Dodecahedron",
"type" : "platonic",
"material" : 3,
"transformation" : {
"translation" : [3.0, 3.0, 0.0]
},
"parameters" : {
"solid_type" : "dodecahedron",
"radius" : 1.0
@ -122,9 +142,6 @@
"name" : "Icosahedron",
"type" : "platonic",
"material" : 4,
"transformation" : {
"translation" : [6.0, 1.5, 0.0]
},
"parameters" : {
"solid_type" : "icosahedron",
"radius" : 1.0

View File

@ -1,38 +1,40 @@
{
"root" : {
"children" : [
{
"name" : "Translated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [0]
},
{
"name" : "Rotated",
"transformation" : {
"rotation" : [0.0, 0.0, 0.7071067811865475, 0.7071067811865476]
},
"children" : [
{
"name" : "Translated and Rotated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"meshes" : [0]
}
]
}
],
"meshes" : [0]
},
"root" : 0,
"materials" : [
{
"name" : "Green",
"color" : [0, 200, 0]
}
],
],
"nodes" : [
{
"children" : [1, 2, 4]
},
{
"name" : "Translated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"children" : [4]
},
{
"name" : "Rotated",
"transformation" : {
"rotation" : [0.0, 0.0, 0.7071067811865475, 0.7071067811865476]
},
"children" : [3]
},
{
"name" : "Translated and Rotated",
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"children" : [4]
},
{
"mesh" : 0
}
],
"meshes" : [
{
"name" : "Cube",