three.js - 如何可以动态改变对象的不透明度? [英] three.js - How can I dynamically change object's opacity?

查看:3079
本文介绍了three.js - 如何可以动态改变对象的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的对象:

var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { map: THREE.ImageUtils.loadTexture( "image.png" ) } ) );
object.position.set(2, 3, 1.5);

现在我在初始化之后创建该对象();功能,我可以直接到该对象并改变他的位置,这样的:

now after I've created this object in init(); function, I can directly go to the object and change his position,like this:

object.position.x = 15;

现在的问题是,我该如何改变纹理???

Now the question is how can I change the opacity of the texture???

感谢: - )

推荐答案

THREE.MeshLambertMaterial 扩展 THREE.Material 这意味着它继承了透明度属性,因此,所有你需要做的是访问你的对象的材质,并改变材料的不透明度:

THREE.MeshLambertMaterial extends THREE.Material which means it inherits the opacity property, so all you need to do is access the material on your object, and change the opacity of the material:

object.materials[0].opacity = 1 + Math.sin(new Date().getTime() * .0025);//or any other value you like

另外请注意,材料必须有它的透明属性设置为true。

Also note that the material must have it's transparent property set to true.

object.materials[0].transparent = true;

(谢谢德鲁和DOI也指出了这一点)

(Thank you Drew and Dois for pointing this out)

我知道有问题了three.js'参考',但你可以看看您使用的类的源文件,并看到它有所有的属性/方法,如果它延伸别的。

I know that there are problems with the three.js 'reference', but you can have a look at the source file for the class you use and see all the properties/methods it has and if it extends anything else.

这篇关于three.js - 如何可以动态改变对象的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆