Viewer查看本地存储的SVF文件

Viewer查看本地存储的SVF文件

本文介绍了如何使用Forge Viewer查看本地存储的SVF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我目前正在一个项目中,我想使用Forge Viewer在浏览器中显示本地存储的SVF文件.我已经尝试过不同的方法,但是它们似乎都不起作用,而且每次都遇到不同的异常.

I'm currently working on a project where I want to display a locally stored SVF-File in the browser using the Forge Viewer. I have already tried different approaches but none of them seem to work and I run into different exceptions every time.

这是我尝试使用React和Typescript做到的方式.

Here is how I try to do it using React and Typescript.

这是我在其中加载查看器组件的App.tsx:

This is the App.tsx where I load the Viewer Component:

<div className="col-sm-8 fill">
    <ForgeViewer />
 </div>

这是我的查看器组件:

import React from 'react';
import {useEffect} from 'react'
import {initializeViewer} from './viewer-helper';

const ForgeViewer: React.FC = () => {

  useEffect(() => {
    initializeViewer()
  }, [])

  return (
    <div>
      <div id="forgeviewer"></div>
    </div>
  );

}

export default ForgeViewer

这是我为Viewer Component编写的帮助程序:

And this is the helper that I wrote for my Viewer Component:

const options : Autodesk.Viewing.InitializerOptions = {
    doc: './models/small-revit-sample-house/Resource/3D_View/_3D_/_3D_.svf',
    env: "Local",
}

export const initializeViewer = () => {
    let container: HTMLElement | null;
    let viewer: Autodesk.Viewing.GuiViewer3D;
    container = document.getElementById('forgeviewer');

    if(container !== null){
      viewer = new Autodesk.Viewing.GuiViewer3D(container);
    }

    Autodesk.Viewing.Initializer(options, function () {
        //viewer.loadDocumentNode(options.doc, "/public/manifest.json");
        //viewer.loadModel(options.doc, onDocumentLoadSuccess, onDocumentLoadFailure);
        //Autodesk.Viewing.Document.load(modelURL, onDocumentLoadSuccess, onDocumentLoadFailure);
        viewer.start(options.doc);
        //loadViewer(modelURL);
    });
}

如您所见,我已经尝试了不同的方法,但是似乎没有一个起作用.

As you can see, I have already tried different approaches but none of them seem to work.

1:使用viewer.start函数,我得到->处理SVF时出错:找不到中央目录记录结尾"

1: Using the viewer.start function I get -> "Error while processing SVF: End of Central Directory Record not found"

2:使用viewer.loadDocumentNode我得到->未处理的拒绝(TypeError):e.getViewableUrn不是函数"

2: Using the viewer.loadDocumentNode i get -> "Unhandled Rejection (TypeError): e.getViewableUrn is not a function"

3:使用viewer.loadModel我得到->未捕获(承诺)TypeError:te未定义".顺便提一句.函数onDocumentLoadSuccess是一个空函数,不会被调用.

3: Using the viewer.loadModel i get -> "Uncaught (in promise) TypeError: te is undefined" Btw. the function onDocumentLoadSuccess is an empty function that doesnt get called.

如果我能继续采用这些工作方式并更多地了解正在发生的事情,我将感到非常高兴.:)

I would be really happy if I could just get on of these ways to work and understand more of whats going on. :)

推荐答案

我可以使用它.这是我的操作方法:模型文件夹现在位于公用文件夹内(出于安全考虑,它是错误的,但对我的项目而言并不重要).比您可以像这样加载svf文件:

I got it to work. Here is how I did it: The models-folder is now located inside the public folder (Bad for secruity but doesnt matter for my project). Than you can load the svf file like this:

Autodesk.Viewing.Initializer(options, function () {

      viewer.start( "./models/path/file.svf");

    });

这篇关于如何使用Forge Viewer查看本地存储的SVF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:16