@@ -4,7 +4,7 @@ import type { Mesh } from "../../Meshes/mesh";
44import type { Effect , IEffectCreationOptions } from "../../Materials/effect" ;
55import type { Scene } from "../../scene" ;
66import type { Matrix } from "../../Maths/math.vector" ;
7- import type { GaussianSplattingMesh } from "../../Meshes" ;
7+ import type { GaussianSplattingMesh } from "../../Meshes/GaussianSplatting/gaussianSplattingMesh " ;
88import { SerializationHelper } from "../../Misc/decorators.serialization" ;
99import { VertexBuffer } from "../../Buffers/buffer" ;
1010import { MaterialDefines } from "../../Materials/materialDefines" ;
@@ -150,6 +150,7 @@ export class GaussianSplattingMaterial extends PushMaterial {
150150 "kernelSize" ,
151151 "viewDirectionFactor" ,
152152 ] ;
153+ private _sourceMesh : GaussianSplattingMesh | null = null ;
153154 /**
154155 * Checks whether the material is ready to be rendered for a given mesh.
155156 * @param mesh The mesh to render
@@ -182,8 +183,12 @@ export class GaussianSplattingMaterial extends PushMaterial {
182183 return true ;
183184 }
184185
186+ if ( ! this . _sourceMesh ) {
187+ return false ;
188+ }
189+
185190 const engine = scene . getEngine ( ) ;
186- const gsMesh = mesh as GaussianSplattingMesh ;
191+ const gsMesh = this . _sourceMesh ;
187192
188193 // Misc.
189194 PrepareDefinesForMisc (
@@ -270,6 +275,13 @@ export class GaussianSplattingMaterial extends PushMaterial {
270275 return true ;
271276 }
272277
278+ /**
279+ * GaussianSplattingMaterial belongs to a single mesh
280+ * @param mesh mesh this material belongs to
281+ */
282+ public setSourceMesh ( mesh : GaussianSplattingMesh ) {
283+ this . _sourceMesh = mesh ;
284+ }
273285 /**
274286 * Bind material effect for a specific Gaussian Splatting mesh
275287 * @param mesh Gaussian splatting mesh
@@ -280,11 +292,16 @@ export class GaussianSplattingMaterial extends PushMaterial {
280292 const engine = scene . getEngine ( ) ;
281293 const camera = scene . activeCamera ;
282294
283- const renderWidth = engine . getRenderWidth ( ) ;
284- const renderHeight = engine . getRenderHeight ( ) ;
295+ const renderWidth = engine . getRenderWidth ( ) * camera ! . viewport . width ;
296+ const renderHeight = engine . getRenderHeight ( ) * camera ! . viewport . height ;
297+
298+ const gsMaterial = mesh . material as GaussianSplattingMaterial ;
299+
300+ if ( ! gsMaterial . _sourceMesh ) {
301+ return ;
302+ }
285303
286- const gsMesh = mesh as GaussianSplattingMesh ;
287- const gsMaterial = gsMesh . material as GaussianSplattingMaterial ;
304+ const gsMesh = gsMaterial . _sourceMesh ;
288305
289306 // check if rigcamera, get number of rigs
290307 const numberOfRigs = camera ?. rigParent ?. rigCameras . length || 1 ;
0 commit comments