#811 Integrated double-click to zoom, and zoom extents with the new viewer. Currently I'm using old existing code just for the sake of less regression, but will revisit it in the future

This commit is contained in:
AlexandruPopovici
2022-06-21 15:47:24 +03:00
parent 499653d983
commit f73384e66f
9 changed files with 198 additions and 64 deletions
+19 -38
View File
@@ -1,46 +1,27 @@
import { Raycaster, Scene } from 'three'
import Batcher from './batching/Batcher'
import { WorldTree } from './tree/WorldTree'
import { Camera, Intersection, Raycaster, Scene, Vector2 } from 'three'
export class Intersections {
private scene: Scene
private batcher: Batcher
private lastTimeCall = 0
private raycaster: Raycaster
public constructor(scene: Scene, batcher: Batcher) {
this.scene = scene
this.batcher = batcher
this.batcher
public constructor() {
this.raycaster = new Raycaster()
this.raycaster.params.Line = { threshold: 0.1 }
;(this.raycaster.params as { Line2? }).Line2 = {}
;(this.raycaster.params as { Line2? }).Line2.threshold = 1
}
public intersectScene(raycaster: Raycaster) {
if (performance.now() - this.lastTimeCall < 100) return
this.lastTimeCall = performance.now()
const target = this.scene.getObjectByName('ContentGroup')
const results = raycaster.intersectObjects(target.children)
if (!results.length) {
this.batcher.resetBatchesDrawRanges()
return
}
public intersect(
scene: Scene,
camera: Camera,
point: Vector2,
nearest = true
): Intersection {
this.raycaster.setFromCamera(point, camera)
const target = scene.getObjectByName('ContentGroup')
const results = this.raycaster.intersectObjects(target.children)
results.sort((value) => value.distance)
console.warn(results[0])
const rv = this.batcher.getRenderView(
results[0].object.uuid,
results[0].faceIndex !== undefined ? results[0].faceIndex : results[0].index
)
const hitId = rv.renderData.id
const hitNode = WorldTree.getInstance().findId(hitId)
console.warn(hitNode)
const renderViews = WorldTree.getRenderTree().getRenderViewsForNode(hitNode)
console.warn(renderViews)
this.batcher.selectRenderViews(renderViews)
// this.batcher.selectRenderView(rv)
// this.batcher.isolateRenderViews(renderViews)
// const node1 = WorldTree.getInstance().findId('62942139c0010e51500ee10655ce33a6')
// const node2 = WorldTree.getInstance().findId('c6268101e02c2c5b1b3af25aed1f722b')
// this.batcher.isolateRenderViews([node1.model.renderView, node2.model.renderView])
if (results.length === 0) return null
if (nearest) results.sort((value) => value.distance)
return results[0]
}
}