UNPKG

@polygonjs/polygonjs

Version:

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

30 lines (29 loc) 962 B
"use strict"; import { BufferAttribute } from "three"; import { isString } from "../../Type"; export function addAttributesFromPoint(geometry, point, attributeNames) { const pointsCount = geometry.getAttribute("position").count; for (const attributeName of attributeNames) { addAttributeFromPoint(geometry, point, attributeName, pointsCount); } } function addAttributeFromPoint(geometry, point, attributeName, pointsCount) { const value = point.attribValue(attributeName); if (!isString(value)) { const size = point.attribSize(attributeName); let values = new Array(pointsCount * size); switch (size) { case 1: { values.fill(value); break; } default: { for (let i = 0; i < pointsCount; i++) { value.toArray(values, i * size); } } } const attribute = new BufferAttribute(new Float32Array(values), size); geometry.setAttribute(attributeName, attribute); } }