Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Algorthim changed Lighting code modified
Browse files Browse the repository at this point in the history
- Moved new_modifier to object_ops
- Added new lighting code, needs cleanup but works
  • Loading branch information
animate1978 committed Feb 12, 2020
1 parent 73072b2 commit ffdc8ea
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 53 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All changes will be documented here

## Added

- Morph Engine added
- Hair Engine now adds hair shaders to Cycles and EEVEE

## Changed
Expand All @@ -21,6 +22,7 @@ All changes will be documented here
- Bump maps now 4k resolution
- Modified Freckle masks
- Modified Material Engine
- Changed lighting code

## Bug Fixes

Expand Down
7 changes: 4 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ def start_lab_session():
scn.render.engine = 'BLENDER_EEVEE'
if scn.mblab_use_lamps:

file_ops.import_object_from_lib(lib_filepath, "Light_Key")
file_ops.import_object_from_lib(lib_filepath, "Light_Fill")
file_ops.import_object_from_lib(lib_filepath, "Light_Backlight")
#file_ops.import_object_from_lib(lib_filepath, "Light_Key")
#file_ops.import_object_from_lib(lib_filepath, "Light_Fill")
#file_ops.import_object_from_lib(lib_filepath, "Light_Backlight")
object_ops.add_lighting()

else:
scn.render.engine = 'BLENDER_WORKBENCH'
Expand Down
43 changes: 1 addition & 42 deletions algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,36 +944,6 @@ def apply_auto_align_bones(armat):
bone.roll = bone_target.roll


def link_to_collection(obj):
# sanity check
if obj.name not in bpy.data.objects:
logger.error("Cannot link obj %s because it's not in bpy.data.objects", obj.name)
return

collection_name = 'MB_LAB_Character'
c = bpy.data.collections.get(collection_name)
scene = bpy.context.scene
# collection is already created
if c is not None:
if obj.name not in c.objects:
c.objects.link(obj)
else:
logger.warning("The object %s is already linked to the scene", obj.name)
else:
# create the collection, link collection to scene and link obj to collection
c = bpy.data.collections.new(collection_name)
scene.collection.children.link(c)
c.objects.link(obj)


def is_armature_linked(obj, armat):
if obj.type == 'MESH':
for modfr in obj.modifiers:
if modfr.type == 'ARMATURE' and modfr.object == armat:
return True
return False


def has_deformation_vgroups(obj, armat):
if obj.type == 'MESH':
if armat:
Expand Down Expand Up @@ -1102,18 +1072,7 @@ def set_modifier_viewport(modfr, value):
modfr.show_viewport = value

#
def new_modifier(obj, name, modifier_type, parameters):
if name in obj.modifiers:
logger.info("Modifier %s already present in %s", modifier_type, obj.name)
return obj.modifiers[name]
_new_modifier = obj.modifiers.new(name, modifier_type)
for parameter, value in parameters.items():
if hasattr(_new_modifier, parameter):
try:
setattr(_new_modifier, parameter, value)
except AttributeError:
logger.info("Setattr failed for attribute '%s' of modifier %s", parameter, name)
return _new_modifier


#
def set_modifier_parameter(modifier, parameter, value):
Expand Down
8 changes: 4 additions & 4 deletions humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ def init_database(self, obj, character_identifier, rigging_type):
def add_subdivision_modifier(self):
obj = self.get_object()
parameters = {"levels": 1, "render_levels": 2, "show_viewport": True, "show_in_editmode": False}
algorithms.new_modifier(obj, self.mat_engine.subdivision_modifier_name, 'SUBSURF', parameters)
object_ops.new_modifier(obj, self.mat_engine.subdivision_modifier_name, 'SUBSURF', parameters)

def add_displacement_modifier(self):
obj = self.get_object()
disp_img = file_ops.get_image(self.mat_engine.image_file_names["body_displ"])
if disp_img:
disp_tex = file_ops.new_texture(self.mat_engine.generated_disp_modifier_ID, disp_img)
parameters = {"texture_coords":'UV', "strength": 0.01, "show_viewport": False, "texture": disp_tex}
displacement_modifier = algorithms.new_modifier(obj, self.mat_engine.generated_disp_modifier_ID, 'DISPLACE', parameters)
displacement_modifier = object_ops.new_modifier(obj, self.mat_engine.generated_disp_modifier_ID, 'DISPLACE', parameters)

def rename_obj(self, prefix):
obj = self.get_object()
Expand Down Expand Up @@ -451,7 +451,7 @@ def save_body_dermal_texture(self, filepath):
self.mat_engine.save_texture(filepath, "body_derm")

def save_all_textures(self, filepath):
targets = ["body_derm", "body_displ", "teeth_albedo", "eyes_albedo", "tongue_albedo", "freckle_mask", "blush", "sebum", "lipmap", "thickness", "iris_color", "iris_bump", "sclera_color", "translucent_mask", "sclera_mask"]
targets = ["body_derm", "body_displ", "teeth_albedo", "eyes_albedo", "tongue_albedo", "freckle_mask", "blush", "sebum", "lipmap", "iris_color", "iris_bump", "sclera_color", "translucent_mask", "sclera_mask", "body_bump"]
for target in targets:
dir_path = os.path.dirname(filepath)
filename = os.path.basename(filepath)
Expand Down Expand Up @@ -1199,4 +1199,4 @@ def set_rest_pose(self):
def add_corrective_smooth_modifier(self):
obj = self.get_object()
parameters = {"show_viewport": True, "invert_vertex_group": True, "vertex_group": "head"}
algorithms.new_modifier(obj, self.corrective_modifier_name, 'CORRECTIVE_SMOOTH', parameters)
object_ops.new_modifier(obj, self.corrective_modifier_name, 'CORRECTIVE_SMOOTH', parameters)
50 changes: 50 additions & 0 deletions object_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ def apply_mod(Ref):
bpy.ops.object.modifier_apply(modifier=m.name)
bpy.context.view_layer.objects.active = act

# Apply new modifier
def new_modifier(obj, name, modifier_type, parameters):
if name in obj.modifiers:
logger.info("Modifier %s already present in %s", modifier_type, obj.name)
return obj.modifiers[name]
_new_modifier = obj.modifiers.new(name, modifier_type)
for parameter, value in parameters.items():
if hasattr(_new_modifier, parameter):
try:
setattr(_new_modifier, parameter, value)
except AttributeError:
logger.info("Setattr failed for attribute '%s' of modifier %s", parameter, name)
return _new_modifier


###############################################################################################################################
Expand Down Expand Up @@ -387,3 +400,40 @@ def bvhtree_from_obj_polygons(obj, indices_of_polygons_subset=None):
vertices = [ vert.co for vert in obj.data.vertices ]
return mathutils.bvhtree.BVHTree.FromPolygons(vertices, polygons)

###############################################################################################################################
# LIGHTING_OPS

def add_lighting():
# create light datablock, set attributes
mblight01 = bpy.data.lights.new(name="light_01", type='AREA')
mblight02 = bpy.data.lights.new(name="light_02", type='AREA')
mblight03 = bpy.data.lights.new(name="light_03", type='AREA')

# create new object with our light datablock
light_object01 = bpy.data.objects.new(name="light_key", object_data=mblight01)
light_object02 = bpy.data.objects.new(name="light_backlight", object_data=mblight02)
light_object03 = bpy.data.objects.new(name="light_fill", object_data=mblight03)

# link light object
bpy.context.collection.objects.link(light_object01)
bpy.context.collection.objects.link(light_object02)
bpy.context.collection.objects.link(light_object03)

# make it active
bpy.context.view_layer.objects.active = light_object01
bpy.context.view_layer.objects.active = light_object02
bpy.context.view_layer.objects.active = light_object03

#change location, rotation and other settings
light_object01.location = (1.5, -1.5, 2.5)
light_object01.rotation_euler = (radians(0), radians(-70), radians(133))
light_object02.location = (-1.5, 1.5, 2.5)
light_object02.rotation_euler = (radians(-60), radians(0), radians(40))
light_object03.location = (-1.5, -2, 2.5)
light_object03.rotation_euler = (radians(0), radians(-70), radians(50))
mblight01.energy = 100
mblight01.color = (0.688, 0.914, 1)
mblight02.energy = 150
mblight02.color = (1, 1, 1)
mblight03.energy = 100
mblight03.color = (0.981, 1, 0.694)
6 changes: 3 additions & 3 deletions proxyengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def add_proxy_armature_modfr(self, proxy, armat):
algorithms.remove_modifier(proxy, self.proxy_armature_modifier)

parameters = {"object": armat}
armature_modifier = algorithms.new_modifier(proxy, self.proxy_armature_modifier,'ARMATURE', parameters)
armature_modifier = object_ops.new_modifier(proxy, self.proxy_armature_modifier,'ARMATURE', parameters)
return armature_modifier

# def add_mask_modifier(self, body, mask_name):
Expand Down Expand Up @@ -475,7 +475,7 @@ def fit_proxy_object(self,proxy_offset=0.0, proxy_threshold = 0.5, create_proxy_
if smoothing:
parameters = {"show_viewport": True}

correct_smooth_mod = algorithms.new_modifier(proxy, self.corrective_modifier_name, 'CORRECTIVE_SMOOTH', parameters)
correct_smooth_mod = object_ops.new_modifier(proxy, self.corrective_modifier_name, 'CORRECTIVE_SMOOTH', parameters)

for i in range(10):
algorithms.move_up_modifier(proxy, correct_smooth_mod)
Expand Down Expand Up @@ -574,7 +574,7 @@ def add_body_mask(self, body, proxy_shapekey, mask_name, proxy_threshold = 0.025

#self.add_mask_modifier(body, mask_name)
parameters = {"vertex_group": mask_name,"invert_vertex_group": True}
algorithms.new_modifier(body, mask_name, 'MASK', parameters)
object_ops.new_modifier(body, mask_name, 'MASK', parameters)

def remove_body_mask(self, body, mask_name):
algorithms.remove_modifier(body, mask_name)
Expand Down
2 changes: 1 addition & 1 deletion skeletonengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def add_armature_modifier(self):
obj = self.get_body()
armat = self.get_armature()
parameters = {"object": armat}
algorithms.new_modifier(obj, self.armature_modifier_name, 'ARMATURE', parameters)
object_ops.new_modifier(obj, self.armature_modifier_name, 'ARMATURE', parameters)

def move_up_armature_modifier(self):
if self.has_data:
Expand Down

0 comments on commit ffdc8ea

Please sign in to comment.