Clean up generator parameters interface.

This commit is contained in:
kovacsv 2021-11-22 14:02:02 +01:00
parent 6efbe02e61
commit 31d472aa9a
3 changed files with 18 additions and 24 deletions

View File

@ -74,19 +74,8 @@ OV.ImporterO3dv = class extends OV.ImporterBase
} }
if (meshContent.transformation !== undefined) { if (meshContent.transformation !== undefined) {
let translation = new OV.Coord3D (0.0, 0.0, 0.0); let meshTransformation = this.GetTransformation (meshContent.transformation);
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0); genParams.SetTransformation (meshTransformation);
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
if (meshContent.transformation.translation !== undefined) {
translation = OV.ArrayToCoord3D (meshContent.transformation.translation);
}
if (meshContent.transformation.rotation !== undefined) {
rotation = OV.ArrayToQuaternion (meshContent.transformation.rotation);
}
if (meshContent.transformation.scale !== undefined) {
scale = OV.ArrayToCoord3D (meshContent.transformation.scale);
}
genParams.SetTransformation (translation, rotation, scale);
} }
let parameters = meshContent.parameters; let parameters = meshContent.parameters;
@ -127,25 +116,25 @@ OV.ImporterO3dv = class extends OV.ImporterBase
} }
} }
ImportNode (nodeContent, meshNode) ImportNode (nodeContent, node)
{ {
if (nodeContent.name !== undefined) { if (nodeContent.name !== undefined) {
meshNode.SetName (nodeContent.name); node.SetName (nodeContent.name);
} }
if (nodeContent.transformation !== undefined) { if (nodeContent.transformation !== undefined) {
const nodeTransformation = this.GetTransformation (nodeContent.transformation); const nodeTransformation = this.GetTransformation (nodeContent.transformation);
meshNode.SetTransformation (nodeTransformation); node.SetTransformation (nodeTransformation);
} }
if (nodeContent.meshes !== undefined) { if (nodeContent.meshes !== undefined) {
for (const meshIndex of nodeContent.meshes) { for (const meshIndex of nodeContent.meshes) {
meshNode.AddMeshIndex (meshIndex); node.AddMeshIndex (meshIndex);
} }
} }
if (nodeContent.children !== undefined) { if (nodeContent.children !== undefined) {
for (const child of nodeContent.children) { for (const child of nodeContent.children) {
let childMeshNode = new OV.Node (); let childNode = new OV.Node ();
meshNode.AddChildNode (childMeshNode); node.AddChildNode (childNode);
this.ImportNode (child, childMeshNode); this.ImportNode (child, childNode);
} }
} }
} }

View File

@ -19,7 +19,7 @@ OV.GeneratorParams = class
return this; return this;
} }
SetTransformation (translation, rotation, scale) SetTransformationTRS (translation, rotation, scale)
{ {
const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale); const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale);
return this.SetTransformationMatrix (matrix); return this.SetTransformationMatrix (matrix);
@ -27,7 +27,12 @@ OV.GeneratorParams = class
SetTransformationMatrix (matrix) SetTransformationMatrix (matrix)
{ {
this.transformation = new OV.Transformation (matrix); return this.SetTransformation (new OV.Transformation (matrix));
}
SetTransformation (transformation)
{
this.transformation = transformation;
return this; return this;
} }
}; };

View File

@ -17,7 +17,7 @@ describe ('Generator', function () {
}); });
it ('Cuboid with Transformation', function () { it ('Cuboid with Transformation', function () {
const params = new OV.GeneratorParams ().SetTransformation ( const params = new OV.GeneratorParams ().SetTransformationTRS (
new OV.Coord3D (1.0, 0.0, 0.0), new OV.Coord3D (1.0, 0.0, 0.0),
new OV.Quaternion (0.0, 0.0, 0.0, 1.0), new OV.Quaternion (0.0, 0.0, 0.0, 1.0),
new OV.Coord3D (1.0, 1.0, 1.0) new OV.Coord3D (1.0, 1.0, 1.0)
@ -60,5 +60,5 @@ describe ('Generator', function () {
let icosahedron = OV.GeneratePlatonicSolid (null, 'icosahedron', 1.0); let icosahedron = OV.GeneratePlatonicSolid (null, 'icosahedron', 1.0);
assert (OV.IsSolid (icosahedron)); assert (OV.IsSolid (icosahedron));
assert (OV.IsEqual (OV.CalculateVolume (icosahedron), 2.5361507101204093)); assert (OV.IsEqual (OV.CalculateVolume (icosahedron), 2.5361507101204093));
}); });
}); });