-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76e40a3
commit 20d4bbf
Showing
3 changed files
with
56 additions
and
25 deletions.
There are no files selected for viewing
69 changes: 48 additions & 21 deletions
69
packages/viewer/src/modules/batching/InstancedBatchObject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
// /* eslint-disable camelcase */ | ||
// import { BatchObject } from './BatchObject' | ||
/* eslint-disable camelcase */ | ||
import { BatchObject, VectorLike } from './BatchObject' | ||
|
||
// import { Matrix4, Vector3 } from 'three' | ||
// import { SpeckleMeshBVH } from '../objects/AccelerationStructure' | ||
// import { NodeRenderView } from '../tree/NodeRenderView' | ||
import { Box3, Matrix4 } from 'three' | ||
import { NodeRenderView } from '../tree/NodeRenderView' | ||
import { AccelerationStructure } from '../objects/AccelerationStructure' | ||
|
||
// export class InstancedBatchObject extends BatchObject { | ||
// protected instanceTransform: Matrix4 = new Matrix4() | ||
export class InstancedBatchObject extends BatchObject { | ||
protected instanceTransform: Matrix4 = new Matrix4() | ||
|
||
// public constructor(renderView: NodeRenderView, batchIndex: number) { | ||
// super(renderView, batchIndex) | ||
// } | ||
public get aabb(): Box3 { | ||
const box = new Box3().copy(this.renderView.aabb) | ||
box.applyMatrix4(this.transform).applyMatrix4(this.instanceTransform) | ||
return box | ||
} | ||
|
||
// public buildInstanceBVH(instanceBVH?: SpeckleMeshBVH) { | ||
// if (instanceBVH) { | ||
// this._bvh = SpeckleMeshBVH.buildBVH(indices, localPositions) | ||
// this._bvh.inputTransform = this.transformInv | ||
// this._bvh.outputTransform = this.transform | ||
// this._bvh.inputOriginTransform = new Matrix4().copy(transform) | ||
// this._bvh.outputOriginTransfom = new Matrix4().copy(transform).invert() | ||
// return | ||
// } else this.buildBVH() | ||
// } | ||
// } | ||
public constructor(renderView: NodeRenderView, batchIndex: number) { | ||
super(renderView, batchIndex) | ||
this.instanceTransform.copy(renderView.renderData.geometry.transform) | ||
this.transform.copy(this.instanceTransform) | ||
this.transformInv.copy(this.instanceTransform) | ||
} | ||
|
||
public buildInstanceBVH(accelerationStructure?: AccelerationStructure) { | ||
if (accelerationStructure) { | ||
this._accelerationStructure = accelerationStructure | ||
this._accelerationStructure.inputTransform = this.transformInv | ||
this._accelerationStructure.outputTransform = this.transform | ||
const transform = new Matrix4().makeTranslation( | ||
this._localOrigin.x, | ||
this._localOrigin.y, | ||
this._localOrigin.z | ||
) | ||
transform.invert() | ||
this._accelerationStructure.inputOriginTransform = new Matrix4().copy(transform) | ||
this._accelerationStructure.outputOriginTransfom = new Matrix4() | ||
.copy(transform) | ||
.invert() | ||
} else this.buildBVH() | ||
} | ||
|
||
public transformTRS( | ||
translation: VectorLike, | ||
euler: VectorLike, | ||
scale: VectorLike, | ||
pivot: VectorLike | ||
) { | ||
super.transformTRS(translation, euler, scale, pivot) | ||
this.transform.multiply(this.instanceTransform) | ||
this.transformInv.multiply(this.instanceTransform) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters