Skip to content

Commit

Permalink
SnowPipeline now resets the snow batch material after rendering. aka,…
Browse files Browse the repository at this point in the history
… the snow no longer stays
  • Loading branch information
AlexandruPopovici committed Dec 20, 2024
1 parent 410bedd commit 0fb775f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
34 changes: 24 additions & 10 deletions packages/frontend-2/lib/viewer/pipelines/snow/SnowPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {
SpeckleRenderer,
MeshBatch,
SpeckleStandardMaterial
SpeckleStandardMaterial,
SpeckleMesh
} from '@speckle/viewer'
import {
ProgressivePipeline,
Expand All @@ -19,12 +20,13 @@ import {
AssetType
} from '@speckle/viewer'
import SnowMaterial from './SnowMaterial'
import type SpeckleMesh from '@speckle/viewer/dist/modules/objects/SpeckleMesh'
import { RepeatWrapping, NearestFilter } from 'three'
import snowTex from './snow.png'
import { SnowFallPass } from './SnowFallPass'

export class SnowPipeline extends ProgressivePipeline {
private batchSnowMaterials: { [id: string]: SnowMaterial } = {}

constructor(speckleRenderer: SpeckleRenderer) {
super(speckleRenderer)

Expand Down Expand Up @@ -135,14 +137,26 @@ export class SnowPipeline extends ProgressivePipeline {
GeometryType.MESH
)

for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
const batchMaterial: SpeckleStandardMaterial = batches[k]
.batchMaterial as SpeckleStandardMaterial
const snowMaterial = new SnowMaterial({}, ['USE_RTE'])
snowMaterial.copy(batchMaterial)
snowMaterial.normalMap = snowTexture
batchRenderable.setOverrideBatchMaterial(snowMaterial)
this.onBeforePipelineRender = () => {
for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
const batchMaterial: SpeckleStandardMaterial = batches[k]
.batchMaterial as SpeckleStandardMaterial
if (!this.batchSnowMaterials[batches[k].id]) {
const snowMaterial = new SnowMaterial({}, ['USE_RTE'])
snowMaterial.copy(batchMaterial)
snowMaterial.normalMap = snowTexture
this.batchSnowMaterials[batches[k].id] = snowMaterial
}
batchRenderable.setOverrideBatchMaterial(this.batchSnowMaterials[batches[k].id])
}
}

this.onAfterPipelineRender = () => {
for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
batchRenderable.restoreBatchMaterial()
}
}
}
}
30 changes: 22 additions & 8 deletions packages/viewer-sandbox/src/Pipelines/Snow/SnowPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import snowTex from '../../../assets/snow.png'
import { SnowFallPass } from './SnowFallPass'

export class SnowPipeline extends ProgressivePipeline {
private batchSnowMaterials: { [id: string]: SnowMaterial } = {}

constructor(speckleRenderer: SpeckleRenderer) {
super(speckleRenderer)

Expand Down Expand Up @@ -133,14 +135,26 @@ export class SnowPipeline extends ProgressivePipeline {
GeometryType.MESH
)

for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
const batchMaterial: SpeckleStandardMaterial = batches[k]
.batchMaterial as SpeckleStandardMaterial
const snowMaterial = new SnowMaterial({}, ['USE_RTE'])
snowMaterial.copy(batchMaterial)
snowMaterial.normalMap = snowTexture
batchRenderable.setOverrideBatchMaterial(snowMaterial)
this.onBeforePipelineRender = () => {
for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
const batchMaterial: SpeckleStandardMaterial = batches[k]
.batchMaterial as SpeckleStandardMaterial
if (!this.batchSnowMaterials[batches[k].id]) {
const snowMaterial = new SnowMaterial({}, ['USE_RTE'])
snowMaterial.copy(batchMaterial)
snowMaterial.normalMap = snowTexture
this.batchSnowMaterials[batches[k].id] = snowMaterial
}
batchRenderable.setOverrideBatchMaterial(this.batchSnowMaterials[batches[k].id])
}
}

this.onAfterPipelineRender = () => {
for (let k = 0; k < batches.length; k++) {
const batchRenderable: SpeckleMesh = batches[k].renderObject as SpeckleMesh
batchRenderable.restoreBatchMaterial()
}
}
}
}
6 changes: 5 additions & 1 deletion packages/viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ import { SpeckleWebGLRenderer } from './modules/objects/SpeckleWebGLRenderer.js'
import { InstancedMeshBatch } from './modules/batching/InstancedMeshBatch.js'
import { ViewModeEvent, ViewModeEventPayload } from './modules/extensions/ViewModes.js'
import { BasitPipeline } from './modules/pipeline/Pipelines/BasitViewPipeline.js'
import SpeckleMesh from './modules/objects/SpeckleMesh.js'
import SpeckleInstancedMesh from './modules/objects/SpeckleInstancedMesh.js'

export {
Viewer,
Expand Down Expand Up @@ -235,7 +237,9 @@ export {
NOT_INTERSECTED,
INTERSECTED,
CONTAINED,
ViewModeEvent
ViewModeEvent,
SpeckleMesh,
SpeckleInstancedMesh
}

export type {
Expand Down

0 comments on commit 0fb775f

Please sign in to comment.