mylingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
74 lines • 2.27 kB
JavaScript
import { Reactive } from "@lincode/reactivity";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
import { Line2 } from "three/examples/jsm/lines/Line2";
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial";
import EventLoopItem from "../api/core/EventLoopItem";
import { scaleDown, scaleUp } from "../engine/constants";
import { addBloom, deleteBloom } from "../engine/renderLoop/effectComposer/selectiveBloomPass/renderSelectiveBloom";
import scene from "../engine/scene";
export default class Line extends EventLoopItem {
material = new LineMaterial({ linewidth: 0.001 });
constructor() {
super();
this.createEffect(() => {
const { from, to, bloom } = this;
if (!from || !to)
return;
const geometry = new LineGeometry().setPositions([
from.x * scaleDown,
from.y * scaleDown,
from.z * scaleDown,
to.x * scaleDown,
to.y * scaleDown,
to.z * scaleDown
]);
const line = new Line2(geometry, this.material);
scene.add(line);
bloom && addBloom(line);
return () => {
scene.remove(line);
geometry.dispose();
deleteBloom(line);
};
}, [this.refresh.get]);
}
dispose() {
if (this.done)
return this;
super.dispose();
this.material.dispose();
return this;
}
refresh = new Reactive({});
_bloom;
get bloom() {
return this._bloom;
}
set bloom(value) {
this._bloom = value;
this.refresh.set({});
}
_from;
get from() {
return this._from;
}
set from(value) {
this._from = value;
this.refresh.set({});
}
_to;
get to() {
return this._to;
}
set to(value) {
this._to = value;
this.refresh.set({});
}
get thickness() {
return this.material.linewidth * scaleUp;
}
set thickness(val) {
this.material.linewidth = val * scaleDown;
}
}
//# sourceMappingURL=Line.js.map