来自viewer3D.min.js的Autodesk Forge,DOMException

时间:2017-06-20 15:02:25

标签: autodesk-forge

我尝试按照Autodesk Forge教程制作基本查看器。 (参见下面的myCoolViewer.html)

当我在Chrome中打开该html文件时,我在Chrome的控制台中看到以下错误:

image: error in chrome console

html中引用的rvt文件先前已使用

成功加载到存储桶中

developer.api.autodesk.com/oss/v2/buckets/MyCoolBucket/objects/rac_basic_sample_project.rvt

并使用

翻译成SVF格式

developer.api.autodesk.com/modelderivative/v2/designdata/job

经过验证

developer.api.autodesk.com/modelderivative/v2/designdata/the-source-URN,-Base64-encoded/manifest

我很感激任何疑难解答步骤!

<head>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
    <meta charset="utf-8">

    <!-- The Viewer CSS -->
    <link rel="stylesheet" href="https://developer.api.autodesk.com/viewingservice/v1/viewers/style.min.css" type="text/css">

    <!-- Developer CSS -->
    <style>
        body {
            margin: 0;
        }
        #MyViewerDiv {
            width: 100%;
            height: 100%;
            margin: 0;
            background-color: #F0F8FF;
        }
    </style>
</head>
<body>

    <!-- The Viewer will be instantiated here -->
    <div id="MyViewerDiv"></div>

    <!-- The Viewer JS -->
    <script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/three.min.js"></script>
    <script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>

    <!-- Developer JS -->
    <script>
        var viewer;
        var options = {
            env: 'AutodeskProduction',
            accessToken: 'eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5In0.eyJjbGllbnRfaWQiOiJCTlgxNHZZeWFPM0xyQ3JNVXBrYlJZMmVTUGMyaHhpWCIsImV4cCI6MTQ5NzkwNTQ4Miwic2NvcGUiOlsiZGF0YTpyZWFkIiwiZGF0YTp3cml0ZSIsImJ1Y2tldDpjcmVhdGUiLCJidWNrZXQ6cmVhZCJdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiI2Nzd4b2o3T3dick1FaVQ5RjIwOFc3VGdhcTRYckpoWlI1dkl1c1FMVll6R3ZrRVdJSm5QYzlYaGgxRUpzQWtVIn0.PF19xEsEb8EcD99bmoLYu83kOCEPpOm6huxyQfHOr-w' 
        };
        var documentId = 'urn:adsk.objects:os.object:b01_a/rac_basic_sample_project.rvt'; 
        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()
            };

            var viewerDiv = document.getElementById('MyViewerDiv');
            viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
            viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
        }

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

        /**
         * viewer.loadModel() success callback.
         * Invoked after the model's SVF has been initially loaded.
         * It may trigger before any geometry has been downloaded and displayed on-screen.
         */
        function onLoadModelSuccess(model) {
            console.log('onLoadModelSuccess()!');
            console.log('Validate model loaded: ' + (viewer.model === model));
            console.log(model);
        }

        /**
         * viewer.loadModel() failure callback.
         * Invoked when there's an error fetching the SVF file.
         */
        function onLoadModelError(viewerErrorCode) {
            console.error('onLoadModelError() - errorCode:' + viewerErrorCode);
        }

    </script>
</body>

2 个答案:

答案 0 :(得分:0)

似乎您的documentId不适合Forge,documentId应该是您上传的ObjectKey文件的rvt的base64编码字符串,如下所示:

Base64URN

通过here了解更多详情。

你能帮我一个忙,用你的JavaScript代码中的documentId替换你的the-source-URN,-Base64-encoded吗?

希望得到这个帮助。

答案 1 :(得分:0)

正如Eason所提到的,documentId需要进行base64编码,并以urn:开头,例如。 "urn:dxgsjsksk......."