Three.js - 如何动态更改对象的不透明度?
这是我的对象:
var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { map: THREE.ImageUtils.loadTexture( "image.png" ) } ) );
object.position.set(2, 3, 1.5);
现在我在 init() 中创建了这个对象之后;函数,我可以直接转到对象并更改他的位置,如下所示:
object.position.x = 15;
现在的问题是如何更改纹理的不透明度???
谢谢 :-)
This is my object:
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???
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
THREE.MeshLambertMaterial
扩展了THREE.Material
这意味着它继承了opacity
属性,因此您需要做的就是访问对象上的材质,并更改材质的不透明度:另请注意,材质的
transparent
属性必须设置为 true。(感谢 Drew 和 Dois 指出了这一点)
更新
该属性现在只是
材料
:THREE.MeshLambertMaterial
extendsTHREE.Material
which means it inherits theopacity
property, so all you need to do is access the material on your object, and change the opacity of the material:Also note that the material must have it's
transparent
property set to true.(Thank you Drew and Dois for pointing this out)
Update
the property is now simply
material
:我知道这个问题很老了,但我想根据我使用过的内容给出答案,以防有人需要。对于 Three.js,我通过 Greensock 的 TweenMax/TweenLite 使用补间。这样,我就能够补间任何对象的任何属性,并且运行顺利。请在此处查看该库。我需要补间的属性是:
其中持续时间以秒为单位,属性位于对象中。这样做的“陷阱”,特别是在使用 Three.js 时,是确保您了解对象参数的具体情况。例如,对于这个问题,如果您要更改网格的不透明度,您不能
这样做,您需要更具体并写下
我希望这对某人有帮助。补间真的太棒了!
I know this question is very old but I wanted to give my answer from what I used in case someone needs it. With three.js, I used tweening through Greensock's TweenMax/TweenLite. With that, I was able to tween any property of any object and it ran smoothly. Check out the library here. All I needed to tween the properties was:
where duration is in seconds and properties are in an object. The "gotcha" for this, especially while using three.js, is to make sure you get specific with the object parameter. For example, per this question, if you are changing the opacity of a mesh, you cannot do
rather, you need to be more specific and write
I hope this helps someone. Tweening is really awesome!