X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=blender_export.py;h=8eb39a365dba70129c69776182175b39a30ea90f;hb=6ab4435fb19beb6af6c52691793d5ca17a120f69;hp=3e6bb108853a4af2d38d0323e2c1812dfcf58397;hpb=e5d79dc0355e04baecce8908e29b8e7569d1e857;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/blender_export.py b/blender_export.py index 3e6bb10..8eb39a3 100644 --- a/blender_export.py +++ b/blender_export.py @@ -35,8 +35,12 @@ sr_entity_list = [ ('ent_swspreview', 'Workshop Preview', '', 14 ), ('ent_menuitem', 'Menu Item', '', 15 ), ('ent_worldinfo', 'World Info', '', 16 ), + ('ent_ccmd', 'CCmd', '', 17 ), + ('ent_challenge', 'Challenge', '', 18 ) ] +MDL_VERSION_NR = 102 + def get_entity_enum_id( alias ): #{ for et in sr_entity_list:#{ @@ -184,8 +188,9 @@ class version_refcount_union(Union): class ent_gate(Structure): #{ - _fields_ = [("type",c_uint32), + _fields_ = [("flags",c_uint32), ("target", c_uint32), + ("key",c_uint32), ("dimensions", c_float*3), ("co", (c_float*3)*2), ("q", (c_float*4)*2), @@ -194,7 +199,10 @@ class ent_gate(Structure): ("_anonymous_union",version_refcount_union), ("timing_time",c_double), ("routes",c_uint16*4), - ("route_count",c_uint8)] + ("route_count",c_uint8), + ("submesh_start",c_uint32), # v102+ + ("submesh_count",c_uint32), # v102+ (can be 0) + ] #} class ent_route_node(Structure): @@ -354,10 +362,16 @@ class ent_skateshop_boards(Structure): ("id_info",c_uint32), ("id_rack",c_uint32)] #} +class ent_skateshop_worlds(Structure): +#{ + _fields_ = [("id_display",c_uint32), + ("id_info",c_uint32)] +#} class ent_skateshop_anon_union(Union): #{ _fields_ = [("boards",ent_skateshop_boards), - ("character",ent_skateshop_characters)] + ("character",ent_skateshop_characters), + ("worlds",ent_skateshop_worlds)] #} class ent_skateshop(Structure): #{ @@ -432,6 +446,22 @@ class ent_worldinfo(Structure): ("timezone",c_float)] #} +class ent_ccmd(Structure): +#{ + _fields_ = [("pstr_command",c_uint32)] +#} + +class ent_challenge(Structure):#{ + _fields_ = [("transform",mdl_transform), + ("submesh_start",c_uint32), ("submesh_count",c_uint32), + ("id_next",c_uint32), + ("filter",c_uint32), + ("time_limit",c_float)] + + sr_functions = { 0: 'trigger', + 1: 'start_challenge' } +#} + def obj_ent_type( obj ): #{ if obj.type == 'ARMATURE': return 'mdl_armature' @@ -455,6 +485,31 @@ def sr_filter_ent_type( obj, ent_types ): return False #} +def v4_dot( a, b ):#{ + return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3] +#} + +def q_identity( q ):#{ + q[0] = 0.0 + q[1] = 0.0 + q[2] = 0.0 + q[3] = 1.0 +#} + +def q_normalize( q ):#{ + l2 = v4_dot(q,q) + if( l2 < 0.00001 ):#{ + q_identity( q ) + #} + else:#{ + s = 1.0/math.sqrt(l2) + q[0] *= s + q[1] *= s + q[2] *= s + q[3] *= s + #} +#} + def compile_obj_transform( obj, transform ): #{ co = obj.matrix_world @ Vector((0,0,0)) @@ -462,6 +517,7 @@ def compile_obj_transform( obj, transform ): # This was changed from matrix_local on 09.05.23 q = obj.matrix_world.to_quaternion() s = obj.scale + q_normalize( q ) # Setup transform # @@ -696,6 +752,7 @@ def sr_compile_material( mat ): if mat.SR_data.skate_surface: flags |= 0x1 if mat.SR_data.grow_grass: flags |= 0x4 if mat.SR_data.grind_surface: flags |= 0x8 + if mat.SR_data.preview_visibile: flags |= 0x40 #} if mat.SR_data.shader == 'invisible': flags |= 0x10 if mat.SR_data.shader == 'boundary': flags |= (0x10|0x20) @@ -746,14 +803,18 @@ def sr_compile_material( mat ): if mat.SR_data.shader == 'boundary':#{ m.shader = 6 #} + + if mat.SR_data.shader == 'fxglow':#{ + m.shader = 7 + #} inf = material_info( mat ) if mat.SR_data.shader == 'standard' or \ mat.SR_data.shader == 'standard_cutout' or \ mat.SR_data.shader == 'terrain_blend' or \ - mat.SR_data.shader == 'vertex_blend': - #{ + mat.SR_data.shader == 'vertex_blend' or \ + mat.SR_data.shader == 'fxglow': #{ if 'tex_diffuse' in inf: m.tex_diffuse = sr_compile_texture(inf['tex_diffuse']) #} @@ -775,8 +836,9 @@ def sr_armature_bones( armature ): yield from _recurse_bone( b ) #} -def sr_entity_id( obj ): -#{ +def sr_entity_id( obj ):#{ + if not obj: return 0 + tipo = get_entity_enum_id( obj_ent_type(obj) ) index = sr_compile.entity_ids[ obj.name ] @@ -1370,6 +1432,7 @@ def sr_compile_armature( obj ): lc_m = smtx.inverted() @ lc_m #} rq = lc_m.to_quaternion() + q_normalize( rq ) kf = mdl_transform() kf.co[0] = loc[0] @@ -1513,6 +1576,13 @@ def sr_compile( collection ): if ent_type == 'ent_font': continue if ent_type == 'ent_font_variant': continue if ent_type == 'ent_menuitem': continue + if ent_type == 'ent_challenge': continue + + #TODO: This is messy. + if ent_type == 'ent_gate':#{ + obj_data = obj.SR_data.ent_gate[0] + if obj_data.custom: continue + #} #-------------------------- print( F'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end='\r' ) @@ -1560,17 +1630,27 @@ def sr_compile( collection ): obj_data = obj.SR_data.ent_gate[0] mesh_data = obj.data.SR_data.ent_gate[0] + flags = 0x0000 + if obj_data.tipo == 'default':#{ if obj_data.target:#{ gate.target = sr_compile.entity_ids[obj_data.target.name] - gate.type = 1 + flags |= 0x0001 #} #} elif obj_data.tipo == 'nonlocal':#{ - gate.target = sr_compile_string(obj_data.key) - gate.type = 2 + gate.target = 0 + gate.key = sr_compile_string(obj_data.key) + flags |= 0x0002 #} - else: gate.type = 0 + + if obj_data.flip: flags |= 0x0004 + if obj_data.custom:#{ + flags |= 0x0008 + gate.submesh_start, gate.submesh_count, _ = \ + sr_compile_mesh_internal( obj ) + #} + gate.flags = flags gate.dimensions[0] = mesh_data.dimensions[0] gate.dimensions[1] = mesh_data.dimensions[1] @@ -1667,6 +1747,7 @@ def sr_compile( collection ): if obj_data.target:#{ volume.target = sr_entity_id( obj_data.target ) + volume._anon.trigger.event = obj_data.event #} sr_ent_push(volume) @@ -1692,6 +1773,11 @@ def sr_compile( collection ): charshop.id_display = sr_entity_id( obj_data.mark_display ) charshop.id_info = sr_entity_id( obj_data.mark_info ) #} + elif skateshop.type == 2:#{ + worldshop = skateshop._anonymous_union.worlds + worldshop.id_display = sr_entity_id( obj_data.mark_display ) + worldshop.id_info = sr_entity_id( obj_data.mark_info ) + #} skateshop.id_camera = sr_entity_id( obj_data.cam ) compile_obj_transform( obj, skateshop.transform ) sr_ent_push(skateshop) @@ -1713,6 +1799,25 @@ def sr_compile( collection ): worldinfo.timezone = obj_data.timezone sr_ent_push( worldinfo ) #} + elif ent_type == 'ent_ccmd':#{ + ccmd = ent_ccmd() + obj_data = obj.SR_data.ent_ccmd[0] + ccmd.pstr_command = sr_compile_string( obj_data.command ) + sr_ent_push( ccmd ) + #} + elif ent_type == 'ent_challenge':#{ + challenge = ent_challenge() + obj_data = obj.SR_data.ent_challenge[0] + challenge.id_next = sr_entity_id( obj_data.proxima ) + challenge.filter = 0 + challenge.time_limit = obj_data.time_limit + + compile_obj_transform( obj, challenge.transform ) + challenge.submesh_start, challenge.submesh_count, _ = \ + sr_compile_mesh_internal( obj ) + + sr_ent_push( challenge ) + #} #} #} @@ -1908,9 +2013,10 @@ def sr_compile( collection ): path = F"{folder}{collection.name}.mdl" print( path ) + os.makedirs(os.path.dirname(path),exist_ok=True) fp = open( path, "wb" ) header = mdl_header() - header.version = 101 + header.version = MDL_VERSION_NR sr_array_title( header.arrays, \ 'index', len(file_array_instructions), \ sizeof(mdl_array), header_size ) @@ -2224,6 +2330,7 @@ class SR_MATERIAL_PANEL(bpy.types.Panel): row.prop( active_mat.SR_data, "skate_surface" ) row.prop( active_mat.SR_data, "grind_surface" ) row.prop( active_mat.SR_data, "grow_grass" ) + row.prop( active_mat.SR_data, "preview_visibile" ) #} #} @@ -2293,7 +2400,10 @@ class SR_OBJECT_ENT_GATE(bpy.types.PropertyGroup): key: bpy.props.StringProperty() tipo: bpy.props.EnumProperty(items=(('default', 'Default', ""), - ('nonlocal', 'Non-Local', ""),)) + ('nonlocal', 'Non-Local', ""))) + + flip: bpy.props.BoolProperty( name="Flip exit", default=False ) + custom: bpy.props.BoolProperty( name="Mesh is surface", default=False ) @staticmethod def sr_inspector( layout, data ): @@ -2303,6 +2413,10 @@ class SR_OBJECT_ENT_GATE(bpy.types.PropertyGroup): if data[0].tipo == 'default': box.prop( data[0], 'target' ) elif data[0].tipo == 'nonlocal': box.prop( data[0], 'key' ) + + flags = box.box() + flags.prop( data[0], 'flip' ) + flags.prop( data[0], 'custom' ) #} #} @@ -2650,8 +2764,7 @@ class SR_OBJECT_ENT_ROUTE(bpy.types.PropertyGroup): #} #} -class SR_OBJECT_ENT_VOLUME(bpy.types.PropertyGroup): -#{ +class SR_OBJECT_ENT_VOLUME(bpy.types.PropertyGroup):#{ subtype: bpy.props.EnumProperty( name="Subtype", items=[('0','Trigger',''), @@ -2661,14 +2774,33 @@ class SR_OBJECT_ENT_VOLUME(bpy.types.PropertyGroup): target: bpy.props.PointerProperty( \ type=bpy.types.Object, name="Target", \ poll=lambda self,obj: sr_filter_ent_type(obj,\ - ['ent_audio','ent_skateshop'])) + ['ent_audio','ent_skateshop','ent_ccmd',\ + 'ent_challenge'])) + + event: bpy.props.IntProperty( name="Event/Method" ) @staticmethod - def sr_inspector( layout, data ): - #{ - data = data[0] - layout.prop( data, 'subtype' ) - layout.prop( data, 'target' ) + def sr_inspector( layout, data ):#{ + layout.prop( data[0], 'subtype' ) + layout.prop( data[0], 'target' ) + + row = layout.row() + row.prop( data[0], 'event' ) + + if data[0].target:#{ + tipo = data[0].target.SR_data.ent_type + cls = globals()[ tipo ] + + table = getattr( cls, 'sr_functions', None ) + if table:#{ + if data[0].event in table:#{ + row.label( text=table[data[0].event] ) + #} + else:#{ + row.label( text="undefined function" ) + #} + #} + #} #} #} @@ -2732,16 +2864,15 @@ class SR_OBJECT_ENT_AUDIO(bpy.types.PropertyGroup): box.prop( data[0], 'flag_loop' ) box.prop( data[0], 'flag_auto' ) + layout.prop( data[0], 'probability_curve' ) + split = layout.split(factor=0.7) c = split.column() c.label( text='Filepath' ) c = split.column() - c.label( text='Chance (0.1s)' ) - - layout.prop( data[0], 'probability_curve' ) - + c.label( text='Chance' ) layout.template_list('SR_UL_AUDIO_LIST', 'Files', \ - data[0], 'files', data[0], 'file_index', rows=5) + data[0], 'files', data[0], 'files_index', rows=5) row = layout.row() row.operator( 'skaterift.al_new_entry', text='Add' ) @@ -2816,7 +2947,8 @@ class SR_OBJECT_ENT_SKATESHOP(bpy.types.PropertyGroup): #{ tipo: bpy.props.EnumProperty( name='Type', items=[('0','boards',''), - ('1','character','')] ) + ('1','character',''), + ('2','world','')] ) mark_rack: bpy.props.PointerProperty( \ type=bpy.types.Object, name="Board Rack", \ poll=lambda self,obj: sr_filter_ent_type(obj,['ent_marker'])) @@ -2945,6 +3077,23 @@ class SR_OBJECT_ENT_WORLD_INFO(bpy.types.PropertyGroup): timezone: bpy.props.FloatProperty(name="Timezone(hrs) (UTC0 +hrs)") #} +class SR_OBJECT_ENT_CCMD(bpy.types.PropertyGroup): +#{ + command: bpy.props.StringProperty(name="Command Line") +#} + +class SR_OBJECT_ENT_CHALLENGE(bpy.types.PropertyGroup):#{ + proxima: bpy.props.PointerProperty( \ + type=bpy.types.Object, name="Next", \ + poll=lambda self,obj: sr_filter_ent_type(obj,['ent_challenge'])) + target: bpy.props.PointerProperty( \ + type=bpy.types.Object, name="Target", \ + poll=lambda self,obj: sr_filter_ent_type(obj,\ + ['ent_audio','ent_ccmd'])) + event: bpy.props.IntProperty( name="Event/Method" ) + time_limit: bpy.props.FloatProperty( name="Time Limit", default=1.0 ) +#} + class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup): #{ ent_gate: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_GATE) @@ -2961,6 +3110,8 @@ class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup): bpy.props.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW) ent_menuitem: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM) ent_worldinfo: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO) + ent_ccmd: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_CCMD) + ent_challenge: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE) ent_type: bpy.props.EnumProperty( name="Type", @@ -3035,7 +3186,8 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup): ('vertex_blend', "vertex_blend", ''), ('water',"water",''), ('invisible','Invisible',''), - ('boundary','Boundary','') + ('boundary','Boundary',''), + ('fxglow','FX Glow',''), ]) surface_prop: bpy.props.EnumProperty( @@ -3068,6 +3220,11 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup): default=False,\ description = "Spawn grass sprites on this surface?" \ ) + preview_visibile: bpy.props.BoolProperty( \ + name="Preview visibile", \ + default=True,\ + description = "Show this material in preview models?" \ + ) blend_offset: bpy.props.FloatVectorProperty( \ name="Blend Offset", \ size=2, \ @@ -3364,7 +3521,8 @@ def cv_draw_lines(): cv_view_shader, 'LINES', \ { "pos":cv_view_verts, "color":cv_view_colours }) - lines.draw( cv_view_shader ) + if bpy.context.scene.SR_data.gizmos: + lines.draw( cv_view_shader ) cv_view_verts = [] cv_view_colours = [] @@ -3441,8 +3599,8 @@ def draw_cone_twist( center, vx, vy, va ): p0 = center + (axis + vx*c0 + vy*s0).normalized() * size p1 = center + (axis + vx*c1 + vy*s1).normalized() * size - col0 = ( abs(c0), abs(s0), 0.0, 1.0 ) - col1 = ( abs(c1), abs(s1), 0.0, 1.0 ) + col0 = ( abs(c0), abs(s0), 0.0 ) + col1 = ( abs(c1), abs(s1), 0.0 ) cv_view_verts += [center, p0, p0, p1] cv_view_colours += [ (0,0,0), col0, col0, col1 ] @@ -3599,14 +3757,14 @@ def cv_ent_volume( obj ): cv_draw_ucube( obj.matrix_world, (0,1,0) ) if data.target:#{ - cv_draw_line( obj.location, data.target.location, (0,1,0) ) + cv_draw_arrow( obj.location, data.target.location, (0,1,0) ) #} #} elif data.subtype == '1':#{ cv_draw_ucube( obj.matrix_world, (1,1,0) ) if data.target:#{ - cv_draw_line( obj.location, data.target.location, (1,1,0) ) + cv_draw_arrow( obj.location, data.target.location, (1,1,0) ) #} #} #} @@ -3885,6 +4043,12 @@ def cv_draw(): elif ent_type == 'ent_volume':#{ cv_ent_volume( obj ) #} + elif ent_type == 'ent_challenge':#{ + data = obj.SR_data.ent_challenge[0] + if data.proxima:#{ + cv_draw_arrow( obj.location, data.proxima.location, (0,0.2,1.0) ) + #} + #} elif ent_type == 'ent_audio':#{ if obj.SR_data.ent_audio[0].flag_3d: cv_draw_sphere( obj.location, obj.scale[0], (1,1,0) ) @@ -3940,6 +4104,15 @@ def cv_draw(): info_cu = Vector((1.2,0.01,0.3))*0.5 info_co = Vector((0.0,0.0,0.0))*0.5 #} + elif data.tipo == '2':#{ + rack = None + cc1 = (1.0,0.0,0.0) + cc2 = (1.0,0.5,0.0) + display_cu = Vector((1.0,1.0,0.5))*0.5 + display_co = Vector((0.0,0.0,0.5))*0.5 + info_cu = Vector((1.2,0.01,0.3))*0.5 + info_co = Vector((0.0,0.0,0.0))*0.5 + #} if rack: cv_draw_ucube( rack.matrix_world, cc, rack_cu, rack_co ) @@ -4066,7 +4239,8 @@ classes = [ SR_INTERFACE, SR_MATERIAL_PANEL,\ SR_UL_FONT_VARIANT_LIST,SR_UL_FONT_GLYPH_LIST,\ SR_OBJECT_ENT_FONT,SR_OBJECT_ENT_TRAFFIC,SR_OBJECT_ENT_SKATESHOP,\ SR_OBJECT_ENT_WORKSHOP_PREVIEW,SR_OBJECT_ENT_MENU_ITEM,\ - SR_OBJECT_ENT_WORLD_INFO,\ + SR_OBJECT_ENT_WORLD_INFO,SR_OBJECT_ENT_CCMD,\ + SR_OBJECT_ENT_CHALLENGE,\ \ SR_OBJECT_PROPERTIES, SR_LIGHT_PROPERTIES, SR_BONE_PROPERTIES, SR_MESH_PROPERTIES, SR_MATERIAL_PROPERTIES \