Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions api/material.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,11 +142,12 @@ export const flockMaterial = {
},
glow(meshName, { color } = {}) {
if (flock.materialsDebug) console.log(`Making ${meshName} glow`);
// Ensure the glow layer is initialised and only affects explicitly
// included meshes.
if (!flock.glowLayer) {
flock.glowLayer = new flock.BABYLON.GlowLayer("glowLayer", flock.scene);
flock.glowLayer.intensity = 0.5;
if (flock.sky) {
flock.glowLayer.addExcludedMesh(flock.sky);
}
}

return new Promise((resolve) => {
Expand All@@ -166,10 +167,6 @@ export const flockMaterial = {
m.metadata = m.metadata || {};
m.metadata.glow = true;

if (flock.glowLayer) {
flock.glowLayer.addIncludedOnlyMesh(m);
}

if (m.material) {
const currentMat = m.material;
const color = glowColor
Expand DownExpand Up@@ -280,13 +277,10 @@ export const flockMaterial = {
targetMesh.metadata.glow = false;

if (flock.glowLayer) {
flock.glowLayer.removeIncludedOnlyMesh(targetMesh);

const hasIncludedMeshes =
flock.glowLayer.includedOnlyMeshes &&
flock.glowLayer.includedOnlyMeshes.length > 0;

if (!hasIncludedMeshes) {
const anyGlowing = flock.scene.meshes.some(
(m) => m !== targetMesh && m.metadata?.glow,
);
if (!anyGlowing) {
flock.glowLayer.dispose();
flock.glowLayer = null;
}
Expand Down
3 changes: 3 additions & 0 deletions api/scene.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@ export const flockScene = {
if (color && color instanceof flock.BABYLON.Material) {
const skySphere = createSkySphere();
flock.sky = skySphere;
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);

const isShader = typeof color.setFloat === "function";
const tex =
Expand DownExpand Up@@ -90,6 +91,7 @@ export const flockScene = {
if (Array.isArray(color) && color.length >= 2) {
const skySphere = createSkySphere();
flock.sky = skySphere;
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);

if (color.length === 2) {
const mat = new flock.GradientMaterial("skyGradient", flock.scene);
Expand DownExpand Up@@ -128,6 +130,7 @@ export const flockScene = {
);
const skySphere = createSkySphere();
flock.sky = skySphere;
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);

const skyMat = new flock.BABYLON.StandardMaterial(
"skyMaterial",
Expand Down
Loading