Add solids example as o3dv file.

This commit is contained in:
kovacsv 2021-11-12 16:30:25 +01:00
parent 6732e8bb70
commit c504d74b5d
2 changed files with 168 additions and 13 deletions

View File

@ -4,7 +4,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
{
super ();
}
CanImportExtension (extension)
{
return extension === 'o3dv';
@ -14,10 +14,10 @@ OV.ImporterO3dv = class extends OV.ImporterBase
{
return OV.Direction.Z;
}
ClearContent ()
{
}
ResetContent ()
@ -44,6 +44,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
if (content.root !== undefined) {
this.ImportNode (content.root, this.model.GetRootNode ());
}
this.ImportProperties (this.model, content);
onFinish ();
}
@ -71,7 +72,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
if (meshContent.material !== undefined) {
genParams.SetMaterial (meshContent.material);
}
// TODO: remove transformation from mesh, and from generator
if (meshContent.transformation !== undefined) {
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
@ -121,26 +122,27 @@ OV.ImporterO3dv = class extends OV.ImporterBase
mesh = OV.GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
}
if (mesh !== null) {
this.ImportProperties (mesh, meshContent);
this.model.AddMesh (mesh);
}
}
ImportNode (node, meshNode)
ImportNode (nodeContent, meshNode)
{
if (node.name !== undefined) {
meshNode.SetName (node.name);
if (nodeContent.name !== undefined) {
meshNode.SetName (nodeContent.name);
}
if (node.transformation !== undefined) {
const nodeTransformation = this.GetTransformation (node.transformation);
if (nodeContent.transformation !== undefined) {
const nodeTransformation = this.GetTransformation (nodeContent.transformation);
meshNode.SetTransformation (nodeTransformation);
}
if (node.meshes !== undefined) {
for (const meshIndex of node.meshes) {
if (nodeContent.meshes !== undefined) {
for (const meshIndex of nodeContent.meshes) {
meshNode.AddMeshIndex (meshIndex);
}
}
if (node.children !== undefined) {
for (const child of node.children) {
if (nodeContent.children !== undefined) {
for (const child of nodeContent.children) {
let childMeshNode = new OV.Node ();
meshNode.AddChildNode (childMeshNode);
this.ImportNode (child, childMeshNode);
@ -148,6 +150,18 @@ OV.ImporterO3dv = class extends OV.ImporterBase
}
}
ImportProperties (element, nodeContent)
{
if (nodeContent.properties !== undefined) {
const propertyGroup = new OV.PropertyGroup ('Properties');
element.AddPropertyGroup (propertyGroup);
for (const nodeProperty of nodeContent.properties) {
const property = new OV.Property (OV.PropertyType.Text, nodeProperty.name, nodeProperty.value);
propertyGroup.AddProperty (property);
}
}
}
GetTransformation (contentTransformation)
{
let translation = new OV.Coord3D (0.0, 0.0, 0.0);

View File

@ -0,0 +1,141 @@
{
"properties" : [
{ "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]
}
],
"transformation" : {
"rotation" : [0.7071067811865475, 0.0, 0.0, 0.7071067811865476]
}
},
"materials" : [
{
"name" : "Red",
"color" : [204, 51, 51]
},
{
"name" : "Green",
"color" : [39, 155, 97]
},
{
"name" : "Blue",
"color" : [0, 138, 184]
},
{
"name" : "Orange",
"color" : [255, 204, 51]
},
{
"name" : "Purple",
"color" : [204, 102, 153]
}
],
"meshes" : [
{
"name" : "Tetrahedron",
"type" : "platonic",
"material" : 0,
"parameters" : {
"solid_type" : "tetrahedron",
"radius" : 1.0
},
"properties" : [
{ "name" : "Name", "value" : "Tetrahedron" },
{ "name" : "Dual", "value" : "Tetrahedron" },
{ "name" : "Vertices", "value" : "4" },
{ "name" : "Edges", "value" : "6" },
{ "name" : "Faces", "value" : "4" }
]
},
{
"name" : "Hexahedron",
"type" : "platonic",
"material" : 1,
"transformation" : {
"translation" : [0.0, 3.0, 0.0]
},
"parameters" : {
"solid_type" : "hexahedron",
"radius" : 1.0
},
"properties" : [
{ "name" : "Name", "value" : "Hexahedron" },
{ "name" : "Dual", "value" : "Octahedron" },
{ "name" : "Vertices", "value" : "8" },
{ "name" : "Edges", "value" : "12" },
{ "name" : "Faces", "value" : "6" }
]
},
{
"name" : "Octahedron",
"type" : "platonic",
"material" : 2,
"transformation" : {
"translation" : [3.0, 0.0, 0.0]
},
"parameters" : {
"solid_type" : "octahedron",
"radius" : 1.0
},
"properties" : [
{ "name" : "Name", "value" : "Octahedron" },
{ "name" : "Dual", "value" : "Hexahedron" },
{ "name" : "Vertices", "value" : "6" },
{ "name" : "Edges", "value" : "12" },
{ "name" : "Faces", "value" : "8" }
]
},
{
"name" : "Dodecahedron",
"type" : "platonic",
"material" : 3,
"transformation" : {
"translation" : [3.0, 3.0, 0.0]
},
"parameters" : {
"solid_type" : "dodecahedron",
"radius" : 1.0
},
"properties" : [
{ "name" : "Name", "value" : "Dodecahedron" },
{ "name" : "Dual", "value" : "Icosahedron" },
{ "name" : "Vertices", "value" : "20" },
{ "name" : "Edges", "value" : "30" },
{ "name" : "Faces", "value" : "12" }
]
},
{
"name" : "Icosahedron",
"type" : "platonic",
"material" : 4,
"transformation" : {
"translation" : [6.0, 1.5, 0.0]
},
"parameters" : {
"solid_type" : "icosahedron",
"radius" : 1.0
},
"properties" : [
{ "name" : "Name", "value" : "Icosahedron" },
{ "name" : "Dual", "value" : "Dodecahedron" },
{ "name" : "Vertices", "value" : "12" },
{ "name" : "Edges", "value" : "30" },
{ "name" : "Faces", "value" : "20" }
]
}
]
}