BIMserver学习笔记

BIMserver 介绍

一、简要描述

1、BIMserver是用户构建应用程序的平台,提供稳定而灵活的平台来创建在线(开放)BIM工具

2、核心功能有修改、授权、比较、查询、合并等…(ifc model);提供IFC文件管理、数据解析、格式化输出、web通信标准、WebGL渲染等功能,一站式解决BIM模型从文件到渲染展示的服务

3、开放接口和一些网络协议(soap,PB,json);

4、提供了众多插件供使用,如IFCopenshell,bimviews等;利用这些插件才使得bimserver底层提供的接口能够友好地和用户进行交互,实现#2中提到的功能;

5、提供了Java、JavaScript、PHP等接口可供二次开发;但是未提供参考文档;

6、BIMserver工作流程

communication

7、BIMServer模型数据主要分成两个阶段来获取:

  • 通过HTTP接口获取IFC Object元数据(Meta Data)——模型的Checkin阶段
  • 通过websocket获取IFC Object几何渲染数据(Geometry Data)——模型的显示前准备

二、官方WiKi

1、单机模式的BIMserver

官方提供单机模式可供使用,直接运行官方提供的jar包,即可运行单机版的BIMserver;目前测试了bimserver-1.5.147.jar利用如下配套的plugins-jars,可以搭建本地单机服务。配套的jars下载地址:https://oss.sonatype.org/content/groups/public/org/opensourcebim/,最新版本的插件也可在此下载。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
- bimserverapi-0.0.166.jar
- bimsurfer3-0.0.239.jar # 此插件仅提供API,不是Application
- bimsurfer-0.0.72.jar # 此插件App报404错误无法使用,可不导入
- bimviews-0.0.155.jar
- binaryserializers-0.0.65.jar
- charting-0.0.7.jar # 多年未更新,导入报错,请勿导入
- collada-0.0.9.jar # 该插件功能已移动到bimserver内部,导入报错,请勿导入
- console-0.0.40.jar
- demoplugins-0.0.57.jar
- gltf-0.0.32.jar
- ifcengine-0.0.16.jar # BIMserver-1.5.x 不可用,导入报错,请勿导入
- ifcopenshellplugin-0.5.60.jar
- ifcplugins-0.0.66.jar
- mergers-0.0.38.jar

此处提供一个单机模式BIMserver搭建的教程:https://blog.brucekong.com/posts/3869274485/

2、BIMserver-1.5.x 的环境需求

  • A working (outgoing) internet connection(from your BIMserver);
  • A working (incoming) internet connection (to allow other people to connect);
  • Disk (to store the database, logs, plugins etc…);
  • Java 8 (or higher);

特殊的对于war需求:

  • A JRE or JDK 8
  • A Servlet Specification 3.0 or higher based Container with WebSocket support (Tomcat 8 or higher, Jetty 8 or higher)

3、ServiceInterface 服务接口

BIMserver不提供关于接口的文档,只通过Java Interface文件中的注释来说明:

4、SOAP:BIMserver提供了soap方式来访问3#中的接口,此处暂未了解太多

简单对象访问协议(SOAP:Simple Object Access Protocol)是交换数据的一种协议规范,是一种轻量的、简单的、基于XML标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。

5、JSON API:

系统提供了3#中接口的json访问途径,JSON接口主要用于帮助从Web应用程序/网站连接到BIMserver。但是,当从其他应用程序(例如Web服务器或BIM / CAD软件)进行连接时,它也非常有用。可以理解为使用类似PostMan等工具发送HTTP POST请求,可以返回json字符串;

6、Protocol Buffers(PB):

由于SOAP方式的缺陷,BIMserver提供的第三中访问3#接口的方式,是为了让BIMserver支持更多的编程语言。Protocol Buffers API中没有“服务接口”方法,因为PB有一些限制。PB中的所有服务调用仅允许1个参数和1个返回类型,因此BIMserver为每个调用生成特定的“请求”和“响应”消息。例如,“login”方法使用“LoginRequest”消息作为输入参数,并使用“LoginResponse”消息作为返回类型。这样就可以破除PB的限制,可以传入和返回多个参数。

Protocol Buffers只是一种消息格式,实际的传输方法可以由开发人员选择。我们选择使用Protobuf Socket RPC。此实现目前仅提供Java和Python版本,但由于实现非常简单,因此可以使用其他语言而不会有太多麻烦。

protocol buffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台。google 提供了多种语言的实现:java、c#c++、go 和 python,每一种实现都包含了相应语言的编译器以及库文件。由于它是一种二进制的格式,比使用 xml 进行数据交换快许多。可以把它用于分布式应用之间的数据通信或者异构环境下的数据交换。作为一种效率和兼容性都很优秀的二进制数据传输格式,可以用于诸如网络传输、配置文件、数据存储等诸多领域。

7、Model的Checkin和download

  • Checkin:ServiceInterface接口中的checkin函数,同样也可以使用上述的其他方式调用该service;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Checkin a new model by sending a serialized form
*
* @param poid The Project's ObjectID
* @param comment A comment
* @param deserializerOid ObjectId of the deserializer to use, use getAllDeserializers to get a list of available deserializers
* @param fileSize The size of the file in bytes
* @param fileName Name of the file
* @param data The actual data
* @param merge Whether to use checkin merging (this will alter your model!) DEPRICATED
* @param sync Whether the call should return immediately (async) or wait for completion (sync)
* @return An id, which you can use for the getCheckinState method
* @throws ServerException, UserException
*/
@WebMethod(action = "checkinSync")
SLongCheckinActionState checkinSync(
@WebParam(name = "poid", partName = "checkin.poid") Long poid,
@WebParam(name = "comment", partName = "checkin.comment") String comment,
@WebParam(name = "deserializerOid", partName = "checkin.deserializerOid") Long deserializerOid,
@WebParam(name = "fileSize", partName = "checkin.fileSize") Long fileSize,
@WebParam(name = "fileName", partName = "checkin.fileName") String fileName,
@WebParam(name = "data", partName = "checkin.data") @XmlMimeType("application/octet-stream") DataHandler data,
@WebParam(name = "merge", partName = "checkin.merge") Boolean merge) throws ServerException, UserException;
  • Download:从BIMserver上下载模型是一个两步的过程

step-1,initiate the download;调用ServiceInterface中的download方法,此方法返回TopicId(Long)。此TopicId可用于获取step-2中描述的实际数据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* Download a compare of a model
*
* @param serializerOid The ObjectID of the Serializer configuration to use
* @param roid1 The ObjectID of the first Revision
* @param roid2 The ObjectID of the second Revision
* @param mcid The ObjectID of the Model Compare plugin configuration
* @param type How to compare (All, Only Added, Only Modified or Only Deleted)
* @param sync Whether to call this method synchronously
* @return A topicId, which you can use for the NotificationRegistryInterface.getProgress method, ServiceInterface.getDownloadData and the download servlet (/download)
* @throws ServerException, UserException
*/
@WebMethod(action = "downloadCompareResults")
Long downloadCompareResults(
@WebParam(name = "serializerOid", partName = "download.serializerOid") Long serializerOid,
@WebParam(name = "roid1", partName = "downloadByOids.roid1") Long roid1,
@WebParam(name = "roid2", partName = "downloadByOids.roid2") Long roid2,
@WebParam(name = "mcid", partName = "downloadByOids.mcid") Long mcid,
@WebParam(name = "type", partName = "downloadByOids.type") SCompareType type,
@WebParam(name = "sync", partName = "downloadByOids.sync") Boolean sync) throws ServerException, UserException;

Step-2,downloading the data;下载模型data有两种途径;

第一种方法:JSON/SOAP/Protocol Buffer,常用,代码如下:

1
2
SDownloadResult result = ServiceInterface.getDownloadData(topicId);
DataHandler dataHandler = result.file;

另一种方法:Using the download servlet (direct HTTP),更好,存在这种方法的原因在于允许浏览器下载模型,不必从其他文件(例如JSON)“提取”下载的文件,并且更高效。使用此方法的方法是将HTTP GET发送到[yourbimserver] / download。所需参数如下:

Name Description Required
token Your BIMserver auth token Yes
topicId The TopicId returned by the download method Yes
zip Whether to download the content in a ZIP file. Even if this argument is not “on” or not supplied, the content might still be compressed, this depends on the HTTP headers sent/received No

8、DataModel

  • SProject
1
2
3
4
5
ServiceInterface.getProjectByPoid(poid);
ServiceInterface.getTopLevelProjectByName(name);
ServiceInterface.getAllProjects(Boolean onlyTopLevel, Boolean onlyActive);
ServiceInterface.getAllReadableProjects();
ServiceInterface.getAllWritableProjects();
  • SRevison:此处暂无内容

三、BIMserver开发

1、插件的开发

BIMserver提供了一个Plugin的接口,来实现插件的开发:Plugin.interface如下:

1
2
3
4
5
6
7
public interface Plugin {
void init(PluginManager pluginManager) throws PluginException; // Initialization code, if your plugin requires other plugins, this is the time to check for them, be sure to throw a PluginException when something is wrong
String getName(); // A short name of this plugin
String getDescription(); // A short description of this plugin
String getVersion(); // A version, not used for dependencies (yet)
boolean isInitialized(); // Should return whether this plugin is successfully initialized
}

一般情况不会直接实例化Plugin,BIMserver在此基础上为不同功能目的的插件制定了二级的接口:

Name Functionality
[Serializer](Serializer Plugin) Create a serialized version of a model (can be text or binary)
[Deserializer](Deserializer Plugin) Parse a serialized version of a model and store it in the database
[Render Engine](Render Engine Plugin) Triangulates IFC geometry
[Query Engine](Query Engine Plugin) Provides a way of querying a model
[Schema](Schema Plugin) Provides the BIMserver with metadata about the models
[Object IDM](Object IDM Plugin) Provides the BIMserver with a way of traversing objects
[Model Merge](Model Merge Plugin) Merge multiple models into one model
[Model Compare](Model Compare Plugin) Compare 2 models
[Service](Service Plugin) Services can be triggered by certain events
1)Serializer Plugin

序列化程序将对象模型序列化为数据流。 默认的序列化器包括:IFC2x3,IfcXml,CityGML等。 大多数序列化程序将输出基于文本的格式,但这不是必需的。

Serializer Plugin必须实例化SerializerPlugin接口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public interface SerializerPlugin extends Plugin {
/**
* @return A serializer
*/
Serializer createSerializer(PluginConfiguration plugin);

/**
* @return Whether this plugin will be needing geometry
*/
boolean needsGeometry();
}

public interface Serializer {
void init(IfcModelInterface model, ProjectInfo projectInfo, PluginManager pluginManager, RenderEnginePlugin renderEnginePlugin, boolean normalizeOids) throws SerializerException;
void writeToFile(File file) throws SerializerException;
byte[] getBytes();
IfcModelInterface getModel();
InputStream getInputStream() throws IOException;
void writeToOutputStream(OutputStream outputStream) throws SerializerException;
void reset();
}

可以继承EmfSerializer,不必实现所有接口方法;

如果您的序列化器需要三角形几何体,可以继承AbstractGeometrySerializer。

目前BIMvie.ws和BIMsurfer在用的Serializer:

  • BinaryGeometrySerializer:此序列化程序以二进制格式写入几何体,在大多数情况下可以轻松地将其发送到GPU。 源代码易读。
  • MessagingBinaryGeometrySerializer:因为现在JavaScript无法以流方式加载二进制数据,所以还有一个消息传递实现。 此实现通过WebSocket批量发送几何体。
2)Deserializer Plugin

将数据流反序列化为对象模型。

1
2
3
4
5
6
7
8
9
public interface DeserializerPlugin extends Plugin {
Deserializer createDeserializer(PluginConfiguration pluginConfiguration);
boolean canHandleExtension(String extension);
}
public interface Deserializer {
void init(SchemaDefinition schemaDefinition);
IfcModelInterface read(File file) throws DeserializeException;
IfcModelInterface read(InputStream inputStream, String fileName, long fileSize) throws DeserializeException;
}

可以继承EmfDeserializer,不必实现所有方法。

3)Model Compare Plugin

比较插件基本上为BIMserver提供了比较2个模型的功能。 比较已经可插拔,因为比较模型是编程中的难题,并且要求变化很大。

1
2
3
4
5
6
7
public interface ModelComparePlugin extends Plugin {
ModelCompare createModelCompare(PluginConfiguration pluginConfiguration) throws ModelCompareException;
}

public interface ModelCompare {
CompareResult compare(IfcModelInterface model1, IfcModelInterface model2, CompareType compareType) throws ModelCompareException;
}
4)Model Merge Plugin

模型合并插件基本上为BIMserver提供了合并2个或更多模型的功能。 合并已经可插拔,因为合并模型在编程中是一个难题,并且需求变化很大。

1
2
3
4
5
6
7
public interface ModelMergerPlugin extends Plugin {
ModelMerger createModelMerger(PluginConfiguration pluginConfiguration);
}

public interface ModelMerger {
IfcModelInterface merge(Project project, IfcModelSet modelSet, ModelHelper modelHelper) throws MergeException;
}

返回的IfcModelInterface必须是新实例。 您无法在新模型中移动/链接给定模型中的对象。 你必须复制它们。 ModelHelper可以帮助您。 给定的项目可用于有关模型的更多信息(例如单位)。 IfcModelSet包含应合并的所有模型。

5)Query Engine Plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public interface QueryEnginePlugin extends Plugin {
/**
* @return A usable QueryEngine implementation
*/
QueryEngine getQueryEngine(PluginConfiguration pluginConfiguration);

/**
* @return Return a list of keys (usually file names) corresponding to code examples for this plugin
*/
Collection<String> getExampleKeys();

/**
* @param key
* @return Return the code example for the given key
*/
String getExample(String key);
}
public interface QueryEngine {
/**
* @param model The complete model
* @param code The query, represented as a string
* @return RunResult
*/
IfcModelInterface query(IfcModelInterface model, String code, Reporter reporter, ModelHelper modelHelper) throws QueryEngineException;
}
6)Render Engine Plugin

渲染引擎可以将IFC文件转换为三角形几何体。

1
2
3
4
5
6
7
8
9
10
public interface RenderEnginePlugin extends Plugin {
RenderEngine createRenderEngine(PluginConfiguration pluginConfiguration) throws RenderEngineException;
}
public interface RenderEngine {
RenderEngineModel openModel(File ifcFile) throws RenderEngineException;
RenderEngineModel openModel(InputStream inputStream, int size) throws RenderEngineException;
RenderEngineModel openModel(byte[] bytes) throws RenderEngineException;
void close() throws RenderEngineException;
void init() throws RenderEngineException;
}
7)ObjectIDM Plugin

ObjectIDM帮助BIMserver决定是否遵循关系/引用以及是否包含/排除某些类。 这可以用于基于给定的起点定义模型的子集。

1
2
3
4
5
6
7
public interface ObjectIDMPlugin extends Plugin {
ObjectIDM getObjectIDM(PluginConfiguration pluginConfiguration);
}
public interface ObjectIDM {
boolean shouldFollowReference(EClass originalClass, EClass eClass, EStructuralFeature eStructuralFeature);
boolean shouldIncludeClass(EClass originalClass, EClass eClass);
}
8)Schema Plugin

模式插件为BIMserver提供有关模式的信息。 目前只有一个实现,并且可以读取快速模式文件(当前为Ifc2x3tc1.exp)。

1
2
3
4
public interface SchemaPlugin extends Plugin {
SchemaDefinition getSchemaDefinition(PluginConfiguration pluginConfiguration);
File getExpressSchemaFile();
}
9)Service Plugin

服务插件可以通过监听通知并对其进行操作来扩展BIM服务器的功能。 例如,当用户签入新版本时,ClashDetection Service插件可以将[ClashDetection]报告创建为[ExtendedData]。

详细查看

2、Eclipse Modeling Framework(EMF)

建筑信息模型(BIM)通常是面向对象的,往往很大。 例如,工业基础类(IFC)有超过一千个不同的类。 因为BIMserver是用Java(面向对象语言)编写的,所以在使用的BIM模型中使用类型化Java类非常有用。 这就是Eclipse Modeling Framework(EMF)发挥作用的地方。 目前,BIMserver内部使用IFC2x3tc1。

大多数BIM元模型以数据格式描述。 由于IFC基于STEP / EXPRESS技术,因此架构可用作.EXP文件。 此文件已使用BuildingSMARTLibrary(BIMserver项目的一部分)转换为EMF Core文件。

EMF框架使用给定的ECore文件生成Java类,这些类用于存储BIM模型并传递给数据库层。

如果从IFC-Step文件加载模型,则浮点数的String值也将存储为String。 如果以编程方式更改浮点值,则应更新(或清除)字符串值。

BIMserver包含5种不同的EMF模型:

  • 保存IFC数据的IFC2x3tc1 Schema模型(如上所述);
  • 保存IFC数据的IFC4 Schema模型(如上所述);
  • 用于记录的Log模式;
  • 存储典型BIMserver数据的Store模型,如项目,用户,修订等;
  • 存储几何体的几何模型,如顶点/索引/法线/颜色;

3、嵌入式地开发

有时将BIMserver嵌入到另一个应用程序中很有用,此页面描述了如何执行此操作。

  • 创建BimInstanceConfig实例
1
2
3
4
5
6
7
8
9
10
// Example
BimServerConfig config = new BimServerConfig();
config.setStartEmbeddedWebServer(false);
config.setHomeDir(new File("[LOCATION]"));
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(new File("[LOCATION]")));
config.setClassPath(System.getProperty("java.class.path"));
config.setPort(8080);
config.setStartCommandLine(false);
config.setLocalDev(true);
config.setAutoMigrate(false);
  • 创建BIMserver实例
1
BimServer bimServer = new BimServer(config);
  • 加载插件
1
2
// Example, if you point [LOCATION] to the BIMserver workspace directory, all plugins delivered with BIMserver will be loaded
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new File[]{new File("[LOCATION]")});
  • 开启服务
1
bimServer.start();
  • 使用BIMserver。 BimServer对象上的getter都可以使用所有有用的对象。
1
2
3
4
5
6
7
8
9
10
11
12
13
BimDatabase bimDatabase = bimServer.getDatabase();
SettingsManager settingsManager = bimServer.getSettingsManager();
ServiceInterface systemService = bimServer.getSystemService();
EmfSerializerFactory emfSerializerFactory = bimServer.getEmfSerializerFactory();
DiskCacheManager diskCacheManager = bimServer.getDiskCacheManager();
VersionChecker versionChecker = bimServer.getVersionChecker();
ServiceFactory serviceFactory = bimServer.getServiceFactory();
ServerInfo serverInfo = bimServer.getServerInfo();
MailSystem mailSystem = bimServer.getMailSystem();
PluginManager pluginManager = bimServer.getPluginManager();
MergerFactory mergerFactory = bimServer.getMergerFactory();
LongActionManager longActionManager = bimServer.getLongActionManager();
// Etcetera

主要接口(也可通过SOAP / ProtocolBuffers / JSON获得):

1
2
// Example getting the ServiceInterface
ServiceInterface si = bimServer.getServiceFactory().get(AccessMethod.INTERNAL).getServiceInterface();

4、专用术语

  • Oid:BIMserver中的所有对象都有唯一的标识符,这称为oid(用于对象标识符)。 这个oid是long型的。 来自Ifc2x3模型的实例(如IfcWall)有oid,但Store模型的实例(如Project,Revision,User)也有oid。 具有独特性,我们的意思是在BIMserver的实例中是唯一的
  • Rid:Rid代表修订标识符。 BIMserver中具有oid的每个对象也有一个摆脱。 Rids的类型为int。 对于Store模型的实例,rid也是-1,因为它们当前没有版本化。 对于其他对象(在Ifc2x3模型中),随着对象的每个新版本的增加,rid会增加。
  • The ConcreteRevision object:对于每个checkin,只创建1个ConcreteRevision实例,此实例表示实际checkin。 但正如您在子项目中检查模型时可能已经看到的那样,还会在父项目上创建修订,这是修订对象发挥作用的地方。 ConcreteRevision对象是具有id属性的对象(不要与oid混淆),id属性与该特定修订中所有对象的rid值相同。
  • The Revision object:对于每个checkin,至少创建一个Revision对象。 为checkin完成的项目的所有父项目创建附加的修订对象。 大多数情况下,您只需使用Revision对象。

5、数据库版本控制

BIMserver将所有数据存储在键值存储中。 通过KeyValueStore接口访问键值存储。 现在只有一个实现,它使用的是开源BerkeleyDB Java版。

键值存储定义为:

  • 一组命名表
  • 每个表有2列,键和值
  • 键和值列都可以包含任意大小的字节数组,此大小可能因记录而异
  • 表中的所有键始终是有序的
  • 不存在重复的密钥

原则:

  • 模型存储在项目中
  • 每个新版本的模型都存储了一个新版本
  • 应始终可以访问项目的每个修订版
  • 一旦存储,修改就永远不会改变
  • 项目中的对象只能引用同一项目中的其他对象。

BIMserver的其他介绍

1、BIMserver数据结构介绍:https://sq.163yun.com/blog/article/173134324857495552

2、数据库的使用为BerkelyDB(BDB),Berkeley DB是一个开源的文件数据库,介于关系数据库与内存数据库之间,使用方式与内存数据库类似,它提供的是一系列直接访问数据库的函数,而不是像关系数据库那样需要网络通讯、SQL解析等步骤。Documentions:https://docs.oracle.com/cd/E17277_02/html/index.html


IFC格式介绍

链接:https://www.bbsmax.com/A/rV57v49JPD/

https://blog.csdn.net/Eivenli/article/details/77763563

官方文档:

IFC2x3:http://www.bim-times.com/ifc/ifc2x3/index.htm

IFC4:http://www.bim-times.com/ifc/ifc4/index.htm


OBJ格式介绍

百度百科

简书


可以参考的开源Demo

1、示例工程:https://github.com/openBIMstandards/DataSetSchependomlaan

2、简单的eclipse demo:https://github.com/opensourceBIM/BimServerJavaClientDemo/tree/master/BimServerJavaClientDemo