Add model filter to exporter model.
This commit is contained in:
parent
fe8012e657
commit
5eca9dade5
@ -1,8 +1,18 @@
|
|||||||
OV.ExporterModel = class
|
OV.ExporterModel = class
|
||||||
{
|
{
|
||||||
constructor (model)
|
constructor (model, parameters)
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.parameters = {
|
||||||
|
isMeshVisible : (meshInstanceId) => {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (OV.IsDefined (parameters)) {
|
||||||
|
if (OV.IsDefined (parameters.isMeshVisible)) {
|
||||||
|
this.parameters.isMeshVisible = parameters.isMeshVisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialCount ()
|
MaterialCount ()
|
||||||
@ -10,24 +20,36 @@ OV.ExporterModel = class
|
|||||||
return this.model.MaterialCount ();
|
return this.model.MaterialCount ();
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexCount ()
|
|
||||||
{
|
|
||||||
return this.model.VertexCount ();
|
|
||||||
}
|
|
||||||
|
|
||||||
TriangleCount ()
|
|
||||||
{
|
|
||||||
return this.model.TriangleCount ();
|
|
||||||
}
|
|
||||||
|
|
||||||
GetMaterial (index)
|
GetMaterial (index)
|
||||||
{
|
{
|
||||||
return this.model.GetMaterial (index);
|
return this.model.GetMaterial (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VertexCount ()
|
||||||
|
{
|
||||||
|
let vertexCount = 0;
|
||||||
|
this.EnumerateMeshInstances ((meshInstance) => {
|
||||||
|
vertexCount += meshInstance.VertexCount ();
|
||||||
|
});
|
||||||
|
return vertexCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
TriangleCount ()
|
||||||
|
{
|
||||||
|
let triangleCount = 0;
|
||||||
|
this.EnumerateMeshInstances ((meshInstance) => {
|
||||||
|
triangleCount += meshInstance.TriangleCount ();
|
||||||
|
});
|
||||||
|
return triangleCount;
|
||||||
|
}
|
||||||
|
|
||||||
EnumerateMeshInstances (onMeshInstance)
|
EnumerateMeshInstances (onMeshInstance)
|
||||||
{
|
{
|
||||||
this.model.EnumerateMeshInstances (onMeshInstance);
|
this.model.EnumerateMeshInstances ((meshInstance) => {
|
||||||
|
if (this.parameters.isMeshVisible (meshInstance.GetId ())) {
|
||||||
|
onMeshInstance (meshInstance);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumerateTransformedMeshes (onMesh)
|
EnumerateTransformedMeshes (onMesh)
|
||||||
|
|||||||
@ -72,6 +72,38 @@ function Export (model, format, extension, onReady)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
describe ('Exporter Model', function () {
|
||||||
|
it ('No filter test', function (done) {
|
||||||
|
let model = CreateTestModel ();
|
||||||
|
let exporterModel = new OV.ExporterModel (model);
|
||||||
|
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 exporterModel = new OV.ExporterModel (model, {
|
||||||
|
isMeshVisible : (meshInstanceId) => {
|
||||||
|
return meshInstanceId.IsEqual (new OV.MeshInstanceId (0, 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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 ();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user