在unity中读取ifc文件模型

本文介绍了如何在Unity中利用xbim库解析IFC文件,由于xbim与Unity的冲突导致的问题,提出了通过wexbim作为中间文件的方法。详细讲解了wexbim的生成及解析过程,包括数据类型、模型组件和优化策略,为在Unity中构建三维模型提供了解决方案。
摘要由CSDN通过智能技术生成

由于xbim是基于.net framework的一款ifc开源库,且unity同样支持C#语言的编写,故使用xbim在unity中解析.ifc文件。本文主要讲解如何在unity中构建三维模型。

使用xbim提供方法

const string fileName = @"SampleHouse4.ifc";
var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
var xbimDbFilename = Path.ChangeExtension(fileName, "xBIM");

// Make sure we are using an IModel implementation that supports saving of '.xbim' files
IfcStore.ModelProviderFactory.UseHeuristicModelProvider();
	
using (var model = IfcStore.Open(fileName))
{
   
	// IFC file is already parsed and open. Now build the 3D
	var context = new Xbim3DModelContext(model);
	context.CreateContext();	// Creates the Geometry using native GeometryEngine

	// Optional: Export to 'wexbim' format for use in WebUI's xViewer - geometry only
	using (var wexBimFile = File.Create(wexBimFilename))
	{
   
		using (var wexBimBinaryWriter = new BinaryWriter(wexBimFile))
		{
   
			model.SaveAsWexBim(wexBimBinaryWriter);
			wexBimBinaryWriter.Close();
		}
		wexBimFile.Close();
	}
		
	// Save IFC to the internal XBIM format, which includes geometry
	model.SaveAs(xbimDbFilename, StorageType.Xbim);
}

然而此种方法在unity中会导致unity闪退,原因见此:因为xbim.Geomotry重写了模型构建的方法,与unity内置模型构建方法冲突,故context.CreateContext()方法与unity冲突。但由于xbim是基于.net framework的开源库,而此bug则是xbim和unity的冲突,故开发者不予以解决。

我的方法

因为context.CreateContext()在unity中会报错,故要在一个新的项目中调用此语句生成中间文件,而后把中间文件解析获得模型。

wexbim

为适配web端,xbim团队开发了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值