添加引用
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js"
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js"
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js"
import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass.js"
import { FXAAShader } from "three/examples/jsm/shaders/FXAAShader.js"
定义广法
function addColor() {
var obj = scene.getObjectByName("货物$A1$1$1");
var selectedObjects = [];
selectedObjects.push(obj);
composer = new THREE.EffectComposer(renderer);
var renderPass = new THREE.RenderPass(scene, camera);
composer.addPass(renderPass);
var outlinePass = new THREE.OutlinePass(
new THREE.Vector2(window.innerWidth, window.innerHeight),
scene,
camera,
selectedObjects ////必须是一个数组,否则不会产生效果
);
outlinePass.selectedObjects = selectedObjects; //必须是一个数组,否则不会产生效果
outlinePass.edgeStrength = 10.0; // 边框的亮度
outlinePass.edgeGlow = 1; // 光晕[0,1]
outlinePass.usePatternTexture = false; // 是否使用父级的材质
outlinePass.edgeThickness = 1.0; // 边框宽度
outlinePass.downSampleRatio = 1; // 边框弯曲度
outlinePass.pulsePeriod = 5; // 呼吸闪烁的速度
outlinePass.visibleEdgeColor.set(parseInt(0x00ff00)); // 呼吸显示的颜色
outlinePass.hiddenEdgeColor = new THREE.Color(0, 0, 0); // 呼吸消失的颜色
outlinePass.clear = true;
composer.addPass(outlinePass);
var effectFXAA = new THREE.ShaderPass(THREE.FXAAShader);
effectFXAA.uniforms.resolution.value.set(
1 / window.innerWidth,
1 / window.innerHeight
);
effectFXAA.renderToScreen = true;
composer.addPass(effectFXAA);
}
必须在render()方法中执行composer.render()
if (composer) {
composer.render();
}
标签:outlinePass,THREE,three,添加,composer,new,js
From: https://www.cnblogs.com/duixue/p/18080295