Skip to content

Commit

Permalink
Improved insolation speed considerablyby using newer methods for look…
Browse files Browse the repository at this point in the history
…ing up nodes and ids (specklesystems#2008)
  • Loading branch information
AlexandruPopovici authored Feb 7, 2024
1 parent 6a5f7bb commit 334f6a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
9 changes: 3 additions & 6 deletions packages/viewer-sandbox/src/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class Sandbox {
this.addStreamControls(url)
this.addViewControls()
this.addBatches()
this.properties = await this.viewer.getObjectProperties()
// this.properties = await this.viewer.getObjectProperties()
this.batchesParams.totalBvhSize = this.getBVHSize()
this.refresh()
})
Expand Down Expand Up @@ -467,11 +467,8 @@ export default class Sandbox {
// )

this.viewer
.getExtension(SelectionExtension)
.selectObjects(this.ids /*['c3138e24a866d447eb86b2a8107b2c09']*/)
setTimeout(() => {
console.log(this.viewer.getRenderer().renderingStats)
}, 1000)
.getExtension(FilteringExtension)
.isolateObjects(this.ids /*['1c8f29e7d48e531f6acbf987a50467f9']*/)
})

const rotate = this.tabs.pages[0].addButton({
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const getStream = () => {
// 'https://latest.speckle.dev/streams/1c2b3db9fb/commits/f12861736e'
// 'https://latest.speckle.dev/streams/1c2b3db9fb/commits/1015d417ea'
// Jedd's views
'https://latest.speckle.dev/streams/c1faab5c62/commits/e6632fe057'
// 'https://latest.speckle.dev/streams/c1faab5c62/commits/e6632fe057'
// 'https://latest.speckle.dev/streams/7d051a6449/commits/7632757a33'
// 'https://latest.speckle.dev/streams/4658eb53b9/commits/d8ec9cccf7'
// MEPs (whatever they are)
Expand Down Expand Up @@ -303,7 +303,7 @@ const getStream = () => {
// 'https://speckle.xyz/streams/2f9f2f3021/commits/75bd13f513'
// 'https://speckle.xyz/streams/0a2f096caf/commits/eee0e4436f?overlay=72828bce0d&c=%5B14.04465,-332.88372,258.40392,53.09575,31.13694,126.39999,0,1%5D&filter=%7B%22propertyInfoKey%22%3A%22level.name%22%7D'
// 'Bilal's tests
// 'https://latest.speckle.dev/streams/97750296c2/commits/5386a0af02' // 700k+ objects 30kk tris
'https://latest.speckle.dev/streams/97750296c2/commits/5386a0af02' // 700k+ objects 30kk tris
// 'https://latest.speckle.dev/streams/97750296c2/commits/2a6fd781f2' // NEW

// 'https://latest.speckle.dev/streams/97750296c2/commits/48f0567a88' // 1015849 objects
Expand Down
57 changes: 41 additions & 16 deletions packages/viewer/src/modules/extensions/FilteringExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,28 @@ export class FilteringExtension extends Extension {

this.VisibilityState.command = command

let walkFunc: (node: TreeNode) => boolean
if (command === Command.HIDE || command === Command.SHOW)
walkFunc = this.visibilityWalk
if (command === Command.ISOLATE || command === Command.UNISOLATE)
walkFunc = this.isolationWalk
this.WTI.walk(walkFunc.bind(this))
this.WTI.walk(this.visibilityWalk.bind(this))
if (command === Command.ISOLATE || command === Command.UNISOLATE) {
// this.WTI.walk(this.isolationWalk.bind(this))
const rvMap = {}
this.WTI.walk((node: TreeNode) => {
if (!node.model.atomic || this.WTI.isRoot(node)) return true
const rvNodes = this.WTI.getRenderTree().getRenderViewNodesForNode(node, node)
if (!this.VisibilityState.ids[node.model.raw.id]) {
rvNodes.forEach((rvNode: TreeNode) => {
rvMap[rvNode.model.id] = rvNode.model.renderView
})
} else {
rvNodes.forEach((rvNode: TreeNode) => {
delete rvMap[rvNode.model.id]
})
}
return true
})
this.VisibilityState.rvs = Object.values(rvMap)
}

return this.setFilters()
}

Expand Down Expand Up @@ -508,17 +524,26 @@ export class FilteringExtension extends Extension {

if (this.idCache[key] && this.idCache[key].length) return this.idCache[key]

this.WTI.walk((node: TreeNode) => {
if (objectIds.includes(node.model.raw.id)) {
const subtree = node.all((node) => {
return node.model.raw !== undefined
})
const idList = subtree.map((node) => node.model.raw.id)
allIds.push(...idList)
this.idCache[node.model.raw.id] = idList
}
return true
})
for (let k = 0; k < objectIds.length; k++) {
const node = this.WTI.findId(objectIds[k])[0]
const subtree = node.all((node) => {
return node.model.raw !== undefined
})
const idList = subtree.map((node) => node.model.raw.id)
allIds.push(...idList)
this.idCache[node.model.raw.id] = idList
}
// this.WTI.walk((node: TreeNode) => {
// if (objectIds.includes(node.model.raw.id)) {
// const subtree = node.all((node) => {
// return node.model.raw !== undefined
// })
// const idList = subtree.map((node) => node.model.raw.id)
// allIds.push(...idList)
// this.idCache[node.model.raw.id] = idList
// }
// return true
// })

this.idCache[key] = allIds
return allIds
Expand Down

0 comments on commit 334f6a4

Please sign in to comment.