Skip to content

Commit

Permalink
Remove octree check, which is presumably O(number of meshes), and use…
Browse files Browse the repository at this point in the history
… mesh.metadata instead
  • Loading branch information
fenomas committed Apr 6, 2023
1 parent ada8642 commit 3f123fc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ var hlpos = []
*/
Rendering.prototype.addMeshToScene = function (mesh, isStatic = false, pos = null, containingChunk = null) {
// exit silently if mesh has already been added and not removed
if (this._octreeManager.includesMesh(mesh)) return
if (!mesh.metadata) mesh.metadata = {}
if (mesh.metadata.noa_added_to_scene) return
mesh.metadata.noa_added_to_scene = true

// find local position for mesh and move it there (unless it's parented)
if (!mesh.parent) {
Expand All @@ -267,6 +269,7 @@ Rendering.prototype.addMeshToScene = function (mesh, isStatic = false, pos = nul
this._octreeManager.addMesh(mesh, isStatic, pos, containingChunk)
mesh.onDisposeObservable.add(() => {
this._octreeManager.removeMesh(mesh)
mesh.metadata.noa_added_to_scene = false
})
}

Expand Down

0 comments on commit 3f123fc

Please sign in to comment.