some gate improvements
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index 820c49ac05e6f721af4ca38ab7f02e200bb5e616..8eb39a365dba70129c69776182175b39a30ea90f 100644 (file)
@@ -39,6 +39,8 @@ sr_entity_list = [
    ('ent_challenge',    'Challenge',      '', 18 )
 ]
 
+MDL_VERSION_NR = 102
+
 def get_entity_enum_id( alias ):
 #{
    for et in sr_entity_list:#{
@@ -186,7 +188,7 @@ 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),
@@ -197,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):
@@ -1572,6 +1577,12 @@ def sr_compile( collection ):
          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' )
@@ -1619,18 +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 = 0
                gate.key = sr_compile_string(obj_data.key)
-               gate.type = 2
+               flags |= 0x0002
+            #}
+
+            if obj_data.flip:   flags |= 0x0004
+            if obj_data.custom:#{
+               flags |= 0x0008
+               gate.submesh_start, gate.submesh_count, _ = \
+                     sr_compile_mesh_internal( obj )
             #}
-            else: gate.type = 0
+            gate.flags = flags
             
             gate.dimensions[0] = mesh_data.dimensions[0]
             gate.dimensions[1] = mesh_data.dimensions[1]
@@ -1996,7 +2016,7 @@ def sr_compile( collection ):
    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 )
@@ -2380,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 ):
@@ -2390,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' )
    #}
 #}