UNPKG

@polygonjs/polygonjs

Version:

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

62 lines (61 loc) 1.85 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { Matrix4, Vector3, Quaternion } from "three"; const _m4 = new Matrix4(); const _t = new Vector3(); const _q = new Quaternion(); const _s = new Vector3(1, 1, 1); const UP = new Vector3(0, 1, 0); class WFCTileTransformSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param south / north */ this.sn = ParamConfig.INTEGER(0, { range: [-2, 2], rangeLocked: [true, true] }); /** @param west / east */ this.we = ParamConfig.INTEGER(0, { range: [-2, 2], rangeLocked: [true, true] }); /** @param bottom / top */ this.bt = ParamConfig.INTEGER(0, { range: [-2, 2], rangeLocked: [true, true] }); /** @param y rotation */ this.ry = ParamConfig.INTEGER(0, { range: [0, 3], rangeLocked: [true, true] }); } } const ParamsConfig = new WFCTileTransformSopParamsConfig(); export class WFCTileTransformSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.WFC_TILE_TRANSFORM; } initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(InputCloneMode.FROM_NODE); } async cook(inputCoreGroups) { const coreGroup = inputCoreGroups[0]; const objects = coreGroup.allObjects(); _t.set(this.pv.sn, this.pv.bt, this.pv.we); _q.setFromAxisAngle(UP, Math.PI * this.pv.ry * 0.5); _m4.compose(_t, _q, _s); for (const object of objects) { object.applyMatrix4(_m4); } this.setCoreGroup(coreGroup); } }