当将多个模型加载到同一查看器中时,是否会更新属性数据库



我设法将多个模型加载到同一查看器中,现在我正在尝试提取每个模型元素的属性和值;但是,当我使用getPropertyDb()executeUserFunction()时,我只能恢复初始模型的属性。

我从此存储库中的代码开始,并使用本文了解如何加载多个模型。

第一个模型是从服务器重定向后加载的。

function onDocumentLoadSuccess(doc) {
    const geometries = doc.getRoot().search({ type: 'geometry' });
    if (geometries.length === 0) {
        console.error('Document contains no viewables.');
        return;
    }
    const initViewable = geometries[0];
    const svfUrl = doc.getViewablePath(initViewable);
    const mat = new THREE.Matrix4();
    const modelOptions = {
        placementTransform: mat,
        globalOffset: { x: 0, y: 0, z: 0 },
        sharedPropertyDbPath: doc.getPropertyDbPath()
    };
    const viewerDiv = document.getElementById('MyViewerDiv');
    const config = {
        extensions: myExtensions
    };
    viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv, config);
    viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
}

加载了每个模型的几何形状后,扩展程序会做一些事情。

function MyExtension(viewer, options) {
    Autodesk.Viewing.Extension.call(this, viewer, options);
}
MyExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
MyExtension.prototype.constructor = MyExtension;
MyExtension.prototype.onGeometryLoadEvent = function(event) {
    const myPromise = this.viewer.model
        .getPropertyDb()
        .executeUserFunction(userFunction);
    myPromise
        .then(function(retValue) {
            if (!retValue) {
                console.log('Model doesn't contain valid elemens.');
            }
            // do stuff...
        })
        .catch(err => console.log(err));
};
MyExtension.prototype.load = function() {
    this.onGeometryLoadBinded = this.onGeometryLoadEvent.bind(this);
    this.viewer.addEventListener(
        Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
        this.onGeometryLoadBinded
    );
    return true;
};
MyExtension.prototype.unload = function() {
    this.viewer.removeEventListener(
        Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
        this.onGeometryLoadBinded
    );
    this.onGeometryLoadBinded = null;
    return true;
};
Autodesk.Viewing.theExtensionManager.registerExtension(
    'MyExtension',
    MyExtension
);
function userFunction(pdb) {
    // get properties of the elements
}

新型号也使用扩展名加载在同一查看器中。

MyOtherExtension.prototype.onDocumentLoadSuccess = function(doc) {
    // get the svfUrl of the initial geometry and set the loading options
    this.viewer.loadModel(
        svfUrl,
        loaderOptions,
        this.onLoadModelSuccessBinded,
        this.onLoadModelErrorBinded
    );
};

如何更新属性数据库,以获取当前加载到查看器的所有模型的属性和值?

尝试通过模型对象访问特定数据库:

viewer.impl.modelQueue().getModels()[index].getPropertyDb()

相关内容

最新更新