UNPKG

@polygonjs/polygonjs

Version:

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

95 lines (94 loc) 4.01 kB
"use strict"; import { Vector3 } from "three"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { PointBuilderPersistedConfig } from "../js/code/assemblers/pointBuilder/PointBuilderPersistedConfig"; import { AssemblerName } from "../../poly/registers/assemblers/_BaseRegister"; import { BasePointBuilderSopNode, BasePointBuilderSopParamsConfig } from "./_BasePointBuilder"; import { Attribute } from "../../../core/geometry/Attribute"; import { ParamConfig } from "../utils/params/ParamsConfig"; import { isBooleanTrue } from "../../../core/Type"; import { pointsCountFromObject } from "../../../core/geometry/entities/point/CorePointUtils"; import { corePointClassFactory } from "../../../core/geometry/CoreObjectFactory"; class PointBuilderSopParamsConfig extends BasePointBuilderSopParamsConfig { constructor() { super(...arguments); /** @param updateNormals */ this.updateNormals = ParamConfig.BOOLEAN(1); } } const ParamsConfig = new PointBuilderSopParamsConfig(); export class PointBuilderSopNode extends BasePointBuilderSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this.persisted_config = new PointBuilderPersistedConfig(this); this._pointContainer = { position: new Vector3(), normal: new Vector3(), ptnum: -1, objnum: -1, normalsUpdated: false }; } static type() { return SopType.POINT_BUILDER; } usedAssembler() { return AssemblerName.JS_POINT_BUILDER; } _processObject(object, objnum, evaluator) { this._pointContainer.objnum = objnum; this._pointContainer.normalsUpdated = false; const readAttributeOptions = this._checkRequiredReadAttributes(object); const writeAttributeOptions = this._checkRequiredWriteAttributes(object); const readAttribNames = readAttributeOptions ? readAttributeOptions.attribNames : []; const readAttributeByName = readAttributeOptions ? readAttributeOptions.attributeByName : /* @__PURE__ */ new Map(); const attribTypeByName = readAttributeOptions ? readAttributeOptions.attribTypeByName : /* @__PURE__ */ new Map(); const writeAttribNames = writeAttributeOptions ? writeAttributeOptions.attribNames : []; const writeAttributeByName = writeAttributeOptions ? writeAttributeOptions.attributeByName : /* @__PURE__ */ new Map(); this._resetRequiredAttributes(); const pointsCount = pointsCountFromObject(object); const corePointClass = corePointClassFactory(object); const positionAttrib = corePointClass.attribute(object, Attribute.POSITION); const normalAttrib = corePointClass.attribute(object, Attribute.NORMAL); const hasPosition = positionAttrib != null; const hasNormal = normalAttrib != null; if (!hasPosition) { this._pointContainer.position.set(0, 0, 0); } if (!hasNormal) { this._pointContainer.normal.set(0, 1, 0); } for (let ptnum = 0; ptnum < pointsCount; ptnum++) { this._pointContainer.ptnum = ptnum; if (hasPosition) { this._pointContainer.position.fromBufferAttribute(positionAttrib, ptnum); } if (hasNormal) { this._pointContainer.normal.fromBufferAttribute(normalAttrib, ptnum); } this._readRequiredAttributes(ptnum, readAttribNames, readAttributeByName, attribTypeByName); evaluator(); if (hasPosition) { positionAttrib.setXYZ( ptnum, this._pointContainer.position.x, this._pointContainer.position.y, this._pointContainer.position.z ); } if (hasNormal) { normalAttrib.setXYZ( ptnum, this._pointContainer.normal.x, this._pointContainer.normal.y, this._pointContainer.normal.z ); } this._writeRequiredAttributes(ptnum, writeAttribNames, writeAttributeByName); } if (isBooleanTrue(this.pv.updateNormals) && !this._pointContainer.normalsUpdated) { corePointClass.computeNormals(object); } } }