Skip to content

Commit

Permalink
Merge pull request #50 from atticus-lv/fix-4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
atticus-lv authored Jun 4, 2024
2 parents 6e55dfb + 73ce8aa commit 3d5e197
Show file tree
Hide file tree
Showing 26 changed files with 750 additions and 126 deletions.
4 changes: 2 additions & 2 deletions addon/asset_helper/op_batch_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class selected_assets:

@classmethod
def poll(cls, context):
return hasattr(context, 'selected_asset_files') and context.selected_asset_files
return hasattr(context, 'selected_assets') and context.selected_assets

def get_local_selected_assets(self, context):
current_library_name = context.area.spaces.active.params.asset_library_ref
match_obj = [asset_file.local_id for asset_file in context.selected_asset_files if
match_obj = [asset_file.local_id for asset_file in context.selected_assets if
current_library_name == "LOCAL"]

return match_obj
Expand Down
10 changes: 6 additions & 4 deletions addon/asset_helper/ops_render_asset_pv.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class render_asset_preview:

@classmethod
def poll(cls, context):
return context.selected_asset_files and bpy.data.filepath != ''
return context.selected_assets and bpy.data.filepath != ''

def invoke(self, context, event):
d = {'WORLD': 'World', 'MATERIAL': 'Material'}
Expand All @@ -139,9 +139,11 @@ def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=250)

def get_match_obj(self, context):
current_library_name = context.area.spaces.active.params.asset_library_ref
match_obj = [asset_file.local_id for asset_file in context.selected_asset_files if
current_library_name == "LOCAL"]
parm = context.area.spaces.active.params
asset_library_reference = parm.asset_library_ref if bpy.app.version < (4, 0, 0) else parm.asset_library_reference
current_library_name = asset_library_reference
match_obj = [asset_file.local_id for asset_file in context.selected_assets if
hasattr(asset_file, 'local_id')]
return match_obj

def draw_settings(self, context, layout):
Expand Down
20 changes: 13 additions & 7 deletions addon/asset_helper/ops_set_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class SPIO_OT_set_preview_to_selected_assets(bpy.types.Operator):

@classmethod
def poll(cls, context):
return context.selected_asset_files
if bpy.app.version < (4, 0, 0):
return context.selected_assets
else:
return context.selected_assets

def draw(self, context):
layout = self.layout
Expand Down Expand Up @@ -60,8 +63,11 @@ def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=400)

def execute(self, context):
current_library_name = context.area.spaces.active.params.asset_library_ref
match_obj = [asset_file.local_id for asset_file in context.selected_asset_files if
parm = context.area.spaces.active.params
asset_library_reference = parm.asset_library_ref if bpy.app.version < (
4, 0, 0) else parm.asset_library_reference
current_library_name = asset_library_reference
match_obj = [asset_file.local_id for asset_file in context.selected_assets if
current_library_name == "LOCAL"]
match_names = [obj.name for obj in match_obj]

Expand All @@ -76,7 +82,8 @@ def execute(self, context):
for obj in match_obj:
override = context.copy()
override['id'] = obj
bpy.ops.ed.lib_id_load_custom_preview(override, filepath=self.filepaths[0])
with bpy.context.temp_override(id=obj):
bpy.ops.ed.lib_id_load_custom_preview(filepath=self.filepaths[0])
else:
for path in self.filepaths:
basename = os.path.basename(path)
Expand All @@ -94,9 +101,8 @@ def execute(self, context):
index = match_names.index(name)
obj = match_obj[index]
# get asset data
override = context.copy()
override['id'] = obj
bpy.ops.ed.lib_id_load_custom_preview(override, filepath=path)
with bpy.context.temp_override(id = obj):
bpy.ops.ed.lib_id_load_custom_preview(filepath=path)

redraw_window()

Expand Down
3 changes: 3 additions & 0 deletions addon/exporter/op_export_anim_abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import bpy
from bpy.props import StringProperty, BoolProperty, EnumProperty

41 changes: 41 additions & 0 deletions asset/scripts/script_export_blend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import argparse
import bpy
import sys


def main(args):
print("Script args: ", args)

if len(args) > 0:
parser = argparse.ArgumentParser()
parser.add_argument('blend')
parser.add_argument('--pack', action='append')
args = parser.parse_args(args)

blend = args.blend

print(f"Blend to fix: {blend}")

bpy.ops.wm.open_mainfile(filepath=blend)

# pack
bpy.ops.file.pack_all()
try:
bpy.ops.file.pack_libraries()
except Exception as e:
print(e)

for o in bpy.data.objects:
bpy.context.scene.collection.objects.link(o)

bpy.context.view_layer.update()
bpy.context.preferences.filepaths.save_version = 0 # No backup blends needed
bpy.ops.wm.save_as_mainfile(filepath=blend, compress=True)


if __name__ == "__main__":
if "--" not in sys.argv:
argv = [] # as if no args are passed
else:
argv = sys.argv[sys.argv.index("--") + 1:] # get all args after "--"
main(argv)
41 changes: 41 additions & 0 deletions asset/scripts/script_export_blend_material_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import argparse
import bpy
import sys


def main(args):
print("Script args: ", args)

if len(args) > 0:
parser = argparse.ArgumentParser()
parser.add_argument('blend')
parser.add_argument('--pack', action='append')
args = parser.parse_args(args)

blend = args.blend

print(f"Blend to fix: {blend}")

bpy.ops.wm.open_mainfile(filepath=blend)

# pack
bpy.ops.file.pack_all()
try:
bpy.ops.file.pack_libraries()
except Exception as e:
print(e)

for o in bpy.data.objects:
bpy.data.objects.remove(o)

bpy.context.view_layer.update()
bpy.context.preferences.filepaths.save_version = 0 # No backup blends needed
bpy.ops.wm.save_as_mainfile(filepath=blend, compress=True)


if __name__ == "__main__":
if "--" not in sys.argv:
argv = [] # as if no args are passed
else:
argv = sys.argv[sys.argv.index("--") + 1:] # get all args after "--"
main(argv)
63 changes: 63 additions & 0 deletions asset/scripts/script_resize_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import argparse
import bpy
import sys
from math import floor


def main(argv):
FILEPATH,OUTPATH, SIZE_X, SCALE, COLORSPACE = argv
SIZE_X = int(SIZE_X)
SCALE = float(SCALE)

context = bpy.context
scene = context.scene

scene.use_nodes = True
node_tree = scene.node_tree

# Remove default nodes, except composite
n_comp = None
for n in node_tree.nodes:
if not n.type == 'COMPOSITE':
node_tree.nodes.remove(n)
else:
n_comp = n

img = bpy.data.images.load(FILEPATH)
n_img = node_tree.nodes.new("CompositorNodeImage")
n_img.image = img

n_blur = node_tree.nodes.new("CompositorNodeBlur")
n_blur.filter_type = 'FLAT'
n_blur.size_x = floor(img.size[0] / SIZE_X / 2)
n_blur.size_y = n_blur.size_x

n_scale = node_tree.nodes.new("CompositorNodeScale")
n_scale.space = "RENDER_SIZE"
n_scale.frame_method = "CROP"

# Links
links = node_tree.links
links.new(n_img.outputs[0], n_blur.inputs[0])
links.new(n_blur.outputs[0], n_scale.inputs[0])
links.new(n_scale.outputs[0], n_comp.inputs[0])

# Render
r = scene.render
r.image_settings.file_format = 'JPEG'
r.image_settings.quality = 95
r.resolution_x = SIZE_X
r.resolution_y = int(SIZE_X / SCALE)
r.resolution_percentage = 100
r.filepath = OUTPATH
scene.view_settings.view_transform = COLORSPACE

bpy.ops.render.render(write_still=True)


if __name__ == "__main__":
if "--" not in sys.argv:
argv = [] # as if no args are passed
else:
argv = sys.argv[sys.argv.index("--") + 1:] # get all args after "--"
main(argv)
File renamed without changes.
11 changes: 11 additions & 0 deletions imexporter/4.0/_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is the config file for blender 4.0
# Define the default category for import and export
# !include will include the yaml file in the same directory
# Check the yaml file for more format details

# version: 0.1
version: 0.1

Import: !include ./import_default.yaml
Export: !include ./export_default.yaml
Import-spio: !include ./import_spio.yaml
104 changes: 104 additions & 0 deletions imexporter/4.0/export_default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# config for default importer
# example for custom importer config using bpy.ops.wm.obj_import()

# English Example:
# Wavefront (.obj) name must be unique
# bl_idname: 'wm.obj_import' bl_idname, call this operator
# icon: 'EXPORT' icon, use blender icon
# category, use blender category
# file_types: {'obj'} file_types, file extension
# args: args, arguments for operator, default pass in 'filepath'
# pre_script: pre_script, run before operator
# post_script: post_script, run after operator

# Chinese Example:
# 导出Obj (.obj) 名称必须唯一
# bl_idname: 'wm.obj_import' bl_idname, 调用这个操作
# icon: 'EXPORT' icon, 使用blender图标
# category, 使用blender分类
# file_types: {'obj'} file_types, 文件扩展名
# args: args, 操作的参数, 默认传入'filepath'
# pre_script: pre_script, 在操作前运行
# post_script: post_script, 在操作后运行

Collada (.dae):
bl_idname: 'wm.collada_export'
icon: 'EXPORT'
file_types: { 'dae' }
pre_script:
post_script:
args:
selected: True

Alembic (.abc):
bl_idname: 'wm.alembic_export'
icon: 'EXPORT'
file_types: { 'abc' }
pre_script:
post_script:
args:
selected: True

USD (.usd):
bl_idname: 'wm.usd_export'
icon: 'EXPORT'
file_types: { 'usd', 'usda', 'usdc' }
pre_script:
post_script:
args:
selected_objects_only: True

Stanford (.ply):
bl_idname: 'import_mesh.ply'
icon: 'EXPORT'
file_types: { 'ply' }
pre_script:
post_script:
args:
use_selection: True

Stl (.stl):
bl_idname: 'import_mesh.stl'
icon: 'EXPORT'
file_types: { 'stl' }
pre_script:
post_script:
args:
use_selection: True

FBX (.fbx):
bl_idname: 'import_scene.fbx'
icon: 'EXPORT'
file_types: { 'fbx' }
pre_script:
post_script:
args:
use_selection: True

Wavefront (.obj):
bl_idname: 'wm.obj_export'
icon: 'EXPORT'
file_types: { 'obj' }
pre_script:
post_script:
args:
use_selection: True

glTF 2.0 (.gltf/.glb):
bl_idname: 'export_scene.gltf'
icon: 'EXPORT'
file_types: { 'gltf'}
pre_script:
post_script:
args:
use_selection: True
export_format: GLTF_EMBEDDED

X3D (.x3d/.wrl):
bl_idname: 'export_scene.x3d'
icon: 'EXPORT'
file_types: {'x3d'}
pre_script:
post_script:
args:

Loading

0 comments on commit 3d5e197

Please sign in to comment.