Skip to content

Commit

Permalink
Hard WIP (Use Only for Testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Oct 22, 2024
1 parent a91861a commit 4a9ae54
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 63 deletions.
Binary file modified MiBlend.blend
Binary file not shown.
15 changes: 13 additions & 2 deletions MiBlend_Source/Assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ def append_collection(asset_name, asset_collection, asset_path):

def run_python_script(name, path):
try:
script_dir = os.path.dirname(path)

if script_dir not in sys.path:
sys.path.append(script_dir)

properties = {}

for index, asset in enumerate(bpy.context.scene.assetsproperties.asset_items):
if asset.get("Asset_name", "") == name:
properties = {key.replace('_property', ''): value for key, value in asset.items() if 'property' in key}

with open(path, 'r') as file:
exec(file.read())
exec(file.read(), {}, properties)
except:
Absolute_Solver("009", name, traceback.print_exc())

Expand Down Expand Up @@ -208,7 +219,7 @@ def update_assets():
asset_info["Type"] = asset_tags[0]
asset_info["File_path"] = asset_file_path

if any('property' in key.lower() for key in asset_info):
if any('property' in key for key in asset_info):
asset_info["has_properties"] = True

assets_list.append(asset_info)
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions MiBlend_Source/Assets/Rigs/Story Mode Rig/Story Mode Rig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Format_version": "a008",
"Asset_name": "Story Mode Character Rig",
"Author": "Faizek, Aspirata",
"Blender_version": ">= 4.0.0",
"File_path": "Rigs\\Story Mode Rig\\Story Mode Rig",
"Collection_name": "Story Mode Character",
"Tags": ["Rig", "Story Mode"]
}
10 changes: 10 additions & 0 deletions MiBlend_Source/Assets/Scripts/Beveler/Beveler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Format_version": "a008",
"Author": "Aspirata",
"Asset_name": "Beveler",
"File_path": "Scripts\\Beveler\\Beveler",
"Use Node_property": false,
"Amount_property": 0.01,
"Segments_property": 4,
"Tags": ["Script"]
}
22 changes: 22 additions & 0 deletions MiBlend_Source/Assets/Scripts/Beveler/Beveler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import bpy

use_node = properties.get("Use Node")
amount = properties.get("Amount")
segments = properties.get("Segments")

for selected_object in bpy.context.selected_objects:
if use_node:
if not selected_object.material_slots:
continue

for material in selected_object.data.materials:
if material is None or not material.use_nodes:
continue
else:
if selected_object.modifiers.get("Bevel") == None:
bevel_modifier = selected_object.modifiers.new('Bevel', type='BEVEL')
else:
bevel_modifier = selected_object.modifiers.get("Bevel")

bevel_modifier.width = amount
bevel_modifier.segments = segments
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Asset_name": "Contact Shadows",
"Author": "Aspirata",
"File_path": "Scripts\\Contact Shadows\\Contact Shadows",
"Mode_property": 1,
"Only Selected Objects_property": false,
"Distance_property": 0.2,
"Bias_property": 0.03,
"Thickness_property": 0.01,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import bpy

addon_dir = os.path.dirname(os.path.abspath(__file__))
if addon_dir not in sys.path:
sys.path.append(addon_dir)

from MCB_API import GetConnectedSocketTo
from MIB_API import GetConnectedSocketTo

for selected_object in bpy.context.selected_objects:
slot = 0
Expand Down Expand Up @@ -53,8 +48,4 @@
if DBSDF != None:
material.node_tree.nodes.remove(DBSDF)

material.node_tree.links.new(PBSDF.outputs[0], Output.inputs[0])
#else:
#Absolute_Solver("m002", slot)
#else:
#Absolute_Solver("m003", selected_object)
material.node_tree.links.new(PBSDF.outputs[0], Output.inputs[0])
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"Asset_name": "Jittered Shadows",
"Author": "Aspirata",
"File_path": "Scripts\\Jittered Shadows\\Jittered Shadows",
"Mode_property": 1,
"Overblur_property": 20.0,
"Only Selected Objects_property": false,
"World Jitter_property": true,
"Overblur_property": 20.0,
"Tags": ["Script"]
}
26 changes: 4 additions & 22 deletions MiBlend_Source/Assets/Scripts/Jittered Shadows/Jittered Shadows.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
import bpy
import os
import json
mode = properties.get("Only Selected Objects", False)
overblur = clamp(0.0, properties.get("Overblur", 20.0), 100.0)
world_jitter = properties.get("World Jitter", False)

addon_dir = os.path.dirname(os.path.abspath(__file__))

current_index = bpy.context.scene.assetsproperties.asset_index
items = bpy.context.scene.assetsproperties.asset_items

current_asset = items[current_index]

json_file_path = os.path.join(addon_dir, "Assets", os.path.splitext(current_asset.get("File_path", ""))[0] + ".json")

with open(json_file_path, 'r') as json_file:
asset_data = json.load(json_file)

properties = {key.replace('_property', ''): value for key, value in current_asset.items() if 'property' in key.lower()}

mode = properties.get("Mode", asset_data["Mode_property"])
overblur = properties.get("Overblur", asset_data["Overblur_property"])
world_jitter = properties.get("World Jitter", asset_data["World Jitter_property"])

if mode == 0:
if mode == False:
for obj in bpy.context.selected_objects:
try:
obj.data.use_shadow_jitter = True
Expand Down
Binary file modified MiBlend_Source/Assets/Shader Nodes/Cracks/Cracks.blend
Binary file not shown.
13 changes: 6 additions & 7 deletions MiBlend_Source/Assets/Shader Nodes/Cracks/Cracks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import sys

addon_dir = os.path.dirname(os.path.abspath(__file__))
if addon_dir not in sys.path:
sys.path.append(addon_dir)
import bpy

from MCB_API import GetConnectedSocketTo

Expand All @@ -29,5 +25,8 @@

if GetConnectedSocketTo("Base Color", PBSDF).node != co_node:
current_material.node_tree.links.new(GetConnectedSocketTo("Base Color", PBSDF), co_node.inputs["Color"])

current_material.node_tree.links.new(co_node.outputs[0], PBSDF.inputs["Base Color"])
current_material.node_tree.links.new(co_node.outputs["Color"], PBSDF.inputs["Base Color"])

if GetConnectedSocketTo("Alpha", PBSDF).node != co_node:
current_material.node_tree.links.new(GetConnectedSocketTo("Alpha", PBSDF), co_node.inputs["Alpha"])
current_material.node_tree.links.new(co_node.outputs["Alpha"], PBSDF.inputs["Alpha"])
10 changes: 10 additions & 0 deletions MiBlend_Source/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@
}
}

Grass_Color = {
"Forest": "#79C05A",
"Taiga": "#8AB689",
}

Foliage_Color = {
"Forest": "#59AE30",
"Taiga": "#6DA36B",
}

Emissive_Materials = {

"Default": {
Expand Down
12 changes: 11 additions & 1 deletion MiBlend_Source/MIB_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ def PBSDF_compability(Input: str) -> str:
}.get(Input, Input)
return Input

def convert_hex_to_rgba(hex_code, alpha=1.0):
hex_code = hex_code.replace("#", "")
r = int(hex_code[0:2], 16) / 255.0
g = int(hex_code[2:4], 16) / 255.0
b = int(hex_code[4:6], 16) / 255.0
a = alpha
return (r, g, b, a)

def clamp(min, value, max):
return max(min(value, 100.0), 0.0)

def convert_to_linux(path):
if sys.platform.startswith('linux'):
return path.replace("\\", "/")

return path

def MaterialIn(Array, material, mode="in"):
Expand Down
19 changes: 17 additions & 2 deletions MiBlend_Source/Materials/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def fix_world():
PBSDF = None
image_texture_node = None
lbcf_node = None
Texture_Animator = None
auvf_node = None
scene = bpy.context.scene
WProperties = scene.world_properties
Expand Down Expand Up @@ -236,12 +237,26 @@ def fix_world():

material.node_tree.links.new(lbcf_node.outputs[0], PBSDF.inputs["Base Color"])

if "water" in texture_parts:
# Simple Biomes Support
if "oak" in texture_parts:
biome = "Forest"
elif "fern" or "spruce" in texture_parts:
biome = "Taiga"
elif "birch" in texture_parts:
biome = "Birch"

if "grass" in texture_parts:
lbcf_node.inputs["Mode"].default_value = 2

if "redstone" in texture_parts:
elif "water" in texture_parts:
lbcf_node.inputs["Mode"].default_value = 3

elif "redstone" in texture_parts:
lbcf_node.inputs["Mode"].default_value = 4

lbcf_node.inputs["Grass Color"].default_value = convert_hex_to_rgba(Grass_Color.get(biome))
lbcf_node.inputs["Foliage Color"].default_value = convert_hex_to_rgba(Foliage_Color.get(biome))

elif lbcf_node is not None:
material.node_tree.links.new(GetConnectedSocketTo(0, lbcf_node), PBSDF.inputs["Base Color"])
material.node_tree.nodes.remove(lbcf_node)
Expand Down
Binary file modified MiBlend_Source/Materials/Nodes.blend
Binary file not shown.
6 changes: 4 additions & 2 deletions MiBlend_Source/Preferences.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from bpy.types import AddonPreferences
from .MIB_API import blender_version
from bpy.props import (IntProperty, BoolProperty, FloatProperty, EnumProperty, StringProperty)
Expand Down Expand Up @@ -145,8 +146,9 @@ def draw(self, context):
row = box.row()
row.prop(self, "experimental_features", toggle=True)

row = box.row()
row.prop(self, "open_console_on_start", toggle=True)
if not sys.platform.startswith('linux'):
row = box.row()
row.prop(self, "open_console_on_start", toggle=True)

row = box.row()
row.prop(self, "dev_packs_path")
Expand Down
5 changes: 5 additions & 0 deletions MiBlend_Source/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ def get_tags(self):

tags: bpy.props.CollectionProperty(type=AssetTagItem)

properties_toggle: BoolProperty(
name="Properties Toggle",
description="",
default=True
)

tags_mode: EnumProperty(
items=[("and", "And", ""), ("or", "Or", "")],
Expand Down
27 changes: 15 additions & 12 deletions MiBlend_Source/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,20 +796,23 @@ def draw(self, context):
current_asset = items[current_index]

if current_asset.get("has_properties", False):
properties = {key.replace('_property', ''): value for key, value in current_asset.items() if 'property' in key.lower()}
properties = {key.replace('_property', ''): value for key, value in current_asset.items() if 'property' in key}

sbox = box.box()
row = sbox.row()
row.label(text="Properties:")
for key, value in properties.items():
row = sbox.row()
if isinstance(value, (bool, int, float, str)):
row.prop(current_asset, f'["{key}_property"]', text=key)
else:
row.label(text=f"{key}: {value}")

row = sbox.row()
row.operator("assets.save_properties")
row.prop(assets_props, "properties_toggle", icon=("TRIA_DOWN" if assets_props.properties_toggle else "TRIA_LEFT"), icon_only=True)
if assets_props.properties_toggle:
for key, value in properties.items():
row = sbox.row()
if isinstance(value, (bool, int, float, str)):
row.prop(current_asset, f'["{key}_property"]', text=key)
else:
row.label(text=f"{key}: {value}")

if Preferences.dev_tools and Preferences.experimental_features:
row = sbox.row()
row.operator("assets.save_properties")

# Filters
row = box.row()
Expand All @@ -818,7 +821,7 @@ def draw(self, context):
if assets_props.filters:
sbox = box.box()
primary_tags = {"Rig", "Script", "Shader Node", "Geo Node", "Compositor Node", "Model", "Material"}
secondary_tags = {"Vanilla", "Realistic", "Node", "Particles"}
secondary_tags = {"Simple", "Realistic", "Node", "Particles"}

row = sbox.row()
row.label(text="Tags:")
Expand Down Expand Up @@ -889,4 +892,4 @@ def filter_items(self, context, data, property):
else:
flt_flags.append(0)

return flt_flags, []
return flt_flags, []
2 changes: 1 addition & 1 deletion MiBlend_Source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def InitOnStart():

update_assets()

if bpy.context.preferences.addons[__package__].preferences.dev_tools and bpy.context.preferences.addons[__package__].preferences.open_console_on_start:
if bpy.context.preferences.addons[__package__].preferences.dev_tools and bpy.context.preferences.addons[__package__].preferences.open_console_on_start and not sys.platform.startswith('linux'):
bpy.ops.wm.console_toggle()

@persistent
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ Links:
Links:
- https://modrinth.com/resourcepack/embrace-pixels

### Faizek - Story Mode Character Rig

Links:
- https://x.com/fluffy_aizek
- https://t.me/fluffyaizekmedia
- https://vk.com/fluffy_aizek

## Special Thanks:

### jabady - Active Testing And Bug Reporting
Expand Down

0 comments on commit 4a9ae54

Please sign in to comment.