【问题标题】:Zoom to a specific Revit model object in Autodesk forge在 Autodesk forge 中缩放到特定的 Revit 模型对象
【发布时间】:2017-03-15 23:49:58
【问题描述】:

我在 Autodesk forge 中加载了一个 Revit 模型。我想知道在加载视图时如何缩放到模型的特定对象。是否可以使用API​​?

我已经成功测试了函数selectItemById。使用函数viewer.bubble.search(av.BubbleNode.MODEL_NODE); 获取主对象的id。我不知道如何获取模型中每个元素的 Id,然后放大。

这是我用来加载模型的代码:

var viewer;
var options = {
    env: 'AutodeskProduction',

    accessToken: 'aaaaaaaaaaaaaaaaaaa'
};

var documentId = 'urn:bbbbbbbbbbbbbbbbbbbbbbbbbb';
Autodesk.Viewing.Initializer(options, function onInitialized(){
    Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});

/**
 * Autodesk.Viewing.Document.load() success callback.
 * Proceeds with model initialization.
 */
function onDocumentLoadSuccess(doc) {

    // A document contains references to 3D and 2D viewables.
    var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {'type':'geometry'}, true);
    if (viewables.length === 0) {
        console.error('Document contains no viewables.');
        return;
    }

    // Choose any of the avialble viewables
    var initialViewable = viewables[0];
    var svfUrl = doc.getViewablePath(initialViewable);
    var modelOptions = {
        sharedPropertyDbPath: doc.getPropertyDbPath()
    };

    viewer = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
    viewer.registerViewer(viewer.k3D, Autodesk.Viewing.Private.GuiViewer3D);
    viewer.loadDocument(documentId, onDocumentLoaded);


    var style3D = "height: 60%; width: 65%; overflow: hidden;";
    $('.adsk-viewing-viewer').attr('style', style3D);

}

/**
 * Autodesk.Viewing.Document.load() failuire callback.
 */
function onDocumentLoadFailure(viewerErrorCode) {
    console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
}



function onDocumentLoaded(lmvDoc) {
    var modelNodes = viewer.bubble.search(av.BubbleNode.MODEL_NODE); // 3D designs
    var sheetNodes = viewer.bubble.search(av.BubbleNode.SHEET_NODE); // 2D designs
    var allNodes = modelNodes.concat(sheetNodes);

}

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

    我使用以下脚本解决了获取对象的 dbId 的问题:

    var _viewer = viewer.getCurrentViewer();
    
    $(_viewer.container).bind("click", onMouseClick);
    
    function onMouseClick(e) {
        var screenPoint = {
            x: event.clientX,
            y: event.clientY
        };
    
        var n = normalize(screenPoint);
        var dbId = getHitDbId(n.x, n.y);
    
        if (dbId == null) return;
    
    };
    
    function getHitDbId(x, y) {
        y = 1.0 - y;
        x = x * 2.0 - 1.0;
        y = y * 2.0 - 1.0;
    
        var vpVec = new THREE.Vector3(x, y, 1);
    
        var result = _viewer.impl.hitTestViewport(vpVec, false);
        return result ? result.dbId : null;
    };
    
    function normalize(screenPoint) {
        var viewport = _viewer.navigation.getScreenViewport();
        var n = {
            x: (screenPoint.x - viewport.left) / viewport.width,
            y: (screenPoint.y - viewport.top) / viewport.height
        };
        return n;
    }
    

    一旦我有了 dbid。我使用以下脚本来缩放和隔离对象:

    _viewer.impl.selector.setSelection([dbId], _viewer.model);
    _viewer.fitToView(dbId);
    _viewer.isolateById(dbId);
    

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2021-10-16
      • 2021-11-05
      • 2021-02-05
      • 2021-03-28
      • 2021-10-02
      • 2019-03-29
      • 1970-01-01
      • 2018-03-09
      相关资源
      最近更新 更多