Separate file for exporter model tests.
This commit is contained in:
parent
3143fb0c09
commit
0a1f158e01
@ -15,3 +15,15 @@ OV.ValueOrDefault = function (val, def)
|
|||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OV.CopyObjectAttributes = function (src, dest)
|
||||||
|
{
|
||||||
|
if (!OV.IsDefined (src)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let attribute of Object.keys (src)) {
|
||||||
|
if (OV.IsDefined (src[attribute])) {
|
||||||
|
dest[attribute] = src[attribute];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@ -5,11 +5,8 @@ OV.ExporterSettings = class
|
|||||||
this.isMeshVisible = (meshInstanceId) => {
|
this.isMeshVisible = (meshInstanceId) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
if (OV.IsDefined (settings)) {
|
|
||||||
if (OV.IsDefined (settings.isMeshVisible)) {
|
OV.CopyObjectAttributes (settings, this);
|
||||||
this.isMeshVisible = settings.isMeshVisible;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,7 +15,7 @@ OV.ExporterModel = class
|
|||||||
constructor (model, settings)
|
constructor (model, settings)
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.settings = settings;
|
this.settings = settings || new OV.ExporterSettings ();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialCount ()
|
MaterialCount ()
|
||||||
|
|||||||
45
test/tests/core_test.js
Normal file
45
test/tests/core_test.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
var assert = require ('assert');
|
||||||
|
|
||||||
|
describe ('Core', function () {
|
||||||
|
it ('Is defined', function () {
|
||||||
|
assert.strictEqual (OV.IsDefined (null), false);
|
||||||
|
assert.strictEqual (OV.IsDefined (undefined), false);
|
||||||
|
assert.strictEqual (OV.IsDefined (0), true);
|
||||||
|
assert.strictEqual (OV.IsDefined (''), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('Value or default', function () {
|
||||||
|
assert.strictEqual (OV.ValueOrDefault (null, 5), 5);
|
||||||
|
assert.strictEqual (OV.ValueOrDefault (undefined, 5), 5);
|
||||||
|
assert.strictEqual (OV.ValueOrDefault (3, 5), 3);
|
||||||
|
assert.strictEqual (OV.ValueOrDefault ('a', 5), 'a');
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('Copy object attributes', function () {
|
||||||
|
let src = {
|
||||||
|
a : null,
|
||||||
|
b : undefined,
|
||||||
|
c : 6
|
||||||
|
};
|
||||||
|
|
||||||
|
let dest = {};
|
||||||
|
OV.CopyObjectAttributes (src, dest);
|
||||||
|
assert.deepStrictEqual (dest, {c : 6});
|
||||||
|
|
||||||
|
let dest2 = {
|
||||||
|
a : 1,
|
||||||
|
b : 2,
|
||||||
|
c : 3
|
||||||
|
};
|
||||||
|
OV.CopyObjectAttributes (src, dest2);
|
||||||
|
assert.deepStrictEqual (dest2, {a : 1, b : 2, c : 6});
|
||||||
|
|
||||||
|
let dest3 = {
|
||||||
|
a : null,
|
||||||
|
b : null,
|
||||||
|
c : null
|
||||||
|
};
|
||||||
|
OV.CopyObjectAttributes (src, dest3);
|
||||||
|
assert.deepStrictEqual (dest3, {a : null, b : null, c : 6});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -73,40 +73,6 @@ function Export (model, format, extension, onReady)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
describe ('Exporter Model', function () {
|
|
||||||
it ('No filter test', function (done) {
|
|
||||||
let model = CreateTestModel ();
|
|
||||||
let settings = new OV.ExporterSettings ();
|
|
||||||
let exporterModel = new OV.ExporterModel (model, settings);
|
|
||||||
let meshInstances = [];
|
|
||||||
exporterModel.EnumerateMeshInstances ((meshInstance) => {
|
|
||||||
meshInstances.push (meshInstance);
|
|
||||||
});
|
|
||||||
assert.strictEqual (meshInstances.length, 2);
|
|
||||||
assert.strictEqual (exporterModel.VertexCount (), 8);
|
|
||||||
assert.strictEqual (exporterModel.TriangleCount (), 4);
|
|
||||||
done ();
|
|
||||||
});
|
|
||||||
|
|
||||||
it ('Model filter test', function (done) {
|
|
||||||
let model = CreateTestModel ();
|
|
||||||
let settings = new OV.ExporterSettings ({
|
|
||||||
isMeshVisible : (meshInstanceId) => {
|
|
||||||
return meshInstanceId.IsEqual (new OV.MeshInstanceId (0, 1));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let exporterModel = new OV.ExporterModel (model, settings);
|
|
||||||
let meshInstances = [];
|
|
||||||
exporterModel.EnumerateMeshInstances ((meshInstance) => {
|
|
||||||
meshInstances.push (meshInstance);
|
|
||||||
});
|
|
||||||
assert.strictEqual (meshInstances.length, 1);
|
|
||||||
assert.strictEqual (exporterModel.VertexCount (), 5);
|
|
||||||
assert.strictEqual (exporterModel.TriangleCount (), 3);
|
|
||||||
done ();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe ('Exporter', function () {
|
describe ('Exporter', function () {
|
||||||
it ('Exporter Error', function (done) {
|
it ('Exporter Error', function (done) {
|
||||||
let model = CreateTestModel ();
|
let model = CreateTestModel ();
|
||||||
|
|||||||
63
test/tests/exportermodel_test.js
Normal file
63
test/tests/exportermodel_test.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
var assert = require ('assert');
|
||||||
|
|
||||||
|
function CreateTestModel ()
|
||||||
|
{
|
||||||
|
let model = new OV.Model ();
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
let material = new OV.PhongMaterial ();
|
||||||
|
material.name = 'Material ' + i.toString ();
|
||||||
|
model.AddMaterial (material);
|
||||||
|
}
|
||||||
|
|
||||||
|
let root = model.GetRootNode ();
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
let genParams = new OV.GeneratorParams ().SetMaterial (i);
|
||||||
|
let cube = OV.GenerateCuboid (genParams, 1.0, 1.0, 1.0);
|
||||||
|
let meshIndex = model.AddMesh (cube);
|
||||||
|
let node = new OV.Node ();
|
||||||
|
node.AddMeshIndex (meshIndex);
|
||||||
|
node.SetTransformation (new OV.Transformation (new OV.Matrix ().CreateTranslation (i, 0.0, 0.0)));
|
||||||
|
root.AddChildNode (node);
|
||||||
|
}
|
||||||
|
|
||||||
|
OV.FinalizeModel (model, null);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetExporterModelBoundingBox (exporterModel)
|
||||||
|
{
|
||||||
|
let calculator = new OV.BoundingBoxCalculator3D ();
|
||||||
|
exporterModel.EnumerateTransformedMeshes ((mesh) => {
|
||||||
|
mesh.EnumerateVertices ((vertex) => {
|
||||||
|
calculator.AddPoint (vertex);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
return calculator.GetBox ();
|
||||||
|
}
|
||||||
|
|
||||||
|
describe ('Exporter Model', function () {
|
||||||
|
it ('No filter test', function () {
|
||||||
|
let model = CreateTestModel ();
|
||||||
|
let exporterModel = new OV.ExporterModel (model);
|
||||||
|
assert.strictEqual (exporterModel.MeshInstanceCount (), 3);
|
||||||
|
let boundingBox = GetExporterModelBoundingBox (exporterModel);
|
||||||
|
assert (OV.CoordIsEqual3D (boundingBox.min, new OV.Coord3D (0.0, 0.0, 0.0)));
|
||||||
|
assert (OV.CoordIsEqual3D (boundingBox.max, new OV.Coord3D (3.0, 1.0, 1.0)));
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('Model filter test', function () {
|
||||||
|
let model = CreateTestModel ();
|
||||||
|
let settings = new OV.ExporterSettings ({
|
||||||
|
isMeshVisible : (meshInstanceId) => {
|
||||||
|
return !meshInstanceId.IsEqual (new OV.MeshInstanceId (3, 2));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let exporterModel = new OV.ExporterModel (model, settings);
|
||||||
|
assert.strictEqual (exporterModel.MeshInstanceCount (), 2);
|
||||||
|
let boundingBox = GetExporterModelBoundingBox (exporterModel);
|
||||||
|
assert (OV.CoordIsEqual3D (boundingBox.min, new OV.Coord3D (0.0, 0.0, 0.0)));
|
||||||
|
assert (OV.CoordIsEqual3D (boundingBox.max, new OV.Coord3D (2.0, 1.0, 1.0)));
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user