Skip to content

Commit 90eac04

Browse files
committed
update to BIMserver 1.4.0-FINAL, cleanup
1 parent fa5a008 commit 90eac04

6 files changed

Lines changed: 66 additions & 190 deletions

File tree

ServerPlugin/plugin/plugin.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PluginDescriptor>
33
<PluginImplementation>
44
<interfaceClass>org.bimserver.plugins.serializers.SerializerPlugin</interfaceClass>
5-
<implementationClass>org.bimserver.serializers.json.JSONModelFormat2SerializerPlugin</implementationClass>
5+
<implementationClass>org.bimserver.serializers.json.ThreeJsSerializerPlugin</implementationClass>
6+
<enabled>true</enabled>
67
</PluginImplementation>
7-
</PluginDescriptor>
8+
</PluginDescriptor>

ServerPlugin/src/org/bimserver/serializers/json/BinaryIndexBuffer.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

ServerPlugin/src/org/bimserver/serializers/json/BinaryVertexBuffer.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

ServerPlugin/src/org/bimserver/serializers/json/SetGeometryResult.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

ServerPlugin/src/org/bimserver/serializers/json/JSONModelFormat2Serializer.java renamed to ServerPlugin/src/org/bimserver/serializers/json/ThreeJsSerializer.java

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@
33
import java.io.OutputStream;
44
import java.io.PrintWriter;
55
import java.nio.ByteBuffer;
6+
import java.nio.ByteOrder;
7+
import java.util.ArrayList;
68
import java.util.List;
79

810
import org.bimserver.emf.IdEObject;
911
import org.bimserver.emf.IfcModelInterface;
10-
import org.bimserver.models.ifc2x3tc1.GeometryData;
11-
import org.bimserver.models.ifc2x3tc1.GeometryInfo;
12+
import org.bimserver.emf.PackageMetaData;
13+
import org.bimserver.models.geometry.GeometryData;
14+
import org.bimserver.models.geometry.GeometryInfo;
1215
import org.bimserver.models.ifc2x3tc1.IfcColumn;
1316
import org.bimserver.models.ifc2x3tc1.IfcDoor;
1417
import org.bimserver.models.ifc2x3tc1.IfcProduct;
1518
import org.bimserver.models.ifc2x3tc1.IfcRoot;
1619
import org.bimserver.models.ifc2x3tc1.IfcSlab;
1720
import org.bimserver.models.ifc2x3tc1.IfcWall;
18-
import org.bimserver.models.ifc2x3tc1.IfcWallStandardCase;
1921
import org.bimserver.models.ifc2x3tc1.IfcWindow;
2022
import org.bimserver.plugins.PluginManager;
2123
import org.bimserver.plugins.renderengine.RenderEnginePlugin;
2224
import org.bimserver.plugins.serializers.EmfSerializer;
25+
import org.bimserver.plugins.serializers.ProgressReporter;
2326
import org.bimserver.plugins.serializers.ProjectInfo;
2427
import org.bimserver.plugins.serializers.SerializerException;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
2730

28-
public class JSONModelFormat2Serializer extends EmfSerializer {
31+
public class ThreeJsSerializer extends EmfSerializer {
2932

30-
private static final Logger LOGGER = LoggerFactory.getLogger(JSONModelFormat2Serializer.class);
33+
private static final Logger LOGGER = LoggerFactory.getLogger(ThreeJsSerializer.class);
3134
private PrintWriter out;
3235

33-
public void init(IfcModelInterface model, ProjectInfo projectInfo, PluginManager pluginManager, RenderEnginePlugin renderEnginePlugin, boolean oids) throws SerializerException {
34-
super.init(model, projectInfo, pluginManager, renderEnginePlugin, false);
36+
public void init(IfcModelInterface model, ProjectInfo projectInfo, PluginManager pluginManager, RenderEnginePlugin renderEnginePlugin, PackageMetaData packageMetaData, boolean oids) throws SerializerException {
37+
super.init(model, projectInfo, pluginManager, renderEnginePlugin, packageMetaData, false);
3538
}
3639

3740
@Override
@@ -40,7 +43,7 @@ public void reset() {
4043
}
4144

4245
@Override
43-
public boolean write(OutputStream outputStream) throws SerializerException {
46+
protected boolean write(OutputStream outputStream, ProgressReporter progressReporter) {
4447
if (getMode() == Mode.BODY) {
4548
out = new PrintWriter(outputStream);
4649
out.println("[");
@@ -56,15 +59,15 @@ public boolean write(OutputStream outputStream) throws SerializerException {
5659
}
5760
}
5861

59-
private void writeGeometry(SetGeometryResult geometry, IfcRoot ifcRoot) {
62+
private void writeGeometry(GeometryData geometryData, IfcRoot ifcRoot) {
6063
out.println(" \"id\" : \"" + ifcRoot.getGlobalId() + "\", ");
6164
out.println(" \"type\" : \"" + ifcRoot.eClass().getName().toUpperCase() + "\", ");
6265
out.println(" \"geometry\" : {");
6366
out.println(" \"metadata\" : { \"formatVersion\" : 3 }, ");
6467
out.println(" \"materials\": [],");
6568
out.print(" \"vertices\": [ ");
6669

67-
List<Float> vertices = geometry.getBinaryVertexBuffer().getVertices();
70+
List<Float> vertices = getFloatList(geometryData.getVertices());
6871
if (vertices != null && vertices.size() > 0) {
6972
for (int i = 0; i < vertices.size(); i++) {
7073
out.print(i == 0 ? "" : ",");
@@ -76,7 +79,7 @@ private void writeGeometry(SetGeometryResult geometry, IfcRoot ifcRoot) {
7679
out.println(" ], ");
7780
out.print(" \"normals\": [");
7881

79-
List<Float> normals = geometry.getBinaryVertexBuffer().getNormals();
82+
List<Float> normals = getFloatList(geometryData.getNormals());
8083
if (normals != null && normals.size() > 0) {
8184
for (int i = 0; i < normals.size(); i++) {
8285
out.print(i == 0 ? "" : ",");
@@ -90,7 +93,7 @@ private void writeGeometry(SetGeometryResult geometry, IfcRoot ifcRoot) {
9093
out.println(" \"uvs\": [ ],");
9194
out.print(" \"faces\": [ ");
9295

93-
List<Integer> indices = geometry.getBinaryIndexBuffer().getIndices();
96+
List<Integer> indices = getIntegerList(geometryData.getIndices());
9497
if (indices != null && indices.size() > 0) {
9598
for (int i = 0; i < indices.size(); i += 3) {
9699
out.print(i == 0 ? "" : ",");
@@ -107,52 +110,45 @@ private void writeGeometry(SetGeometryResult geometry, IfcRoot ifcRoot) {
107110

108111
@SuppressWarnings("unchecked")
109112
private void writeGeometries() {
110-
// Class[] eClasses = new Class[] { IfcSlab.class, IfcRoof.class,
111-
// IfcWall.class, IfcWallStandardCase.class, IfcWindow.class,
112-
// IfcDoor.class, IfcColumn.class, IfcRamp.class,
113-
// IfcStair.class, IfcStairFlight.class, IfcRailing.class };
114-
Class<IdEObject>[] eClasses = new Class[] { IfcWallStandardCase.class, IfcWall.class, IfcWindow.class, IfcDoor.class, IfcSlab.class, IfcColumn.class };
115-
116-
try {
117-
boolean first = true;
118-
for (Class<? extends IdEObject> eClass : eClasses) {
119-
for (IdEObject object : model.getAll(eClass)) {
120-
IfcProduct ifcRoot = (IfcProduct) object;
121-
SetGeometryResult geometry = getGeometry(ifcRoot);
122-
if (geometry != null) {
123-
out.println(first ? " {" : " ,{");
124-
first = false;
125-
writeGeometry(geometry, ifcRoot);
126-
out.print(" }");
127-
}
128-
}
129-
}
130-
} catch (SerializerException e) {
131-
LOGGER.error("", e);
132-
}
113+
Class<IdEObject>[] eClasses = new Class[] {
114+
IfcWall.class, IfcWindow.class, IfcDoor.class, IfcSlab.class, IfcColumn.class,
115+
org.bimserver.models.ifc4.IfcWall.class,org.bimserver.models.ifc4.IfcWindow.class,
116+
org.bimserver.models.ifc4.IfcDoor.class, org.bimserver.models.ifc4.IfcSlab.class,
117+
org.bimserver.models.ifc4.IfcColumn.class
118+
};
119+
120+
boolean first = true;
121+
for (Class<? extends IdEObject> eClass : eClasses) {
122+
for (IdEObject object : model.getAllWithSubTypes(eClass)) {
123+
IfcProduct ifcRoot = (IfcProduct) object;
124+
GeometryInfo geometryInfo = ifcRoot.getGeometry();
125+
if (geometryInfo != null) {
126+
out.println(first ? " {" : " ,{");
127+
first = false;
128+
writeGeometry(geometryInfo.getData(), ifcRoot);
129+
out.print(" }");
130+
}
131+
}
132+
}
133133
}
134134

135-
private SetGeometryResult getGeometry(IfcProduct ifcRootObject) throws SerializerException {
136-
GeometryInfo geometryInfo = ifcRootObject.getGeometry();
137-
if (geometryInfo != null) {
138-
GeometryData geometryData = geometryInfo.getData();
139-
ByteBuffer verticesBuffer = ByteBuffer.wrap(geometryData.getVertices());
140-
ByteBuffer normalsBuffer = ByteBuffer.wrap(geometryData.getNormals());
141-
142-
int t = geometryInfo.getPrimitiveCount() * 3 * 3;
143-
144-
BinaryIndexBuffer binaryIndexBuffer = new BinaryIndexBuffer();
145-
BinaryVertexBuffer binaryVertexBuffer = new BinaryVertexBuffer();
146-
147-
for (int i = 0; i < t; i++) {
148-
binaryVertexBuffer.addVertex(verticesBuffer.getFloat());
149-
binaryVertexBuffer.addNormal(normalsBuffer.getFloat());
150-
}
151-
for (int i = 0; i < geometryInfo.getPrimitiveCount() * 3; i++) {
152-
binaryIndexBuffer.addIndex(i);
153-
}
154-
return new SetGeometryResult(geometryInfo.getPrimitiveCount() * 3, geometryInfo.getData().getVertices().length, binaryIndexBuffer, binaryVertexBuffer);
135+
private List<Float> getFloatList(byte[] byteArray) {
136+
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
137+
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
138+
List<Float> floatList = new ArrayList<Float>();
139+
while(byteBuffer.hasRemaining()){
140+
floatList.add(byteBuffer.getFloat());
141+
}
142+
return floatList;
143+
}
144+
private List<Integer> getIntegerList(byte[] byteArray) {
145+
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
146+
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
147+
List<Integer> integerList = new ArrayList<Integer>();
148+
while(byteBuffer.hasRemaining()){
149+
integerList.add(byteBuffer.getInt());
155150
}
156-
return null;
151+
return integerList;
157152
}
153+
158154
}

ServerPlugin/src/org/bimserver/serializers/json/JSONModelFormat2SerializerPlugin.java renamed to ServerPlugin/src/org/bimserver/serializers/json/ThreeJsSerializerPlugin.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
package org.bimserver.serializers.json;
22

3+
import org.bimserver.emf.Schema;
34
import org.bimserver.models.store.ObjectDefinition;
45
import org.bimserver.plugins.PluginConfiguration;
56
import org.bimserver.plugins.PluginException;
67
import org.bimserver.plugins.PluginManager;
78
import org.bimserver.plugins.serializers.AbstractSerializerPlugin;
89
import org.bimserver.plugins.serializers.Serializer;
910

10-
public class JSONModelFormat2SerializerPlugin extends AbstractSerializerPlugin {
11+
import java.util.Set;
12+
13+
public class ThreeJsSerializerPlugin extends AbstractSerializerPlugin {
1114

1215
private boolean initialized = false;
1316

1417
@Override
1518
public Serializer createSerializer(PluginConfiguration pluginConfiguration) {
16-
return new JSONModelFormat2Serializer();
19+
return new ThreeJsSerializer();
1720
}
1821

1922
@Override
2023
public boolean needsGeometry() {
2124
return true;
2225
}
2326

27+
@Override
28+
public Set<Schema> getSupportedSchemas() {
29+
return Schema.asSet(Schema.IFC2X3TC1, Schema.IFC4);
30+
}
31+
2432
@Override
2533
public String getDescription() {
26-
return "JSONModelFormat2Serializer"; // TODO: better names and descriptions
34+
return "serializer for three.js json geometry";
2735
}
2836

2937
@Override
@@ -38,7 +46,6 @@ public ObjectDefinition getSettingsDefinition() {
3846

3947
@Override
4048
public void init(PluginManager pluginManager) throws PluginException {
41-
pluginManager.requireSchemaDefinition();
4249
initialized = true;
4350
}
4451

0 commit comments

Comments
 (0)