Skip to content

Commit

Permalink
Change fadeOnZoom internally to manipulate content list instead of me…
Browse files Browse the repository at this point in the history
…sh properties

Also makes octreeManager store its data on mesh.metadata instead of mesh object.
  • Loading branch information
fenomas committed Apr 10, 2023
1 parent f484989 commit e77addb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/components/fadeOnZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ export default function (noa) {

system: function fadeOnZoomProc(dt, states) {
var zoom = noa.camera.currentZoom
var ents = noa.entities
for (var i = 0; i < states.length; i++) {
checkZoom(states[i], zoom, ents)
checkZoom(states[i], zoom, noa)
}
}
}
}


function checkZoom(state, zoom, ents) {
if (!ents.hasMesh(state.__id)) return

var shouldShow = (zoom > state.cutoff)
ents.getMeshData(state.__id).mesh.setEnabled(shouldShow)
function checkZoom(state, zoom, noa) {
if (!noa.ents.hasMesh(state.__id)) return
var mesh = noa.ents.getMeshData(state.__id).mesh
if (!mesh.metadata) return
var shouldHide = (zoom < state.cutoff)
noa.rendering._octreeManager.setDynamicMeshVisibility(mesh, !shouldHide)
}
39 changes: 29 additions & 10 deletions src/lib/sceneOctreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class SceneOctreeManager {
var scene = rendering._scene
scene._addComponent(new OctreeSceneComponent(scene))

// mesh metadata flags
var octreeBlock = 'noa_parent_octree_block'
var inDynamicList = 'noa_in_dynamic_list'

// the root octree object
var octree = new Octree(NOP)
scene._selectionOctree = octree
Expand All @@ -41,16 +45,18 @@ export class SceneOctreeManager {
*/

this.rebase = (offset) => { recurseRebaseBlocks(octree, offset) }
this.includesMesh = (mesh) => {
return (mesh._noaContainingBlock || mesh._noaIsDynamicContent)
}

this.addMesh = (mesh, isStatic, pos, chunk) => {
if (!mesh.metadata) mesh.metadata = {}

// dynamic content is just rendered from a list on the octree
if (!isStatic) {
mesh._noaIsDynamicContent = true
if (mesh.metadata[inDynamicList]) return
octree.dynamicContent.push(mesh)
mesh.metadata[inDynamicList] = true
return
}

// octreeBlock-space integer coords of mesh position, and hashed key
var ci = Math.floor(pos[0] / bs)
var cj = Math.floor(pos[1] / bs)
Expand All @@ -73,20 +79,22 @@ export class SceneOctreeManager {

// do the actual adding logic
block.entries.push(mesh)
mesh._noaContainingBlock = block
mesh.metadata[octreeBlock] = block

// rely on octrees for selection, skipping bounds checks
mesh.alwaysSelectAsActiveMesh = true
}

this.removeMesh = (mesh) => {
if (mesh._noaIsDynamicContent) {
mesh._noaIsDynamicContent = null
if (!mesh.metadata) return

if (mesh.metadata[inDynamicList]) {
mesh.metadata[inDynamicList] = false
removeUnorderedListItem(octree.dynamicContent, mesh)
}
if (mesh._noaContainingBlock) {
mesh._noaContainingChunk = null
var block = mesh._noaContainingBlock
if (mesh.metadata[octreeBlock]) {
var block = mesh.metadata[octreeBlock]
mesh.metadata[octreeBlock] = null
removeUnorderedListItem(block.entries, mesh)
if (block.entries.length === 0) {
delete octBlocksHash[block._noaMapKey]
Expand All @@ -95,6 +103,17 @@ export class SceneOctreeManager {
}
}

// experimental helper
this.setDynamicMeshVisibility = (mesh, visible = false) => {
if (mesh.metadata[inDynamicList] === visible) return
if (visible) {
octree.dynamicContent.push(mesh)
} else {
removeUnorderedListItem(octree.dynamicContent, mesh)
}
mesh.metadata[inDynamicList] = visible
}

/*
*
* internals
Expand Down

0 comments on commit e77addb

Please sign in to comment.