Forge Viewer中模型的默认材料 [英] Default material for model in Forge Viewer

查看:83
本文介绍了Forge Viewer中模型的默认材料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让完整的模型使用默认材质(例如灰色),然后为每个节点使用外部定义的材质.

I'd need to have the complete model use a default material (e.g. grey color) and then use externally defined materials for each node.

因此,我在两点上寻求一些建议:1)在所有节点上设置默认材质.2)从外部来源获取给定节点后,为其设置材质/颜色.

So I'm looking for some advice on two points: 1) Setting a default material on all nodes. 2) Setting the material / color for given nodes after they're fetched from an external source.

可以在将模型加载到查看器之前的某个时候完成此操作吗?(即服务器端)?如果没有,可以在查看器中完成吗?

Could this be done at some point before the model is loaded into the viewer? (i.e. server-side)? If not, can it be done in the viewer?

推荐答案

所有来自Forge的几何图形都会始终为其定义一些材料,但是您可以遍历模型上所有对象的dbID并设置自定义THREE.js遵循以下方式为他们准备的材料:

All geometry coming from Forge will always have some material defined for it, but you can iterate over dbIDs of all objects on the model and set a custom THREE.js material for them using something along these lines:

function setCustomMaterial(viewer, dbids) {
    const material = new THREE.MeshPhongMaterial({
        color: 0xAB00EE,
        specular: 0xEEABEE
    });
    viewer.impl.matman().addMaterial('CustomMaterial', material, true);
    const fragList = viewer.model.getFragmentList();
    const instanceTree = viewer.model.getData().instanceTree;
    for (let dbid of dbids) {
        instanceTree.enumNodeFragments(dbid, function(frag) {
            fragList.setMaterial(frag, material);
        });
    }
}

这篇关于Forge Viewer中模型的默认材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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