Store transformation in node.

This commit is contained in:
kovacsv 2021-10-22 15:55:38 +02:00
parent 055e817097
commit cd2adbeab3
4 changed files with 71 additions and 5 deletions

View File

@ -41,6 +41,9 @@ OV.ImporterO3dv = class extends OV.ImporterBase
this.ImportMesh (meshContent);
}
}
if (content.root !== undefined) {
this.ImportNode (content.root, this.model.GetRootNode ());
}
onFinish ();
}
@ -68,6 +71,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);
@ -120,4 +124,45 @@ OV.ImporterO3dv = class extends OV.ImporterBase
this.model.AddMesh (mesh);
}
}
ImportNode (node, meshNode)
{
if (node.name !== undefined) {
meshNode.SetName (node.name);
}
if (node.transformation !== undefined) {
const nodeTransformation = this.GetTransformation (node.transformation);
meshNode.SetTransformation (nodeTransformation);
}
if (node.meshes !== undefined) {
for (const meshIndex of node.meshes) {
meshNode.AddMeshIndex (meshIndex);
}
}
if (node.children !== undefined) {
for (const child of node.children) {
let childMeshNode = new OV.Node ();
meshNode.AddChildNode (childMeshNode);
this.ImportNode (child, childMeshNode);
}
}
}
GetTransformation (contentTransformation)
{
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
if (contentTransformation.translation !== undefined) {
translation = OV.ArrayToCoord3D (contentTransformation.translation);
}
if (contentTransformation.rotation !== undefined) {
rotation = OV.ArrayToQuaternion (contentTransformation.rotation);
}
if (contentTransformation.scale !== undefined) {
scale = OV.ArrayToCoord3D (contentTransformation.scale);
}
const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale);
return new OV.Transformation (matrix);
}
};

View File

@ -4,10 +4,21 @@ OV.Node = class
{
this.name = '';
this.parent = null;
this.transformation = new OV.Transformation ();
this.childNodes = [];
this.meshIndices = [];
}
GetName ()
{
return this.name;
}
SetName (name)
{
this.name = name;
}
HasParent ()
{
return this.parent !== null;
@ -18,14 +29,14 @@ OV.Node = class
return this.parent;
}
GetName ()
GetTransformation ()
{
return this.name;
return this.transformation;
}
SetName (name)
SetTransformation (transformation)
{
this.name = name;
this.transformation = transformation;
}
AddChildNode (node)

View File

@ -100,6 +100,7 @@
},
"meshes" : [
{
"name" : "Cube",
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
@ -108,6 +109,7 @@
}
},
{
"name" : "Sphere",
"type" : "sphere",
"parameters" : {
"radius" : 0.5

View File

@ -14,6 +14,14 @@ describe ('Node', function() {
assert.strictEqual (node.GetName (), 'New Name');
});
it ('Set Transformation', function () {
let node = new OV.Node ();
assert (node.GetTransformation ().IsIdentity ());
let tr = new OV.Transformation (new OV.Matrix ().CreateScale (3.0, 4.0, 5.0));
node.SetTransformation (tr);
assert (!node.GetTransformation ().IsIdentity ());
});
it ('Add Mesh Indices', function () {
let node = new OV.Node ();
node.AddMeshIndex (0);