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

Add LightTag and call Three.js light.dispose when removed #5915

Merged
merged 1 commit into from
Jan 30, 2023
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
1 change: 1 addition & 0 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const NetworkedTransform = defineComponent({
export const AEntity = defineComponent();
export const Object3DTag = defineComponent();
export const GLTFModel = defineComponent();
export const LightTag = defineComponent();
export const DirectionalLight = defineComponent();
export const CursorRaycastable = defineComponent();
export const RemoteHoverTarget = defineComponent();
Expand Down
7 changes: 2 additions & 5 deletions src/inflators/directional-light.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addComponent } from "bitecs";
import { addObject3DComponent } from "../utils/jsx-entity";
import { DirectionalLight } from "../bit-components";
import { DirectionalLight, LightTag } from "../bit-components";
import { DirectionalLight as DL } from "three";
import { HubsWorld } from "../app";

Expand All @@ -24,12 +24,9 @@ export function inflateDirectionalLight(world: HubsWorld, eid: number, params: D
light.shadow.bias = params.shadowBias;
light.shadow.radius = params.shadowRadius;
light.shadow.mapSize.set(params.shadowMapResolution[0], params.shadowMapResolution[1]);
if (light.shadow.map) {
light.shadow.map.dispose();
(light.shadow.map as any) = null; // TODO: Correct the Typescript definition in three. This /is/ nullable.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Thanks for removing this


addObject3DComponent(world, eid, light);
addComponent(world, LightTag, eid);
addComponent(world, DirectionalLight, eid);
return eid;
}
3 changes: 3 additions & 0 deletions src/systems/remove-object3D-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AudioEmitter,
EnvironmentSettings,
GLTFModel,
LightTag,
MediaImage,
MediaFrame,
MediaVideo,
Expand Down Expand Up @@ -40,6 +41,7 @@ const cleanupGLTFs = cleanupObjOnExit(GLTFModel, obj => {
obj.dispose();
}
});
const cleanupLights = cleanupObjOnExit(LightTag, obj => obj.dispose());
const cleanupTexts = cleanupObjOnExit(Text, obj => obj.dispose());
const cleanupMediaFrames = cleanupObjOnExit(MediaFrame, obj => obj.geometry.dispose());
const cleanupAudioEmitters = cleanupObjOnExit(AudioEmitter, obj => {
Expand Down Expand Up @@ -107,6 +109,7 @@ export function removeObject3DSystem(world) {
// cleanup any component specific resources
cleanupGLTFs(world);
cleanupSlice9s(world);
cleanupLights(world);
cleanupTexts(world);
cleanupMediaFrames(world);
cleanupImages(world);
Expand Down