Add multiple instances of the same mesh in tests.

This commit is contained in:
kovacsv 2021-10-25 08:32:11 +02:00
parent d35a23bb43
commit 0143d29a9d
3 changed files with 43 additions and 9 deletions

View File

@ -32,10 +32,22 @@ OV.Transformation = class
return this;
}
Append (transformation)
{
this.AppendMatrix (transformation.GetMatrix ());
return this;
}
TransformCoord3D (coord)
{
let resultVector = this.matrix.MultiplyVector ([coord.x, coord.y, coord.z, 1.0]);
let result = new OV.Coord3D (resultVector[0], resultVector[1], resultVector[2]);
return result;
}
Clone ()
{
const clonedMatrix = this.matrix.Clone ();
return new OV.Transformation (clonedMatrix);
}
};

View File

@ -115,6 +115,19 @@ describe ('Transformation', function() {
assert (OV.CoordIsEqual3D (tr2.TransformCoord3D (coord), new OV.Coord3D (19.0, 13.0, 3.0)));
});
it ('Append Test', function () {
let coord = new OV.Coord3D (1.0, 2.0, 3.0);
let tr = new OV.Transformation ();
assert (tr.IsIdentity ());
assert (OV.CoordIsEqual3D (tr.TransformCoord3D (coord), new OV.Coord3D (1.0, 2.0, 3.0)));
let tr2 = new OV.Transformation (new OV.Matrix ().CreateScale (3.0, 4.0, 5.0));
tr.Append (tr2);
assert (!tr.IsIdentity ());
assert (OV.CoordIsEqual3D (tr.TransformCoord3D (coord), new OV.Coord3D (3.0, 8.0, 15.0)));
});
it ('TRS Compose Test', function () {
let rotation = CreateYRot90Quaternion ();
let coord = new OV.Coord3D (1.0, 2.0, 3.0);
@ -144,7 +157,14 @@ describe ('Transformation', function() {
let tr = new OV.Transformation ();
tr.SetMatrix (new OV.Matrix ().CreateRotation (0.0, 0.0, 0.0, 1.0));
assert (OV.CoordIsEqual3D (tr.TransformCoord3D (coord), coord));
});
});
it ('Clone Test', function () {
let tr = new OV.Transformation ();
let cloned = tr.Clone ();
tr.matrix.matrix[0] = 5.0;
assert.strictEqual (cloned.matrix.matrix[0], 1.0);
});
});
describe ('Tween', function() {

View File

@ -200,7 +200,7 @@ describe ('Color Conversion', function () {
});
});
function CreateHierarchicModel ()
function CreateHierarchicalModel ()
{
/*
+ <Root>
@ -208,6 +208,7 @@ function CreateHierarchicModel ()
+ Node 3
Mesh 5
Mesh 6
Mesh 7
+ Node 4
Mesh 7
Mesh 3
@ -272,6 +273,7 @@ function CreateHierarchicModel ()
node1.AddMeshIndex (mesh4Ind);
node3.AddMeshIndex (mesh5Ind);
node3.AddMeshIndex (mesh6Ind);
node3.AddMeshIndex (mesh7Ind);
node4.AddMeshIndex (mesh7Ind);
return model;
@ -302,7 +304,7 @@ function GetModelTree (model)
describe ('Node Hierarchy', function () {
it ('Enumerate hierarchy', function () {
let model = CreateHierarchicModel ();
let model = CreateHierarchicalModel ();
let modelTree = GetModelTree (model);
assert.deepStrictEqual (modelTree, {
name : '<Root>',
@ -313,7 +315,7 @@ describe ('Node Hierarchy', function () {
{
name : 'Node 3',
childNodes : [],
meshNames : ['Mesh 5', 'Mesh 6']
meshNames : ['Mesh 5', 'Mesh 6', 'Mesh 7']
},
{
name : 'Node 4',
@ -334,7 +336,7 @@ describe ('Node Hierarchy', function () {
});
it ('Remove mesh', function () {
let model = CreateHierarchicModel ();
let model = CreateHierarchicalModel ();
model.RemoveMesh (2);
let modelTree = GetModelTree (model);
assert.deepStrictEqual (modelTree, {
@ -346,7 +348,7 @@ describe ('Node Hierarchy', function () {
{
name : 'Node 3',
childNodes : [],
meshNames : ['Mesh 5', 'Mesh 6']
meshNames : ['Mesh 5', 'Mesh 6', 'Mesh 7']
},
{
name : 'Node 4',
@ -367,7 +369,7 @@ describe ('Node Hierarchy', function () {
});
it ('Add mesh to index', function () {
let model = CreateHierarchicModel ();
let model = CreateHierarchicalModel ();
let mesh = new OV.Mesh ();
mesh.SetName ('Mesh 8');
model.AddMeshToIndex (mesh, 3);
@ -381,7 +383,7 @@ describe ('Node Hierarchy', function () {
{
name : 'Node 3',
childNodes : [],
meshNames : ['Mesh 5', 'Mesh 6']
meshNames : ['Mesh 5', 'Mesh 6', 'Mesh 7']
},
{
name : 'Node 4',
@ -399,5 +401,5 @@ describe ('Node Hierarchy', function () {
],
meshNames : ['Mesh 1', 'Mesh 2']
});
});
});
});