mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Allow generated mesh representations such as bounding box
This commit is contained in:
@@ -444,28 +444,44 @@ class IfcParser():
|
|||||||
or object.data.name in results:
|
or object.data.name in results:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.is_mesh_context_sensitive(object.data.name):
|
self.append_default_representation(object, results)
|
||||||
context = self.get_ifc_context(object.data.name)
|
self.append_representation_per_context(object, results)
|
||||||
name = self.get_ifc_representation_name(object.data.name)
|
self.append_generated_representation_per_context(object, results)
|
||||||
for subcontext in self.ifc_export_settings.subcontexts:
|
|
||||||
try:
|
|
||||||
mesh = bpy.data.meshes['/'.join([context, subcontext, name])]
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
results[mesh.name] = self.get_representation(
|
|
||||||
mesh, context, subcontext)
|
|
||||||
else:
|
|
||||||
results['Model/Body/{}'.format(object.data.name)] = self.get_representation(
|
|
||||||
object.data, 'Model', 'Body')
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def get_representation(self, mesh, context, subcontext):
|
def append_default_representation(self, object, results):
|
||||||
|
if not self.is_mesh_context_sensitive(object.data.name):
|
||||||
|
results['Model/Body/{}'.format(object.data.name)] = self.get_representation(
|
||||||
|
object.data, 'Model', 'Body')
|
||||||
|
|
||||||
|
def append_representation_per_context(self, object, results):
|
||||||
|
context = self.get_ifc_context(object.data.name)
|
||||||
|
name = self.get_ifc_representation_name(object.data.name)
|
||||||
|
for subcontext in self.ifc_export_settings.subcontexts:
|
||||||
|
try:
|
||||||
|
mesh = bpy.data.meshes['/'.join([context, subcontext, name])]
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
results[mesh.name] = self.get_representation(
|
||||||
|
mesh, context, subcontext)
|
||||||
|
|
||||||
|
def append_generated_representation_per_context(self, object, results):
|
||||||
|
context = self.get_ifc_context(object.data.name)
|
||||||
|
name = self.get_ifc_representation_name(object.data.name)
|
||||||
|
for subcontext in self.ifc_export_settings.generated_subcontexts:
|
||||||
|
representation = self.get_representation(
|
||||||
|
object, context, subcontext, is_generated=True)
|
||||||
|
representation['raw_object'] = object
|
||||||
|
results['/'.join([context, subcontext, name])] = representation
|
||||||
|
|
||||||
|
def get_representation(self, mesh, context, subcontext, is_generated=False):
|
||||||
return {
|
return {
|
||||||
'ifc': None,
|
'ifc': None,
|
||||||
'raw': mesh,
|
'raw': mesh,
|
||||||
'context': context,
|
'context': context,
|
||||||
'subcontext': subcontext,
|
'subcontext': subcontext,
|
||||||
'is_wireframe': True if 'IsWireframe' in mesh else False,
|
'is_wireframe': True if 'IsWireframe' in mesh else False,
|
||||||
|
'is_generated': is_generated,
|
||||||
'attributes': { 'Name': mesh.name }
|
'attributes': { 'Name': mesh.name }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +582,7 @@ class IfcParser():
|
|||||||
if not object.data:
|
if not object.data:
|
||||||
return names
|
return names
|
||||||
if not self.is_mesh_context_sensitive(object.data.name):
|
if not self.is_mesh_context_sensitive(object.data.name):
|
||||||
return ['Model/Body/{}'.format(object.data.name)]
|
names.append('Model/Body/{}'.format(object.data.name))
|
||||||
for subcontext in self.ifc_export_settings.subcontexts:
|
for subcontext in self.ifc_export_settings.subcontexts:
|
||||||
try:
|
try:
|
||||||
mesh = bpy.data.meshes['/'.join([
|
mesh = bpy.data.meshes['/'.join([
|
||||||
@@ -576,6 +592,8 @@ class IfcParser():
|
|||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
names.append(mesh.name)
|
names.append(mesh.name)
|
||||||
|
for subcontext in self.ifc_export_settings.generated_subcontexts:
|
||||||
|
names.append('Model/{}/{}'.format(subcontext, self.get_ifc_representation_name(object.data.name)))
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def get_spatial_structure_elements_tree(self, collections, name_filter):
|
def get_spatial_structure_elements_tree(self, collections, name_filter):
|
||||||
@@ -798,7 +816,8 @@ class IfcExporter():
|
|||||||
self.ifc_rep_context['Plan'] = {
|
self.ifc_rep_context['Plan'] = {
|
||||||
'ifc': self.file.createIfcGeometricRepresentationContext(
|
'ifc': self.file.createIfcGeometricRepresentationContext(
|
||||||
None, 'Plan', 2, 1.0E-05, self.origin)}
|
None, 'Plan', 2, 1.0E-05, self.origin)}
|
||||||
for subcontext in self.ifc_export_settings.subcontexts:
|
for subcontext in (self.ifc_export_settings.subcontexts +
|
||||||
|
self.ifc_export_settings.generated_subcontexts):
|
||||||
self.ifc_rep_context['Model'][subcontext] = {
|
self.ifc_rep_context['Model'][subcontext] = {
|
||||||
'ifc': self.file.createIfcGeometricRepresentationSubContext(
|
'ifc': self.file.createIfcGeometricRepresentationSubContext(
|
||||||
subcontext, 'Model',
|
subcontext, 'Model',
|
||||||
@@ -1021,11 +1040,25 @@ class IfcExporter():
|
|||||||
self.ifc_vertices = []
|
self.ifc_vertices = []
|
||||||
self.ifc_edges = []
|
self.ifc_edges = []
|
||||||
self.ifc_faces = []
|
self.ifc_faces = []
|
||||||
if representation['context'] == 'Plan' \
|
if representation['is_generated']:
|
||||||
|
if representation['subcontext'] == 'Box':
|
||||||
|
return self.create_box_representation(representation)
|
||||||
|
elif representation['context'] == 'Plan' \
|
||||||
or representation['subcontext'] == 'Axis' \
|
or representation['subcontext'] == 'Axis' \
|
||||||
or representation['is_wireframe']:
|
or representation['is_wireframe']:
|
||||||
return self.create_wireframe_representation(representation)
|
return self.create_wireframe_representation(representation)
|
||||||
return self.create_solid_representation(representation)
|
else:
|
||||||
|
return self.create_solid_representation(representation)
|
||||||
|
|
||||||
|
def create_box_representation(self, representation):
|
||||||
|
object = representation['raw_object']
|
||||||
|
bounding_box = self.file.createIfcBoundingBox(
|
||||||
|
self.create_cartesian_point(
|
||||||
|
object.bound_box[0][0], object.bound_box[0][1], object.bound_box[0][2]),
|
||||||
|
object.dimensions[0], object.dimensions[1], object.dimensions[2])
|
||||||
|
return self.file.createIfcShapeRepresentation(
|
||||||
|
self.ifc_rep_context[representation['context']][representation['subcontext']]['ifc'],
|
||||||
|
representation['subcontext'], 'BoundingBox', [bounding_box])
|
||||||
|
|
||||||
def create_wireframe_representation(self, representation):
|
def create_wireframe_representation(self, representation):
|
||||||
mesh = representation['raw']
|
mesh = representation['raw']
|
||||||
@@ -1053,8 +1086,11 @@ class IfcExporter():
|
|||||||
|
|
||||||
def create_vertices(self, vertices):
|
def create_vertices(self, vertices):
|
||||||
for vertice in vertices:
|
for vertice in vertices:
|
||||||
self.ifc_vertices.append(
|
self.ifc_vertices.append(self.create_cartesian_point(
|
||||||
self.file.createIfcCartesianPoint((vertice.co.x, vertice.co.y, vertice.co.z)))
|
vertice.co.x, vertice.co.y, vertice.co.z))
|
||||||
|
|
||||||
|
def create_cartesian_point(self, x, y, z):
|
||||||
|
return self.file.createIfcCartesianPoint((x, y, z))
|
||||||
|
|
||||||
def relate_elements_to_spatial_structures(self):
|
def relate_elements_to_spatial_structures(self):
|
||||||
for relating_structure, related_elements in self.ifc_parser.rel_contained_in_spatial_structure.items():
|
for relating_structure, related_elements in self.ifc_parser.rel_contained_in_spatial_structure.items():
|
||||||
@@ -1117,6 +1153,7 @@ class IfcExportSettings:
|
|||||||
self.has_representations = True
|
self.has_representations = True
|
||||||
self.has_quantities = True
|
self.has_quantities = True
|
||||||
self.subcontexts = ['Axis', 'FootPrint', 'Reference', 'Body', 'Clearance']
|
self.subcontexts = ['Axis', 'FootPrint', 'Reference', 'Body', 'Clearance']
|
||||||
|
self.generated_subcontexts = ['Box']
|
||||||
|
|
||||||
print('# Starting export')
|
print('# Starting export')
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user