finish vt_mtl and vt_group Panel system
This commit is contained in:
parent
4701164a6c
commit
dde95c3e4f
@ -2,7 +2,7 @@ import bpy,bmesh,bpy_extras,mathutils
|
|||||||
import pathlib,zipfile,time,os,tempfile,math
|
import pathlib,zipfile,time,os,tempfile,math
|
||||||
import struct, shutil
|
import struct, shutil
|
||||||
from bpy_extras import io_utils, node_shader_utils
|
from bpy_extras import io_utils, node_shader_utils
|
||||||
from . import UTILS_constants, UTILS_functions, UTILS_file_io, UTILS_zip_helper
|
from . import UTILS_constants, UTILS_functions, UTILS_file_io, UTILS_zip_helper, UTILS_virtools_prop
|
||||||
|
|
||||||
class BALLANCE_OT_export_bm(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
|
class BALLANCE_OT_export_bm(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
|
||||||
"""Save a Ballance Map File (BM file spec 1.4)"""
|
"""Save a Ballance Map File (BM file spec 1.4)"""
|
||||||
@ -118,8 +118,7 @@ def export_bm(context, bmx_filepath, prefs_fncg, opts_exportMode, opts_exportTar
|
|||||||
object_isHidden = not obj.visible_get()
|
object_isHidden = not obj.visible_get()
|
||||||
|
|
||||||
# try get grouping data
|
# try get grouping data
|
||||||
object_groupList = _try_get_custom_property(obj, 'virtools-group')
|
object_groupList = UTILS_virtools_prop.get_virtools_group_data(obj)
|
||||||
object_groupList = _set_value_when_none(object_groupList, [])
|
|
||||||
|
|
||||||
# =======================
|
# =======================
|
||||||
# write to files
|
# write to files
|
||||||
@ -242,15 +241,17 @@ def export_bm(context, bmx_filepath, prefs_fncg, opts_exportMode, opts_exportTar
|
|||||||
UTILS_file_io.write_uint64(finfo, fmaterial.tell())
|
UTILS_file_io.write_uint64(finfo, fmaterial.tell())
|
||||||
|
|
||||||
# try get original written data
|
# try get original written data
|
||||||
material_colAmbient = _try_get_custom_property(material, 'virtools-ambient')
|
(material_colAmbient, material_colDiffuse, material_colSpecular,
|
||||||
material_colDiffuse = _try_get_custom_property(material, 'virtools-diffuse')
|
material_colEmissive, material_specularPower) = UTILS_virtools_prop.get_virtools_material_data(material)
|
||||||
material_colSpecular = _try_get_custom_property(material, 'virtools-specular')
|
|
||||||
material_colEmissive = _try_get_custom_property(material, 'virtools-emissive')
|
|
||||||
material_specularPower = _try_get_custom_property(material, 'virtools-power')
|
|
||||||
|
|
||||||
# get basic color
|
# get basic color
|
||||||
mat_wrap = node_shader_utils.PrincipledBSDFWrapper(material)
|
mat_wrap = node_shader_utils.PrincipledBSDFWrapper(material)
|
||||||
if mat_wrap:
|
if mat_wrap:
|
||||||
|
# we trying get texture data from Principled BSDF
|
||||||
|
# because bpy.types.Material.virtools_material now can provide
|
||||||
|
# Virtools material data stablely, so i annotate following code
|
||||||
|
# only keep texture data
|
||||||
|
'''
|
||||||
use_mirror = mat_wrap.metallic != 0.0
|
use_mirror = mat_wrap.metallic != 0.0
|
||||||
if use_mirror:
|
if use_mirror:
|
||||||
material_colAmbient = _set_value_when_none(material_colAmbient, (mat_wrap.metallic, mat_wrap.metallic, mat_wrap.metallic))
|
material_colAmbient = _set_value_when_none(material_colAmbient, (mat_wrap.metallic, mat_wrap.metallic, mat_wrap.metallic))
|
||||||
@ -260,6 +261,7 @@ def export_bm(context, bmx_filepath, prefs_fncg, opts_exportMode, opts_exportTar
|
|||||||
material_colSpecular = _set_value_when_none(material_colSpecular, (mat_wrap.specular, mat_wrap.specular, mat_wrap.specular))
|
material_colSpecular = _set_value_when_none(material_colSpecular, (mat_wrap.specular, mat_wrap.specular, mat_wrap.specular))
|
||||||
material_colEmissive = _set_value_when_none(material_colEmissive, mat_wrap.emission_color[:3])
|
material_colEmissive = _set_value_when_none(material_colEmissive, mat_wrap.emission_color[:3])
|
||||||
material_specularPower = _set_value_when_none(material_specularPower, 0.0)
|
material_specularPower = _set_value_when_none(material_specularPower, 0.0)
|
||||||
|
'''
|
||||||
|
|
||||||
# confirm texture
|
# confirm texture
|
||||||
tex_wrap = getattr(mat_wrap, "base_color_texture", None)
|
tex_wrap = getattr(mat_wrap, "base_color_texture", None)
|
||||||
@ -288,11 +290,14 @@ def export_bm(context, bmx_filepath, prefs_fncg, opts_exportMode, opts_exportTar
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# no Principled BSDF. write garbage
|
# no Principled BSDF. write garbage
|
||||||
|
# same reason for disabling following code
|
||||||
|
'''
|
||||||
material_colAmbient = _set_value_when_none(material_colAmbient, (0.8, 0.8, 0.8))
|
material_colAmbient = _set_value_when_none(material_colAmbient, (0.8, 0.8, 0.8))
|
||||||
material_colDiffuse = _set_value_when_none(material_colDiffuse, (0.8, 0.8, 0.8))
|
material_colDiffuse = _set_value_when_none(material_colDiffuse, (0.8, 0.8, 0.8))
|
||||||
material_colSpecular = _set_value_when_none(material_colSpecular, (0.8, 0.8, 0.8))
|
material_colSpecular = _set_value_when_none(material_colSpecular, (0.8, 0.8, 0.8))
|
||||||
material_colEmissive = _set_value_when_none(material_colEmissive, (0.8, 0.8, 0.8))
|
material_colEmissive = _set_value_when_none(material_colEmissive, (0.8, 0.8, 0.8))
|
||||||
material_specularPower = _set_value_when_none(material_specularPower, 0.0)
|
material_specularPower = _set_value_when_none(material_specularPower, 0.0)
|
||||||
|
'''
|
||||||
|
|
||||||
material_useTexture = False
|
material_useTexture = False
|
||||||
material_textureIndex = 0
|
material_textureIndex = 0
|
||||||
@ -356,12 +361,6 @@ def _mesh_triangulate(me):
|
|||||||
bm.to_mesh(me)
|
bm.to_mesh(me)
|
||||||
bm.free()
|
bm.free()
|
||||||
|
|
||||||
def _try_get_custom_property(obj, field):
|
|
||||||
try:
|
|
||||||
return obj[field]
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _set_value_when_none(obj, newValue):
|
def _set_value_when_none(obj, newValue):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return newValue
|
return newValue
|
||||||
|
@ -4,7 +4,7 @@ import struct, shutil
|
|||||||
from bpy_extras import io_utils,node_shader_utils
|
from bpy_extras import io_utils,node_shader_utils
|
||||||
from bpy_extras.io_utils import unpack_list
|
from bpy_extras.io_utils import unpack_list
|
||||||
from bpy_extras.image_utils import load_image
|
from bpy_extras.image_utils import load_image
|
||||||
from . import UTILS_constants, UTILS_functions, UTILS_file_io, UTILS_zip_helper
|
from . import UTILS_constants, UTILS_functions, UTILS_file_io, UTILS_zip_helper, UTILS_virtools_prop
|
||||||
|
|
||||||
class BALLANCE_OT_import_bm(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
|
class BALLANCE_OT_import_bm(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
|
||||||
"""Load a Ballance Map File (BM file spec 1.4)"""
|
"""Load a Ballance Map File (BM file spec 1.4)"""
|
||||||
@ -327,7 +327,9 @@ def import_bm(context, bmx_filepath, prefs_fncg, prefs_externalTexture, prefs_te
|
|||||||
|
|
||||||
# write custom property
|
# write custom property
|
||||||
if len(object_groupList) != 0:
|
if len(object_groupList) != 0:
|
||||||
object_target['virtools-group'] = tuple(object_groupList)
|
UTILS_virtools_prop.set_virtools_group_data(object_target, tuple(object_groupList))
|
||||||
|
else:
|
||||||
|
UTILS_virtools_prop.set_virtools_group_data(object_target, None)
|
||||||
|
|
||||||
# update view layer after all objects has been imported
|
# update view layer after all objects has been imported
|
||||||
blender_viewLayer.update()
|
blender_viewLayer.update()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from . import UTILS_constants, UTILS_functions
|
from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop
|
||||||
|
|
||||||
class rename_system_props(bpy.types.Operator):
|
class rename_system_props(bpy.types.Operator):
|
||||||
name_standard: bpy.props.EnumProperty(
|
name_standard: bpy.props.EnumProperty(
|
||||||
@ -114,12 +114,6 @@ class _NameInfoHelper():
|
|||||||
def _get_selected_objects():
|
def _get_selected_objects():
|
||||||
return bpy.context.view_layer.active_layer_collection.collection.objects
|
return bpy.context.view_layer.active_layer_collection.collection.objects
|
||||||
|
|
||||||
def _try_get_custom_property(obj, field):
|
|
||||||
try:
|
|
||||||
return obj[field]
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _get_sector_from_ckgroup(group_set):
|
def _get_sector_from_ckgroup(group_set):
|
||||||
# this counter is served for stupid
|
# this counter is served for stupid
|
||||||
# multi-sector-grouping accident.
|
# multi-sector-grouping accident.
|
||||||
@ -248,8 +242,8 @@ def _get_name_info_from_imengyu_name(obj_name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_name_info_from_group(obj):
|
def _get_name_info_from_group(obj):
|
||||||
group_list = _try_get_custom_property(obj, 'virtools-group')
|
group_list = UTILS_virtools_prop.get_virtools_group_data(obj)
|
||||||
if group_list is None:
|
if len(group_list) == 0:
|
||||||
# name it as a decoration
|
# name it as a decoration
|
||||||
return _NameInfoHelper(_ObjectBasicType.DECORATION)
|
return _NameInfoHelper(_ObjectBasicType.DECORATION)
|
||||||
|
|
||||||
@ -442,7 +436,7 @@ def _set_for_group(obj, name_info):
|
|||||||
|
|
||||||
|
|
||||||
# apply to custom property
|
# apply to custom property
|
||||||
obj['virtools-group'] = tuple(gps)
|
UTILS_virtools_prop.set_virtools_group_data(obj, tuple(gps))
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# assemble funcs
|
# assemble funcs
|
||||||
|
@ -13,7 +13,11 @@ class BALLANCE_OT_add_virtools_group(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
obj = context.object
|
obj = context.object
|
||||||
UTILS_virtools_prop.set_virtools_group_data(obj, ("aaa", "bbb", "ccc"))
|
gp = UTILS_virtools_prop.get_virtools_group(obj)
|
||||||
|
item = gp.add()
|
||||||
|
item.name = ""
|
||||||
|
item.group_name = "CKGroup"
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
|
class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
|
||||||
@ -24,16 +28,32 @@ class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(self, context):
|
def poll(self, context):
|
||||||
return context.object is not None
|
if context.object is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = context.object
|
||||||
|
gp = UTILS_virtools_prop.get_virtools_group(obj)
|
||||||
|
active_gp = UTILS_virtools_prop.get_active_virtools_group(obj)
|
||||||
|
data = gp[active_gp]
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
obj = context.object
|
obj = context.object
|
||||||
print(UTILS_virtools_prop.get_virtools_group_data(obj))
|
gp = UTILS_virtools_prop.get_virtools_group(obj)
|
||||||
|
active_gp = UTILS_virtools_prop.get_active_virtools_group(obj)
|
||||||
|
idx = int(active_gp)
|
||||||
|
|
||||||
|
active_gp -= 1
|
||||||
|
gp.remove(idx)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class BALLANCE_UL_virtools_group(bpy.types.UIList):
|
class BALLANCE_UL_virtools_group(bpy.types.UIList):
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
layout.prop(item, 'group_name', icon='GROUP', text="")
|
layout.prop(item, 'group_name', icon='GROUP', emboss=False, text="")
|
||||||
|
|
||||||
class BALLANCE_PT_virtools_group(bpy.types.Panel):
|
class BALLANCE_PT_virtools_group(bpy.types.Panel):
|
||||||
"""Show Virtools Group Properties."""
|
"""Show Virtools Group Properties."""
|
||||||
|
@ -293,4 +293,8 @@ rename_regexYYCComponent = re.compile('^(' + '|'.join(rename_normalComponentsGro
|
|||||||
rename_regexYYCPC = re.compile('^PC_TwoFlames_(0[1-7])$')
|
rename_regexYYCPC = re.compile('^PC_TwoFlames_(0[1-7])$')
|
||||||
rename_regexYYCPR = re.compile('^PR_Resetpoint_(0[1-8])$')
|
rename_regexYYCPR = re.compile('^PR_Resetpoint_(0[1-8])$')
|
||||||
rename_regexImengyuComponent = re.compile('^(' + '|'.join(rename_normalComponentsGroupName) + '):[^:]*:([1-9]|[1-9][0-9])$')
|
rename_regexImengyuComponent = re.compile('^(' + '|'.join(rename_normalComponentsGroupName) + '):[^:]*:([1-9]|[1-9][0-9])$')
|
||||||
rename_regexImengyuPCRComp = re.compile('^(PC_CheckPoint|PR_ResetPoint):([0-9]+)$')
|
rename_regexImengyuPCRComp = re.compile('^(PC_CheckPoint|PR_ResetPoint):([0-9]+)$')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import struct, shutil, os
|
|||||||
from bpy_extras.io_utils import unpack_list
|
from bpy_extras.io_utils import unpack_list
|
||||||
from bpy_extras.image_utils import load_image
|
from bpy_extras.image_utils import load_image
|
||||||
from bpy_extras import io_utils, node_shader_utils
|
from bpy_extras import io_utils, node_shader_utils
|
||||||
from . import UTILS_file_io, UTILS_constants
|
from . import UTILS_file_io, UTILS_constants, UTILS_virtools_prop
|
||||||
|
|
||||||
# =================================
|
# =================================
|
||||||
# scene operation
|
# scene operation
|
||||||
@ -65,12 +65,10 @@ def create_material_nodes(input_mtl, ambient, diffuse, specular, emissive,
|
|||||||
input_mtl.node_tree.links.new(inode.outputs[0], bnode.inputs[0])
|
input_mtl.node_tree.links.new(inode.outputs[0], bnode.inputs[0])
|
||||||
|
|
||||||
# write custom property
|
# write custom property
|
||||||
input_mtl['virtools-ambient'] = ambient
|
UTILS_virtools_prop.set_virtools_material_data(input_mtl,
|
||||||
input_mtl['virtools-diffuse'] = diffuse
|
ambient, diffuse, specular, emissive, specular_power
|
||||||
input_mtl['virtools-specular'] = specular
|
)
|
||||||
input_mtl['virtools-emissive'] = emissive
|
|
||||||
input_mtl['virtools-power'] = specular_power
|
|
||||||
|
|
||||||
# =================================
|
# =================================
|
||||||
# load component
|
# load component
|
||||||
|
|
||||||
|
@ -54,6 +54,8 @@ def set_virtools_material_data(mtl, ambient, diffuse, specular, emissive, specul
|
|||||||
data.emissive = emissive
|
data.emissive = emissive
|
||||||
data.specular_power = specular_power
|
data.specular_power = specular_power
|
||||||
|
|
||||||
|
def get_active_virtools_group(obj):
|
||||||
|
return obj.active_virtools_group
|
||||||
def get_virtools_group(obj):
|
def get_virtools_group(obj):
|
||||||
return obj.virtools_group
|
return obj.virtools_group
|
||||||
|
|
||||||
@ -64,10 +66,11 @@ def set_virtools_group_data(obj, new_data):
|
|||||||
data = get_virtools_group(obj)
|
data = get_virtools_group(obj)
|
||||||
data.clear()
|
data.clear()
|
||||||
|
|
||||||
for item in new_data:
|
if new_data is not None:
|
||||||
it = data.add()
|
for item in new_data:
|
||||||
it.name = ""
|
it = data.add()
|
||||||
it.group_name = item
|
it.name = ""
|
||||||
|
it.group_name = item
|
||||||
|
|
||||||
def register_props():
|
def register_props():
|
||||||
bpy.types.Object.virtools_group = bpy.props.CollectionProperty(type=BALLANCE_PG_virtools_group)
|
bpy.types.Object.virtools_group = bpy.props.CollectionProperty(type=BALLANCE_PG_virtools_group)
|
||||||
|
Loading…
Reference in New Issue
Block a user