three#Line TypeScript Examples
The following examples show how to use
three#Line.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NeighborDebugSystem.tsx From react-ecs with MIT License | 6 votes |
fetch(parent: Object3D, v1: Vector3, v2: Vector3) {
if (this.pool.length) {
const line = this.pool.pop();
line.geometry.setFromPoints([v1, v2]);
parent.attach(line)
return line;
} else {
const points = [v1, v2];
const geometry = new BufferGeometry();
const line = new Line( geometry, material );
line.geometry.setFromPoints(points)
parent.attach(line)
return line;
}
}
Example #2
Source File: NeighborDebugSystem.tsx From react-ecs with MIT License | 5 votes |
reset(line: Line) {
const vec = new Vector3();
line.parent.remove(line);
line.position.set(0, 0, 0)
line.geometry.setFromPoints(zeroLine)
this.pool.push(line)
}
Example #3
Source File: NeighborDebugSystem.tsx From react-ecs with MIT License | 5 votes |
pool: Line[];
Example #4
Source File: NeighborDebugSystem.tsx From react-ecs with MIT License | 5 votes |
NeighborDebugSystem = (props) => {
let id = 0;
const pool = useRef(new LinePool())
const targetQuery = useQuery(e => e.hasAll(ThreeView, Neighbor));
const debugQuery = useQuery(e => e.hasAll(ThreeView, NeighborDebugger));
const create = (target: KnockEntity) => {
const key = id++;
const targetView = target.get(ThreeView)
const targetNeighorhood = target.get(Neighbor)
if (!targetView) return null;
return (
<Entity key={key}>
<NeighborDebugger
targetView={targetView}
targetNeighorhood={targetNeighorhood} />
<ThreeView>
<group position={targetView.object3d.position} />
</ThreeView>
</Entity>
)
}
useSystem((dt) => {
debugQuery.loop([ThreeView, NeighborDebugger], (e, [view, debug]) => {
const debugObj = view.object3d;
const targetObj = debug.targetView.object3d;
let idx = 0;
const children = [...debugObj.children];
for (const neighbor of debug.targetNeighorhood.meta.neighbors) {
const neighborPosition = neighbor.get(ThreeView).object3d.position;
const oldLine = children.pop() as Line;
if (oldLine) {
oldLine.geometry.setFromPoints([
targetObj.position,
neighborPosition,
]);
} else {
pool.current.fetch(
debugObj,
targetObj.position,
neighborPosition,
);
}
idx++;
}
children.forEach(c => pool.current.reset(c as Line))
})
})
return targetQuery.entities?.map(create) || null;
}