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

Snow Doesn't Stay #3736

Merged
merged 11 commits into from
Dec 20, 2024
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
Loading