Skip to content

Commit

Permalink
updated blender extension plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
NicSavichev committed Feb 20, 2024
1 parent 2153de4 commit da4694f
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 131 deletions.
1 change: 1 addition & 0 deletions prog/tools/dag4blend/__build_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'dag4blend/exporter/export_panel.py', 'dag4blend/exporter/exporter.py', 'dag4blend/exporter/writer.py',
'dag4blend/importer/import_panel.py', 'dag4blend/importer/importer.py', 'dag4blend/importer/reader.py',
'dag4blend/object_properties/object_properties.py', 'dag4blend/smooth_groups/smooth_groups.py',
'dag4blend/smooth_groups/mesh_calc_smooth_groups.py',
'dag4blend/colprops/colprops.py',
'dag4blend/pyparsing.py', 'dag4blend/datablock.py',
]
Expand Down
4 changes: 2 additions & 2 deletions prog/tools/dag4blend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
bl_info = {"name": "dag4blend",
"description": "Tools for editing dag files",
"author": "Gaijin Entertainment",
"version": (2, 1, 6),#2023.12.22
"blender": (3, 5, 1),
"version": (2, 1, 7),#2024.02.20
"blender": (4, 0, 2),
"location": "File > Export",
"wiki_url": "",
"tracker_url": "",
Expand Down
2 changes: 1 addition & 1 deletion prog/tools/dag4blend/cmp/cmp_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def draw_entity_editor(self,context,layout):
return
#Node explode n stuff
def draw_node_converter(self,context,layout):
P = bpy.data.scenes[0].dag4blend.cmp
P = bpy.data.scenes[0].dag4blend.cmp.tools
addon_name = basename(__package__)
pref = bpy.context.preferences.addons[addon_name].preferences
box = layout.box()
Expand Down
4 changes: 2 additions & 2 deletions prog/tools/dag4blend/dagormat/rw_dagormat_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def dagormat_to_text(mat,text):
text.write('\n twosided:b=')
if DM.sides == 1:
text.write('yes\n')
elif DM.sides == 2:
text.write('\n script:t="real_two_sided=yes"\n')
else:
text.write('no\n')
text.write('\n tex16support:b=yes')
Expand All @@ -94,8 +96,6 @@ def dagormat_to_text(mat,text):
text.write(str(int(DM.emissive[0]*255))+',')
text.write(str(int(DM.emissive[1]*255))+',')
text.write(str(int(DM.emissive[2]*255)))
if DM.sides == 2:
text.write('\n script:t="real_two_sided=yes"\n')
for param in list(DM.optional.keys()):
text.write('\n script:t="'+param+'=')
try:
Expand Down
5 changes: 3 additions & 2 deletions prog/tools/dag4blend/exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from ..tools.tools_panel import apply_modifiers, fix_mat_slots, optimize_mat_slots, preserve_sharp
from ..tools.tools_functions import *

from ..smooth_groups.smooth_groups import int_to_uint,precalc_sg
from ..smooth_groups.smooth_groups import int_to_uint
from ..smooth_groups.mesh_calc_smooth_groups import mesh_calc_smooth_groups


SUPPORTED_TYPES = ('MESH', 'CURVE') # ,'CURVE','EMPTY','TEXT','CAMERA','LAMP')
Expand Down Expand Up @@ -364,7 +365,7 @@ def dumpMesh(self, obj, node, scene):
fix_mat_slots(exp_obj)
reorder_uv_layers(me)
if exp_obj.data.attributes.get('SG') is None:
precalc_sg(exp_obj.data)
mesh_calc_smooth_groups(exp_obj.data)
#collecting from pre-triangulated mesh to make it reversable on import
edge_keys = self.getEdgeKeys(exp_obj, scene)
#dag contains only triangles
Expand Down
2 changes: 2 additions & 0 deletions prog/tools/dag4blend/importer/import_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def draw(self,context):
layout = self.layout
layout.prop(P, 'with_subfolders')
layout.prop(P, 'mopt')
layout.prop(P, 'preserve_sg')
layout.prop(P, 'replace_existing')
layout.prop(P, 'preserve_path')
layout.prop(P, 'masks')
Expand Down Expand Up @@ -91,6 +92,7 @@ def execute(self, context):
for dag in dags:
try:
bpy.ops.import_scene.dag(filepath = dag,
preserve_sg = P.preserve_sg,
replace_existing = P.replace_existing,
mopt = P.mopt,
preserve_path = P.preserve_path)
Expand Down
10 changes: 9 additions & 1 deletion prog/tools/dag4blend/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class DagImporter(Operator, ImportHelper):
description = 'Override export path for imported files',
default = False)

preserve_sg: BoolProperty(
name = "Preserve Smoothing Groups",
description = "Store Smoothing Groups in a integer face attribute called 'SG'",
default = False)


rootNode = None
reader = reader.DagReader()
Expand Down Expand Up @@ -355,6 +360,8 @@ def buildMesh(self, node, tm, parent):
sg.value=uint_to_int(SG[i])
i+=1
sg_to_sharp_edges(me)
if not self.preserve_sg:
me.attributes.remove(me.attributes.get('SG'))

if len(node.mesh.normals_ver_list):
normals = []
Expand Down Expand Up @@ -975,7 +982,8 @@ def execute(self, context):
msg = f'IMPORTING {filepath}\n'
pref = context.preferences.addons[basename(__package__)].preferences
if not pref.project_active:
show_popup(message='Please configure at least one project in addon preferences',title='ERROR!', icon='ERROR')
show_popup(message='Please configure at least one project in addon preferences',
title='ERROR!', icon='ERROR')
return {'CANCELLED'}
log(msg)#isn't necessary in the info panel
if self.with_dmgs is False and self.with_dps is False and self.with_lods is False:
Expand Down
60 changes: 38 additions & 22 deletions prog/tools/dag4blend/object_properties/object_properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bpy, os
from bpy.props import StringProperty, PointerProperty, FloatProperty
from bpy.utils import register_class, unregister_class, user_resource
from bpy.utils import register_class, unregister_class
from bpy.types import Operator, Panel, PropertyGroup
from ..helpers.texts import *
from ..helpers.popup import show_popup
Expand Down Expand Up @@ -54,8 +54,8 @@ def props_to_text(obj):

def get_presets_list():
addon_name = basename(__package__)
path = user_resource('SCRIPTS') + f'\\addons\\{addon_name}\\object_properties\\presets\\'
items = []
pref = bpy.context.preferences.addons[addon_name].preferences
path = pref.props_presets_path
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))]
return files

Expand Down Expand Up @@ -108,11 +108,14 @@ def execute(self, context):
addon_name = basename(__package__)
pref=bpy.context.preferences.addons[addon_name].preferences
preset = pref.prop_preset
path = user_resource('SCRIPTS') + f"\\addons\\{addon_name}\\object_properties\\presets\\{preset}.txt"
with open(path,'r') as t:
temp.write(t.read())
t.close()
text_to_props(obj)
path = pref.props_presets_path + f"\\{preset}.txt"
if os.path.exists(path):
with open(path,'r') as t:
temp.write(t.read())
t.close()
text_to_props(obj)
else:
show_popup(message = f'"{preset}.txt" not found in {pref.props_presets_path}', title='Error', icon='ERROR')
return {'FINISHED'}


Expand All @@ -132,7 +135,7 @@ def execute(self, context):
name = pref.prop_preset_name
if name == '':
name = 'unnamed'
dirpath = user_resource('SCRIPTS') + f"\\addons\\{addon_name}\\object_properties\\presets"
dirpath = pref.props_presets_path
if not os.path.exists(dirpath):
os.makedirs(dirpath)
path = f"{dirpath}\\{name}.txt"
Expand All @@ -158,15 +161,15 @@ def execute(self, context):
addon_name = basename(__package__)
pref=bpy.context.preferences.addons[addon_name].preferences
name = pref.prop_preset
path = user_resource('SCRIPTS') + f"\\addons\\{addon_name}\\object_properties\\presets\\{name}.txt"
path = pref.props_presets_path + f"\\{name}.txt"
os.remove(path)
list = get_presets_list()
if list.__len__()>0:
pref.props_preset = 0
return {'FINISHED'}


class DAGOR_invert_dagbool(bpy.types.Operator):
class DAGOR_invert_dagbool(Operator):
bl_idname = 'dt.invert_dagbool'
bl_label = 'Switch value'
bl_description = 'invert dag_bool value'
Expand Down Expand Up @@ -286,22 +289,35 @@ def draw(self, context):
else:
rem.prop(C.object.dagorprops,'["'+key+'"]',text='')
rem.operator('dt.remove_prop',text='',icon='TRASH').prop=key

presets = l.box()
header=presets.row()
header.prop(pref, 'props_preset_maximized',icon = 'DOWNARROW_HLT'if pref.props_preset_maximized else 'RIGHTARROW_THIN',
emboss=False,text='Presets')
header.prop(pref, 'props_preset_maximized',
icon = 'DOWNARROW_HLT'if pref.props_preset_maximized else 'RIGHTARROW_THIN', emboss=False,text='Presets')
header.label(text='',icon='THREE_DOTS')

if pref.props_preset_maximized:
presets.operator('dt.save_op_preset',text = "Save preset as:")
presets.prop(pref, 'prop_preset_name', text = '')
presets.operator('dt.apply_op_preset', text = 'Apply preset:')
act = presets.row()
act.prop(pref, 'prop_preset', text = "")
act.operator('dt.remove_op_preset', text = "", icon = "TRASH")
#no need to use custom operator for each folder

addon_name = basename(__package__)
path = user_resource('SCRIPTS') + f"\\addons\\{addon_name}\\object_properties\\presets"
presets.operator('wm.path_open', icon = 'FILE_FOLDER', text = "open presets folder").filepath = path
path = pref.props_presets_path
path_exists = os.path.exists(path)
if path_exists:
presets.operator('dt.save_op_preset',text = "Save preset as:")
presets.prop(pref, 'prop_preset_name', text = '')
presets.operator('dt.apply_op_preset', text = 'Apply preset:')
act = presets.row()
act.prop(pref, 'prop_preset', text = "")
act.operator('dt.remove_op_preset', text = "", icon = "TRASH")
#no need to use custom operator for each folder
col = presets.column(align = True)
row = col.row(align = True)
row.operator('wm.path_open', icon = 'FILE_FOLDER', text = "open presets folder").filepath = path
else:
col = presets.column()
col.label(icon = 'ERROR')
col.label(text = 'Presets folder not found')
col.label(text = 'Please, set existing one')
col.label(text = 'in addon preferences!')

tools = l.box()
header = tools.row()
Expand Down
9 changes: 7 additions & 2 deletions prog/tools/dag4blend/read_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import configparser
import os
import bpy
from .helpers.basename import basename
from shutil import copyfile

#modifying of original file to make it readable by python configparser
#TODO: make custom parser instead of fixing unreadable comments in copy
def cfg_upd():
blend_cfg=os.path.join(os.path.dirname(__file__), 'fixed_dagorShaders.cfg')
max_cfg=os.path.join(os.path.dirname(__file__), 'dagorShaders.cfg')
addon_name = basename(__package__)
pref = bpy.context.preferences.addons[addon_name].preferences
max_cfg = pref.cfg_path
copyfile (max_cfg,blend_cfg)
cfg=open(blend_cfg,'r')
fixed=cfg.read().replace('//','#')#turning comments into python-like
Expand All @@ -21,7 +24,9 @@ def read_config():
shader_categories = []

config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), 'fixed_dagorShaders.cfg'))
config_filepath = os.path.join(os.path.dirname(__file__), 'fixed_dagorShaders.cfg')
config.read(config_filepath)
os.remove(config_filepath)
category = None
global_params_section = config["_global_params"]
global_params = []
Expand Down
44 changes: 29 additions & 15 deletions prog/tools/dag4blend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DagShaderClass(PropertyGroup):

def get_obj_prop_presets(self, context):
pref=bpy.context.preferences.addons[__package__].preferences
path = user_resource('SCRIPTS') + f'\\addons\\{__package__}\\object_properties\\presets\\'
path = pref.props_presets_path
items = []
files = [f for f in listdir(path) if isfile(join(path,f))]
for f in files:
Expand All @@ -167,13 +167,22 @@ def get_obj_prop_presets(self, context):

#IMPORTER
class Dag_Import_Props(PropertyGroup):
with_subfolders :BoolProperty (name="Search in subfolders", default=False, description = 'Search for .dags in subfolders as well')
mopt :BoolProperty (name="Optimize material slots", default=True, description = 'Remove unnecessary material slots')
replace_existing:BoolProperty (name="Reimport existing", default=False, description = 'Replace dags that already exist in scene by imported versions')
preserve_path :BoolProperty (name="Preserve paths", default=False, description = 'Override export path for each imported dag')
dirpath :StringProperty(name="Path", default='C:\\tmp\\', subtype = 'DIR_PATH', description = "Where search for .dag files?",update=upd_imp_path)
masks :StringProperty(name="Masks", default='', description = 'name should contain at least one to be imported. Split by";"')
excludes :StringProperty(name="Excludes",default='', description = 'name should not contain any to be imported. Split by";"')
with_subfolders :BoolProperty (name="Search in subfolders", default=False,
description = 'Search for .dags in subfolders as well')
mopt :BoolProperty (name="Optimize material slots", default=True,
description = 'Remove unnecessary material slots')
preserve_sg :BoolProperty (name="Preserve Smoothing Groups", default=False,
description = "Store Smoothing Groups in a integer face attribute called 'SG'")
replace_existing:BoolProperty (name="Reimport existing", default=False,
description = 'Replace dags that already exist in scene by imported versions')
preserve_path :BoolProperty (name="Preserve paths", default=False,
description = 'Override export path for each imported dag')
dirpath :StringProperty(name="Path", default='C:\\tmp\\', subtype = 'DIR_PATH',
description = "Where search for .dag files?",update=upd_imp_path)
masks :StringProperty(name="Masks", default='',
description = 'name should contain at least one to be imported. Split by";"')
excludes :StringProperty(name="Excludes",default='',
description = 'name should not contain any to be imported. Split by";"')

#EXPORTER
class Dag_Export_Props(PropertyGroup):
Expand Down Expand Up @@ -249,10 +258,12 @@ class dag4blend_props(PropertyGroup):
class DagSettings(AddonPreferences):
bl_idname = __package__
def_path='C:\\replace_by_correct_path\\'
def_cfg_path='D:\\dagor2\tools\\dagor3_cdk\\plugin3dsMax-x64\\dagorShaders.cfg'
def_cfg_path=bpy.utils.user_resource('SCRIPTS') + f"\\addons\\{__package__}\\dagorShaders.cfg"
#global
assets_path: StringProperty(default=def_path, subtype = 'DIR_PATH', description = 'assets location')
#cfg_path: StringProperty(default=def_cfg_path, subtype = 'FILE_PATH',description = 'dagorShaders.cfg location')
props_presets_path: StringProperty(subtype = 'DIR_PATH',
default = bpy.utils.user_resource('SCRIPTS') + f"\\addons\\{__package__}\\object_properties\\presets")
cfg_path: StringProperty(default=def_cfg_path, subtype = 'FILE_PATH',description = 'dagorShaders.cfg location')

new_project_name: StringProperty(description = 'name of project')
new_project_path: StringProperty(description = 'where assets(dags, textures, composits) of that project stored?',
Expand Down Expand Up @@ -322,16 +333,19 @@ class DagSettings(AddonPreferences):

def draw(self, context):
l = self.layout
proj=l.box()
new=proj.row()
new.prop (self,'new_project_name',text='Name')
new.prop (self,'new_project_path',text='Path')
new.operator('dt.add_project',icon='ADD',text='ADD Project')
paths = l.box()
paths.prop(self, 'props_presets_path', text = "ObjProps presets")
paths.prop(self, 'cfg_path', text = "dagorShaders.cfg")
projects = l.box()
header = projects.row()
header.prop(self, 'projects_maximized', text = 'Projects',icon = 'DOWNARROW_HLT'if self.projects_maximized else 'RIGHTARROW_THIN',
emboss=False,expand=True)
if self.projects_maximized:
box = projects.box()
new=box.row()
new.prop (self,'new_project_name',text='Name')
new.prop (self,'new_project_path',text='Path')
new.operator('dt.add_project',icon='ADD',text='ADD Project')
index=0
for project in self.projects:
box = projects.box()
Expand Down
Loading

0 comments on commit da4694f

Please sign in to comment.