Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Modes Support for Instances undead-patch #3411

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/viewer/src/modules/objects/SpeckleInstancedMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ export default class SpeckleInstancedMesh extends Group {
public static MeshBatchNumber = 0

private tas: TopLevelAccelerationStructure
private batchMaterial: Material | null = null
private batchMaterial: Material
private materialCache: { [id: string]: Material } = {}
private materialStack: Array<Array<Material | Material[]>> = []
private batchMaterialStack: Array<Material> = []
private materialCacheLUT: { [id: string]: number } = {}

private _batchObjects!: BatchObject[]
Expand Down Expand Up @@ -107,6 +108,36 @@ export default class SpeckleInstancedMesh extends Group {
this.instances.forEach((value) => (value.material = overrideMaterial))
}

public setOverrideBatchMaterial(material: Material) {
const overrideMaterial = this.getCachedMaterial(material, true)
this.batchMaterialStack.push(overrideMaterial)
const materials = this.materials
for (let k = 0; k < materials.length; k++) {
if (materials[k].uuid === this.batchMaterial.uuid) {
materials[k] = overrideMaterial
}
}
this.instances.forEach((value) => {
if ((value.material as Material).uuid === this.batchMaterial.uuid)
value.material = overrideMaterial
})
}

public restoreBatchMaterial() {
const overrideBatchMaterial = this.batchMaterialStack.pop()
if (!overrideBatchMaterial) return

for (let k = 0; k < this.materials.length; k++) {
if (this.materials[k].uuid === overrideBatchMaterial.uuid) {
this.materials[k] = this.batchMaterial
}
}
this.instances.forEach((value) => {
if ((value.material as Material).uuid === overrideBatchMaterial.uuid)
value.material = this.batchMaterial
})
}

private lookupMaterial(material: Material) {
return (
this.materialCache[material.id] ||
Expand Down
2 changes: 0 additions & 2 deletions packages/viewer/src/modules/pipeline/Pipelines/Pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export abstract class Pipeline {
this.jitterIndex = 0
}

public renderRequest() {}

public render(): boolean {
this.speckleRenderer.renderer.getDrawingBufferSize(this.drawingSize)
if (this.drawingSize.length() === 0) return false
Expand Down
Loading