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

Toggle-able Basit Mode #3672

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions packages/viewer-sandbox/src/Extensions/ViewModesKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class ViewModesKeys extends Extension {
case '5':
viewModes.setViewMode(ViewMode.ARCTIC)
break
case '6':
viewModes.setViewMode(ViewMode.BASIT)
break
}
})
}
Expand Down
5 changes: 4 additions & 1 deletion packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const getStream = () => {
// 'https://app.speckle.systems/streams/da9e320dad/commits/5388ef24b8'
// 'https://latest.speckle.systems/streams/58b5648c4d/commits/60371ecb2d'
// 'Super' heavy revit shit
'https://app.speckle.systems/streams/e6f9156405/commits/0694d53bb5'
// 'https://app.speckle.systems/streams/e6f9156405/commits/0694d53bb5'
// IFC building (good for a tree based structure)
// 'https://latest.speckle.systems/streams/92b620fb17/commits/2ebd336223'
// IFC story, a subtree of the above
Expand Down Expand Up @@ -454,6 +454,9 @@ const getStream = () => {
// 'https://app.speckle.systems/projects/344f803f81/models/5582ab673e'

// 'https://speckle.xyz/streams/27e89d0ad6/commits/5ed4b74252'

// DUI3 Mesh Colors
'https://app.speckle.systems/projects/93200a735d/models/cbacd3eaeb@344a397239'
)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import {
} from './modules/materials/Materials.js'
import { AccelerationStructure } from './modules/objects/AccelerationStructure.js'
import { TopLevelAccelerationStructure } from './modules/objects/TopLevelAccelerationStructure.js'
import { BasitPipeline } from './modules/pipeline/Pipelines/BasitViewPipeline.js'

export {
Viewer,
Expand Down Expand Up @@ -214,6 +215,7 @@ export {
MRTEdgesPipeline,
MRTShadedViewPipeline,
MRTPenViewPipeline,
BasitPipeline,
ViewModes,
ViewMode,
FilterMaterial,
Expand Down
7 changes: 6 additions & 1 deletion packages/viewer/src/modules/extensions/ViewModes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UpdateFlags } from '../../IViewer.js'
import { ArcticViewPipeline } from '../pipeline/Pipelines/ArcticViewPipeline.js'
import { BasitPipeline } from '../pipeline/Pipelines/BasitViewPipeline.js'
import { DefaultPipeline } from '../pipeline/Pipelines/DefaultPipeline.js'
import { EdgesPipeline } from '../pipeline/Pipelines/EdgesPipeline.js'
import { MRTEdgesPipeline } from '../pipeline/Pipelines/MRT/MRTEdgesPipeline.js'
Expand All @@ -14,7 +15,8 @@ export enum ViewMode {
DEFAULT_EDGES,
SHADED,
PEN,
ARCTIC
ARCTIC,
BASIT
}

export class ViewModes extends Extension {
Expand Down Expand Up @@ -46,6 +48,9 @@ export class ViewModes extends Extension {
case ViewMode.ARCTIC:
renderer.pipeline = new ArcticViewPipeline(renderer)
break
case ViewMode.BASIT:
renderer.pipeline = new BasitPipeline(renderer, this.viewer.getWorldTree())
break
}
this.viewer.requestRender(UpdateFlags.RENDER_RESET)
}
Expand Down
7 changes: 4 additions & 3 deletions packages/viewer/src/modules/pipeline/Passes/BasitPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export class BasitPass extends BaseGPass {
super()
this.tree = tree
this.speckleRenderer = renderer
this.buildMaterials()
}

public get displayName(): string {
return 'BASIT'
}

onBeforeRender = () => {
protected buildMaterials() {
const batches: MeshBatch[] = this.speckleRenderer.batcher.getBatches(
undefined,
GeometryType.MESH
Expand Down Expand Up @@ -112,14 +113,14 @@ export class BasitPass extends BaseGPass {
protected overrideMaterials() {
for (const k in this.materialMap) {
const tuple = this.materialMap[k]
;(tuple[0].renderObject as SpeckleMesh).setOverrideMaterial(tuple[2])
;(tuple[0].renderObject as SpeckleMesh).setOverrideBatchMaterial(tuple[2])
}
}

protected restoreMaterials() {
for (const k in this.materialMap) {
const tuple = this.materialMap[k]
;(tuple[0].renderObject as SpeckleMesh).restoreMaterial()
;(tuple[0].renderObject as SpeckleMesh).restoreBatchMaterial()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import SpeckleRenderer from '../../SpeckleRenderer.js'
import { GeometryPass } from '../Passes/GeometryPass.js'
import { Pipeline } from './Pipeline.js'
import { BasitPass } from '../Passes/BasitPass.js'
import { ClearFlags } from '../Passes/GPass.js'
import { ClearFlags, ObjectVisibility } from '../Passes/GPass.js'
import { StencilPass } from '../Passes/StencilPass.js'
import { StencilMaskPass } from '../Passes/StencilMaskPass.js'

export class BasitPipeline extends Pipeline {
constructor(speckleRenderer: SpeckleRenderer, tree: WorldTree) {
Expand All @@ -12,13 +14,38 @@ export class BasitPipeline extends Pipeline {
const basitPass = new BasitPass(tree, speckleRenderer)
basitPass.setLayers([ObjectLayers.STREAM_CONTENT_MESH])
basitPass.setClearColor(0x000000, 0)
basitPass.setClearFlags(ClearFlags.COLOR | ClearFlags.DEPTH | ClearFlags.STENCIL)
basitPass.setClearFlags(ClearFlags.COLOR)
basitPass.outputTarget = null

const transparentColorPass = new GeometryPass()
transparentColorPass.setLayers([ObjectLayers.SHADOWCATCHER])
transparentColorPass.outputTarget = null
const nonMeshPass = new GeometryPass()
nonMeshPass.setLayers([
ObjectLayers.STREAM_CONTENT_LINE,
ObjectLayers.STREAM_CONTENT_POINT,
ObjectLayers.STREAM_CONTENT_POINT_CLOUD,
ObjectLayers.STREAM_CONTENT_TEXT
])
const stencilPass = new StencilPass()
stencilPass.setVisibility(ObjectVisibility.STENCIL)
stencilPass.setLayers([ObjectLayers.STREAM_CONTENT_MESH])

this.passList.push(basitPass, transparentColorPass)
const stencilMaskPass = new StencilMaskPass()
stencilMaskPass.setVisibility(ObjectVisibility.STENCIL)
stencilMaskPass.setLayers([ObjectLayers.STREAM_CONTENT_MESH])
stencilMaskPass.setClearFlags(ClearFlags.DEPTH)

const overlayPass = new GeometryPass()
overlayPass.setLayers([
ObjectLayers.PROPS,
ObjectLayers.OVERLAY,
ObjectLayers.MEASUREMENTS
])

this.passList.push(
stencilPass,
basitPass,
nonMeshPass,
stencilMaskPass,
overlayPass
)
}
}
Loading