Visualisation of WCS now takes into account blender session offsets

This commit is contained in:
Dion Moult
2024-07-25 23:34:23 +10:00
parent 59a3c019a4
commit 33e188b321
2 changed files with 38 additions and 26 deletions
@@ -21,7 +21,7 @@ import bpy
import numpy as np import numpy as np
import blenderbim.tool as tool import blenderbim.tool as tool
import ifcopenshell.util.geolocation import ifcopenshell.util.geolocation
from mathutils import Matrix from mathutils import Matrix, Vector
from ifcopenshell.util.doc import get_entity_doc from ifcopenshell.util.doc import get_entity_doc
@@ -162,6 +162,25 @@ class GeoreferenceData:
result["has_transformation"] = True result["has_transformation"] = True
result["rotation"] = str(round(ifcopenshell.util.geolocation.yaxis2angle(*wcs[:, 1][:2]), 3)) result["rotation"] = str(round(ifcopenshell.util.geolocation.yaxis2angle(*wcs[:, 1][:2]), 3))
result["x"], result["y"], result["z"] = wcs[:, 3][:3] result["x"], result["y"], result["z"] = wcs[:, 3][:3]
props = bpy.context.scene.BIMGeoreferenceProperties
if props.has_blender_offset:
blender_xyz = ifcopenshell.util.geolocation.xyz2enh(
result["x"],
result["y"],
result["z"],
float(props.blender_offset_x),
float(props.blender_offset_y),
float(props.blender_offset_z),
float(props.blender_x_axis_abscissa),
float(props.blender_x_axis_ordinate),
)
else:
blender_xyz = wcs[:, 3][:3]
result["blender_x"], result["blender_y"], result["blender_z"] = blender_xyz
result["blender_location"] = Vector([co * unit_scale for co in blender_xyz])
wcs[0][3] *= unit_scale wcs[0][3] *= unit_scale
wcs[1][3] *= unit_scale wcs[1][3] *= unit_scale
wcs[2][3] *= unit_scale wcs[2][3] *= unit_scale
@@ -62,10 +62,6 @@ class GeoreferenceDecorator:
props = context.scene.BIMGeoreferenceProperties props = context.scene.BIMGeoreferenceProperties
e, n, h = [round(float(o), 7) for o in props.model_origin.split(",")] e, n, h = [round(float(o), 7) for o in props.model_origin.split(",")]
wcs_matrix = None
if GeoreferenceData.data["world_coordinate_system"]["has_transformation"]:
wcs_matrix = GeoreferenceData.data["world_coordinate_system"]["matrix"]
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 0 self.font_id = 0
@@ -75,7 +71,7 @@ class GeoreferenceDecorator:
blf.enable(self.font_id, blf.SHADOW) blf.enable(self.font_id, blf.SHADOW)
blf.shadow(self.font_id, 6, 0, 0, 0, 1) blf.shadow(self.font_id, 6, 0, 0, 0, 1)
text = "Blender Coordinates X: 0, Y: 0, Z: 0" text = f"Blender Coordinates ({GeoreferenceData.data['local_unit_symbol']}) X: 0, Y: 0, Z: 0"
text += f"\nLocal Coordinates ({GeoreferenceData.data['local_unit_symbol']}) X: {props.blender_offset_x}, Y: {props.blender_offset_y}, Z: {props.blender_offset_z}" text += f"\nLocal Coordinates ({GeoreferenceData.data['local_unit_symbol']}) X: {props.blender_offset_x}, Y: {props.blender_offset_y}, Z: {props.blender_offset_z}"
if GeoreferenceData.data["projected_crs"]: if GeoreferenceData.data["projected_crs"]:
text += f"\nMap Coordinates ({GeoreferenceData.data['local_unit_symbol']}) E: {e}, N: {n}, H: {h}" text += f"\nMap Coordinates ({GeoreferenceData.data['local_unit_symbol']}) E: {e}, N: {n}, H: {h}"
@@ -111,20 +107,20 @@ class GeoreferenceDecorator:
arc_mid = angle_half @ arc_start arc_mid = angle_half @ arc_start
self.draw_text_at_position(context, f"{self.tn_angle}deg", arc_mid) self.draw_text_at_position(context, f"{self.tn_angle}deg", arc_mid)
if wcs_matrix: if (wcs := GeoreferenceData.data["world_coordinate_system"]) and ["has_transformation"]:
x, y, z = wcs_matrix.translation text = "WCS"
text += f"\nBlender Coordinates ({GeoreferenceData.data['local_unit_symbol']}) X: {wcs['blender_x']}, Y: {wcs['blender_y']}, Z: {wcs['blender_z']}"
text += f"\nLocal Coordinates ({GeoreferenceData.data['local_unit_symbol']}) X: {wcs['x']}, Y: {wcs['y']}, Z: {wcs['z']}"
if operation := GeoreferenceData.data["coordinate_operation"]: if operation := GeoreferenceData.data["coordinate_operation"]:
e = operation.get("Eastings") e = operation.get("Eastings")
n = operation.get("Northings") n = operation.get("Northings")
h = operation.get("OrthogonalHeight") h = operation.get("OrthogonalHeight")
text = f"WCS\n X: {x}, Y: {y}, Z: {z}\nE: {e}, N: {n}, H: {h}" text += f"\nMap Coordinates ({GeoreferenceData.data['map_unit_symbol']}) E: {e}, N: {n}, H: {h}"
else:
text = f"WCS\n X: {x}, Y: {y}, Z: {z}"
if wcs_matrix.translation.length < 1000: if wcs["blender_location"].length < 1000:
position = wcs_matrix.translation.copy() position = wcs["blender_location"].copy()
else: else:
position = wcs_matrix.translation.normalized() * 3 position = wcs["blender_location"].normalized() * 3
text += "\n(Warning: Actual XYZ Not Shown)" text += "\n(Warning: Actual XYZ Not Shown)"
position -= Vector((0, 0.1, 0)) position -= Vector((0, 0.1, 0))
@@ -144,10 +140,6 @@ class GeoreferenceDecorator:
def draw_geometry(self, context): def draw_geometry(self, context):
self.calculate_angles(context) self.calculate_angles(context)
wcs_matrix = None
if GeoreferenceData.data["world_coordinate_system"]["has_transformation"]:
wcs_matrix = GeoreferenceData.data["world_coordinate_system"]["matrix"]
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
decorator_color = self.addon_prefs.decorations_colour decorator_color = self.addon_prefs.decorations_colour
decorator_color_special = self.addon_prefs.decorator_color_special decorator_color_special = self.addon_prefs.decorator_color_special
@@ -263,23 +255,24 @@ class GeoreferenceDecorator:
verts, edges = arc_segments verts, edges = arc_segments
self.draw_batch("LINES", verts, decorator_color_special, edges) self.draw_batch("LINES", verts, decorator_color_special, edges)
if wcs_matrix: if (wcs := GeoreferenceData.data["world_coordinate_system"]) and ["has_transformation"]:
if wcs_matrix.translation.length < 1000:
verts = [Vector((0, 0, 0)), wcs_matrix.translation] if wcs["blender_location"].length < 1000:
verts = [Vector((0, 0, 0)), wcs["blender_location"]]
edges = [[0, 1]] edges = [[0, 1]]
self.draw_batch("LINES", verts, decorator_color_special, edges) self.draw_batch("LINES", verts, decorator_color_special, edges)
self.draw_batch("POINTS", verts[1:], decorator_color_special) self.draw_batch("POINTS", verts[1:], decorator_color_special)
else: else:
edges = [[0, 1]] edges = [[0, 1]]
verts = [Vector((0, 0, 0)), wcs_matrix.translation.normalized() * 3] verts = [Vector((0, 0, 0)), wcs["blender_location"].normalized() * 3]
self.draw_batch("LINES", verts, decorator_color_special, edges) self.draw_batch("LINES", verts, decorator_color_special, edges)
verts = [wcs_matrix.translation.normalized() * 3, wcs_matrix.translation.normalized() * 3.1] verts = [wcs["blender_location"].normalized() * 3, wcs["blender_location"].normalized() * 3.1]
self.draw_batch("LINES", verts, decorator_color_error, edges) self.draw_batch("LINES", verts, decorator_color_error, edges)
verts = [wcs_matrix.translation.normalized() * 3.12, wcs_matrix.translation.normalized() * 3.2] verts = [wcs["blender_location"].normalized() * 3.12, wcs["blender_location"].normalized() * 3.2]
self.draw_batch("LINES", verts, decorator_color_error, edges) self.draw_batch("LINES", verts, decorator_color_error, edges)
verts = [wcs_matrix.translation.normalized() * 3.22, wcs_matrix.translation.normalized() * 3.3] verts = [wcs["blender_location"].normalized() * 3.22, wcs["blender_location"].normalized() * 3.3]
self.draw_batch("LINES", verts, decorator_color_error, edges) self.draw_batch("LINES", verts, decorator_color_error, edges)
verts = [wcs_matrix.translation.normalized() * 3.32, wcs_matrix.translation.normalized() * 3.4] verts = [wcs["blender_location"].normalized() * 3.32, wcs["blender_location"].normalized() * 3.4]
self.draw_batch("LINES", verts, decorator_color_error, edges) self.draw_batch("LINES", verts, decorator_color_error, edges)
def calculate_angles(self, context): def calculate_angles(self, context):