javascript - 尝试将自定义网格添加到离线查看器
问题描述
我尝试将自定义 sphereMesh 添加到离线查看器。我看到这可以通过查看器的在线版本来完成。但是我得到一个未捕获的 TypeError: Cannot read property 'Add' of undefined 如果我在我的查看器中尝试这个。
<div id="MyViewerDiv"></div>
<script>
var myViewerDiv = document.getElementById('MyViewerDiv');
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(myViewerDiv);
var options = {
'env' : 'Local',
'document' : './_3D_ 197440/_3D_.svf'
};
Autodesk.Viewing.Initializer(options, function() {
viewer.start(options.document, options);
});
var geom = new THREE.SphereGeometry(1000, 8, 8);
var material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
var sphereMesh = new THREE.Mesh(geom, material);
sphereMesh.position.set(0, 0, 0);
viewer.impl.scene.add(sphereMesh);
</script>
解决方案
在添加自定义几何体的方式方面,在线查看器和离线查看器没有区别。在您的情况下,您遇到类似于“竞争条件”的情况,您尝试在初始化时使用资源:有时 init 进程首先完成 => 成功,有时它稍后完成 => 出错。
为了解决这个问题,有两种方法:
- 如文档(推荐)中所述,将您的代码添加到扩展中并加载扩展。示例:https ://apprentice3d.github.io/SD226781-Samples/02.html
- 将您的自定义网格代码移动到文档加载回调函数的主体中。示例:检查https://s3.amazonaws.com/sample-collection/GiroWatch_Latest.html的来源
推荐阅读
- snowflake-cloud-data-platform - 阶段命令 metadata$filename 显示数百个单个文件的出现
- azure-api-management - 问题:Azure Logic App 在 Azure API 管理中不可见
- html - 根据用户输入改变不同页面上嵌入元素的高度
- python - 如何用哨兵捕捉python警告?
- python - Why my python program returning different Output on every execution
- javascript - User.findUserByEmail 不是函数
- sql - 如何避免在数据库中创建新列
- python - 使用opencv python对网格中的单元格进行编号
- python - Fitbit 到 Dataframe 的步骤
- reactjs - 如何启用一键运行 Fastapi 和 React 应用程序?