#828 Implemented the SpeckleMesh which extends three's Mesh and corrects the raycasting implementation to work with the positions encoded as pairs of lows and highs

This commit is contained in:
AlexandruPopovici
2022-07-27 21:46:03 +03:00
parent 9e7c80bb4f
commit 3ca2d08e18
10 changed files with 426 additions and 28 deletions
@@ -9,7 +9,7 @@ import { NodeRenderView } from '../tree/NodeRenderView'
import { Batch, BatchUpdateRange, GeometryType } from './Batch'
import PointBatch from './PointBatch'
import { FilterMaterialType } from '../FilteringManager'
import { Material, WebGLRenderer } from 'three'
import { WebGLRenderer } from 'three'
import { FilterMaterial } from '../FilteringManager'
export default class Batcher {
@@ -170,8 +170,14 @@ export default class Batcher {
const batchIds = [...Array.from(new Set(rvs.map((value) => value.batchId)))]
for (const k in this.batches) {
if (!batchIds.includes(k)) {
;(this.batches[k].renderObject as unknown as { material: Material }).material =
this.materials.getGhostMaterial(this.batches[k].renderViews[0])
this.batches[k].setDrawRanges({
offset: 0,
count: Infinity,
material: this.materials.getFilterMaterial(
this.batches[k].renderViews[0],
FilterMaterialType.GHOST
)
})
} else {
const drawRanges = []
for (let i = 0; i < this.batches[k].renderViews.length; i++) {
@@ -24,7 +24,7 @@ export default class LineBatch implements Batch {
public batchMaterial: SpeckleLineMaterial
private mesh: LineSegments2 | Line
public colorBuffer: InstancedInterleavedBuffer
public static vectorBuffer: Vector4 = new Vector4()
private static readonly vector4Buffer: Vector4 = new Vector4()
public constructor(id: string, renderViews: NodeRenderView[]) {
this.id = id
@@ -87,11 +87,11 @@ export default class LineBatch implements Batch {
ranges[i].offset * this.colorBuffer.stride +
ranges[i].count * this.colorBuffer.stride
LineBatch.vectorBuffer.set(color.r, color.g, color.b, 1)
LineBatch.vector4Buffer.set(color.r, color.g, color.b, 1)
this.updateColorBuffer(
start,
ranges[i].count === Infinity ? this.colorBuffer.array.length : len,
LineBatch.vectorBuffer
LineBatch.vector4Buffer
)
}
this.colorBuffer.updateRange = { offset: 0, count: data.length }
@@ -4,7 +4,6 @@ import {
DynamicDrawUsage,
Float32BufferAttribute,
Material,
Mesh,
Object3D,
Uint16BufferAttribute,
Uint32BufferAttribute,
@@ -12,6 +11,7 @@ import {
} from 'three'
import { Geometry } from '../converter/Geometry'
import SpeckleStandardColoredMaterial from '../materials/SpeckleStandardColoredMaterial'
import SpeckleMesh from '../objects/SpeckleMesh'
import { NodeRenderView } from '../tree/NodeRenderView'
import { World } from '../World'
import { Batch, BatchUpdateRange, HideAllBatchUpdateRange } from './Batch'
@@ -21,7 +21,7 @@ export default class MeshBatch implements Batch {
public renderViews: NodeRenderView[]
private geometry: BufferGeometry
public batchMaterial: Material
public mesh: Mesh
public mesh: SpeckleMesh
private gradientIndexBuffer: BufferAttribute
public constructor(id: string, renderViews: NodeRenderView[]) {
@@ -257,7 +257,7 @@ export default class MeshBatch implements Batch {
position,
this.batchMaterial.vertexColors ? color : null
)
this.mesh = new Mesh(this.geometry, this.batchMaterial)
this.mesh = new SpeckleMesh(this.geometry, this.batchMaterial)
this.mesh.uuid = this.id
}
@@ -285,6 +285,7 @@ export default class MeshBatch implements Batch {
}
if (position) {
/** When RTE enabled, we'll be storing the high component of the encoding here */
this.geometry.setAttribute('position', new Float32BufferAttribute(position, 3))
}