light module true_north prop - use Blender angle subtype

This commit is contained in:
Andrej730
2025-06-23 18:43:59 +05:00
parent f684a6058c
commit c1e6e7d736
3 changed files with 9 additions and 8 deletions
@@ -22,7 +22,7 @@ import gpu
import bmesh import bmesh
import bonsai.tool as tool import bonsai.tool as tool
from bpy.types import SpaceView3D from bpy.types import SpaceView3D
from math import radians from math import radians, degrees
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from gpu_extras.batch import batch_for_shader from gpu_extras.batch import batch_for_shader
from bpy_extras.view3d_utils import location_3d_to_region_2d from bpy_extras.view3d_utils import location_3d_to_region_2d
@@ -72,7 +72,7 @@ class SolarDecorator:
self.draw_text_at_position(context, f"{props.hour:02}:{props.minute:02}", location) self.draw_text_at_position(context, f"{props.hour:02}:{props.minute:02}", location)
self.tn_angle = props.true_north self.tn_angle = props.true_north
angle = Matrix.Rotation(radians(self.tn_angle), 4, "Z") angle = Matrix.Rotation(props.true_north, 4, "Z")
grid_north_p = origin @ angle @ (Vector((0, 0.8, 0)) * props.sun_path_size) grid_north_p = origin @ angle @ (Vector((0, 0.8, 0)) * props.sun_path_size)
self.draw_text_at_position(context, "True North", grid_north_p) self.draw_text_at_position(context, "True North", grid_north_p)
@@ -155,13 +155,13 @@ class SolarDecorator:
# True north # True north
self.tn_angle = props.true_north self.tn_angle = props.true_north
points = [Vector((0, 0, 0)), Vector((0, 0.75, 0))] points = [Vector((0, 0, 0)), Vector((0, 0.75, 0))]
angle = Matrix.Rotation(radians(self.tn_angle), 4, "Z") angle = Matrix.Rotation(self.tn_angle, 4, "Z")
points = [origin @ angle @ (v * props.sun_path_size) for v in points] points = [origin @ angle @ (v * props.sun_path_size) for v in points]
self.draw_batch("POINTS", points, decorator_color_special) self.draw_batch("POINTS", points, decorator_color_special)
verts = [Vector((0, 0, 0)), Vector((0, 0.75, 0))] verts = [Vector((0, 0, 0)), Vector((0, 0.75, 0))]
edges = [[0, 1]] edges = [[0, 1]]
angle = Matrix.Rotation(radians(self.tn_angle), 4, "Z") angle = Matrix.Rotation(self.tn_angle, 4, "Z")
verts = [origin @ angle @ (v * props.sun_path_size) for v in verts] verts = [origin @ angle @ (v * props.sun_path_size) for v in verts]
self.draw_batch("LINES", verts, decorator_color_special, edges) self.draw_batch("LINES", verts, decorator_color_special, edges)
@@ -174,7 +174,7 @@ class SolarDecorator:
arc_start = Vector((0, 0.25, 0)) * props.sun_path_size arc_start = Vector((0, 0.25, 0)) * props.sun_path_size
arc_end = angle @ arc_start arc_end = angle @ arc_start
angle_half = Matrix.Rotation(radians(self.tn_angle / 2), 4, "Z") angle_half = Matrix.Rotation(self.tn_angle / 2, 4, "Z")
arc_mid = angle_half @ arc_start arc_mid = angle_half @ arc_start
arc_segments = tool.Cad.create_arc_segments( arc_segments = tool.Cad.create_arc_segments(
pts=[origin @ v for v in [arc_start, arc_mid, arc_end]], num_verts=12, make_edges=True pts=[origin @ v for v in [arc_start, arc_mid, arc_end]], num_verts=12, make_edges=True
@@ -38,6 +38,7 @@ import webbrowser
import ifcopenshell.geom import ifcopenshell.geom
import multiprocessing import multiprocessing
import requests import requests
from math import radians
from mathutils import Vector from mathutils import Vector
from bonsai.bim.module.light.data import SolarData from bonsai.bim.module.light.data import SolarData
from bpy_extras.io_utils import ExportHelper from bpy_extras.io_utils import ExportHelper
@@ -512,7 +513,7 @@ class ImportTrueNorth(bpy.types.Operator):
if not context.TrueNorth: if not context.TrueNorth:
continue continue
value = context.TrueNorth.DirectionRatios value = context.TrueNorth.DirectionRatios
props.true_north = ifcopenshell.util.geolocation.yaxis2angle(*value[:2]) props.true_north = radians(ifcopenshell.util.geolocation.yaxis2angle(*value[:2]))
return {"FINISHED"} return {"FINISHED"}
+2 -2
View File
@@ -151,7 +151,7 @@ def update_sun_path(self: "BIMSolarProperties") -> None:
sun_props.day = self.day sun_props.day = self.day
sun_props.time = self.hour + (self.minute / 60) sun_props.time = self.hour + (self.minute / 60)
# Preserve IFC sign convention # Preserve IFC sign convention
sun_props.north_offset = radians(self.true_north * -1) sun_props.north_offset = self.true_north * -1
props.timezone = tzfpy.get_tz(props.longitude, props.latitude) props.timezone = tzfpy.get_tz(props.longitude, props.latitude)
timezone = pytz.timezone(props.timezone) timezone = pytz.timezone(props.timezone)
@@ -457,7 +457,7 @@ class BIMSolarProperties(PropertyGroup):
default=151.209900, default=151.209900,
) )
timezone: StringProperty(name="Timezone", default="Etc/GMT") timezone: StringProperty(name="Timezone", default="Etc/GMT")
true_north: FloatProperty(name="True North", min=-180, max=180, update=update_true_north) true_north: FloatProperty(name="True North", min=-pi, max=pi, subtype="ANGLE", update=update_true_north)
year: IntProperty(name="Year", min=1, max=9999, default=now.year, update=update_date) year: IntProperty(name="Year", min=1, max=9999, default=now.year, update=update_date)
month: IntProperty(name="Month", min=1, max=12, default=now.month, update=update_date) month: IntProperty(name="Month", min=1, max=12, default=now.month, update=update_date)
day: IntProperty(name="Date", min=1, max=31, default=now.day, update=update_date) day: IntProperty(name="Date", min=1, max=31, default=now.day, update=update_date)