@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
54 lines (53 loc) • 1.59 kB
JavaScript
;
import { BaseSopOperation } from "./_Base";
import { InputCloneMode } from "../../../engine/poly/InputCloneMode";
import { isArray } from "../../../core/Type";
export class TextureCopySopOperation extends BaseSopOperation {
static type() {
return "TextureCopy";
}
async cook(inputContents, params) {
const coreGroupTarget = inputContents[0];
const coreGroupSrc = inputContents[1];
let texture;
const srcObjects = coreGroupSrc.allObjects();
for (let object of srcObjects) {
object.traverse((child) => {
const mat = child.material;
if (mat) {
if (!isArray(mat)) {
if (!texture) {
texture = mat[params.textureName];
}
}
}
});
}
if (texture) {
const targetObjects = coreGroupTarget.allObjects();
for (let object of targetObjects) {
object.traverse((child) => {
const mat = child.material;
if (mat) {
if (!isArray(mat)) {
mat[params.textureName] = texture;
const uniforms = mat.uniforms;
if (uniforms) {
const uniform = uniforms[params.textureName];
if (uniform) {
uniform.value = texture;
}
}
mat.needsUpdate = true;
}
}
});
}
}
return coreGroupTarget;
}
}
TextureCopySopOperation.DEFAULT_PARAMS = {
textureName: "map"
};
TextureCopySopOperation.INPUT_CLONED_STATE = [InputCloneMode.FROM_NODE, InputCloneMode.NEVER];