更改alphaMap不透明度不会更新(THREE.JS R76)

时间:2016-05-05 17:25:41

标签: javascript three.js opacity alpha

我有一个带有旋转纹理和alpha贴图的隧道。我想改变alpha映射的不透明度,最终补间。

我在0处开始不透明度然后再提高它。但是,在不透明度属性的情况下,实时视图不会发生变化。在实时视图中,它完全不透明。我尝试将材质的needsUpdate属性切换为true,但它没有改变任何内容。

这是设置......

function addTunnel(){
var cylTexture = loader.load("wormhole.jpg"),
    cylAlpha = loader.load("wormholeAlpha2.jpg");
    cylTexture.wrapT = THREE.RepeatWrapping;
    cylTexture.wrapS = THREE.RepeatWrapping;
    cylAlpha.wrapT = THREE.RepeatWrapping;
    cylAlpha.wrapS = THREE.RepeatWrapping;

var cylGeom = new THREE.CylinderGeometry(5000, 5000, 50000, 32, 32, true),
    cylMat = new THREE.MeshPhongMaterial({
        side: THREE.BackSide,
        map: cylTexture,
        alphaMap: cylAlpha,
        transparent: true
    }),
    cyl = new THREE.Mesh(cylGeom, cylMat);

cyl.name = "tunnel";
scene.add(cyl);
scene.getObjectByName("tunnel").position.z= -9000;
rotateObject(scene.getObjectByName("tunnel"), -90, 0, 0);
octree.add(scene.getObjectByName("tunnel"));
tunnel = scene.getObjectByName("tunnel");
tunnel.material.alphaMap.opacity = 0;
}

1 个答案:

答案 0 :(得分:1)

PhongMaterial着色器使用alphaMap的像素值作为源HERE中显示的alpha值。
如果不动态生成aphaMap或更改着色器,您将无法对此进行补间 听起来我觉得创建自己的ShaderMaterial可能会更好。

HERE是Dr Who时间隧道类型着色器的示例,它具有透明度(更改正文背景颜色)

$ set 'arg1a arg1b' 'arg2a arg2b' 'arg3a arg3b'
$ for arg in "$@"; do echo "$arg"; done
arg1a arg1b
arg2a arg2b
arg3a arg3b
$ for arg in "$*"; do echo "$arg"; done
arg1a arg1b arg2a arg2b arg3a arg3b
$ for arg in $@; do echo "$arg"; done
arg1a
arg1b
arg2a
arg2b
arg3a
arg3b
$ for arg in $*; do echo "$arg"; done
arg1a
arg1b
arg2a
arg2b
arg3a
arg3b