Skip to content

Commit

Permalink
Added Texel Density Unit Scale in preferences
Browse files Browse the repository at this point in the history
Allows to adjust the system unit scale to a custom unit by a multiplier for the texel density, so it is shown and managed in that custom unit (e.g., pixels per centimeter when the system unit is meters); the setting can be found in the add-on preferences. Fixes #146
  • Loading branch information
franMarz committed Jan 6, 2024
1 parent 3da585a commit 7723e2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TexTools",
"description": "Professional UV and Texture tools for Blender.",
"author": "renderhjs, franMarz, Sav Martin",
"version": (1, 5),
"version": (1, 6),
"blender": (2, 80, 0),
"category": "UV",
"location": "UV Image Editor > Tools > 'TexTools' panel"
Expand Down Expand Up @@ -251,6 +251,7 @@ class Panel_Preferences(AddonPreferences):
bool_clean_transmission : BoolProperty(name="Ignore other channels when baking Transmission", default=False)
bool_modifier_auto_high : BoolProperty(name="Detect Objects with Subdiv or Bevel Mods as a Highpoly pair for baking", default=True)
bool_help : BoolProperty(name="Show help buttons on panels", default=True)
texel_density_scale: FloatProperty(name="Texel Density Unit Scale", description="Multiplier for scaling the System Units when working with Texel Density values", default=1, min=0.00000000001)


def draw(self, context):
Expand Down Expand Up @@ -313,8 +314,12 @@ def draw(self, context):
box.separator()
col = box.column(align=True)
col.prop(self, "bool_help", icon='INFO')



box.separator()
col = box.column(align=True)
col.prop(self, "texel_density_scale", icon='UV_DATA')


if not hasattr(bpy.types,"ShaderNodeBevel"):
box.separator()
col = box.column(align=True)
Expand Down Expand Up @@ -704,10 +709,9 @@ def set_bake_color_space(self, value):
)
texel_density : FloatProperty(
name = "Texel",
description = "Texel size or Pixels per 1 unit ratio",
description = "Texel size or Pixels per unit ratio",
default = 256,
min = 0.0
# max = 100.00
)
meshtexture_wrap : FloatProperty(
name = "Wrap",
Expand Down
2 changes: 1 addition & 1 deletion op_texel_density_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def execute(self, context):
sum_area_vt += area_pair[1]

if sum_area_uv != 0 and sum_area_vt != 0:
bpy.context.scene.texToolsSettings.texel_density = sum_area_uv / sum_area_vt
bpy.context.scene.texToolsSettings.texel_density = (sum_area_uv / sum_area_vt) * bpy.context.preferences.addons[__package__].preferences.texel_density_scale

if not edit_mode:
bpy.ops.object.mode_set(mode='OBJECT')
Expand Down
2 changes: 1 addition & 1 deletion op_texel_density_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def set_texel_density(self, context, edit_mode, getmode, setmode, density, udim_
else:
if udim_tile != 1001:
pre_center = Vector((column, row))
scale = density / (sum_area_uv / sum_area_vt)
scale = (density / (sum_area_uv / sum_area_vt)) / bpy.context.preferences.addons[__package__].preferences.texel_density_scale

if scale != 1:
if setmode == 'ISLAND' or udim_tile != 1001:
Expand Down

0 comments on commit 7723e2b

Please sign in to comment.