Default material for model in Forge Viewer

好久不见. 提交于 2021-02-11 13:23:40

问题


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.

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?


回答1:


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);
        });
    }
}


来源:https://stackoverflow.com/questions/54475341/default-material-for-model-in-forge-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!