#827 Fixed an issue with raycaster not having a null check. Removed massive redundancy in applyin filters. Now filters apply 30-40 times faster. More improvement can be done, but this was a low hanging fruit
This commit is contained in:
@@ -39,6 +39,4 @@ sandbox.makeGenericUI()
|
||||
sandbox.makeSceneUI()
|
||||
sandbox.makeFilteringUI()
|
||||
// Load demo object
|
||||
sandbox.loadUrl(
|
||||
'https://speckle.xyz/streams/1c17f17bec/commits/44c1d59787?c=%5B837.71176,649.65785,206.47337,16.8377,146.34869,-215.2331,0,1%5D'
|
||||
)
|
||||
sandbox.loadUrl('https://speckle.xyz/streams/e6f9156405/commits/0694d53bb5')
|
||||
|
||||
@@ -21,7 +21,10 @@ export class Intersections {
|
||||
): Intersection {
|
||||
this.raycaster.setFromCamera(point, camera)
|
||||
const target = scene.getObjectByName('ContentGroup')
|
||||
const results = this.raycaster.intersectObjects(target.children)
|
||||
let results = []
|
||||
if (target) {
|
||||
results = this.raycaster.intersectObjects(target.children)
|
||||
}
|
||||
|
||||
if (results.length === 0) return null
|
||||
if (nearest) results.sort((value) => value.distance)
|
||||
|
||||
@@ -28,6 +28,7 @@ import { FilterMaterial } from './FilteringManager'
|
||||
import Input, { InputOptionsDefault } from './input/Input'
|
||||
import { Intersections } from './Intersections'
|
||||
import SpeckleStandardMaterial from './materials/SpeckleStandardMaterial'
|
||||
import { NodeRenderView } from './tree/NodeRenderView'
|
||||
import { Viewer } from './Viewer'
|
||||
|
||||
export default class SpeckleRenderer {
|
||||
@@ -169,7 +170,7 @@ export default class SpeckleRenderer {
|
||||
this.filterBatchRecording = []
|
||||
}
|
||||
|
||||
public applyFilter(ids: string[], filterMaterial: FilterMaterial) {
|
||||
public applyFilter(ids: NodeRenderView[], filterMaterial: FilterMaterial) {
|
||||
this.filterBatchRecording.push(
|
||||
...this.batcher.setObjectsFilterMaterial(ids, filterMaterial)
|
||||
)
|
||||
|
||||
@@ -328,6 +328,7 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
min?: number,
|
||||
max?: number
|
||||
) {
|
||||
const start = performance.now()
|
||||
const nodesGradient = []
|
||||
const nodesGhost = []
|
||||
const values = []
|
||||
@@ -360,27 +361,31 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
})
|
||||
this.speckleRenderer.clearFilter()
|
||||
this.speckleRenderer.beginFilter()
|
||||
|
||||
const ghostRvs = []
|
||||
for (let k = 0; k < nodesGhost.length; k++) {
|
||||
const ghostIds = WorldTree.getRenderTree()
|
||||
.getRenderViewsForNode(nodesGhost[k], nodesGhost[k])
|
||||
.map((value) => value.renderData.id)
|
||||
this.speckleRenderer.applyFilter(ghostIds, {
|
||||
filterType: FilterMaterialType.GHOST
|
||||
})
|
||||
ghostRvs.push(
|
||||
...WorldTree.getRenderTree().getRenderViewsForNode(nodesGhost[k], nodesGhost[k])
|
||||
)
|
||||
}
|
||||
this.speckleRenderer.applyFilter(ghostRvs, {
|
||||
filterType: FilterMaterialType.GHOST
|
||||
})
|
||||
|
||||
for (let k = 0; k < nodesGradient.length; k++) {
|
||||
const ids = WorldTree.getRenderTree()
|
||||
.getRenderViewsForNode(nodesGradient[k], nodesGradient[k])
|
||||
.map((value) => value.renderData.id)
|
||||
const rvs = WorldTree.getRenderTree().getRenderViewsForNode(
|
||||
nodesGradient[k],
|
||||
nodesGradient[k]
|
||||
)
|
||||
// .map((value) => value.renderData.id)
|
||||
const t = (values[k] - data.min) / (data.max - data.min)
|
||||
this.speckleRenderer.applyFilter(ids, {
|
||||
this.speckleRenderer.applyFilter(rvs, {
|
||||
filterType: FilterMaterialType.GRADIENT,
|
||||
rampIndex: t
|
||||
})
|
||||
}
|
||||
|
||||
this.speckleRenderer.endFilter()
|
||||
console.warn(`Filter time: ${performance.now() - start}`)
|
||||
}
|
||||
|
||||
public debugGetFilterByNonNumericPropetyData(propertyName: string): {
|
||||
@@ -429,6 +434,7 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
public debugApplyByNonNumericPropetyFilter(data: {
|
||||
color?: { name: string; color: string; colorIndex: number; nodes: [] }
|
||||
}) {
|
||||
const start = performance.now()
|
||||
const colors = Object.values(data)
|
||||
colors.sort((a, b) => a.colorIndex - b.colorIndex)
|
||||
|
||||
@@ -437,17 +443,16 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
)
|
||||
this.speckleRenderer.clearFilter()
|
||||
this.speckleRenderer.beginFilter()
|
||||
|
||||
for (let k = 0; k < colors.length; k++) {
|
||||
const nodes = colors[k].nodes
|
||||
let ids = []
|
||||
let rvs = []
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
ids = ids.concat(
|
||||
WorldTree.getRenderTree()
|
||||
.getRenderViewsForNode(nodes[i], nodes[i])
|
||||
.map((value) => value.renderData.id)
|
||||
rvs = rvs.concat(
|
||||
WorldTree.getRenderTree().getRenderViewsForNode(nodes[i], nodes[i])
|
||||
)
|
||||
}
|
||||
this.speckleRenderer.applyFilter(ids, {
|
||||
this.speckleRenderer.applyFilter(rvs, {
|
||||
filterType: FilterMaterialType.COLORED,
|
||||
rampIndex: colors[k].colorIndex / colors.length,
|
||||
rampIndexColor: new Color(colors[k].color),
|
||||
@@ -455,6 +460,7 @@ export class Viewer extends EventEmitter implements IViewer {
|
||||
})
|
||||
}
|
||||
this.speckleRenderer.endFilter()
|
||||
console.warn(`Filter time: ${performance.now() - start}`)
|
||||
}
|
||||
|
||||
// private isObject(value) {
|
||||
|
||||
@@ -111,21 +111,21 @@ export default class Batcher {
|
||||
}
|
||||
|
||||
public setObjectsFilterMaterial(
|
||||
ids: string[],
|
||||
rvs: NodeRenderView[],
|
||||
filterMaterial: FilterMaterial
|
||||
): string[] {
|
||||
const rvs = []
|
||||
ids.forEach((val: string) => {
|
||||
rvs.push(WorldTree.getRenderTree().getRenderViewForNodeId(val))
|
||||
/** The batcher should take the explicit IDs it's given and roll with them
|
||||
* It shouldn;t try to expand the list of render views on it's own
|
||||
*/
|
||||
// const views = WorldTree.getRenderTree().getRenderViewsForNodeId(val)
|
||||
// for (let k = 0; k < views.length; k++) {
|
||||
// if (rvs.includes(views[k])) return
|
||||
// }
|
||||
// rvs = rvs.concat(views)
|
||||
})
|
||||
// const rvs = []
|
||||
// ids.forEach((val: string) => {
|
||||
// rvs.push(WorldTree.getRenderTree().getRenderViewForNodeId(val))
|
||||
// /** The batcher should take the explicit IDs it's given and roll with them
|
||||
// * It shouldn;t try to expand the list of render views on it's own
|
||||
// */
|
||||
// // const views = WorldTree.getRenderTree().getRenderViewsForNodeId(val)
|
||||
// // for (let k = 0; k < views.length; k++) {
|
||||
// // if (rvs.includes(views[k])) return
|
||||
// // }
|
||||
// // rvs = rvs.concat(views)
|
||||
// })
|
||||
// console.log(ids)
|
||||
// console.log(rvs)
|
||||
const batchIds = [...Array.from(new Set(rvs.map((value) => value.batchId)))]
|
||||
|
||||
Reference in New Issue
Block a user