xBIM 实战01 在浏览器中加载IFC模型文件

新建完成后,项目结构如下:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="100000000" /><!--100MB-->
</requestFiltering>
</security>
<staticContent>
<mimeMap fileExtension=".wexbim" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
如果将应用程序发布到IIS,则在IIS中添加MIME类型,
扩展名为 .wexbim,类型为 application/octet-stream

将下列目录添加到项目中

添加一个静态页面 001.html,打开文件,添加以下引用
<script src="Content/Libs/gl-matrix.js"></script>
<script src="Content/Libs/webgl-utils.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-product-type.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-state.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-shaders.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-model-geometry.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-model-handle.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-binary-reader.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-triangulated-shape.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-viewer.debug.js"></script> <script src="Content/Plugins/NavigationCube/xbim-navigation-cube-shaders.debug.js"></script>
<script src="Content/Plugins/NavigationCube/xbim-navigation-cube.debug.js"></script>
<script src="Content/Plugins/NavigationCube/xbim-navigation-cube-textures.debug.js"></script> <script src="Content/Plugins/NavigationHome/xbim-navigation-home-textures.debug.js"></script>
<script src="Content/Plugins/NavigationHome/xbim-navigation-home.debug.js"></script>
xbim-viewer.debug.js 依赖 gl-matrix.js 与 webgl-utils.js 2个文件。其他文件根据功能需要再添加引用即可。
在页面的<body></body>中添加
<canvas id="xBIM-viewer" width="600" height="500"></canvas>
canvas 是HTML5中的新标签元素,使用 JavaScript 在网页上绘制图像。
xbim-viewer.js中封装了 xViewer 对象用于绘制呈现模型文件。
完整的代码如下:
<!DOCTYPE html>
<html>
<head>
<title>xViewer</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <script src="Content/Libs/gl-matrix.js"></script>
<script src="Content/Libs/webgl-utils.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-product-type.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-state.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-shaders.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-model-geometry.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-model-handle.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-binary-reader.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-triangulated-shape.debug.js"></script>
<script type="text/javascript" src="Content/Viewer/xbim-viewer.debug.js"></script> <script src="Content/Plugins/NavigationCube/xbim-navigation-cube-shaders.debug.js"></script>
<script src="Content/Plugins/NavigationCube/xbim-navigation-cube.debug.js"></script>
<script src="Content/Plugins/NavigationCube/xbim-navigation-cube-textures.debug.js"></script> <script src="Content/Plugins/NavigationHome/xbim-navigation-home-textures.debug.js"></script>
<script src="Content/Plugins/NavigationHome/xbim-navigation-home.debug.js"></script>
<style> html, body {
height: 100%;
padding: 0;
margin: 0;
} canvas {
display: block;
border: none;
margin-left: auto;
margin-right: auto;
}
</style> </head>
<body>
<div id="msg"></div>
<canvas id="xBIM-viewer" width="600" height="500"></canvas>
<script type="text/javascript">
var check = xViewer.check();
if (check.noErrors) {
var viewer = new xViewer("xBIM-viewer");
viewer.background = [0, 0, 0];//设置模型浏览器的背景色 viewer.on("error",
function (arg) {
var container = viewer._canvas.parentNode;
if (container) {
container.innerHTML = "<pre style='color:red;'>" + arg.message + "</pre>" + container.innerHTML;
}
});//实时监控异常发生事件 viewer.load("Content/tests/data/rac_advanced_sample_project.wexbim"); //加载模型文件
viewer.start(); //使用此函数可以启动模型的动画。如果在加载几何图形之前启动动画,它将等待内容呈现。此函数绑定到屏幕的浏览器帧速率,因此如果切换到其他选项卡,它将停止消耗任何资源。 var cube = new xNavigationCube();
viewer.addPlugin(cube);// 添加立方体导航 var home = new xNavigationHome();
viewer.addPlugin(home);// 添加首页导航 } else {
alert("您浏览器版本过低,不支持WebGL技术。请升级浏览器。"); var msg = document.getElementById("msg");
for (var i in check.errors) {
var error = check.errors[i];
msg.innerHTML += "<div style='color: red;'>" + error + "</div>";
}
}
</script>
</body>
</html>
在浏览器中加载 IFC模型文件,使用了先进的WebGL技术,所以它无法在旧浏览器中运行,Chrome或Mozzilla,IE11及以上版本和其他支持该技术的应用程序都可以很好地展示出3D模型效果。
var check = xViewer.check(); 用于检查浏览器是否支持WebGL技术,检查结果返回一个错误信息集合check.noErrors。如果有错误,则循环遍历该错误信息并提示给用户。
viewer.load(); 用于加载目标模型文件,必须是wexbim文件的url或表示wexbim文件的二进制流。
viewer.start(); 使用此函数可以启动模型的动画。如果在加载几何图形之前启动动画,它将等待内容呈现。此函数绑定到屏幕的浏览器帧速率,因此如果切换到其他选项卡,它将停止消耗任何资源。
如果从Revit或者其他工具中导出IFC文件,则使用下面的方法转换为.wexbim格斯的文件
const string fileName = @"rac_advanced_sample_project.ifc";
using (var model = IfcStore.Open(fileName, null, -))
{
var context = new Xbim3DModelContext(model);
context.CreateContext(); var wexBimFilename = Path.ChangeExtension(fileName, "wexbim");
using (var wexBimFile = File.Create(wexBimFilename))
{
using (var wexBimBinaryWriter = new BinaryWriter(wexBimFile))
{
model.SaveAsWexBim(wexBimBinaryWriter);
wexBimBinaryWriter.Close();
}
wexBimFile.Close();
}
}
五、在浏览器中查看
在VS中右键点击该文件,选择“在浏览器中查看”
效果如下
xBIM 实战01 在浏览器中加载IFC模型文件的更多相关文章
- xBIM 实战02 在浏览器中加载IFC模型文件并设置特效
系列目录 [已更新最新开发文章,点击查看详细] 在模型浏览器中加载模型后,可以对模型做一些特殊操作.下图是常用的设置. 都是通过 xbim-viewer.js 中的 API 来设置以达到一定的 ...
- 解决方案:带格式化文本控件( RichText)的模板如果在InfoPath的浏览器中加载可能出现 COM 组件的80040154错误
建议大家在微软的组件出现问题时,在GOOGLE上搜索解决方案,一般来说,总有结果: 带格式化文本控件( RichText)的模板如果在InfoPath的浏览器中加载,可能出现 COM 组件的80 ...
- Spring中加载ApplicationContext.xml文件的方式
Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...
- VC中加载LIB库文件的三种方法
VC中加载LIB库文件的三种方法 在VC中加载LIB文件的三种方法如下: 方法1:LIB文件直接加入到工程文件列表中 在VC中打开File View一页,选中工程名,单击鼠标右键,然后选中&quo ...
- 在C 中加载TorchScript模型
本教程已更新为可与PyTorch 1.2一起使用 顾名思义,PyTorch的主要接口是Python编程语言.尽管Python是合适于许多需要动态性和易于迭代的场景,并且是首选的语言,但同样的,在 许多 ...
- 如何让Chrome浏览器可以加载本地XML文件?
Chrome浏览器的安全限制,禁止本地加载XML等外部文件,如何设置让其可以加载呢? 有两种方法,第一种是在本地服务器环境下浏览,采用 http://localhost/ 的方式浏览你的网页和文件,就 ...
- 机器学习之保存与加载.pickle模型文件
import pickle from sklearn.externals import joblib from sklearn.svm import SVC from sklearn import d ...
- Qt3D使用assimp加载常规模型文件
Qt3D使用assimp加载三维模型文件,assimp支持很多常规格式的三维模型格式: 其中支持导入的格式有: 3D 3DS 3MF AC AC3D ACC AMJ ASE ASK B3D BLEND ...
- tensorflow c++ API加载.pb模型文件并预测图片
tensorflow python创建模型,训练模型,得到.pb模型文件后,用c++ api进行预测 #include <iostream> #include <map> # ...
随机推荐
- 存储概念解析:NAS与SAN的区别
目前存储网络技术领域中的两个主旋律是SAN(存储区域网络)和NAS(网络连接区域存储),两者都宣称是解决现代企业高容量数据存储需求的最佳选择. 正如在餐厅就餐时大厨不会为您传菜,跑堂不会为您烹制鲜橙烩 ...
- 【POJ 2828】Buy Tickets
[题目链接] http://poj.org/problem?id=2828 [算法] 离线用线段树维护序列即可 [代码] #include <algorithm> #include < ...
- Extjs 可重用组件开始写 2014 8 23日
今天开始自己去写组件. 这次写组件重点在于参考cfWeb来写出自己的组件. 首先先把结构做出来. 对于这次的自定义组件,现在所做的事情关键在于上面四个文件.于是将上面四个文件贴出来. MyApp.js ...
- caffe下python环境的编译
安装python所需的依赖包 (1)sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-n ...
- android编译ffmpeg+x264
下载最新版的x264ftp://ftp.videolan.org/pub/videolan/x264/snapshots/1.解压到指定的目录2.切换当前目录为该目录3.创建一个shell脚本buil ...
- 对MySQL交换分区的实践
前言 在介绍交换分区之前,我们先了解一下 mysql 分区. 数据库的分区有两种:水平分区和垂直分区.而MySQL暂时不支持垂直分区,因此接下来说的都是水平分区.水平分区即:以行为单位对表进行分区.比 ...
- Linux中安装redis的phpredis扩展
下载phpredis扩展 http://pecl.php.net/package/redis wget http://pecl.php.net/get/redis-4.0.2.tgz 需要环境配置文件 ...
- js滑动提示效果
js代码 漂亮的动画效果:在靠右上角:背景颜色为红,字体颜色为白色 滑动 变大 上移 缓慢渐变消失 function tishi() { $("#tishi").attr(&q ...
- Python3之时间模块详述
Python3之时间模块 time & datetime & calendar 一. 概述 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多p ...
- activity_note
在activiti任务中,主要分为两大类查询任务(个人任务和组任务): 1.确切指定了办理者的任务,这个任务将成为指定者的私有任务,即个人任务. 2.无法指定具体的某一个人来办理的任务,可以把任务分配 ...