UNPKG

@polygonjs/polygonjs

Version:

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

59 lines (58 loc) 2.4 kB
"use strict"; import { BaseSopOperation } from "./_Base"; import { Vector2 } from "three"; import { Vector3 } from "three"; import { Vector4 } from "three"; import { ATTRIBUTE_CLASSES, AttribClass, AttribType, ATTRIBUTE_TYPES } from "../../../core/geometry/Constant"; import { InputCloneMode } from "../../../engine/poly/InputCloneMode"; import { TypeAssert } from "../../../engine/poly/Assert"; import { addPointAttribute } from "./utils/attribCreate/AttribCreatePoint"; import { addVertexAttribute } from "./utils/attribCreate/AttribCreateVertex"; import { addPrimitiveAttribute } from "./utils/attribCreate/AttribCreatePrimitive"; import { addObjectAttributeWithoutExpression } from "./utils/attribCreate/AttribCreateObject"; import { addCoreGroupAttribute } from "./utils/attribCreate/AttribCreateCoreGroup"; export class AttribCreateSopOperation extends BaseSopOperation { static type() { return "attribCreate"; } cook(inputCoreGroups, params) { var _a; const coreGroup = inputCoreGroups[0]; const attribName = params.name; if (attribName && attribName.trim() != "") { this._addAttribute(ATTRIBUTE_CLASSES[params.class], coreGroup, params); } else { (_a = this.states) == null ? void 0 : _a.error.set("attribute name is not valid"); } return coreGroup; } _addAttribute(attribClass, coreGroup, params) { const attribType = ATTRIBUTE_TYPES[params.type]; switch (attribClass) { case AttribClass.POINT: return addPointAttribute(attribType, coreGroup, params); case AttribClass.VERTEX: return addVertexAttribute(attribType, coreGroup, params); case AttribClass.PRIMITIVE: return addPrimitiveAttribute(attribType, coreGroup, params); case AttribClass.OBJECT: return addObjectAttributeWithoutExpression(attribType, coreGroup, params); case AttribClass.CORE_GROUP: return addCoreGroupAttribute(attribType, coreGroup, params); } TypeAssert.unreachable(attribClass); } } AttribCreateSopOperation.DEFAULT_PARAMS = { group: "", class: ATTRIBUTE_CLASSES.indexOf(AttribClass.POINT), type: ATTRIBUTE_TYPES.indexOf(AttribType.NUMERIC), name: "newAttrib", size: 1, value1: 0, value2: new Vector2(0, 0), value3: new Vector3(0, 0, 0), value4: new Vector4(0, 0, 0, 0), string: "" }; AttribCreateSopOperation.INPUT_CLONED_STATE = InputCloneMode.FROM_NODE;