Google Filament 加载 glb 文件,改变材质颜色

40 天前
 DateData

我这里使用 Google 开源的 filament 加载 glb 文件,想要改变其中一个材质的颜色,在网上搜了好久也没有找到办法,不知道有没有使用过这个项目的,能指点一二,不胜感激! https://github.com/google/filament

1448 次点击
所在节点    Android
7 条回复
psklf
40 天前
材质是写在 glb 里面的,改一下 glb 嘛
DateData
40 天前
@psklf 我的需求是要动态改变,类似懂车帝里查看车辆时,改变车的颜色一样
wangtian2020
40 天前
只用过 threejs 的时候动态改过材质颜色。首先在 blender 里打开素材,找到要改变的组件的 id 或者是 name 。然后用程序里用 api 选中组件改就行了。自己去翻翻 API 吧
psklf
40 天前
@DateData #2 material 里面 setParameter 看试试?大概在这一块了,附近找找。
DateData
40 天前
@psklf 多谢 多谢
b821025551b
40 天前
静下心来翻翻文档嘛
https://google.github.io/filament/Materials.md.html#materialdefinitions/format/example
至于到安卓怎么写,随便搜了一下有个重置天空盒的: https://www.cnblogs.com/crane13/p/15876270.html
我觉得材质对象应该也有一堆吧,打印出来看看和文档有没有相似的东西。
DateData
40 天前
@psklf 下面代码是可行的
val materialInstances: Array<out MaterialInstance>? = modelViewer.asset?.instance?.materialInstances


// val textureSampler = TextureSampler()

if (materialInstances != null) {
for (materialInstance in materialInstances) {
L.l().d("setColor :"+materialInstance.name)
if (materialInstance.name =="touming") {
materialInstance.setParameter(
"baseColorFactor",
0.5f,
0.10f,
0.10f
) // Values for Red, Green and Blue
}
}
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1031183

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX