Visualization is slow in case of large number of meshes #82
This commit is contained in:
parent
8fbe59d656
commit
1cdf592c4f
@ -19,6 +19,19 @@ OV.TaskRunner = class
|
||||
}
|
||||
}
|
||||
|
||||
RunBatch (count, batchCount, callbacks)
|
||||
{
|
||||
const stepCount = parseInt ((count - 1) / batchCount, 10) + 1;
|
||||
this.Run (stepCount, {
|
||||
runTask : function (index, ready) {
|
||||
const firstIndex = index * batchCount;
|
||||
const lastIndex = Math.min ((index + 1) * batchCount, count) - 1;
|
||||
callbacks.runTask (firstIndex, lastIndex, ready);
|
||||
},
|
||||
onReady : callbacks.onReady
|
||||
});
|
||||
}
|
||||
|
||||
RunOnce ()
|
||||
{
|
||||
let obj = this;
|
||||
|
||||
18
source/external/threeconverter.js
vendored
18
source/external/threeconverter.js
vendored
@ -189,16 +189,16 @@ OV.ConvertModelToThreeMeshes = function (model, params, callbacks)
|
||||
|
||||
let threeMeshes = [];
|
||||
let taskRunner = new OV.TaskRunner ();
|
||||
taskRunner.Run (model.MeshCount (), {
|
||||
runTask : function (index, ready) {
|
||||
let mesh = model.GetMesh (index);
|
||||
if (mesh.TriangleCount () === 0) {
|
||||
ready ();
|
||||
} else {
|
||||
let threeMesh = CreateThreeMesh (model, index, modelThreeMaterials);
|
||||
threeMeshes.push (threeMesh);
|
||||
ready ();
|
||||
taskRunner.RunBatch (model.MeshCount (), 100, {
|
||||
runTask : function (firstIndex, lastIndex, ready) {
|
||||
for (let meshIndex = firstIndex; meshIndex <= lastIndex; meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
if (mesh.TriangleCount () > 0) {
|
||||
let threeMesh = CreateThreeMesh (model, meshIndex, modelThreeMaterials);
|
||||
threeMeshes.push (threeMesh);
|
||||
}
|
||||
}
|
||||
ready ();
|
||||
},
|
||||
onReady : function () {
|
||||
callbacks.onModelLoaded (threeMeshes);
|
||||
|
||||
@ -29,5 +29,20 @@ describe ('Task Runner', function () {
|
||||
done ();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it ('Run task batched', function (done) {
|
||||
var tr = new OV.TaskRunner ();
|
||||
var indices = [];
|
||||
tr.RunBatch (10, 3, {
|
||||
runTask : function (firstIndex, lastIndex, ready) {
|
||||
indices.push ([firstIndex, lastIndex]);
|
||||
ready ();
|
||||
},
|
||||
onReady : function () {
|
||||
assert.deepStrictEqual (indices, [[0, 2], [3, 5], [6, 8], [9, 9]]);
|
||||
done ();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user