UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

34 lines (33 loc) 1 kB
"use strict"; import { BufferGeometry, Float32BufferAttribute } from "three"; export function createGeometriesFromTypeLine(params) { var _a; return (_a = params.shapes) == null ? void 0 : _a.map((shapes) => createGeometryFromTypeLine(shapes)); } function createGeometryFromTypeLine(shapes) { if (!shapes) { return; } const positions = []; const indices = []; let currentIndex = 0; for (let i = 0; i < shapes.length; i++) { const shape = shapes[i]; const points = shape.getPoints(); for (let j = 0; j < points.length; j++) { const point = points[j]; positions.push(point.x); positions.push(point.y); positions.push(0); indices.push(currentIndex); if (j > 0 && j < points.length - 1) { indices.push(currentIndex); } currentIndex += 1; } } const geometry = new BufferGeometry(); geometry.setAttribute("position", new Float32BufferAttribute(positions, 3)); geometry.setIndex(indices); return geometry; }