Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting faces to Unity style vertices + triangles? #37

Closed
daveime opened this issue Feb 17, 2017 · 4 comments
Closed

Converting faces to Unity style vertices + triangles? #37

daveime opened this issue Feb 17, 2017 · 4 comments

Comments

@daveime
Copy link

daveime commented Feb 17, 2017

I'm trying to convert each type of ShapeRepresentation into a format suitable for Unity i.e. meshes with vertices + triangles.

Right now I'm looking at the Extruded Area Solid, and can already convert this to an IXbimSolid that contains N Faces and N Vertices using :-

XbimGeometryEngine geom = new XbimGeometryEngine();
IXbimSolid solid = geom.CreateSolid((IIfcExtrudedAreaSolid)shape);

Now I note that each Face has an OuterBound which describes the outside edge, and 0..N InnerBounds which describe inner voids contained wholly inside the OuterBound that also don't overlap each other.

For clarification - can a Face only contain either 3 or 4 edges, or is there a possibility of more? Right now, I'm assuming only 3 or 4 edges, and the conversion of the OuterBound to 1 or 2 triangles is easy enough.

However, what happens when a face has one or more InnerBounds, that need to be cut out of the face while creating the triangle mesh?

Does the geometry library offer any functionality to do this conversion of Faces to a vertices + triangles type construct? And if not, what would you recommend in terms of 3rd party libraries that do offer this functionality?

@daveime
Copy link
Author

daveime commented Feb 17, 2017

EDIT: Ignore all the above, I'm an idiot. Okay, so I now worked out how to populate the models thus 👎

var context = new Xbim3DModelContext(model);
context.CreateContext();

And can now see all the shapes with cutouts and voids already applied with what appears to be vertices and triangle data inside the ShapeGeometries.ShapeData

So my question now is simply, how do I get the values back out of ShapeData ?

I can get the counts of the vertices and triangles thus
var tri = XbimShapeTriangulation.TriangleCount(((IXbimShapeGeometryData)item).ShapeData);
var vert = XbimShapeTriangulation.VerticesCount(((IXbimShapeGeometryData)item).ShapeData);

But how do I get the individual values for each triangle and vertex?

I can see the basic storage mechanism for the vertices and triangles inside the binary blob, but surely there must be a built-in method in the library to avoid all this low level hacking?

@CBenghi
Copy link
Member

CBenghi commented Apr 27, 2017

@daveime,
you are right, we have been quite brainiacs (derogatory use) about this.
I'll see if this can be rectified.
Thanks for the feedback.

@thorade
Copy link

thorade commented Sep 8, 2017

I would be interrested in the same and am unsure what the comment means: Is this already easily possible and just not well documented, or this this a feature that might be added in the future?

@daveime
Copy link
Author

daveime commented Sep 16, 2017

@thorade It is possible but requires some custom code - there's nothing built in to the XbimShapeTriangulation class to convert the binary ShapeData blob back into vertices, triangles and normals.

If you're interested, check out http://marikinacgi.com/XBIM/convert.txt

The function takes the shapedata as a byte[] array, references to the lists of vertices, triangles and normals you want to extract, an XbimMatrix3D matrix to convert the points directly to world coordinates, and a double onemeter which can be parsed from the model data so that the points are expressed in meters.

@CBenghi if you're interested to add this to the XbimShapeTriangulation class or just add to the documentation as an example of how to parse the data, please feel free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants