Skip to content

Commit

Permalink
Merge pull request #94 from TheDuckCow/dev
Browse files Browse the repository at this point in the history
Merging in dev for 3.2.2
  • Loading branch information
TheDuckCow authored Nov 12, 2019
2 parents 3ad5386 + b6be67b commit 55f7407
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 47 deletions.
2 changes: 1 addition & 1 deletion MCprep_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
bl_info = {
"name": "MCprep",
"category": "Object",
"version": (3, 2, 1),
"version": (3, 2, 2),
"blender": (2, 80, 0),
"location": "3D window toolshelf > MCprep tab",
"description": "Minecraft workflow addon for rendering and animation",
Expand Down
14 changes: 12 additions & 2 deletions MCprep_addon/load_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
importlib.reload(item)
# importlib.reload(bridge)
importlib.reload(mcprep_ui)
importlib.reload(util)
importlib.reload(tracking)
importlib.reload(addon_updater)
importlib.reload(addon_updater_ops)
importlib.reload(generate)

if conf.v:
print("Reload, verbose is enabled")
Expand All @@ -45,12 +50,17 @@
mcprep_ui,
util_operators,
world_tools,
addon_updater_ops,
util,
tracking,
addon_updater,
addon_updater_ops
)
from .materials import(
prep,
skin,
sequences
sequences,
generate
)
from .spawner import(
spawn_util,
Expand All @@ -74,7 +84,7 @@
item,
world_tools,
# bridge,
mcprep_ui
mcprep_ui,
)


Expand Down
23 changes: 18 additions & 5 deletions MCprep_addon/materials/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ def set_cycles_texture(image, material, extra_passes=False):
else:
node.mute = True
node.hide = True

# remove the link between normal map and principled shader
# normal_map = node.outputs[0].links[0].to_node
# principled = ...

elif "MCPREP_specular" in node:
if "specular" in img_sets:
new_img = util.loadTexture(img_sets["specular"])
Expand All @@ -436,6 +441,7 @@ def set_cycles_texture(image, material, extra_passes=False):
else:
node.mute = True
node.hide = True

elif node.type == "TEX_IMAGE":
# assume all unlabeled texture nodes should be the diffuse
node["MCPREP_diffuse"] = True # annotate node for future reference
Expand Down Expand Up @@ -909,7 +915,8 @@ def matgen_cycles_principled(mat, passes, use_reflections, only_solid):
nodeTexNorm.image.colorspace_settings.name = 'Non-Color'

# apply additional settings
mat.cycles.sample_as_light = False
if hasattr(mat, "cycles"):
mat.cycles.sample_as_light = False
addToAlpha = None
if use_reflections and checklist(canon, "reflective"):
principled.inputs[5].default_value = 0.5 # spec
Expand Down Expand Up @@ -973,8 +980,12 @@ def matgen_cycles_principled(mat, passes, use_reflections, only_solid):

# noisy, but workable for partial trans; bad for materials with
# no partial trans (makes view-through all somewhat noisy)
mat.blend_method = 'HASHED'
mat.shadow_method = 'HASHED'
# Note: placed with hasattr to reduce bugs, seemingly only on old
# 2.80 build
if hasattr(mat, "blend_method"):
mat.blend_method = 'HASHED'
if hasattr(mat, "shadow_method"):
mat.shadow_method = 'HASHED'

# best if there is no partial transparency
# material.blend_method = 'CLIP' for no partial transparency
Expand Down Expand Up @@ -1114,7 +1125,8 @@ def matgen_cycles_original(mat, passes, use_reflections, only_solid):
nodeNormal.inputs[0].default_value = 0.1 # tone down normal maps

# the above are all default nodes. Now see if in specific lists
mat.cycles.sample_as_light = False
if hasattr(mat, "cycles"):
mat.cycles.sample_as_light = False
if use_reflections and checklist(canon, "reflective"):
nodeMix2.inputs[0].default_value = 0.3 # mix factor
nodeGloss.inputs[1].default_value = 0.0 # roughness, used to be 0.05
Expand Down Expand Up @@ -1235,7 +1247,8 @@ def matgen_cycles_emit(mat, passes):
nodeFalloff.inputs[0].default_value = 30 # controls actual light emitted
nodeFalloff.inputs[1].default_value = 0.03

mat.cycles.sample_as_light = True
if hasattr(mat, "cycles"):
mat.cycles.sample_as_light = True

# reapply animation data if any to generated nodes
apply_texture_animation_pass_settings(mat, animated_data)
Expand Down
2 changes: 1 addition & 1 deletion MCprep_addon/materials/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def execute(self, context):
# 2-level structure to hold base name and all
# images blocks with the same base
if (bpy.app.version[0]>=2 and bpy.app.version[1] >= 78) == False:
self.report({'ERROR',"Must use blender 2.78 or higher to use this operator"})
self.report({'ERROR'}, "Must use blender 2.78 or higher to use this operator")
return {'CANCELLED'}

if self.selection_only==True:
Expand Down
7 changes: 4 additions & 3 deletions MCprep_addon/mcprep_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,10 @@ def draw(self, context):
col.operator("mcprep.prep_materials", text="Prep Materials")
p = col.operator("mcprep.swap_texture_pack")
p.filepath = context.scene.mcprep_texturepack_path
col.operator("mcprep.meshswap", text="Mesh Swap")
if addon_prefs.MCprep_exporter_type == "(choose)":
col.label(text="Select exporter!",icon='ERROR')
if context.mode == "OBJECT":
col.operator("mcprep.meshswap", text="Mesh Swap")
if addon_prefs.MCprep_exporter_type == "(choose)":
col.label(text="Select exporter!",icon='ERROR')
if context.mode == 'EDIT_MESH':
col.operator("mcprep.scale_uv")
col.operator("mcprep.select_alpha_faces")
Expand Down
7 changes: 7 additions & 0 deletions MCprep_addon/spawner/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def spawn_item_from_filepath(context, path, max_pixels, thickness, threshold,
width = image.size[0] # ie columns
height = image.size[1] # ie rows

if width == 0 or height == 0:
return None, "Image has invalid 0-size dimension"

w_even_add = (-0.5 if width%2==0 else 0) + width
h_even_add = (-0.5 if height%2==0 else 0) + height

Expand Down Expand Up @@ -158,6 +161,10 @@ def spawn_item_from_filepath(context, path, max_pixels, thickness, threshold,
location=(0,0,0))
itm_obj = context.object

if not itm_obj:
print("Error, could not create the item primitive object")
return None, "Could not create the item primitive object"

# scale the object to match ratio, keeping max dimension as set above
if width < height:
itm_obj.scale[0] = width/height
Expand Down
31 changes: 23 additions & 8 deletions MCprep_addon/spawner/meshswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,11 @@ def swap_enum(self, context):
default=True,
description="Automatically make groups real after placement")


# toLink = bpy.props.BoolProperty(
# name = "Library Link mob",
# description = "Library link instead of append the group",
# default = False
# )

# option to force load from library instead of reuse local group?

@classmethod
Expand Down Expand Up @@ -229,7 +227,11 @@ def execute(self, context):
importedObj["MCprep_noSwap"] = "True"
importedObj.location = self.location
if self.prep_materials is True:
bpy.ops.mcprep.prep_materials(skipUsage=True) # if cycles
try:
bpy.ops.mcprep.prep_materials(skipUsage=True) # if cycles
except:
print("Could not prep materials")
self.report({"WARNING"}, "Could not prep materials")
else:
if not use_cache:
group = self.prep_collection(context, block, pre_groups)
Expand Down Expand Up @@ -359,7 +361,10 @@ def prep_collection(self, context, block, pre_groups):
if self.prep_materials is True:
for ob in objlist:
util.select_set(ob, True)
bpy.ops.mcprep.prep_materials(skipUsage=True) # if cycles
try:
bpy.ops.mcprep.prep_materials(skipUsage=True) # if cycles
except:
print("Could not prep materials")
for ob in util.get_objects_conext(context):
util.select_set(ob, False)

Expand All @@ -369,7 +374,6 @@ def prep_collection(self, context, block, pre_groups):
return group



class MCPREP_OT_reload_meshswap(bpy.types.Operator):
"""Force reload the MeshSwap objects and cache."""
bl_idname = "mcprep.reload_meshswap"
Expand Down Expand Up @@ -451,7 +455,7 @@ class MCPREP_OT_meshswap(bpy.types.Operator):
@classmethod
def poll(cls, context):
addon_prefs = util.get_user_preferences(context)
return addon_prefs.MCprep_exporter_type != "(choose)"
return addon_prefs.MCprep_exporter_type != "(choose)" and context.mode == 'OBJECT'

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(
Expand Down Expand Up @@ -725,8 +729,13 @@ def execute(self, context):
conf.log("Using scale: {}".format(gScale))
conf.log(objList)

# setup the progress bar
denom = len(objList)
bpy.context.window_manager.progress_begin(0, 100)

#primary loop, for each OBJECT needing swapping
for swap in objList:
for iter_index, swap in enumerate(objList):
bpy.context.window_manager.progress_update(iter_index/denom)
swapGen = util.nameGeneralize(swap.name)
conf.log("Simplified name: {x}".format(x=swapGen))
swapProps = self.checkExternal(context, swapGen) # IMPORTS, gets lists properties, etc
Expand Down Expand Up @@ -1042,7 +1051,10 @@ def execute(self, context):
if obtemp in selList:
selList.pop(selList.index(obtemp))
bpy.ops.object.join()
selList.append(context.selected_objects[0])
if context.selected_objects:
selList.append(context.selected_objects[0])
else:
conf.log("No selected objects after join")

removeList.append(swap)

Expand Down Expand Up @@ -1089,6 +1101,9 @@ def execute(self, context):
# util.hide_viewport(grp, True)
# grp.hide_render = True

# end progress bar, end of primary section
bpy.context.window_manager.progress_end()

if runcount==0:
self.report({'ERROR'}, "Nothing swapped, likely no materials of selected objects match the meshswap file objects/groups")
return {'CANCELLED'}
Expand Down
8 changes: 6 additions & 2 deletions MCprep_addon/spawner/mobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def _add_rigs_from_blend(path, blend_name, category):

for name in getattr(data_from, get_attr):
# special cases, skip some groups
if name.lower() == "Rigidbodyworld".lower():
if name.lower() in ("rigidbodyworld", "collection"):
continue

description = "Spawn one {x} rig".format(x=name)
mob = context.scene.mcprep_props.mob_list_all.add()
mob.description = description # add in non all-list
Expand Down Expand Up @@ -320,7 +321,10 @@ def execute(self, context):
self.attemptScriptLoad(path)

if self.auto_prep and not self.toLink and context.selected_objects:
bpy.ops.mcprep.prep_materials(skipUsage=True)
try:
bpy.ops.mcprep.prep_materials(skipUsage=True)
except:
self.report({"WARNING"}, "Failed to prep materials on mob load")

self.track_param = self.mcmob_type.split(":/:")[1]
return {'FINISHED'}
Expand Down
4 changes: 2 additions & 2 deletions MCprep_addon/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from datetime import datetime
except Exception as err:
print("[MCPREP Error] Failed tracker module load, invalid import module:")
print('\t'+err)
print('\t'+str(err))
VALID_IMPORT = False


Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(self):
self.json = {}
self._httpclient_fallback = None # set to True/False after first req
self._last_request = {} # used to debounce sequential requests
self._debounce = 3 # seconds to avoid duplicative requests
self._debounce = 5 # seconds to avoid duplicative requests


# -------------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions MCprep_addon/util_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,14 @@ class MCPREP_OT_prep_material_legacy(bpy.types.Operator):
@tracking.report_error
def execute(self, context):
print("Using legacy operator call for MCprep materials, move to use bpy.ops.mcprep.prep_materials")
bpy.ops.mcprep.prep_materials(
useReflections = self.useReflections,
combineMaterials = self.combineMaterials
)
try:
bpy.ops.mcprep.prep_materials(
useReflections = self.useReflections,
combineMaterials = self.combineMaterials
)
except:
self.report({"ERROR"}, "Legacy Prep Materials failed; use new operator name 'mcprep.prep_materials' going forward and to get more info")
return {'CANCELLED'}
return {'FINISHED'}


Expand Down
44 changes: 26 additions & 18 deletions MCprep_addon/world_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,20 @@ def prep_world_cycles(self, context):
world_links.new(background.outputs["Background"], output.inputs[0])

context.scene.world.light_settings.use_ambient_occlusion = False
context.scene.cycles.caustics_reflective = False
context.scene.cycles.caustics_refractive = False

# higher = faster, though potentially noisier; this is a good balance
context.scene.cycles.light_sampling_threshold = 0.1
context.scene.cycles.max_bounces = 8
if hasattr(context.scene, "cycles"):
context.scene.cycles.caustics_reflective = False
context.scene.cycles.caustics_refractive = False

# Renders faster at a (minor?) cost of the image output
# TODO: given the output change, consider make a bool toggle for this
bpy.context.scene.render.use_simplify = True
bpy.context.scene.cycles.ao_bounces = 2
bpy.context.scene.cycles.ao_bounces_render = 2
# higher = faster, though potentially noisier; this is a good balance
context.scene.cycles.light_sampling_threshold = 0.1
context.scene.cycles.max_bounces = 8

# Renders faster at a (minor?) cost of the image output
# TODO: given the output change, consider adding a bool toggle
context.scene.render.use_simplify = True
context.scene.cycles.ao_bounces = 2
context.scene.cycles.ao_bounces_render = 2

def prep_world_eevee(self, context):
"""Default world settings for Eevee rendering"""
Expand Down Expand Up @@ -302,8 +304,8 @@ def prep_world_eevee(self, context):
# higher = faster, though potentially noisier; this is a good balance
context.scene.cycles.light_sampling_threshold = 0.1
context.scene.cycles.max_bounces = 8
bpy.context.scene.cycles.ao_bounces = 2
bpy.context.scene.cycles.ao_bounces_render = 2
context.scene.cycles.ao_bounces = 2
context.scene.cycles.ao_bounces_render = 2

# Renders faster at a (minor?) cost of the image output
# TODO: given the output change, consider make a bool toggle for this
Expand Down Expand Up @@ -480,14 +482,20 @@ def execute(self, context):
resource = blendfile +"/Object"

util.bAppendLink(resource, "MoonMesh", False)
moonmesh = context.selected_objects[0]
moonmesh.parent = get_time_object()
new_objs.append(moonmesh)
if context.selected_objects:
moonmesh = context.selected_objects[0]
moonmesh.parent = get_time_object()
new_objs.append(moonmesh)
else:
self.report({'WARNING'}, "Could not add moon")

util.bAppendLink(resource, "SunMesh", False)
sunmesh = context.selected_objects[0]
sunmesh.parent = get_time_object()
new_objs.append(sunmesh)
if context.selected_objects:
sunmesh = context.selected_objects[0]
sunmesh.parent = get_time_object()
new_objs.append(sunmesh)
else:
self.report({'WARNING'}, "Could not add sun")

if prev_world:
bpy.data.worlds.remove(prev_world)
Expand Down
Loading

0 comments on commit 55f7407

Please sign in to comment.