补间threejs平面和css3d对象的透明度的问题

时间:2015-09-22 09:57:42

标签: three.js tweenmax

我创建如下所示的对象:

var element = document.createElement( 'div' );
element.innerHTML = '<i class="fa fa-exclamation-triangle fa-5x"></i>';
object = new THREE.CSS3DObject( element );
object.position.set(11,4,8)
object.name = "error"
object.transparent = true;
object.scale.set(0.01,0.01,0.01)

SceneService.sceneCss.add(object);

var material = new THREE.MeshBasicMaterial({
   color: 0xFF0101,
   side: THREE.DoubleSide
});

var geometry = new THREE.PlaneGeometry(100, 100);
var mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(object.position);
mesh.rotation.copy(object.rotation);
mesh.scale.copy(object.scale);
mesh.transparent = true;
mesh.name = "error_plane"
SceneService.scene.add(mesh);

我已设置透明属性。我试图隐藏“错误平面”

object = SceneService.scene.getObjectByName('error_plane');
tweens.push(tl.to(object.material, 5, {opacity: 0}, 0));

但它没有用。 css3d对象没有任何材料。我有什么想法可以补充不透明度?

1 个答案:

答案 0 :(得分:2)

您可以使用类似的模式补间CSS3DObject的不透明度:

var current = {
    opacity: 1
};

new TWEEN.Tween( current )
    .to( { opacity: 0 }, 2000 )
    .onUpdate( function () {
        object.element.style.opacity = current.opacity;
    } )
    .start();

然后,在动画循环中,调用

TWEEN.update();

您可以使用类似这样的模式补间Mesh对象的不透明度:

var current = {
    opacity: 1
};

new TWEEN.Tween( current )
    .to( { opacity: 0 }, 2000 )
    .onUpdate( function () {
        object.material.opacity = current.opacity;
    } )
    .start();
}

您必须设置object.material.transparent = true;才能使第二种模式生效。您还必须在动画循环中调用TWEEN.update();

three.js r.72