Skip to content

Commit

Permalink
Merge pull request #408 from TheDuckCow/dev
Browse files Browse the repository at this point in the history
Dev to master for v3.4.3
  • Loading branch information
TheDuckCow authored Mar 26, 2023
2 parents adbc2ba + e107731 commit b365666
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 108 deletions.
217 changes: 174 additions & 43 deletions MCprep_addon/MCprep_resources/mcprep_data_update.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MCprep_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
bl_info = {
"name": "MCprep",
"category": "Object",
"version": (3, 4, 2),
"version": (3, 4, 3),
"blender": (2, 80, 0),
"location": "3D window toolshelf > MCprep tab",
"description": "Minecraft workflow addon for rendering and animation",
Expand Down
8 changes: 7 additions & 1 deletion MCprep_addon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
# ADDON GLOBAL VARIABLES AND INITIAL SETTINGS
# -----------------------------------------------------------------------------


def init():

# -----------------------------------------------
# Verbose, use as conf.v
# Used to print out extra information, set false with distribution
# -----------------------------------------------
global dev
dev = False
dev = True

global v
v = True # $VERBOSE, UI setting
Expand All @@ -64,11 +65,16 @@ def init():
os.path.dirname(__file__),
"MCprep_resources",
"mcprep_data.json")
global json_path_update
json_path_update = os.path.join(
os.path.dirname(__file__),
"MCprep_resources",
"mcprep_data_update.json")

# Used to avoid checking for update file on disk too frequently.
global last_check_for_updated
last_check_for_updated = 0

# if new update file found from install, replace old one with new
if os.path.isfile(json_path_update):
if os.path.isfile(json_path) is True:
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 @@ -595,7 +595,7 @@ def generate_base_material(self, context, name, path):
# need to create at least one texture node first, then the rest works
mat.use_nodes = True
nodes = mat.node_tree.nodes
node_diff = generate.create_node(nodes, 'ShaderNodeTexImage', image = image)
node_diff = generate.create_node(nodes, 'ShaderNodeTexImage', image=image)
node_diff["MCPREP_diffuse"] = True

# Initialize extra passes as well
Expand Down
114 changes: 106 additions & 8 deletions MCprep_addon/mcprep_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#
# ##### END GPL LICENSE BLOCK #####

import os
import time

# library imports
import bpy
import os

# addon imports
from . import addon_updater_ops
Expand All @@ -45,12 +45,63 @@
OPT_IN = 'URL' if util.bv28() else 'HAND'


def addon_just_updated():
"""Indicates an addon was updated mid session, to force a user restart.
Put into UI calls, therefore called often and should lightweight.
"""
if addon_updater_ops.updater.invalid_updater:
return False
if not addon_updater_ops.updater.json:
return False
did_update = addon_updater_ops.updater.json.get("just_updated") is True
if did_update:
return True

# If not alreaedy flipped to be recongized as an update, do a slightly more
# thorough check by seeing if the mcprep_data_update.json exists (ie it
# hasn't been renamed yet to mcprep_data.json, which happens on init after
# an install/update)
check_interval = 5 # Time in seconds
if time.time() - check_interval > conf.last_check_for_updated:
check_for_updated_files()
conf.last_check_for_updated = time.time()
return


def check_for_updated_files():
"""Checks for a file which would only exist after an auto/manual update.
We check for the mcprep_data_update.json file, which would only exist after
an automated or manual update and before blender has been restarted. This
file is auto renamed to overwrite any existing mcprep_data.json file, but
that only runs on addon startup, so it's a good flag to use to force users
to restart.
This covers the scenario where someone used the native blender install
addon *instead* of the auto updater route to update the addon.
"""
if os.path.isfile(conf.json_path_update):
addon_updater_ops.updater.json["just_updated"] = True


def restart_layout(layout):
"""Draws a restart button, used when addon_just_updated is true."""
box = layout.box()
col = box.column()
alert_row = col.row()
alert_row.alert = True
alert_row.operator(
"wm.quit_blender",
text="Restart blender",
icon="ERROR")
col.label(text="to complete update")


# -----------------------------------------------------------------------------
# Above for class functions/operators
# Below for UI
# UI class functions
# -----------------------------------------------------------------------------


class MCPREP_MT_mob_spawner(bpy.types.Menu):
"""Shift-A menu in the 3D view"""
bl_label = "Mob Spawner"
Expand Down Expand Up @@ -236,6 +287,9 @@ class MCPREP_MT_3dview_add(bpy.types.Menu):
bl_idname = "MCPREP_MT_3dview_add"

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
layout = self.layout
props = context.scene.mcprep_props

Expand Down Expand Up @@ -686,6 +740,12 @@ def draw(self, context):
# check for update in background thread if appropraite
addon_updater_ops.check_for_update_background()

# show update ready if available
addon_updater_ops.update_notice_box_ui(self, context)
if addon_just_updated():
# Don't draw restart_layout() here, as we already have a box
return

layout = self.layout
split = layout.split()
col = split.column(align=True)
Expand Down Expand Up @@ -832,9 +892,6 @@ def draw(self, context):
split = layout.split()
row = split.row(align=True)

# show update ready if available
addon_updater_ops.update_notice_box_ui(self, context)


class MCPREP_PT_bridge(bpy.types.Panel):
"""MCprep panel for directly importing and reloading minecraft saves"""
Expand All @@ -845,6 +902,10 @@ class MCPREP_PT_bridge(bpy.types.Panel):
bl_category = "MCprep"

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return

# bridge.panel_draw(self, context)
pass

Expand All @@ -858,6 +919,10 @@ class MCPREP_PT_world_tools(bpy.types.Panel):

def draw(self, context):
layout = self.layout
if addon_just_updated():
restart_layout(layout)
return

rw = layout.row()
col = rw.column()
row = col.row(align=True)
Expand Down Expand Up @@ -909,6 +974,10 @@ class MCPREP_PT_skins(bpy.types.Panel):

def draw(self, context):
layout = self.layout
if addon_just_updated():
restart_layout(layout)
return

scn_props = context.scene.mcprep_props
sind = context.scene.mcprep_skins_list_index
mob_ind = context.scene.mcprep_props.mob_list_index
Expand Down Expand Up @@ -1020,6 +1089,10 @@ def draw(self, context):
scn_props = context.scene.mcprep_props

layout = self.layout
if addon_just_updated():
restart_layout(layout)
return

row = layout.row()
# row.operator("mcprep.create_default_material")
split = layout.split()
Expand Down Expand Up @@ -1061,6 +1134,10 @@ class MCPREP_PT_materials_subsettings(bpy.types.Panel):
bl_context = "material"

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return

b_row = self.layout.row()
b_col = b_row.column(align=False)
b_col.label(text="Resource pack")
Expand Down Expand Up @@ -1619,6 +1696,9 @@ class MCPREP_PT_spawn(bpy.types.Panel):
bl_category = "MCprep"

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
row = self.layout.row(align=True)
row.label(text="Click triangle to open")
ops = row.operator(
Expand All @@ -1637,6 +1717,9 @@ class MCPREP_PT_mob_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
if not is_obj_mode:
draw_mode_warning(self.layout)
Expand All @@ -1662,6 +1745,9 @@ class MCPREP_PT_model_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
if not is_obj_mode:
draw_mode_warning(self.layout)
Expand All @@ -1687,6 +1773,9 @@ class MCPREP_PT_item_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
is_pose_mode = context.mode == "POSE"
if not is_obj_mode and not is_pose_mode:
Expand All @@ -1713,6 +1802,9 @@ class MCPREP_PT_effects_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
if not is_obj_mode:
draw_mode_warning(self.layout)
Expand All @@ -1738,6 +1830,9 @@ class MCPREP_PT_entity_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
if not is_obj_mode:
draw_mode_warning(self.layout)
Expand All @@ -1763,6 +1858,9 @@ class MCPREP_PT_meshswap_spawner(bpy.types.Panel):
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
if addon_just_updated():
restart_layout(self.layout)
return
is_obj_mode = context.mode == "OBJECT"
if not is_obj_mode:
draw_mode_warning(self.layout)
Expand Down
29 changes: 13 additions & 16 deletions MCprep_addon/spawner/mcmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .. import conf
from .. import util
from .. import tracking
from ..materials import generate


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -102,22 +103,18 @@ def add_element(

def add_material(name="material", path=""):
"""Creates a simple material with an image texture from path."""
conf.log(name + ": " + path, vv_only=True)
mat = bpy.data.materials.new(name=name)
mat.blend_method = 'CLIP'
mat.shadow_method = 'CLIP'
mat.use_nodes = True
matnodes = mat.node_tree.nodes

tex = matnodes.new('ShaderNodeTexImage')
if os.path.isfile(path):
img = bpy.data.images.load(path, check_existing=True)
tex.image = img
tex.interpolation = 'Closest'

shader = matnodes['Principled BSDF']
mat.node_tree.links.new(shader.inputs['Base Color'], tex.outputs['Color'])
mat.node_tree.links.new(shader.inputs['Alpha'], tex.outputs['Alpha'])
cur_mats = list(bpy.data.materials)
res = bpy.ops.mcprep.load_material(filepath=path, skipUsage=True)
if res != {'FINISHED'}:
conf.log("Failed to generate material as specified")
post_mats = list(bpy.data.materials)

new_mats = list(set(post_mats) - set(cur_mats))
if not new_mats:
conf.log("Failed to fetch any generated material")
return None

mat = new_mats[0]
return mat


Expand Down
Loading

0 comments on commit b365666

Please sign in to comment.