mylingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
55 lines • 2.04 kB
JavaScript
import { pullEnvironmentStack, pushEnvironmentStack, refreshEnvironmentStack } from "../states/useEnvironmentStack";
import { environmentDefaults, environmentSchema } from "../interface/IEnvironment";
import PositionedItem from "../api/core/PositionedItem";
import { onSelectionTarget, emitSelectionTarget } from "../events/onSelectionTarget";
import makeLightSprite from "./core/utils/makeLightSprite";
import { getCameraRendered } from "../states/useCameraRendered";
import mainCamera from "../engine/mainCamera";
import { Reactive } from "@lincode/reactivity";
import scene from "../engine/scene";
export default class Environment extends PositionedItem {
static componentName = "environment";
static defaults = environmentDefaults;
static schema = environmentSchema;
constructor() {
super();
scene.add(this.outerObject3d);
pushEnvironmentStack(this);
this.createEffect(() => {
if (getCameraRendered() !== mainCamera || !this.helperState.get())
return;
const sprite = makeLightSprite();
const handle = onSelectionTarget(({ target }) => {
target === sprite && emitSelectionTarget(this);
});
this.outerObject3d.add(sprite.outerObject3d);
return () => {
handle.cancel();
sprite.dispose();
};
}, [getCameraRendered, this.helperState.get]);
}
dispose() {
if (this.done)
return this;
super.dispose();
pullEnvironmentStack(this);
return this;
}
_texture = "studio";
get texture() {
return this._texture;
}
set texture(value) {
this._texture = value;
refreshEnvironmentStack();
}
helperState = new Reactive(true);
get helper() {
return this.helperState.get();
}
set helper(val) {
this.helperState.set(val);
}
}
//# sourceMappingURL=Environment.js.map