@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
43 lines (42 loc) • 1.46 kB
JavaScript
;
import { BaseSopOperation } from "./_Base";
import { Vector3 } from "three";
import { Euler } from "three";
import { Mesh } from "three";
import { InputCloneMode } from "../../../engine/poly/InputCloneMode";
import { DecalGeometry } from "three/examples/jsm/geometries/DecalGeometry";
import { MathUtils } from "three";
export class DecalSopOperation extends BaseSopOperation {
constructor() {
super(...arguments);
this._r = new Vector3();
this._rotation = new Euler(0, 0, 0);
this._scale = new Vector3(1, 1, 1);
}
static type() {
return "decal";
}
cook(inputContents, params) {
const inputCoreGroup = inputContents[0];
this._r.copy(params.r).multiplyScalar(MathUtils.DEG2RAD);
this._rotation.set(this._r.x, this._r.y, this._r.z);
this._scale.copy(params.s).multiplyScalar(params.scale);
const objects = inputCoreGroup.threejsObjectsWithGeo();
const decalObjects = [];
for (let object of objects) {
if (object.isMesh) {
const decal = new DecalGeometry(object, params.t, this._rotation, this._scale);
const decalObject = new Mesh(decal, object.material);
decalObjects.push(decalObject);
}
}
return this.createCoreGroupFromObjects(decalObjects);
}
}
DecalSopOperation.DEFAULT_PARAMS = {
t: new Vector3(0, 0, 0),
r: new Vector3(0, 0, 0),
s: new Vector3(1, 1, 1),
scale: 1
};
DecalSopOperation.INPUT_CLONED_STATE = InputCloneMode.NEVER;