Skip to content

Commit

Permalink
plugin - add hair helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Nov 11, 2023
1 parent e7bf8fa commit 717ef47
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 138 deletions.
126 changes: 7 additions & 119 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import bpy
import bpy.utils.previews
from bpy.props import IntProperty, EnumProperty
from bpy.props import IntProperty
from bpy.types import PropertyGroup

import addon_utils

copies_of_tools = []
Expand All @@ -37,22 +36,16 @@
sys.path.append(plugin_dir)

from ovl_util.logs import logging_setup

logging_setup("blender_plugin")
from root_path import root_dir

from plugin import addon_updater_ops
from plugin.utils import shell
from plugin.utils.hair import vcol_to_comb, comb_to_vcol, transfer_hair_combing
from plugin.utils.matrix_util import handle_errors

from plugin.modules_import.operators import ImportBanis, ImportManis, ImportMatcol, ImportFgm, ImportMS2, ImportSPL, \
ImportVoxelskirt, ImportMS2FromBrowser, ImportFGMFromBrowser

from plugin.modules_export.operators import ExportMS2, ExportSPL, ExportManis, ExportBanis
from plugin.utils.operators import CreateFins, CreateLods, VcolToHair, HairToVcol, TransferHairCombing, AddHair
from plugin.utils.properties import CobraSceneSettings, CobraMeshSettings, CobraCollisionSettings

from root_path import root_dir
from generated.formats.ms2.enums.MeshFormat import MeshFormat
from generated.formats.ms2.enums.RigidBodyFlag import RigidBodyFlag

global preview_collection

Expand Down Expand Up @@ -123,56 +116,6 @@ def execute(self, context):
return {'FINISHED'}


class CreateFins(bpy.types.Operator):
"""Create fins for all objects with shells in this scene, and overwrite existing fin geometry"""
bl_idname = "object.create_fins"
bl_label = "Create Fins"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, shell.create_fins_wrapper, {})


class CreateLods(bpy.types.Operator):
"""Create LODs for this scene"""
bl_idname = "object.create_lods"
bl_label = "Create LODs"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, shell.create_lods, {})


class VcolToHair(bpy.types.Operator):
"""Convert vertex color layer to hair combing"""
bl_idname = "object.vcol_to_comb"
bl_label = "Vcol to Hair"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, vcol_to_comb, {})


class HairToVcol(bpy.types.Operator):
"""Convert hair combing to vertex color layer"""
bl_idname = "object.comb_to_vcol"
bl_label = "Hair to Vcol"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, comb_to_vcol, {})


class TransferHairCombing(bpy.types.Operator):
"""Transfer particle hair combing from one mesh to another"""
bl_idname = "object.transfer_hair_combing"
bl_label = "Transfer Combing"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, transfer_hair_combing, {})


class MESH_PT_CobraTools(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Cobra Mesh Tools"
Expand Down Expand Up @@ -202,6 +145,8 @@ def draw(self, context):
sub.operator("object.comb_to_vcol", icon_value=icon)
row = layout.row(align=True)
row.operator("object.transfer_hair_combing", icon_value=icon)
sub = row.row()
sub.operator("object.add_hair", icon_value=icon)

row = layout.row(align=True)
row.prop(context.mesh.cobra, "mesh_format")
Expand Down Expand Up @@ -259,64 +204,6 @@ def draw(self, context):
row.prop(rb, "flag")


class CobraSceneSettings(PropertyGroup):
num_streams: IntProperty(
name="External Streams",
description="Number of lod levels stored in external .modelstream files",
default=0,
min=0,
max=6
)
version: IntProperty(
name="MS2 Version",
description="Version to use for export",
default=50,
min=0,
max=100
)


class CobraMeshSettings(PropertyGroup):
mesh_format: EnumProperty(
name='Mesh Format',
description='Mesh format used for this mesh - JWE2 after Biosyn update',
items=[("NONE", "None", "")] + [(item.name, item.name, "") for i, item in enumerate(MeshFormat)],
# default = 'MO_SYS_FIXED',

)


class CobraCollisionSettings(PropertyGroup):
air_resistance: bpy.props.FloatVectorProperty(
name='Air Resistance',
description="Air Resistance in 3D, relative to the joint's axes",
default=(0.0, 0.0, 0.0),
min=sys.float_info.min,
max=sys.float_info.max,
soft_min=sys.float_info.min,
soft_max=sys.float_info.max,
step=3,
precision=2,
subtype="XYZ")
damping_3d: bpy.props.FloatVectorProperty(
name='Damping',
description='Damping in 3D',
default=(0.0, 0.0, 0.0),
min=sys.float_info.min,
max=sys.float_info.max,
soft_min=sys.float_info.min,
soft_max=sys.float_info.max,
step=1,
precision=6)
plasticity_min: bpy.props.FloatProperty(name="Plasticity Lower", subtype="ANGLE")
plasticity_max: bpy.props.FloatProperty(name="Upper", subtype="ANGLE")
flag: EnumProperty(
name='Dynamics Flag',
description='Current state of this rigidbody',
items=[(item.name, item.name, "") for i, item in enumerate(RigidBodyFlag)],
)


def draw_rigid_body_constraints_cobra(self, context):
scene = context.scene
layout = self.layout
Expand Down Expand Up @@ -389,6 +276,7 @@ def CT_FileBrowser_Context_Menu(self, context):
VcolToHair,
HairToVcol,
TransferHairCombing,
AddHair,
CobraPreferences,
CobraSceneSettings,
CobraMeshSettings,
Expand Down
2 changes: 1 addition & 1 deletion plugin/import_ms2.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def load(filepath="", use_custom_normals=False, mirror_mesh=False):
# we can't assume that the first ob referencing this mesh has it already
if not is_old(ms2.info) and is_shell(b_ob):
logging.debug(f"{b_ob.name} has shells, adding psys")
add_psys(b_ob, mesh)
add_psys(b_ob, mesh.fur_length)
coll_name = f"{scene.name}_LOD{lod_i}"
# show lod 0, hide the others
set_collection_visibility(scene, coll_name, lod_i != 0)
Expand Down
4 changes: 2 additions & 2 deletions plugin/utils/hair.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def find_modifier_for_particle_system(b_ob, particle_system):
return modifier


def add_psys(ob, model):
def add_psys(ob, fur_length=0.1):
if not ob.particle_systems:
name = "hair"
ps_mod = ob.modifiers.new(name, 'PARTICLE_SYSTEM')
Expand All @@ -70,7 +70,7 @@ def add_psys(ob, model):
psys.settings.type = 'HAIR'
psys.settings.emit_from = 'VERT'
psys.settings.use_emit_random = False
psys.settings.hair_length = model.fur_length
psys.settings.hair_length = fur_length
psys.settings.hair_step = 1
psys.settings.display_step = 1
psys.settings.clump_factor = 1.0
Expand Down
64 changes: 64 additions & 0 deletions plugin/utils/operators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import bpy
from plugin.utils import shell
from plugin.utils.hair import comb_to_vcol, transfer_hair_combing, vcol_to_comb
from plugin.utils.matrix_util import handle_errors


class CreateFins(bpy.types.Operator):
"""Create fins for all objects with shells in this scene, and overwrite existing fin geometry"""
bl_idname = "object.create_fins"
bl_label = "Create Fins"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, shell.create_fins_wrapper, {})


class CreateLods(bpy.types.Operator):
"""Create LODs for this scene"""
bl_idname = "object.create_lods"
bl_label = "Create LODs"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, shell.create_lods, {})


class VcolToHair(bpy.types.Operator):
"""Convert vertex color layer to hair combing"""
bl_idname = "object.vcol_to_comb"
bl_label = "Vcol to Hair"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, vcol_to_comb, {})


class HairToVcol(bpy.types.Operator):
"""Convert hair combing to vertex color layer"""
bl_idname = "object.comb_to_vcol"
bl_label = "Hair to Vcol"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, comb_to_vcol, {})


class TransferHairCombing(bpy.types.Operator):
"""Transfer particle hair combing from one mesh to another"""
bl_idname = "object.transfer_hair_combing"
bl_label = "Transfer Combing"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, transfer_hair_combing, {})


class AddHair(bpy.types.Operator):
"""Add hair setup to a mesh that didn't have it"""
bl_idname = "object.add_hair"
bl_label = "Add Hair"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return handle_errors(self, shell.add_hair, {})
66 changes: 66 additions & 0 deletions plugin/utils/properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sys

import bpy.props
from bpy.props import IntProperty, EnumProperty
from bpy.types import PropertyGroup

from generated.formats.ms2.enums.MeshFormat import MeshFormat
from generated.formats.ms2.enums.RigidBodyFlag import RigidBodyFlag


class CobraSceneSettings(PropertyGroup):
num_streams: IntProperty(
name="External Streams",
description="Number of lod levels stored in external .modelstream files",
default=0,
min=0,
max=6
)
version: IntProperty(
name="MS2 Version",
description="Version to use for export",
default=50,
min=0,
max=100
)


class CobraMeshSettings(PropertyGroup):
mesh_format: EnumProperty(
name='Mesh Format',
description='Mesh format used for this mesh - JWE2 after Biosyn update',
items=[("NONE", "None", "")] + [(item.name, item.name, "") for i, item in enumerate(MeshFormat)],
# default = 'MO_SYS_FIXED',

)


class CobraCollisionSettings(PropertyGroup):
air_resistance: bpy.props.FloatVectorProperty(
name='Air Resistance',
description="Air Resistance in 3D, relative to the joint's axes",
default=(0.0, 0.0, 0.0),
min=sys.float_info.min,
max=sys.float_info.max,
soft_min=sys.float_info.min,
soft_max=sys.float_info.max,
step=3,
precision=2,
subtype="XYZ")
damping_3d: bpy.props.FloatVectorProperty(
name='Damping',
description='Damping in 3D',
default=(0.0, 0.0, 0.0),
min=sys.float_info.min,
max=sys.float_info.max,
soft_min=sys.float_info.min,
soft_max=sys.float_info.max,
step=1,
precision=6)
plasticity_min: bpy.props.FloatProperty(name="Plasticity Lower", subtype="ANGLE")
plasticity_max: bpy.props.FloatProperty(name="Upper", subtype="ANGLE")
flag: EnumProperty(
name='Dynamics Flag',
description='Current state of this rigidbody',
items=[(item.name, item.name, "") for i, item in enumerate(RigidBodyFlag)],
)
Loading

0 comments on commit 717ef47

Please sign in to comment.