Create mesh nodes during o3dv import.

This commit is contained in:
kovacsv 2021-11-22 14:25:56 +01:00
parent 31d472aa9a
commit 583ab14e34
5 changed files with 78 additions and 60 deletions

View File

@ -42,7 +42,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
}
}
if (content.root !== undefined) {
this.ImportNode (content.root, this.model.GetRootNode ());
this.ImportNode (content, content.root, this.model.GetRootNode ());
}
this.ImportProperties (this.model, content);
onFinish ();
@ -73,11 +73,6 @@ OV.ImporterO3dv = class extends OV.ImporterBase
genParams.SetMaterial (meshContent.material);
}
if (meshContent.transformation !== undefined) {
let meshTransformation = this.GetTransformation (meshContent.transformation);
genParams.SetTransformation (meshTransformation);
}
let parameters = meshContent.parameters;
if (parameters === undefined) {
return;
@ -116,7 +111,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
}
}
ImportNode (nodeContent, node)
ImportNode (content, nodeContent, node)
{
if (nodeContent.name !== undefined) {
node.SetName (nodeContent.name);
@ -125,16 +120,24 @@ OV.ImporterO3dv = class extends OV.ImporterBase
const nodeTransformation = this.GetTransformation (nodeContent.transformation);
node.SetTransformation (nodeTransformation);
}
if (nodeContent.meshes !== undefined) {
for (const meshIndex of nodeContent.meshes) {
node.AddMeshIndex (meshIndex);
}
}
if (nodeContent.children !== undefined) {
for (const child of nodeContent.children) {
let childNode = new OV.Node ();
node.AddChildNode (childNode);
this.ImportNode (child, childNode);
this.ImportNode (content, child, 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);
}
}
}

View File

@ -4,7 +4,6 @@ OV.GeneratorParams = class
{
this.name = null;
this.material = null;
this.transformation = null;
}
SetName (name)
@ -18,23 +17,6 @@ OV.GeneratorParams = class
this.material = material;
return this;
}
SetTransformationTRS (translation, rotation, scale)
{
const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale);
return this.SetTransformationMatrix (matrix);
}
SetTransformationMatrix (matrix)
{
return this.SetTransformation (new OV.Transformation (matrix));
}
SetTransformation (transformation)
{
this.transformation = transformation;
return this;
}
};
OV.Generator = class
@ -57,9 +39,6 @@ OV.Generator = class
AddVertex (x, y, z)
{
let coord = new OV.Coord3D (x, y, z);
if (this.params.transformation !== null) {
coord = this.params.transformation.TransformCoord3D (coord);
}
return this.mesh.AddVertex (coord);
}

View File

@ -16,18 +16,6 @@ describe ('Generator', function () {
}
});
it ('Cuboid with Transformation', function () {
const params = new OV.GeneratorParams ().SetTransformationTRS (
new OV.Coord3D (1.0, 0.0, 0.0),
new OV.Quaternion (0.0, 0.0, 0.0, 1.0),
new OV.Coord3D (1.0, 1.0, 1.0)
);
const cuboid = OV.GenerateCuboid (params, 1.0, 1.0, 1.0);
const bounds = OV.GetBoundingBox (cuboid);
assert (OV.CoordIsEqual3D (bounds.min, new OV.Coord3D (1.0, 0.0, 0.0)));
assert (OV.CoordIsEqual3D (bounds.max, new OV.Coord3D (2.0, 1.0, 1.0)));
});
it ('Cylinder with Default Parameters', function () {
const cylinder = OV.GenerateCylinder (null, 0.5, 1.0, 25, false);
assert (OV.IsSolid (cylinder));

View File

@ -11,22 +11,39 @@ describe ('O3dv Importer', function () {
childNodes : [
{
name : 'Translated',
childNodes : [],
meshNames : ['Cube']
childNodes : [
{
name : '',
childNodes : [],
meshNames : ['Cube']
}
],
meshNames : []
},
{
name : 'Rotated',
childNodes : [
{
name : 'Translated and Rotated',
childNodes : [],
meshNames : ['Cube']
childNodes : [
{
name : '',
childNodes : [],
meshNames : ['Cube']
}
],
meshNames : []
}
],
meshNames : []
},
{
name : '',
childNodes : [],
meshNames : ['Cube']
}
],
meshNames : ['Cube']
meshNames : []
});
assert.strictEqual (model.MeshInstanceCount (), 3);
@ -46,17 +63,45 @@ describe ('O3dv Importer', function () {
childNodes : [
{
name : 'Tetrahedral',
childNodes : [],
meshNames : ['Tetrahedron']
childNodes : [
{
name : '',
childNodes : [],
meshNames : ['Tetrahedron']
}
],
meshNames : []
},
{
name : 'Octahedral',
childNodes : [],
meshNames : ['Hexahedron', 'Octahedron']
childNodes : [
{
name : '',
childNodes : [],
meshNames : ['Hexahedron']
},
{
name : '',
childNodes : [],
meshNames : ['Octahedron']
}
],
meshNames : []
}, {
name : 'Icosahedral',
childNodes : [],
meshNames : ['Dodecahedron', 'Icosahedron']
childNodes : [
{
name : '',
childNodes : [],
meshNames : ['Dodecahedron']
},
{
name : '',
childNodes : [],
meshNames : ['Icosahedron']
}
],
meshNames : []
}
],
meshNames : []

View File

@ -165,8 +165,9 @@ module.exports =
let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
model.AddMeshToRootNode (cube1);
let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
let matrix = new OV.Matrix ().CreateTranslation (1.0, 1.0, 1.0);
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
OV.TransformMesh (cube2, new OV.Transformation (matrix));
model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
@ -180,8 +181,9 @@ module.exports =
let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
model.AddMeshToRootNode (cube1);
let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 1.0);
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
OV.TransformMesh (cube2, new OV.Transformation (matrix))
model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
@ -195,8 +197,9 @@ module.exports =
let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
model.AddMeshToRootNode (cube1);
let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 0.0);
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
OV.TransformMesh (cube2, new OV.Transformation (matrix));
model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });