簡體   English   中英

放大到Autodesk forge中的特定Revit模型對象

[英]Zoom to a specific Revit model object in Autodesk forge

我已在Autodesk forge中創建Revit模型。 我想知道在加載視圖時如何縮放到模型的特定對象。 是否可以使用API​​?

我已經成功測試了功能selectItemById 使用功能viewer.bubble.search(av.BubbleNode.MODEL_NODE);獲取主對象的ID viewer.bubble.search(av.BubbleNode.MODEL_NODE); 我不知道如何獲取模型中每個元素的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);

}

我使用以下腳本解決了獲取對象的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;
}

一旦我有中標。 我使用以下腳本來縮放和隔離對象:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM