Store transformation in node.
This commit is contained in:
parent
055e817097
commit
cd2adbeab3
@ -41,6 +41,9 @@ OV.ImporterO3dv = class extends OV.ImporterBase
|
|||||||
this.ImportMesh (meshContent);
|
this.ImportMesh (meshContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (content.root !== undefined) {
|
||||||
|
this.ImportNode (content.root, this.model.GetRootNode ());
|
||||||
|
}
|
||||||
onFinish ();
|
onFinish ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
|
|||||||
if (meshContent.material !== undefined) {
|
if (meshContent.material !== undefined) {
|
||||||
genParams.SetMaterial (meshContent.material);
|
genParams.SetMaterial (meshContent.material);
|
||||||
}
|
}
|
||||||
|
// TODO: remove transformation from mesh, and from generator
|
||||||
if (meshContent.transformation !== undefined) {
|
if (meshContent.transformation !== undefined) {
|
||||||
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
|
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 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);
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,10 +4,21 @@ OV.Node = class
|
|||||||
{
|
{
|
||||||
this.name = '';
|
this.name = '';
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
|
this.transformation = new OV.Transformation ();
|
||||||
this.childNodes = [];
|
this.childNodes = [];
|
||||||
this.meshIndices = [];
|
this.meshIndices = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetName ()
|
||||||
|
{
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetName (name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
HasParent ()
|
HasParent ()
|
||||||
{
|
{
|
||||||
return this.parent !== null;
|
return this.parent !== null;
|
||||||
@ -18,14 +29,14 @@ OV.Node = class
|
|||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetName ()
|
GetTransformation ()
|
||||||
{
|
{
|
||||||
return this.name;
|
return this.transformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetName (name)
|
SetTransformation (transformation)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.transformation = transformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddChildNode (node)
|
AddChildNode (node)
|
||||||
|
|||||||
@ -100,6 +100,7 @@
|
|||||||
},
|
},
|
||||||
"meshes" : [
|
"meshes" : [
|
||||||
{
|
{
|
||||||
|
"name" : "Cube",
|
||||||
"type" : "cuboid",
|
"type" : "cuboid",
|
||||||
"parameters" : {
|
"parameters" : {
|
||||||
"size_x" : 1.0,
|
"size_x" : 1.0,
|
||||||
@ -108,6 +109,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"name" : "Sphere",
|
||||||
"type" : "sphere",
|
"type" : "sphere",
|
||||||
"parameters" : {
|
"parameters" : {
|
||||||
"radius" : 0.5
|
"radius" : 0.5
|
||||||
|
|||||||
@ -14,6 +14,14 @@ describe ('Node', function() {
|
|||||||
assert.strictEqual (node.GetName (), 'New Name');
|
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 () {
|
it ('Add Mesh Indices', function () {
|
||||||
let node = new OV.Node ();
|
let node = new OV.Node ();
|
||||||
node.AddMeshIndex (0);
|
node.AddMeshIndex (0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user