Hi!
I have a sample here that shows my problem. When balls get hit, I want them to glow for 30 or 45 frames or so, then make them stop glowing. However when I try to remove the glow by setting thisItem.materials.emissiveColor = null;
my whole app crashes lol!
Falling balls that make blocks glow | Babylon.js Playground (babylonjs.com)
I’m doing this by adding an emissiveColor effect to the items and also setting a paired glowFrames
property, then pushing the item into an array called glowingIndicators
.
In my register before render, I call a method that iterates through the items in the glowingIndicators
array, and debit 1 from every item’s glowFrames
. When glowFrames
is zero, I am trying to remove the item from the array and then change it from emissiveColor to diffuseColor.
function updateGlowingIndicators() {
for (let i = glowingIndicators.length - 1; i >= 0; i--) {
const thisItem = glowingIndicators[i];
thisItem.glowFrames--;
if (thisItem.glowFrames < 1) {
// Log when the condition is met
// Check if the mesh is currently glowing
if (glowLayer.hasMesh(thisItem)) {
// Remove the mesh from the glow layer
glowLayer.removeIncludedOnlyMesh(thisItem);
console.log(`Removing item at index from glowLayer glowFrames reached less than 1`);
// // Optionally, dispose of the glow layer if no other meshes are included
// if (glowLayer.isEnabled && glowLayer.getRenderingMeshes().length === 0) {
// glowLayer.dispose();
// }
}
thisItem.material.diffuseColor = thisItem.material.diffuseColor;
// Set emissiveColor to null makes it crash!
// thisItem.material.emissiveColor = null;
// try{
// glowingIndicators.splice(i, 1);
// }
// catch{
// glowingIndicators = [];
// break;
// }
}
}
}