Skip to content

Commit 96508e6

Browse files
scale in place implemented for babylonjs meshes, enabled shadows for gaussian splat meshes, improved how lights dispose shadow generators.
1 parent d11c87d commit 96508e6

6 files changed

Lines changed: 79 additions & 7 deletions

File tree

packages/dev/babylonjs/lib/api/bitbybit/babylon/gaussian-splatting.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class BabylonGaussianSplatting {
2020
const gs = BABYLON.SceneLoader.ImportMeshAsync(null, inputs.url, undefined, this.context.scene, undefined, ".ply").then((result) => {
2121
const gaussianSplattingMesh = result.meshes[0] as BABYLON.GaussianSplattingMesh;
2222
gaussianSplattingMesh.name = `gaussian-splatting-${Math.random()}`;
23+
this.enableShadows(gaussianSplattingMesh);
2324
return gaussianSplattingMesh;
2425
});
2526
return gs;
@@ -29,7 +30,6 @@ export class BabylonGaussianSplatting {
2930
}
3031
}
3132

32-
3333
/** Clones gaussian splatting mesh
3434
* @param inputs Contains BabylonJS mesh that should be cloned
3535
* @group multiply
@@ -55,5 +55,16 @@ export class BabylonGaussianSplatting {
5555
}
5656
return points;
5757
}
58+
59+
private enableShadows(mesh: BABYLON.Mesh) {
60+
if (this.context.scene.metadata.shadowGenerators) {
61+
mesh.receiveShadows = true;
62+
const sgs = this.context.scene.metadata.shadowGenerators as BABYLON.ShadowGenerator[];
63+
sgs.forEach(s => {
64+
s.addShadowCaster(mesh);
65+
});
66+
}
67+
}
68+
5869
}
5970

packages/dev/babylonjs/lib/api/bitbybit/babylon/mesh.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,16 @@ export class BabylonMesh {
681681
inputs.babylonMesh.scaling = new BABYLON.Vector3(inputs.scale[0], inputs.scale[1], inputs.scale[2]);
682682
}
683683

684+
/**
685+
* Scales the BabylonJS mesh or instanced mesh in place by a given factor
686+
* @param inputs BabylonJS mesh and scale factor
687+
* @group set
688+
* @shortname scale in place
689+
*/
690+
setLocalScale(inputs: Inputs.BabylonMesh.ScaleInPlaceDto): void {
691+
inputs.babylonMesh.scaling.scaleInPlace(inputs.scale);
692+
}
693+
684694
/**
685695
* Checks wether mesh intersects another mesh mesh
686696
* @param inputs Two BabylonJS meshes

packages/dev/babylonjs/lib/api/bitbybit/babylon/scene.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,32 @@ export class BabylonScene {
103103
shadowGenerator.contactHardeningLightSizeUVRatio = inputs.shadowContactHardeningLightSizeUVRatio;
104104
shadowGenerator.bias = inputs.shadowBias;
105105
shadowGenerator.normalBias = inputs.shadowNormalBias;
106+
if (inputs.transparencyShadow === true) {
107+
shadowGenerator.setTransparencyShadow(true);
108+
}
106109
if (inputs.shadowRefreshRate !== undefined) {
107110
shadowGenerator.getShadowMap().refreshRate = inputs.shadowRefreshRate;
108111
}
109112
light.shadowMaxZ = inputs.shadowMaxZ;
110113
light.shadowMinZ = inputs.shadowMinZ;
111114
this.context.scene.metadata.shadowGenerators.push(shadowGenerator);
115+
112116
this.context.scene.meshes.forEach(m => {
113-
if (m.name !== "bitbybit-hdrSkyBox" && !m.name.includes("bitbybit-ground") && (!m.metadata || (m.metadata && m.metadata.shadows !== false))) {
117+
if (m.name !== "bitbybit-hdrSkyBox" && !m.name.includes("poi_") && !m.name.includes("dimension_text_3d") && !m.name.includes("bitbybit-ground") && (!m.metadata || (m.metadata && m.metadata.shadows !== false))) {
114118
shadowGenerator.addShadowCaster(m, true);
115119
m.receiveShadows = true;
116120
}
117121
});
122+
123+
light.onDispose = () => {
124+
shadowGenerator.dispose();
125+
if (this.context.scene.metadata && this.context.scene.metadata.shadowGenerators) {
126+
const index = this.context.scene.metadata.shadowGenerators.indexOf(shadowGenerator);
127+
if (index > -1) {
128+
this.context.scene.metadata.shadowGenerators.splice(index, 1);
129+
}
130+
}
131+
};
118132
}
119133

120134
light.diffuse = BABYLON.Color3.FromHexString(inputs.diffuse);
@@ -168,10 +182,14 @@ export class BabylonScene {
168182
light.shadowEnabled = true;
169183
const shadowGenerator = new BABYLON.ShadowGenerator(inputs.shadowGeneratorMapSize, light);
170184
shadowGenerator.darkness = inputs.shadowDarkness;
185+
171186
shadowGenerator.usePercentageCloserFiltering = inputs.shadowUsePercentageCloserFiltering;
172187
shadowGenerator.contactHardeningLightSizeUVRatio = inputs.shadowContactHardeningLightSizeUVRatio;
173188
shadowGenerator.bias = inputs.shadowBias;
174189
shadowGenerator.normalBias = inputs.shadowNormalBias;
190+
if (inputs.transparencyShadow === true) {
191+
shadowGenerator.setTransparencyShadow(true);
192+
}
175193
if (inputs.shadowRefreshRate !== undefined) {
176194
shadowGenerator.getShadowMap().refreshRate = inputs.shadowRefreshRate;
177195
}
@@ -180,11 +198,20 @@ export class BabylonScene {
180198
light.shadowMinZ = inputs.shadowMinZ;
181199
this.context.scene.metadata.shadowGenerators.push(shadowGenerator);
182200
this.context.scene.meshes.forEach(m => {
183-
if (m.name !== "bitbybit-hdrSkyBox" && !m.name.includes("bitbybit-ground") && (!m.metadata || (m.metadata && m.metadata.shadows !== false))) {
201+
if (m.name !== "bitbybit-hdrSkyBox" && !m.name.includes("poi_") && !m.name.includes("dimension_text_3d") && !m.name.includes("bitbybit-ground") && (!m.metadata || (m.metadata && m.metadata.shadows !== false))) {
184202
shadowGenerator.addShadowCaster(m, true);
185203
m.receiveShadows = true;
186204
}
187205
});
206+
light.onDispose = () => {
207+
shadowGenerator.dispose();
208+
if (this.context.scene.metadata && this.context.scene.metadata.shadowGenerators) {
209+
const index = this.context.scene.metadata.shadowGenerators.indexOf(shadowGenerator);
210+
if (index > -1) {
211+
this.context.scene.metadata.shadowGenerators.splice(index, 1);
212+
}
213+
}
214+
};
188215
}
189216

190217
light.diffuse = BABYLON.Color3.FromHexString(inputs.diffuse);

packages/dev/babylonjs/lib/api/inputs/babylon-gaussian-splatting-inputs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ export namespace BabylonGaussianSplatting {
2323
*/
2424
babylonMesh: BABYLON.GaussianSplattingMesh;
2525
}
26-
2726
}

packages/dev/babylonjs/lib/api/inputs/babylon-mesh-inputs.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,22 @@ export namespace BabylonMesh {
111111
*/
112112
scale: Base.Vector3;
113113
}
114-
114+
export class ScaleInPlaceDto {
115+
constructor(babylonMesh?: BABYLON.Mesh | BABYLON.InstancedMesh, scale?: number) {
116+
if (babylonMesh !== undefined) { this.babylonMesh = babylonMesh; }
117+
if (scale !== undefined) { this.scale = scale; }
118+
}
119+
/**
120+
* Babylon Mesh that needs to be updated
121+
* @default undefined
122+
*/
123+
babylonMesh: BABYLON.Mesh | BABYLON.InstancedMesh;
124+
/**
125+
* factor for the scale
126+
* @default 1
127+
*/
128+
scale = 1;
129+
}
115130
export class IntersectsMeshDto {
116131
constructor(babylonMesh?: BABYLON.Mesh | BABYLON.InstancedMesh, babylonMesh2?: BABYLON.Mesh | BABYLON.InstancedMesh, precise?: boolean, includeDescendants?: boolean) {
117132
if (babylonMesh !== undefined) { this.babylonMesh = babylonMesh; }

packages/dev/babylonjs/lib/api/inputs/scene-inputs.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export namespace BabylonScene {
4141
vector: Base.Vector3 = [0, -9.81, 0];
4242
}
4343
export class PointLightDto {
44-
constructor(position?: Base.Point3, intensity?: number, diffuse?: Base.Color, specular?: Base.Color, radius?: number, shadowGeneratorMapSize?: number, enableShadows?: boolean, shadowDarkness?: number, shadowUsePercentageCloserFiltering?: boolean, shadowContactHardeningLightSizeUVRatio?: number, shadowBias?: number, shadowNormalBias?: number, shadowMaxZ?: number, shadowMinZ?: number, shadowRefreshRate?: number) {
44+
constructor(position?: Base.Point3, intensity?: number, diffuse?: Base.Color, specular?: Base.Color, radius?: number, shadowGeneratorMapSize?: number, enableShadows?: boolean, shadowDarkness?: number, transparencyShadow?: boolean, shadowUsePercentageCloserFiltering?: boolean, shadowContactHardeningLightSizeUVRatio?: number, shadowBias?: number, shadowNormalBias?: number, shadowMaxZ?: number, shadowMinZ?: number, shadowRefreshRate?: number) {
4545
if (position !== undefined) { this.position = position; }
4646
if (intensity !== undefined) { this.intensity = intensity; }
4747
if (diffuse !== undefined) { this.diffuse = diffuse; }
@@ -50,6 +50,7 @@ export namespace BabylonScene {
5050
if (shadowGeneratorMapSize !== undefined) { this.shadowGeneratorMapSize = shadowGeneratorMapSize; }
5151
if (enableShadows !== undefined) { this.enableShadows = enableShadows; }
5252
if (shadowDarkness !== undefined) { this.shadowDarkness = shadowDarkness; }
53+
if (transparencyShadow !== undefined) { this.transparencyShadow = transparencyShadow; }
5354
if (shadowUsePercentageCloserFiltering !== undefined) { this.shadowUsePercentageCloserFiltering = shadowUsePercentageCloserFiltering; }
5455
if (shadowContactHardeningLightSizeUVRatio !== undefined) { this.shadowContactHardeningLightSizeUVRatio = shadowContactHardeningLightSizeUVRatio; }
5556
if (shadowBias !== undefined) { this.shadowBias = shadowBias; }
@@ -110,7 +111,11 @@ export namespace BabylonScene {
110111
* @step 0.1
111112
*/
112113
shadowDarkness? = 0;
113-
114+
/**
115+
* Sets the ability to have transparent shadow (useful for Gaussian Splatting Meshes)
116+
* @default false
117+
*/
118+
transparencyShadow = false;
114119
/**
115120
* Use percentage closer filtering
116121
* @default true
@@ -250,6 +255,11 @@ export namespace BabylonScene {
250255
* @default true
251256
*/
252257
shadowUsePercentageCloserFiltering = true;
258+
/**
259+
* Sets the ability to have transparent shadow (useful for Gaussian Splatting Meshes)
260+
* @default false
261+
*/
262+
transparencyShadow = false;
253263
/**
254264
* Shadow contact hardening light size UV ratio - only applies if usePercentageCloserFiltering is true
255265
* @default 0.2

0 commit comments

Comments
 (0)