@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
53 lines (52 loc) • 1.4 kB
JavaScript
;
import { Vector3 } from "three";
import { ThreejsPrimitive } from "./ThreejsPrimitive";
import { Attribute } from "../../Attribute";
const _p0 = new Vector3();
export class ThreejsPrimitivePoint extends ThreejsPrimitive {
constructor(object, index) {
super(object, index);
this._geometry = object.geometry;
}
static primitiveName() {
return "point";
}
static entitiesCount(object) {
const geometry = object.geometry;
if (!geometry) {
return 0;
}
const index = geometry.getIndex();
if (!index) {
return 0;
}
return index.count;
}
static position(object, primitiveIndex, target) {
if (!(object && object.geometry)) {
return target;
}
const positionAttribute = object.geometry.getAttribute(Attribute.POSITION);
if (!positionAttribute) {
return target;
}
const positionArray = positionAttribute.array;
_p0.fromArray(positionArray, primitiveIndex * 3 + 0);
target.copy(_p0);
return target;
}
static normal(object, primitiveIndex, target) {
return target.set(0, 1, 0);
}
position(target) {
return this.constructor.position(this._object, this._index, target);
}
normal(target) {
return this.constructor.normal(this._object, this._index, target);
}
static computeVertexNormalsIfAttributeVersionChanged(object) {
}
static stride() {
return 1;
}
}