io_scene_3ds: Update for Blender 3.x #104511
@ -3,7 +3,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "3D-Print Toolbox",
|
"name": "3D-Print Toolbox",
|
||||||
"author": "Campbell Barton",
|
"author": "Campbell Barton",
|
||||||
"blender": (3, 0, 0),
|
"blender": (3, 6, 0),
|
||||||
"location": "3D View > Sidebar",
|
"location": "3D View > Sidebar",
|
||||||
"description": "Utilities for 3D printing",
|
"description": "Utilities for 3D printing",
|
||||||
"doc_url": "{BLENDER_MANUAL_URL}/addons/mesh/3d_print_toolbox.html",
|
"doc_url": "{BLENDER_MANUAL_URL}/addons/mesh/3d_print_toolbox.html",
|
||||||
|
@ -79,7 +79,8 @@ def write_mesh(context, report_cb):
|
|||||||
name = data_("untitled")
|
name = data_("untitled")
|
||||||
|
|
||||||
# add object name
|
# add object name
|
||||||
name += f"-{bpy.path.clean_name(obj.name)}"
|
import re
|
||||||
|
name += "-" + re.sub(r'[\\/:*?"<>|]', "", obj.name)
|
||||||
|
|
||||||
# first ensure the path is created
|
# first ensure the path is created
|
||||||
if export_path:
|
if export_path:
|
||||||
@ -113,17 +114,16 @@ def write_mesh(context, report_cb):
|
|||||||
global_scale=global_scale,
|
global_scale=global_scale,
|
||||||
)
|
)
|
||||||
elif export_format == 'PLY':
|
elif export_format == 'PLY':
|
||||||
addon_ensure("io_mesh_ply")
|
|
||||||
filepath = bpy.path.ensure_ext(filepath, ".ply")
|
filepath = bpy.path.ensure_ext(filepath, ".ply")
|
||||||
ret = bpy.ops.export_mesh.ply(
|
ret = bpy.ops.wm.ply_export(
|
||||||
filepath=filepath,
|
filepath=filepath,
|
||||||
use_ascii=False,
|
ascii_format=False,
|
||||||
use_mesh_modifiers=True,
|
apply_modifiers=True,
|
||||||
use_selection=True,
|
export_selected_objects=True,
|
||||||
global_scale=global_scale,
|
global_scale=global_scale,
|
||||||
use_normals=export_data_layers,
|
export_normals=export_data_layers,
|
||||||
use_uv_coords=export_data_layers,
|
export_uv=export_data_layers,
|
||||||
use_colors=export_data_layers,
|
export_colors="SRGB" if export_data_layers else "NONE",
|
||||||
)
|
)
|
||||||
elif export_format == 'X3D':
|
elif export_format == 'X3D':
|
||||||
addon_ensure("io_scene_x3d")
|
addon_ensure("io_scene_x3d")
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "Sun Position",
|
"name": "Sun Position",
|
||||||
"author": "Michael Martin, Damien Picard",
|
"author": "Michael Martin, Damien Picard",
|
||||||
"version": (3, 3, 1),
|
"version": (3, 3, 3),
|
||||||
"blender": (3, 0, 0),
|
"blender": (3, 0, 0),
|
||||||
"location": "World > Sun Position",
|
"location": "World > Sun Position",
|
||||||
"description": "Show sun position with objects and/or sky texture",
|
"description": "Show sun position with objects and/or sky texture",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
# Copyright 2010 Maximilian Hoegner <hp.maxi@hoegners.de>.
|
# Copyright 2010 Maximilian Hoegner <hp.maxi@hoegners.de>.
|
||||||
|
|
||||||
# geo.py is a python module with no dependencies on extra packages,
|
# geo.py is a python module with no dependencies on extra packages,
|
||||||
|
@ -86,14 +86,14 @@ class SunPosProperties(PropertyGroup):
|
|||||||
description="Time at which the Sun rises",
|
description="Time at which the Sun rises",
|
||||||
soft_min=0.0, soft_max=24.0,
|
soft_min=0.0, soft_max=24.0,
|
||||||
default=0.0,
|
default=0.0,
|
||||||
get=lambda _: sun.sunrise.time)
|
get=lambda _: sun.sunrise)
|
||||||
|
|
||||||
sunset_time: FloatProperty(
|
sunset_time: FloatProperty(
|
||||||
name="Sunset Time",
|
name="Sunset Time",
|
||||||
description="Time at which the Sun sets",
|
description="Time at which the Sun sets",
|
||||||
soft_min=0.0, soft_max=24.0,
|
soft_min=0.0, soft_max=24.0,
|
||||||
default=0.0,
|
default=0.0,
|
||||||
get=lambda _: sun.sunset.time)
|
get=lambda _: sun.sunset)
|
||||||
|
|
||||||
sun_azimuth: FloatProperty(
|
sun_azimuth: FloatProperty(
|
||||||
name="Sun Azimuth",
|
name="Sun Azimuth",
|
||||||
|
@ -16,21 +16,14 @@ class SunInfo:
|
|||||||
"""
|
"""
|
||||||
Store intermediate sun calculations
|
Store intermediate sun calculations
|
||||||
"""
|
"""
|
||||||
class TAzEl:
|
|
||||||
time = 0.0
|
|
||||||
azimuth = 0.0
|
|
||||||
elevation = 0.0
|
|
||||||
|
|
||||||
class CLAMP:
|
class SunBind:
|
||||||
azimuth = 0.0
|
azimuth = 0.0
|
||||||
elevation = 0.0
|
elevation = 0.0
|
||||||
az_start_sun = 0.0
|
az_start_sun = 0.0
|
||||||
az_start_env = 0.0
|
az_start_env = 0.0
|
||||||
|
|
||||||
sunrise = TAzEl()
|
bind = SunBind()
|
||||||
sunset = TAzEl()
|
|
||||||
|
|
||||||
bind = CLAMP()
|
|
||||||
bind_to_sun = False
|
bind_to_sun = False
|
||||||
|
|
||||||
latitude = 0.0
|
latitude = 0.0
|
||||||
@ -38,6 +31,9 @@ class SunInfo:
|
|||||||
elevation = 0.0
|
elevation = 0.0
|
||||||
azimuth = 0.0
|
azimuth = 0.0
|
||||||
|
|
||||||
|
sunrise = 0.0
|
||||||
|
sunset = 0.0
|
||||||
|
|
||||||
month = 0
|
month = 0
|
||||||
day = 0
|
day = 0
|
||||||
year = 0
|
year = 0
|
||||||
@ -86,8 +82,6 @@ def move_sun(context):
|
|||||||
addon_prefs = context.preferences.addons[__package__].preferences
|
addon_prefs = context.preferences.addons[__package__].preferences
|
||||||
sun_props = context.scene.sun_pos_properties
|
sun_props = context.scene.sun_pos_properties
|
||||||
|
|
||||||
north_offset = sun_props.north_offset
|
|
||||||
|
|
||||||
if sun_props.usage_mode == "HDR":
|
if sun_props.usage_mode == "HDR":
|
||||||
nt = context.scene.world.node_tree.nodes
|
nt = context.scene.world.node_tree.nodes
|
||||||
env_tex = nt.get(sun_props.hdr_texture)
|
env_tex = nt.get(sun_props.hdr_texture)
|
||||||
@ -106,8 +100,7 @@ def move_sun(context):
|
|||||||
if sun_props.sun_object:
|
if sun_props.sun_object:
|
||||||
obj = sun_props.sun_object
|
obj = sun_props.sun_object
|
||||||
obj.location = get_sun_vector(
|
obj.location = get_sun_vector(
|
||||||
sun_props.hdr_azimuth, sun_props.hdr_elevation,
|
sun_props.hdr_azimuth, sun_props.hdr_elevation) * sun_props.sun_distance
|
||||||
north_offset) * sun_props.sun_distance
|
|
||||||
|
|
||||||
rotation_euler = Euler((sun_props.hdr_elevation - pi/2,
|
rotation_euler = Euler((sun_props.hdr_elevation - pi/2,
|
||||||
0, -sun_props.hdr_azimuth))
|
0, -sun_props.hdr_azimuth))
|
||||||
@ -129,14 +122,16 @@ def move_sun(context):
|
|||||||
local_time, sun_props.latitude, sun_props.longitude,
|
local_time, sun_props.latitude, sun_props.longitude,
|
||||||
zone, sun_props.month, sun_props.day, sun_props.year,
|
zone, sun_props.month, sun_props.day, sun_props.year,
|
||||||
sun_props.sun_distance)
|
sun_props.sun_distance)
|
||||||
|
|
||||||
sun.azimuth = azimuth
|
sun.azimuth = azimuth
|
||||||
sun.elevation = elevation
|
sun.elevation = elevation
|
||||||
|
sun_vector = get_sun_vector(azimuth, elevation)
|
||||||
|
|
||||||
if sun_props.sky_texture:
|
if sun_props.sky_texture:
|
||||||
sky_node = bpy.context.scene.world.node_tree.nodes.get(sun_props.sky_texture)
|
sky_node = bpy.context.scene.world.node_tree.nodes.get(sun_props.sky_texture)
|
||||||
if sky_node is not None and sky_node.type == "TEX_SKY":
|
if sky_node is not None and sky_node.type == "TEX_SKY":
|
||||||
sky_node.texture_mapping.rotation.z = 0.0
|
sky_node.texture_mapping.rotation.z = 0.0
|
||||||
sky_node.sun_direction = get_sun_vector(azimuth, elevation, north_offset)
|
sky_node.sun_direction = sun_vector
|
||||||
sky_node.sun_elevation = elevation
|
sky_node.sun_elevation = elevation
|
||||||
sky_node.sun_rotation = azimuth
|
sky_node.sun_rotation = azimuth
|
||||||
|
|
||||||
@ -144,7 +139,7 @@ def move_sun(context):
|
|||||||
if (sun_props.sun_object is not None
|
if (sun_props.sun_object is not None
|
||||||
and sun_props.sun_object.name in context.view_layer.objects):
|
and sun_props.sun_object.name in context.view_layer.objects):
|
||||||
obj = sun_props.sun_object
|
obj = sun_props.sun_object
|
||||||
obj.location = get_sun_vector(azimuth, elevation, north_offset) * sun_props.sun_distance
|
obj.location = sun_vector * sun_props.sun_distance
|
||||||
rotation_euler = Euler((elevation - pi/2, 0, -azimuth))
|
rotation_euler = Euler((elevation - pi/2, 0, -azimuth))
|
||||||
set_sun_rotations(obj, rotation_euler)
|
set_sun_rotations(obj, rotation_euler)
|
||||||
|
|
||||||
@ -166,7 +161,7 @@ def move_sun(context):
|
|||||||
sun_props.longitude, zone,
|
sun_props.longitude, zone,
|
||||||
sun_props.month, sun_props.day,
|
sun_props.month, sun_props.day,
|
||||||
sun_props.year, sun_props.sun_distance)
|
sun_props.year, sun_props.sun_distance)
|
||||||
obj.location = get_sun_vector(azimuth, elevation, north_offset) * sun_props.sun_distance
|
obj.location = get_sun_vector(azimuth, elevation) * sun_props.sun_distance
|
||||||
local_time -= time_increment
|
local_time -= time_increment
|
||||||
obj.rotation_euler = ((elevation - pi/2, 0, -azimuth))
|
obj.rotation_euler = ((elevation - pi/2, 0, -azimuth))
|
||||||
else:
|
else:
|
||||||
@ -181,7 +176,7 @@ def move_sun(context):
|
|||||||
sun_props.longitude, zone,
|
sun_props.longitude, zone,
|
||||||
dt.month, dt.day, sun_props.year,
|
dt.month, dt.day, sun_props.year,
|
||||||
sun_props.sun_distance)
|
sun_props.sun_distance)
|
||||||
obj.location = get_sun_vector(azimuth, elevation, north_offset) * sun_props.sun_distance
|
obj.location = get_sun_vector(azimuth, elevation) * sun_props.sun_distance
|
||||||
day -= day_increment
|
day -= day_increment
|
||||||
obj.rotation_euler = (elevation - pi/2, 0, -azimuth)
|
obj.rotation_euler = (elevation - pi/2, 0, -azimuth)
|
||||||
|
|
||||||
@ -366,14 +361,16 @@ def get_sun_coordinates(local_time, latitude, longitude,
|
|||||||
else:
|
else:
|
||||||
elevation = pi/2 - zenith
|
elevation = pi/2 - zenith
|
||||||
|
|
||||||
|
azimuth += sun_props.north_offset
|
||||||
|
|
||||||
return azimuth, elevation
|
return azimuth, elevation
|
||||||
|
|
||||||
|
|
||||||
def get_sun_vector(azimuth, elevation, north_offset):
|
def get_sun_vector(azimuth, elevation):
|
||||||
"""
|
"""
|
||||||
Convert the sun coordinates to cartesian
|
Convert the sun coordinates to cartesian
|
||||||
"""
|
"""
|
||||||
phi = -(azimuth + north_offset)
|
phi = -azimuth
|
||||||
theta = pi/2 - elevation
|
theta = pi/2 - elevation
|
||||||
|
|
||||||
loc_x = sin(phi) * sin(-theta)
|
loc_x = sin(phi) * sin(-theta)
|
||||||
@ -458,13 +455,9 @@ def calc_sunrise_sunset(rise):
|
|||||||
tl = time_local / 60.0
|
tl = time_local / 60.0
|
||||||
tl %= 24.0
|
tl %= 24.0
|
||||||
if rise:
|
if rise:
|
||||||
sun.sunrise.time = tl
|
sun.sunrise = tl
|
||||||
sun.sunrise.azimuth = azimuth
|
|
||||||
sun.sunrise.elevation = elevation
|
|
||||||
else:
|
else:
|
||||||
sun.sunset.time = tl
|
sun.sunset = tl
|
||||||
sun.sunset.azimuth = azimuth
|
|
||||||
sun.sunset.elevation = elevation
|
|
||||||
|
|
||||||
|
|
||||||
def julian_time_from_y2k(utc_time, year, month, day):
|
def julian_time_from_y2k(utc_time, year, month, day):
|
||||||
@ -566,13 +559,12 @@ def calc_surface(context):
|
|||||||
coords = []
|
coords = []
|
||||||
sun_props = context.scene.sun_pos_properties
|
sun_props = context.scene.sun_pos_properties
|
||||||
zone = -sun_props.UTC_zone
|
zone = -sun_props.UTC_zone
|
||||||
north_offset = sun_props.north_offset
|
|
||||||
|
|
||||||
def get_surface_coordinates(time, month):
|
def get_surface_coordinates(time, month):
|
||||||
azimuth, elevation = get_sun_coordinates(
|
azimuth, elevation = get_sun_coordinates(
|
||||||
time, sun_props.latitude, sun_props.longitude,
|
time, sun_props.latitude, sun_props.longitude,
|
||||||
zone, month, 1, sun_props.year, sun_props.sun_distance)
|
zone, month, 1, sun_props.year, sun_props.sun_distance)
|
||||||
sun_vector = get_sun_vector(azimuth, elevation, north_offset) * sun_props.sun_distance
|
sun_vector = get_sun_vector(azimuth, elevation) * sun_props.sun_distance
|
||||||
sun_vector.z = max(0, sun_vector.z)
|
sun_vector.z = max(0, sun_vector.z)
|
||||||
return sun_vector
|
return sun_vector
|
||||||
|
|
||||||
@ -592,14 +584,13 @@ def calc_analemma(context, h):
|
|||||||
vertices = []
|
vertices = []
|
||||||
sun_props = context.scene.sun_pos_properties
|
sun_props = context.scene.sun_pos_properties
|
||||||
zone = -sun_props.UTC_zone
|
zone = -sun_props.UTC_zone
|
||||||
north_offset = sun_props.north_offset
|
|
||||||
for day_of_year in range(1, 367, 5):
|
for day_of_year in range(1, 367, 5):
|
||||||
day, month = day_of_year_to_month_day(sun_props.year, day_of_year)
|
day, month = day_of_year_to_month_day(sun_props.year, day_of_year)
|
||||||
azimuth, elevation = get_sun_coordinates(
|
azimuth, elevation = get_sun_coordinates(
|
||||||
h, sun_props.latitude, sun_props.longitude,
|
h, sun_props.latitude, sun_props.longitude,
|
||||||
zone, month, day, sun_props.year,
|
zone, month, day, sun_props.year,
|
||||||
sun_props.sun_distance)
|
sun_props.sun_distance)
|
||||||
sun_vector = get_sun_vector(azimuth, elevation, north_offset) * sun_props.sun_distance
|
sun_vector = get_sun_vector(azimuth, elevation) * sun_props.sun_distance
|
||||||
if sun_vector.z > 0:
|
if sun_vector.z > 0:
|
||||||
vertices.append(sun_vector)
|
vertices.append(sun_vector)
|
||||||
return vertices
|
return vertices
|
||||||
|
@ -287,8 +287,8 @@ class SUNPOS_PT_Time(bpy.types.Panel):
|
|||||||
col = flow.column(align=True)
|
col = flow.column(align=True)
|
||||||
col.alignment = 'CENTER'
|
col.alignment = 'CENTER'
|
||||||
if p.show_rise_set:
|
if p.show_rise_set:
|
||||||
sr = format_hms(sun.sunrise.time)
|
sr = format_hms(sun.sunrise)
|
||||||
ss = format_hms(sun.sunset.time)
|
ss = format_hms(sun.sunset)
|
||||||
|
|
||||||
split = col.split(factor=0.5, align=True)
|
split = col.split(factor=0.5, align=True)
|
||||||
split.label(text="Sunrise:", icon='LIGHT_SUN')
|
split.label(text="Sunrise:", icon='LIGHT_SUN')
|
||||||
|
Loading…
Reference in New Issue
Block a user