V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
DateData
V2EX  ›  Android

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

  •  
  •   DateData · 20 天前 · 926 次点击

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

    7 条回复    2024-04-10 14:15:44 +08:00
    psklf
        1
    psklf  
       20 天前
    材质是写在 glb 里面的,改一下 glb 嘛
    DateData
        2
    DateData  
    OP
       20 天前
    @psklf 我的需求是要动态改变,类似懂车帝里查看车辆时,改变车的颜色一样
    wangtian2020
        3
    wangtian2020  
       20 天前
    只用过 threejs 的时候动态改过材质颜色。首先在 blender 里打开素材,找到要改变的组件的 id 或者是 name 。然后用程序里用 api 选中组件改就行了。自己去翻翻 API 吧
    psklf
        4
    psklf  
       20 天前
    @DateData #2 material 里面 setParameter 看试试?大概在这一块了,附近找找。
    DateData
        5
    DateData  
    OP
       20 天前
    @psklf 多谢 多谢
    b821025551b
        6
    b821025551b  
       20 天前
    静下心来翻翻文档嘛
    https://google.github.io/filament/Materials.md.html#materialdefinitions/format/example
    至于到安卓怎么写,随便搜了一下有个重置天空盒的: https://www.cnblogs.com/crane13/p/15876270.html
    我觉得材质对象应该也有一堆吧,打印出来看看和文档有没有相似的东西。
    DateData
        7
    DateData  
    OP
       20 天前
    @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
    }
    }
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2505 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:59 · PVG 19:59 · LAX 04:59 · JFK 07:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.