mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 19:30:25 +00:00
fix: ifcclash bcfxml export
This commit is contained in:
committed by
Dion Moult
parent
4ee3458ff9
commit
a4566797fe
@@ -22,8 +22,6 @@
|
||||
import numpy as np
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
import logging
|
||||
import multiprocessing
|
||||
import ifcopenshell
|
||||
import ifcopenshell.geom
|
||||
@@ -117,71 +115,22 @@ class Clasher:
|
||||
self.export_json()
|
||||
|
||||
def export_bcfxml(self):
|
||||
import bcf
|
||||
import bcf.v2.bcfxml
|
||||
from bcf.v2.bcfxml import BcfXml
|
||||
|
||||
for i, clash_set in enumerate(self.clash_sets):
|
||||
bcfxml = bcf.v2.bcfxml.BcfXml()
|
||||
bcfxml.new_project()
|
||||
bcfxml.project.name = clash_set["name"]
|
||||
bcfxml.edit_project()
|
||||
for key, clash in clash_set["clashes"].items():
|
||||
topic = bcf.v2.data.Topic()
|
||||
topic.title = "{}/{} and {}/{}".format(
|
||||
clash["a_ifc_class"], clash["a_name"], clash["b_ifc_class"], clash["b_name"]
|
||||
bcfxml = BcfXml.create_new(clash_set["name"])
|
||||
for clash in clash_set["clashes"].values():
|
||||
title = f'{clash["a_ifc_class"]}/{clash["a_name"]} and {clash["b_ifc_class"]}/{clash["b_name"]}'
|
||||
topic = bcfxml.add_topic(title, title, "IfcClash")
|
||||
topic.add_viewpoint_from_point_and_guids(
|
||||
np.array(clash["position"]), clash["a_global_id"], clash["b_global_id"],
|
||||
)
|
||||
topic = bcfxml.add_topic(topic)
|
||||
viewpoint = bcf.v2.data.Viewpoint()
|
||||
viewpoint.perspective_camera = bcf.v2.data.PerspectiveCamera()
|
||||
position = np.array(clash["position"])
|
||||
point = position + np.array((5, 5, 5)) # Dumb, but works (for now)!
|
||||
viewpoint.perspective_camera.camera_view_point.x = point[0]
|
||||
viewpoint.perspective_camera.camera_view_point.y = point[1]
|
||||
viewpoint.perspective_camera.camera_view_point.z = point[2]
|
||||
mat = self.get_track_to_matrix(point, position)
|
||||
viewpoint.perspective_camera.camera_direction.x = mat[0][2] * -1
|
||||
viewpoint.perspective_camera.camera_direction.y = mat[1][2] * -1
|
||||
viewpoint.perspective_camera.camera_direction.z = mat[2][2] * -1
|
||||
viewpoint.perspective_camera.camera_up_vector.x = mat[0][1]
|
||||
viewpoint.perspective_camera.camera_up_vector.y = mat[1][1]
|
||||
viewpoint.perspective_camera.camera_up_vector.z = mat[2][1]
|
||||
viewpoint.components = bcf.v2.data.Components()
|
||||
c1 = bcf.v2.data.Component()
|
||||
c1.ifc_guid = clash["a_global_id"]
|
||||
c2 = bcf.v2.data.Component()
|
||||
c2.ifc_guid = clash["b_global_id"]
|
||||
viewpoint.components.selection.append(c1)
|
||||
viewpoint.components.selection.append(c2)
|
||||
viewpoint.components.visibility = bcf.v2.data.ComponentVisibility()
|
||||
viewpoint.components.visibility.default_visibility = True
|
||||
viewpoint.snapshot = self.get_viewpoint_snapshot(viewpoint, mat)
|
||||
bcfxml.add_viewpoint(topic, viewpoint)
|
||||
if i == 0:
|
||||
bcfxml.save_project(self.settings.output)
|
||||
else:
|
||||
bcfxml.save_project(self.settings.output + f".{i}")
|
||||
suffix = f".{i}" if i else ""
|
||||
bcfxml.save_project(f"{self.settings.output}{suffix}")
|
||||
|
||||
def get_viewpoint_snapshot(self, viewpoint, mat):
|
||||
return None # Possible to overload this function in a GUI application if used as a library
|
||||
|
||||
# https://blender.stackexchange.com/questions/68834/recreate-to-track-quat-with-two-vectors-using-python/141706#141706
|
||||
def get_track_to_matrix(self, camera_position, target_position):
|
||||
camera_direction = camera_position - target_position
|
||||
camera_direction = camera_direction / np.linalg.norm(camera_direction)
|
||||
camera_right = np.cross(np.array([0.0, 0.0, 1.0]), camera_direction)
|
||||
camera_right = camera_right / np.linalg.norm(camera_right)
|
||||
camera_up = np.cross(camera_direction, camera_right)
|
||||
camera_up = camera_up / np.linalg.norm(camera_up)
|
||||
rotation_transform = np.zeros((4, 4))
|
||||
rotation_transform[0, :3] = camera_right
|
||||
rotation_transform[1, :3] = camera_up
|
||||
rotation_transform[2, :3] = camera_direction
|
||||
rotation_transform[-1, -1] = 1
|
||||
translation_transform = np.eye(4)
|
||||
translation_transform[:3, -1] = -camera_position
|
||||
look_at_transform = np.matmul(rotation_transform, translation_transform)
|
||||
return np.linalg.inv(look_at_transform)
|
||||
|
||||
def export_json(self):
|
||||
clash_sets = self.clash_sets.copy()
|
||||
for clash_set in clash_sets:
|
||||
|
||||
Reference in New Issue
Block a user