无法读取未定义的属性'enumNodeFragments'

时间:2018-03-16 08:30:31

标签: javascript jquery 3d autodesk-forge autodesk-viewer

我正在尝试使用Autodesk-forge平台更改3D Viewer中的元素颜色,为此我使用Daniel Du的这个API Import-Clixml。 但问题是在跑步时我得到了这个 https://forge.autodesk.com/cloud_and_mobile/2015/12/change-color-of-elements-with-view-and-data-api.html

这个功能:

Autodesk.Viewing.Viewer3D.prototype.setColorMaterial = function(objectIds, color) {
        var material = addMaterial(color);

        for (var i=0; i<objectIds.length; i++) {

            var dbid = objectIds[i];

            //from dbid to node, to fragid
            viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
                var it = viewer.model.getData().instanceTree;
                console.log(it);

                it.enumNodeFragments(dbid, function (fragId) {          
                    var renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId);
                    console.log("r prox : " + renderProxy);

                    renderProxy.meshProxy = new THREE.Mesh(renderProxy.geometry, renderProxy.material);

                    renderProxy.meshProxy.matrix.copy(renderProxy.matrixWorld);
                    renderProxy.meshProxy.matrixWorldNeedsUpdate = true;
                    renderProxy.meshProxy.matrixAutoUpdate = false;
                    renderProxy.meshProxy.frustumCulled = false;

                    viewer.impl.addOverlay(overlayName, renderProxy.meshProxy);
                    viewer.impl.invalidate(true);

                }, false);

            });

        }

    }

希望任何人都有解决这个问题的方法......

1 个答案:

答案 0 :(得分:0)

很可能在加载实例树之前运行此代码,这会引发错误无法在 it 变量上读取未定义的属性'enumNodeFragments'。在运行该代码之前,您需要等待Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT

另请查看previous question about modifying materials in the viewer