Skip to content

Commit

Permalink
updated code and errors in general
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDuckCow committed Oct 5, 2016
1 parent 344d307 commit bd2f042
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 127 deletions.
25 changes: 19 additions & 6 deletions MCprep_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@
#
# ##### END MIT LICENSE BLOCK #####



# -----------------------------------------------------------------------------
# Additional disclaimer & terms
# -----------------------------------------------------------------------------

"""
By installing and using this addon, you agree to the following privacy policy:
http://theduckcow.com/privacy-policy/
which should have been present on the original download page.
This code is open source under the MIT license.
Its purpose is to increase the workflow of creating Minecraft
related renders and animations, by automating certain tasks.
Expand All @@ -35,15 +46,20 @@
"""

# -----------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------


bl_info = {
"name": "MCprep",
"category": "Object",
"version": (2, 99, 1),
"blender": (2, 76, 0),
"version": (3, 0, 0),
"blender": (2, 78, 0),
"location": "3D window toolshelf > MCprep tab",
"description": "Minecraft workflow addon for rendering and animation",
"warning": "",
"wiki_url": "https://github.com/TheDuckCow/MCprep",
"wiki_url": "https://TheDuckCow.com/MCprep",
"author": "Patrick W. Crawford <[email protected]>",
"tracker_url":"https://github.com/TheDuckCow/MCprep/issues"
}
Expand Down Expand Up @@ -80,9 +96,6 @@
conf.init() #initialize global variables
if conf.v:print("MCprep: Verbose is enabled")
if conf.vv:print("MCprep: Very Verbose is enabled")
# except:
# print("Importing errors occured")
# pass


def register():
Expand Down
2 changes: 1 addition & 1 deletion MCprep_addon/addon_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self):
# "" # assume specific cache name, use addon?.cache
self._check_interval_enable = False
self._check_interval_months = 0
self._check_interval_days = 14
self._check_interval_days = 7
self._check_interval_hours = 0
self._check_interval_minutes = 0

Expand Down
80 changes: 57 additions & 23 deletions MCprep_addon/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def materialsInternal(self, mat):
mat.emit = 1
else:
mat.emit = 0
return 0

### Function for default cycles materials
def materialsCycles(self, mat):
Expand Down Expand Up @@ -267,7 +268,17 @@ def materialsCycles(self, mat):
nodeTex.image_user.frame_duration = intlength
except:
pass
return 0

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)

def draw(self, context):
row = self.layout.row()
col = row.column()
col.prop(self, "useReflections")
col.prop(self, "consolidateMaterials")
# tick box to enable tracking

def execute(self, context):

Expand Down Expand Up @@ -296,13 +307,17 @@ def execute(self, context):
if (render_engine == 'BLENDER_RENDER'):
#print('BI mat')
if conf.vv:print("Blender internal material prep")
self.materialsInternal(mat)
res = self.materialsInternal(mat)
if res==0: count+=1
elif (render_engine == 'CYCLES'):
#print('cycles mat')
if conf.vv:print("Cycles material prep")
self.materialsCycles(mat)
res = self.materialsCycles(mat)
if res==0: count+=1
else:
if conf.v:print('Get the linked material instead!')

self.report({"INFO"},"Modified "+str(count)+" materials")
return {'FINISHED'}


Expand Down Expand Up @@ -331,6 +346,14 @@ def execute(self, context):
else:
print("Skipping, already added material")

# pre 2.78 solution, deep loop
if (bpy.app.version[0]>=2 and bpy.app.version[1] >= 78) == False:
for ob in bpy.data.objects:
for sl in ob.material_slots:
if sl == None or sl.material == None:continue
sl.material = bpy.data.materials[nameCat[ util.nameGeneralize(sl.material.name) ][0]]
return {'FINISHED'}

# perform the consolidation with one basename set at a time
for base in nameCat:
if len(base)<2: continue
Expand Down Expand Up @@ -390,11 +413,25 @@ def execute(self, context):
# return {'FINISHED'}


class MCPREP_improveUI(bpy.types.Operator):
"""Improve the UI with specific view settings"""
bl_idname = "mcprep.improve_ui"
bl_label = "Prep UI"
bl_description = "Improve UI for minecraft by disabling mipmaps & setting texture solid"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
context.space_data.show_textured_solid = True # need to make it 3d space
context.user_preferences.system.use_mipmaps = True

return {'FINISHED'}


# -----------------------------------------------------------------------------
# Skin swapping lists
# -----------------------------------------------------------------------------


# for asset listing UIList drawing
class MCPREP_skin_UIList(bpy.types.UIList):
def draw_item(self, context, layout, data, set, icon, active_data, active_propname, index):
Expand All @@ -410,8 +447,6 @@ class ListColl(bpy.types.PropertyGroup):
# reload the skins in the directory for UI list
def reloadSkinList(context):

#addon_prefs = bpy.context.user_preferences.addons[__package__].preferences

skinfolder = context.scene.mcskin_path
files = [ f for f in os.listdir(skinfolder) if\
os.path.isfile(os.path.join(skinfolder,f)) ]
Expand All @@ -427,8 +462,6 @@ def reloadSkinList(context):

# recreate
for i, (skin, description) in enumerate(skinlist, 1):
print("#",i)

item = context.scene.mcprep_skins_list.add()
conf.skin_list.append( (skin,os.path.join(skinfolder,skin)) )
item.label = description
Expand Down Expand Up @@ -484,16 +517,26 @@ def collhack_skins(scene):

try:
reloadSkinList(bpy.context)
#bpy.ops.mcprep.reload_skins()
except:
print("Didin't run callback")
if conf.v:print("Didn't run callback")
pass


# input is either UV image itself or filepath
def swapCycles(image, mats):
print("Skin swapping cycles")
#self.report({'ERROR'}, "Work in progress operator")
if conf.vv:print("Texture swapping cycles")
changed = 0
for mat in mats:
if mat.node_tree == None:continue
for node in mat.node_tree.nodes:
if node.type != "TEX_IMAGE": continue
node.image = image
changed+=1

if changed == 0:
return False # nothing updated
else:
return True # updated at least one texture (the first)


# input is either UV image itself or filepath
Expand Down Expand Up @@ -563,7 +606,7 @@ class MCPREP_skinSwapper(bpy.types.Operator, ImportHelper):
files = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)

def execute(self,context):

tracking.trackUsage("skin","file import")
res = loadSkinFile(self, context)
if res!=0:
return {'CANCELLED'}
Expand All @@ -584,7 +627,7 @@ class MCPREP_applySkin(bpy.types.Operator):
description="selected")

def execute(self,context):

tracking.trackUsage("skin","ui list")
res = loadSkinFile(self, context)
if res!=0:
return {'CANCELLED'}
Expand All @@ -609,23 +652,20 @@ class MCPREP_applyUsernameSkin(bpy.types.Operator):
description="Re-download if already locally found",
default=False)


def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)


def draw(self, context):
self.layout.label("Enter exact username below")
self.layout.prop(self,"username",text="")
self.layout.label(
"and then press OK; blender may pause briefly to download")


def execute(self,context):
if self.username == "":
self.report({"ERROR","Invalid username"})
return {'CANCELLED'}

tracking.trackUsage("skin","username")

skins = [ str(skin[0]).lower() for skin in conf.skin_list ]
paths = [ skin[1] for skin in conf.skin_list ]
Expand All @@ -641,7 +681,6 @@ def execute(self,context):

def downloadUser(self, context):


#http://minotar.net/skin/theduckcow
src_link = "http://minotar.net/skin/"
saveloc = os.path.join(bpy.path.abspath(context.scene.mcskin_path),
Expand Down Expand Up @@ -681,7 +720,6 @@ def execute(self,context):
self.report({'ERROR'}, "Work in progress operator")
return {'CANCELLED'}


return {'FINISHED'}


Expand All @@ -701,18 +739,14 @@ class MCPREP_addSkin(bpy.types.Operator, ImportHelper):
files = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)

def execute(self,context):

# filepath editor dialog
# select file, apply change

new_skin = bpy.path.abspath(self.filepath)
if os.path.isfile(new_skin) == False:
self.report({"ERROR"},"Not a image file path")
return {'CANCELLED'}

base = bpy.path.basename(new_skin)

# copy the skin file
base = bpy.path.basename(new_skin)
shutil.copy2(new_skin, os.path.join(context.scene.mcskin_path,base))

# in future, select multiple
Expand Down
Loading

0 comments on commit bd2f042

Please sign in to comment.