Skip to content

Commit

Permalink
Merge pull request #401 from Weisl/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Weisl authored Jun 13, 2023
2 parents 2bb2b62 + 836b6de commit 718e10f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
4 changes: 3 additions & 1 deletion collider_shapes/add_bounding_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gpu_extras.batch import batch_for_shader

from ..groups.user_groups import get_groups_identifier, set_groups_object_color
from ..pyshics_materials.material_functions import assign_physics_material
from ..pyshics_materials.material_functions import assign_physics_material, create_default_material, set_active_physics_material

collider_groups = ['USER_01', 'USER_02', 'USER_03']

Expand Down Expand Up @@ -870,6 +870,8 @@ def primitive_postprocessing(self, context, bounding_object, base_object_collect
mat_name = context.scene.active_physics_material.name
elif prefs.physics_material_name:
mat_name = prefs.physics_material_name
mat = create_default_material()
set_active_physics_material(context, mat.name)
else:
mat_name = ''

Expand Down
10 changes: 2 additions & 8 deletions preferences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import keymap
from .properties import ColliderTools_Properties
from .preferences import update_panel_category
from ..pyshics_materials import material_functions
from ..pyshics_materials.material_functions import set_default_active_mat

classes = (
properties.ColliderTools_Properties,
Expand All @@ -19,13 +19,7 @@

@persistent
def _load_handler(dummy):
prefs = bpy.context.preferences.addons[__package__.split('.')[0]].preferences
default_mat_name = prefs.physics_material_name

mat = bpy.data.materials.get(default_mat_name, material_functions.create_default_material())
bpy.context.scene.active_physics_material = mat
# bpy.context.scene.collider_tools.material_list_index = list(bpy.data.materials).index(mat)

set_default_active_mat()

def register():
from bpy.utils import register_class
Expand Down
4 changes: 4 additions & 0 deletions pyshics_materials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
physics_materials.MATERIAL_OT_physics_material_random_color,
)

# def defaultActive():
# mat = material_functions.create_default_material()
# return mat

def register():
scene = bpy.types.Scene
scene.use_physics_tag = bpy.props.BoolProperty(name="Filter", default=False)
# scene.active_physics_material = bpy.props.StringProperty(name="Active Physics Material", default="")
materialType = bpy.types.Material

#scene.active_physics_material = bpy.props.PointerProperty(name="My Node", default=defaultActive(), type=materialType)
scene.active_physics_material = bpy.props.PointerProperty(name="My Node", type=materialType)

materialType.edit = bpy.props.BoolProperty(name="Manipulate", default=False)
Expand Down
23 changes: 15 additions & 8 deletions pyshics_materials/material_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def create_material(name, diffuse, fakeUser=True):

return mat


def set_material(ob, mat):
'''Assign material to object'''
# add material to object
Expand All @@ -36,17 +35,21 @@ def remove_materials(obj):
def create_default_material():
'''Create a default material'''
prefs = bpy.context.preferences.addons[__package__.split('.')[0]].preferences
default_mat_name = prefs.physics_material_name

if not default_mat_name:
default_mat_name = 'COL_DEFAULT'
if prefs:
default_mat_name = prefs.physics_material_name

if default_mat_name and default_mat_name in bpy.data.materials:
default_material = bpy.data.materials[default_mat_name]
if not default_mat_name:
default_mat_name = 'COL_DEFAULT'

if default_mat_name and default_mat_name in bpy.data.materials:
default_material = bpy.data.materials[default_mat_name]
else:
default_material = create_material(default_mat_name, (0.0, 0.5, 1, 0.5))
else:
default_mat_name = 'COL_DEFAULT'
default_material = create_material(default_mat_name, (0.0, 0.5, 1, 0.5))


return default_material

def create_physics_material(physics_material_name):
Expand Down Expand Up @@ -89,8 +92,12 @@ def assign_physics_material(object, physics_material_name):
mat = create_physics_material(physics_material_name)
set_material(object, mat)

def set_default_active_mat():
prefs = bpy.context.preferences.addons[__package__.split('.')[0]].preferences
default_mat_name = prefs.physics_material_name


mat = bpy.data.materials.get(default_mat_name, create_default_material())
bpy.context.scene.active_physics_material = mat



Expand Down
2 changes: 1 addition & 1 deletion ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .properties_panels import collider_presets_folder

classes = (
properties_panels.EXPLORER_OT_open_directory,
properties_panels.EXPLORER_OT_open_directory_new,
properties_panels.PREFERENCES_OT_open_addon,
properties_panels.BUTTON_OT_auto_convex,
properties_panels.OBJECT_MT_collision_presets,
Expand Down
17 changes: 7 additions & 10 deletions ui/properties_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import textwrap
from bpy.types import Menu

from ..pyshics_materials.material_functions import create_default_material, set_active_physics_material

def collider_presets_folder():
# Make sure there is a directory for presets
Expand Down Expand Up @@ -206,7 +207,7 @@ def draw_naming_presets(self, context):

############## OPERATORS ##############################

class EXPLORER_OT_open_directory(bpy.types.Operator):
class EXPLORER_OT_open_directory_new(bpy.types.Operator):
"""Open render output directory in Explorer"""
bl_idname = "explorer.open_in_explorer"
bl_label = "Open Folder"
Expand Down Expand Up @@ -415,20 +416,16 @@ def draw(self, context):
# self.draw_active_physics_material(colSettings, layout)
scene = context.scene
activeMat = scene.active_physics_material
if activeMat:
split_left = layout.split(factor=0.75, align=True)
col_01 = split_left.column(align=True)
col_02 = split_left.column(align=True)

col_01.prop_search(scene, "active_physics_material", bpy.data, "materials", text='')
col_02.prop(activeMat, 'diffuse_color', text='')
split_left = layout.split(factor=0.75, align=True)
col_01 = split_left.column(align=True)
col_02 = split_left.column(align=True)

else:
layout.label(text="None")
col_01.prop_search(scene, "active_physics_material", bpy.data, "materials", text='')
col_02.prop(activeMat, 'diffuse_color', text='')

if prefs.use_physics_material:
layout.label(text='Material List')
# self.draw_active_physics_material(colSettings, layout)
layout.template_list("MATERIAL_UL_physics_materials", "", bpy.data, "materials", colSettings,
"material_list_index")

Expand Down

0 comments on commit 718e10f

Please sign in to comment.