Improve conversion speed in case of high number of nodes.
This commit is contained in:
parent
c639821249
commit
71cfe70c71
@ -54,32 +54,33 @@ OV.ThreeNodeTree = class
|
|||||||
{
|
{
|
||||||
constructor (rootNode, threeRootNode)
|
constructor (rootNode, threeRootNode)
|
||||||
{
|
{
|
||||||
this.nodes = [];
|
this.meshInstances = [];
|
||||||
this.AddNode (rootNode, threeRootNode);
|
this.AddNode (rootNode, threeRootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddNode (node, threeNode)
|
AddNode (node, threeNode)
|
||||||
{
|
{
|
||||||
this.nodes.push ({
|
|
||||||
node : node,
|
|
||||||
threeNode : threeNode
|
|
||||||
});
|
|
||||||
|
|
||||||
let matrix = node.GetTransformation ().GetMatrix ();
|
let matrix = node.GetTransformation ().GetMatrix ();
|
||||||
let threeMatrix = new THREE.Matrix4 ().fromArray (matrix.Get ());
|
let threeMatrix = new THREE.Matrix4 ().fromArray (matrix.Get ());
|
||||||
threeNode.applyMatrix4 (threeMatrix);
|
threeNode.applyMatrix4 (threeMatrix);
|
||||||
|
|
||||||
const nodeIndex = this.nodes.length - 1;
|
|
||||||
for (let childNode of node.GetChildNodes ()) {
|
for (let childNode of node.GetChildNodes ()) {
|
||||||
let threeChildNode = new THREE.Object3D ();
|
let threeChildNode = new THREE.Object3D ();
|
||||||
this.nodes[nodeIndex].threeNode.add (threeChildNode);
|
threeNode.add (threeChildNode);
|
||||||
this.AddNode (childNode, threeChildNode);
|
this.AddNode (childNode, threeChildNode);
|
||||||
}
|
}
|
||||||
|
for (let meshIndex of node.GetMeshIndices ()) {
|
||||||
|
this.meshInstances.push ({
|
||||||
|
node : node,
|
||||||
|
threeNode : threeNode,
|
||||||
|
meshIndex : meshIndex
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetNodes ()
|
GetMeshInstances ()
|
||||||
{
|
{
|
||||||
return this.nodes;
|
return this.meshInstances;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -293,24 +294,18 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
|||||||
{
|
{
|
||||||
let rootNode = model.GetRootNode ();
|
let rootNode = model.GetRootNode ();
|
||||||
let nodeTree = new OV.ThreeNodeTree (rootNode, threeRootNode);
|
let nodeTree = new OV.ThreeNodeTree (rootNode, threeRootNode);
|
||||||
let nodes = nodeTree.GetNodes ();
|
let meshInstances = nodeTree.GetMeshInstances ();
|
||||||
OV.RunTasks (nodes.length, {
|
|
||||||
runTask : (nodeIndex, nodeReady) => {
|
OV.RunTasksBatch (meshInstances.length, 100, {
|
||||||
let treeNode = nodes[nodeIndex];
|
runTask : (firstMeshInstanceIndex, lastMeshInstanceIndex, onReady) => {
|
||||||
let node = treeNode.node;
|
for (let meshInstanceIndex = firstMeshInstanceIndex; meshInstanceIndex <= lastMeshInstanceIndex; meshInstanceIndex++) {
|
||||||
let threeNode = treeNode.threeNode;
|
let meshInstance = meshInstances[meshInstanceIndex];
|
||||||
OV.RunTasksBatch (node.MeshIndexCount (), 100, {
|
let node = meshInstance.node;
|
||||||
runTask : (firstNodeMeshIndex, lastNodeMeshIndex, ready) => {
|
let threeNode = meshInstance.threeNode;
|
||||||
for (let nodeMeshIndex = firstNodeMeshIndex; nodeMeshIndex <= lastNodeMeshIndex; nodeMeshIndex++) {
|
let meshInstanceId = new OV.MeshInstanceId (node.GetId (), meshInstance.meshIndex);
|
||||||
let meshInstanceId = new OV.MeshInstanceId (node.GetId (), node.GetMeshIndex (nodeMeshIndex));
|
ConvertMesh (threeNode, model, meshInstanceId, modelThreeMaterials);
|
||||||
ConvertMesh (threeNode, model, meshInstanceId, modelThreeMaterials);
|
}
|
||||||
}
|
onReady ();
|
||||||
ready ();
|
|
||||||
},
|
|
||||||
onReady : () => {
|
|
||||||
nodeReady ();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
onReady : () => {
|
onReady : () => {
|
||||||
stateHandler.OnModelLoaded (threeRootNode);
|
stateHandler.OnModelLoaded (threeRootNode);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user