22
33import java .io .OutputStream ;
44import java .io .PrintWriter ;
5- import java .util . ArrayList ;
5+ import java .nio . ByteBuffer ;
66import java .util .List ;
77
8+ import org .bimserver .emf .IdEObject ;
89import org .bimserver .emf .IfcModelInterface ;
9- import org .bimserver .models .ifc2x3tc1 .*;
10+ import org .bimserver .models .ifc2x3tc1 .GeometryData ;
11+ import org .bimserver .models .ifc2x3tc1 .GeometryInfo ;
12+ import org .bimserver .models .ifc2x3tc1 .IfcColumn ;
13+ import org .bimserver .models .ifc2x3tc1 .IfcDoor ;
14+ import org .bimserver .models .ifc2x3tc1 .IfcProduct ;
15+ import org .bimserver .models .ifc2x3tc1 .IfcRoot ;
16+ import org .bimserver .models .ifc2x3tc1 .IfcSlab ;
17+ import org .bimserver .models .ifc2x3tc1 .IfcWall ;
18+ import org .bimserver .models .ifc2x3tc1 .IfcWallStandardCase ;
19+ import org .bimserver .models .ifc2x3tc1 .IfcWindow ;
1020import org .bimserver .plugins .PluginManager ;
11- import org .bimserver .plugins .ifcengine .* ;
21+ import org .bimserver .plugins .renderengine . RenderEnginePlugin ;
1222import org .bimserver .plugins .serializers .EmfSerializer ;
1323import org .bimserver .plugins .serializers .ProjectInfo ;
14- import org .bimserver .plugins .serializers .Serializer ;
1524import org .bimserver .plugins .serializers .SerializerException ;
16- import org .eclipse .emf .ecore .EObject ;
1725import org .slf4j .Logger ;
1826import org .slf4j .LoggerFactory ;
1927
2028public class JSONModelFormat2Serializer extends EmfSerializer {
2129
2230 private static final Logger LOGGER = LoggerFactory .getLogger (JSONModelFormat2Serializer .class );
2331 private PrintWriter out ;
24- private IfcEngineModel ifcEngineModel ;
25- private IfcEngineGeometry geometry ;
2632
27- public void init (IfcModelInterface model , ProjectInfo projectInfo , PluginManager pluginManager , IfcEnginePlugin ifcEnginPlugin , boolean oids ) throws SerializerException {
28- super .init (model , projectInfo , pluginManager , ifcEnginPlugin , false );
29- try {
30- IfcEngine ifcEngine = ifcEnginPlugin .createIfcEngine ();
31- ifcEngine .init ();
32- Serializer serializer = getPluginManager ().requireIfcStepSerializer ();
33- serializer .init (model , getProjectInfo (), getPluginManager (), ifcEnginPlugin , true );
34- ifcEngineModel = ifcEngine .openModel (serializer .getBytes ());
35- ifcEngineModel .setPostProcessing (true );
36- geometry = ifcEngineModel .finalizeModelling (ifcEngineModel .initializeModelling ());
37- } catch (Exception e ) {
38- throw new SerializerException (e );
39- }
33+ public void init (IfcModelInterface model , ProjectInfo projectInfo , PluginManager pluginManager , RenderEnginePlugin renderEnginePlugin , boolean oids ) throws SerializerException {
34+ super .init (model , projectInfo , pluginManager , renderEnginePlugin , false );
4035 }
4136
4237 @ Override
@@ -62,8 +57,7 @@ public boolean write(OutputStream outputStream) throws SerializerException {
6257 }
6358
6459 private void writeGeometry (SetGeometryResult geometry , IfcRoot ifcRoot ) {
65-
66- out .println (" \" id\" : \" " + ifcRoot .getGlobalId ().getWrappedValue () + "\" , " );
60+ out .println (" \" id\" : \" " + ifcRoot .getGlobalId () + "\" , " );
6761 out .println (" \" type\" : \" " + ifcRoot .eClass ().getName ().toUpperCase () + "\" , " );
6862 out .println (" \" geometry\" : {" );
6963 out .println (" \" metadata\" : { \" formatVersion\" : 3 }, " );
@@ -111,18 +105,18 @@ private void writeGeometry(SetGeometryResult geometry, IfcRoot ifcRoot) {
111105 out .println ();
112106 }
113107
108+ @ SuppressWarnings ("unchecked" )
114109 private void writeGeometries () {
115- List <SetGeometryResult > geometryList = new ArrayList <SetGeometryResult >();
116110 // Class[] eClasses = new Class[] { IfcSlab.class, IfcRoof.class,
117111 // IfcWall.class, IfcWallStandardCase.class, IfcWindow.class,
118112 // IfcDoor.class, IfcColumn.class, IfcRamp.class,
119113 // IfcStair.class, IfcStairFlight.class, IfcRailing.class };
120- Class [] eClasses = new Class [] { IfcWallStandardCase .class , IfcWall .class , IfcWindow .class , IfcDoor .class , IfcSlab .class , IfcColumn .class };
114+ Class < IdEObject > [] eClasses = new Class [] { IfcWallStandardCase .class , IfcWall .class , IfcWindow .class , IfcDoor .class , IfcSlab .class , IfcColumn .class };
121115
122116 try {
123117 boolean first = true ;
124- for (Class <? extends EObject > eClass : eClasses ) {
125- for (Object object : model .getAll (eClass )) {
118+ for (Class <? extends IdEObject > eClass : eClasses ) {
119+ for (IdEObject object : model .getAll (eClass )) {
126120 IfcProduct ifcRoot = (IfcProduct ) object ;
127121 SetGeometryResult geometry = getGeometry (ifcRoot );
128122 if (geometry != null ) {
@@ -135,33 +129,30 @@ private void writeGeometries() {
135129 }
136130 } catch (SerializerException e ) {
137131 LOGGER .error ("" , e );
138- } catch (IfcEngineException e ) {
139- LOGGER .error ("" , e );
140132 }
141133 }
142134
143- private SetGeometryResult getGeometry (IfcProduct ifcRootObject ) throws SerializerException , IfcEngineException {
144- BinaryIndexBuffer binaryIndexBuffer = new BinaryIndexBuffer ();
145- BinaryVertexBuffer binaryVertexBuffer = new BinaryVertexBuffer ();
146- int nrIndices = 0 ;
147- IfcEngineInstance instance = ifcEngineModel .getInstanceFromExpressId (ifcRootObject .getExpressId ());
148- IfcEngineInstanceVisualisationProperties visualisationProperties = instance .getVisualisationProperties ();
149- for (int i = visualisationProperties .getStartIndex (); i < visualisationProperties .getPrimitiveCount () * 3 + visualisationProperties .getStartIndex (); i += 3 ) {
150- binaryIndexBuffer .addIndex (geometry .getIndex (i ));
151- binaryIndexBuffer .addIndex (geometry .getIndex (i + 2 ));
152- binaryIndexBuffer .addIndex (geometry .getIndex (i + 1 ));
153- nrIndices ++;
154- }
155- for (int i = 0 ; i < geometry .getNrVertices (); i += 3 ) {
156- binaryVertexBuffer .addVertex (geometry .getVertex (i ));
157- binaryVertexBuffer .addVertex (geometry .getVertex (i + 1 ));
158- binaryVertexBuffer .addVertex (geometry .getVertex (i + 2 ));
159- }
160- for (int i = 0 ; i < geometry .getNrNormals (); i += 3 ) {
161- binaryVertexBuffer .addNormal (geometry .getNormal (i ));
162- binaryVertexBuffer .addNormal (geometry .getNormal (i + 1 ));
163- binaryVertexBuffer .addNormal (geometry .getNormal (i + 2 ));
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 );
164155 }
165- return new SetGeometryResult ( nrIndices * 3 , geometry . getNrVertices (), binaryIndexBuffer , binaryVertexBuffer ) ;
156+ return null ;
166157 }
167158}
0 commit comments