challenge effects
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index 3f1b04f1dd00e7a91ee3afa2651ac069e5151994..50f46c3d7184917431fad6d799748b6ea56ea24b 100644 (file)
@@ -1,9 +1,10 @@
-import bpy, math, gpu, os
+import bpy, blf, math, gpu, os
 import cProfile
 from ctypes import *
 from mathutils import *
 from gpu_extras.batch import batch_for_shader
 from bpy_extras import mesh_utils
+from bpy_extras import view3d_utils
 
 bl_info = {
    "name":"Skaterift .mdl exporter",
@@ -36,9 +37,15 @@ sr_entity_list = [
    ('ent_menuitem',     'Menu Item',      '', 15 ),
    ('ent_worldinfo',    'World Info',     '', 16 ),
    ('ent_ccmd',         'CCmd',           '', 17 ),
-   ('ent_challenge',    'Challenge',      '', 18 )
+   ('ent_objective',    'Objective',      '', 18 ),
+   ('ent_challenge',    'Challenge',      '', 19 ),
+   ('ent_relay',        'Relay',          '', 20 )
 ]
 
+MDL_VERSION_NR = 102
+SR_TRIGGERABLE = [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
+                   'ent_relay', 'ent_skateshop', 'ent_objective' ]
+
 def get_entity_enum_id( alias ):
 #{
    for et in sr_entity_list:#{
@@ -47,6 +54,8 @@ def get_entity_enum_id( alias ):
       #}
    #}
 
+   if alias == 'ent_cubemap': return 21
+
    return 0
 #}
 
@@ -186,7 +195,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 +206,11 @@ 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)
+               ]
+   sr_functions = { 0: 'unlock' }
 #}
 
 class ent_route_node(Structure):
@@ -446,11 +459,50 @@ class ent_ccmd(Structure):
    _fields_ = [("pstr_command",c_uint32)]
 #}
 
-class ent_challenge(Structure):#{
+class ent_objective(Structure):#{
    _fields_ = [("transform",mdl_transform),
                ("submesh_start",c_uint32), ("submesh_count",c_uint32),
+               ("flags",c_uint32),
                ("id_next",c_uint32),
-               ("filter",c_uint32)]
+               ("filter",c_uint32),("filter2",c_uint32),
+               ("id_win",c_uint32),
+               ("win_event",c_uint32),
+               ("time_limit",c_float)]
+
+   sr_functions = { 0: 'trigger',
+                    2: 'show',
+                    3: 'hide' }
+#}
+
+class ent_challenge(Structure):#{
+   _fields_ = [("transform",mdl_transform),
+               ("pstr_alias",c_uint32),
+               ("flags",c_uint32),
+               ("target",c_uint32),
+               ("target_event",c_uint32),
+               ("reset",c_uint32),
+               ("reset_event",c_uint32),
+               ("first",c_uint32),
+               ("camera",c_uint32),
+               ("status",c_uint32)] #runtime
+   sr_functions = { 0: 'unlock',
+                    1: 'view/reset' }
+#}
+
+class ent_relay(Structure):#{
+   _fields_ = [("targets",(c_uint32*2)*4),
+               ("targets_events",c_uint32*4)]
+   sr_functions = { 0: 'trigger' }
+#}
+
+class ent_cubemap(Structure):#{
+   _fields_ = [("co",c_float*3),
+               ("resolution",c_uint32), #placeholder
+               ("live",c_uint32),       #placeholder
+               ("texture_id",c_uint32), #engine
+               ("framebuffer_id",c_uint32),#engine
+               ("renderbuffer_id",c_uint32),#engine
+               ("placeholder",c_uint32*2)]
 #}
 
 def obj_ent_type( obj ):
@@ -458,6 +510,8 @@ def obj_ent_type( obj ):
    if obj.type == 'ARMATURE': return 'mdl_armature'
    elif obj.type == 'LIGHT': return 'ent_light'
    elif obj.type == 'CAMERA': return 'ent_camera'
+   elif obj.type == 'LIGHT_PROBE' and obj.data.type == 'CUBEMAP':
+      return 'ent_cubemap'
    else: return obj.SR_data.ent_type
 #}
 
@@ -722,8 +776,7 @@ def sr_compile_texture( img ):
    return texture_index
 #}
 
-def sr_compile_material( mat ):
-#{
+def sr_compile_material( mat ):#{
    if mat == None: 
       return 0
    if mat.name in sr_compile.material_cache: 
@@ -747,11 +800,13 @@ def sr_compile_material( mat ):
       #}
       if mat.SR_data.shader == 'invisible': flags |= 0x10
       if mat.SR_data.shader == 'boundary': flags |= (0x10|0x20)
+      if mat.SR_data.shader == 'walking': flags |= (0x10|0x80)
    #}
 
    m.flags = flags
 
    m.surface_prop = int(mat.SR_data.surface_prop)
+   inf = material_info( mat )
 
    if mat.SR_data.shader == 'standard': m.shader = 0
    if mat.SR_data.shader == 'standard_cutout': m.shader = 1
@@ -798,14 +853,23 @@ def sr_compile_material( mat ):
    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' or \
-      mat.SR_data.shader == 'fxglow': #{
+   if mat.SR_data.shader == 'cubemap':#{
+      m.shader = 8
+      m.tex_none0 = sr_entity_id( mat.SR_data.cubemap )
+
+      m.colour[0]  = pow( mat.SR_data.tint[0], 1.0/2.2 )
+      m.colour[1]  = pow( mat.SR_data.tint[1], 1.0/2.2 )
+      m.colour[2]  = pow( mat.SR_data.tint[2], 1.0/2.2 )
+      m.colour[3]  = pow( mat.SR_data.tint[3], 1.0/2.2 )
+   #}
+
+   if mat.SR_data.shader == 'walking':#{
+      m.shader = 9
+   #}
+   
+   if mat.SR_data.shader in ['standard', 'standard_cutout', 'terrain_blend', \
+                             'vertex_blend', 'fxglow', 'cubemap' ]: #{
       if 'tex_diffuse' in inf: 
          m.tex_diffuse = sr_compile_texture(inf['tex_diffuse'])
    #}
@@ -1567,7 +1631,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
+         if ent_type == 'ent_objective': 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' )
@@ -1615,18 +1685,28 @@ 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
+            if obj_data.locked: flags |= 0x0010
+            gate.flags = flags
             
             gate.dimensions[0] = mesh_data.dimensions[0]
             gate.dimensions[1] = mesh_data.dimensions[1]
@@ -1723,6 +1803,7 @@ def sr_compile( collection ):
 
             if obj_data.target:#{
                volume.target = sr_entity_id( obj_data.target )
+               volume._anon.trigger.event = obj_data.target_event
             #}
 
             sr_ent_push(volume)
@@ -1780,17 +1861,61 @@ def sr_compile( collection ):
             ccmd.pstr_command = sr_compile_string( obj_data.command )
             sr_ent_push( ccmd )
          #}
+         elif ent_type == 'ent_objective':#{
+            objective = ent_objective()
+            obj_data = obj.SR_data.ent_objective[0]
+            objective.id_next = sr_entity_id( obj_data.proxima )
+            objective.id_win = sr_entity_id( obj_data.target )
+            objective.win_event = obj_data.target_event
+            objective.filter = int(obj_data.filtrar)
+            objective.filter2 = 0
+            objective.time_limit = obj_data.time_limit
+
+            compile_obj_transform( obj, objective.transform )
+            objective.submesh_start, objective.submesh_count, _ = \
+                  sr_compile_mesh_internal( obj )
+
+            sr_ent_push( objective )
+         #}
          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 )
-
             compile_obj_transform( obj, challenge.transform )
-            challenge.submesh_start, challenge.submesh_count, _ = \
-                  sr_compile_mesh_internal( obj )
-
+            challenge.pstr_alias = sr_compile_string( obj_data.alias )
+            challenge.target = sr_entity_id( obj_data.target )
+            challenge.target_event = obj_data.target_event
+            challenge.reset = sr_entity_id( obj_data.reset )
+            challenge.reset_event = obj_data.reset_event
+            challenge.first = sr_entity_id( obj_data.first )
+            challenge.flags = 0x00
+            challenge.camera = sr_entity_id( obj_data.camera )
+            if obj_data.time_limit: challenge.flags |= 0x01
+            challenge.status = 0
             sr_ent_push( challenge )
          #}
+         elif ent_type == 'ent_relay':#{
+            relay = ent_relay()
+            obj_data = obj.SR_data.ent_relay[0]
+            relay.targets[0][0] = sr_entity_id( obj_data.target0 )
+            relay.targets[1][0] = sr_entity_id( obj_data.target1 )
+            relay.targets[2][0] = sr_entity_id( obj_data.target2 )
+            relay.targets[3][0] = sr_entity_id( obj_data.target3 )
+            relay.targets[0][1] = obj_data.target0_event
+            relay.targets[1][1] = obj_data.target1_event
+            relay.targets[2][1] = obj_data.target2_event
+            relay.targets[3][1] = obj_data.target3_event
+            sr_ent_push( relay )
+         #}
+         elif ent_type == 'ent_cubemap':#{
+            cubemap = ent_cubemap()
+            co = obj.matrix_world @ Vector((0,0,0))
+            cubemap.co[0] =  co[0]
+            cubemap.co[1] =  co[2]
+            cubemap.co[2] = -co[1]
+            cubemap.resolution = 0
+            cubemap.live = 60
+            sr_ent_push( cubemap )
+         #}
       #}
    #}
 
@@ -1989,7 +2114,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 )
@@ -2023,7 +2148,7 @@ class SR_SCENE_SETTINGS(bpy.types.PropertyGroup):
 #{
    use_hidden: bpy.props.BoolProperty( name="use hidden", default=False )
    export_dir: bpy.props.StringProperty( name="Export Dir", subtype='DIR_PATH' )
-   gizmos: bpy.props.BoolProperty( name="Draw Gizmos", default=True )
+   gizmos: bpy.props.BoolProperty( name="Draw Gizmos", default=False )
 
    panel: bpy.props.EnumProperty(
         name='Panel',
@@ -2203,9 +2328,12 @@ class SR_INTERFACE(bpy.types.Panel):
          active_object = context.active_object
          if not active_object: return
 
-         _.layout.operator( 'skaterift.copy_entity_data', \
-               text=F'Copy entity data to {len(context.selected_objects)-1} '+\
-                    F'other objects' )
+         amount = max( 0, len(context.selected_objects)-1 )
+         
+         row = _.layout.row()
+         row.operator( 'skaterift.copy_entity_data', \
+               text=F'Copy entity data to {amount} other objects' )
+         if amount == 0: row.enabled=False
 
          box = _.layout.box()
          row = box.row()
@@ -2213,13 +2341,13 @@ class SR_INTERFACE(bpy.types.Panel):
          row.label( text=active_object.name )
          row.scale_y = 1.5
 
-         def _draw_prop_collection( data ): #{
+         def _draw_prop_collection( source, data ): #{
             nonlocal box
             row = box.row()
             row.alignment = 'CENTER'
             row.enabled = False
             row.scale_y = 1.5
-            row.label( text=F'{data[0]}' )
+            row.label( text=F'{source}' )
             
             if hasattr(type(data[0]),'sr_inspector'):#{
                type(data[0]).sr_inspector( box, data )
@@ -2239,7 +2367,9 @@ class SR_INTERFACE(bpy.types.Panel):
                                  text=F'Mirror attributes to {mb.name}' )
                #}
 
-               _draw_prop_collection( [bones.active.SR_data ] )
+               _draw_prop_collection( \
+                     F'bpy.types.Bone["{bones.active.name}"].SR_data',\
+                     [bones.active.SR_data ] )
             #}
             else: #{
                row = box.row()
@@ -2250,18 +2380,26 @@ class SR_INTERFACE(bpy.types.Panel):
             #}
          #}
          elif active_object.type == 'LIGHT': #{
-            _draw_prop_collection( [active_object.data.SR_data] )
+            _draw_prop_collection( \
+                  F'bpy.types.Light["{active_object.data.name}"].SR_data', \
+                  [active_object.data.SR_data] )
          #}
          elif active_object.type in ['EMPTY','CURVE','MESH']:#{
             box.prop( active_object.SR_data, "ent_type" )
             ent_type = active_object.SR_data.ent_type
             
             col = getattr( active_object.SR_data, ent_type, None )
-            if col != None and len(col)!=0: _draw_prop_collection( col )
+            if col != None and len(col)!=0: 
+               _draw_prop_collection( \
+         F'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
+         col )
 
             if active_object.type == 'MESH':#{
                col = getattr( active_object.data.SR_data, ent_type, None )
-               if col != None and len(col)!=0: _draw_prop_collection( col )
+               if col != None and len(col)!=0: 
+                  _draw_prop_collection( \
+         F'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
+         col )
             #}
          #}
       #}
@@ -2299,7 +2437,8 @@ class SR_MATERIAL_PANEL(bpy.types.Panel):
          row = box.row()
 
          if (active_mat.SR_data.shader != 'invisible') and \
-            (active_mat.SR_data.shader != 'boundary'):#{
+            (active_mat.SR_data.shader != 'boundary') and \
+            (active_mat.SR_data.shader != 'walking'):#{
             row.prop( active_mat.SR_data, "skate_surface" )
             row.prop( active_mat.SR_data, "grind_surface" )
             row.prop( active_mat.SR_data, "grow_grass" )
@@ -2323,6 +2462,11 @@ class SR_MATERIAL_PANEL(bpy.types.Panel):
          box.prop( active_mat.SR_data, "shore_colour" )
          box.prop( active_mat.SR_data, "ocean_colour" )
       #}
+      elif active_mat.SR_data.shader == "cubemap":#{
+         box = _.layout.box()
+         box.prop( active_mat.SR_data, "cubemap" )
+         box.prop( active_mat.SR_data, "tint" )
+      #}
    #}
 #}
 
@@ -2373,7 +2517,11 @@ 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 )
+   locked: bpy.props.BoolProperty( name="Start Locked", default=False )
 
    @staticmethod
    def sr_inspector( layout, data ):
@@ -2383,6 +2531,11 @@ 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' )
+      flags.prop( data[0], 'locked' )
    #}
 #}
 
@@ -2730,8 +2883,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',''),
@@ -2740,15 +2892,41 @@ 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_ccmd']))
+           poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target_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 inspect_target( layout, data, propname ):#{
+      box = layout.box()
+      box.prop( data[0], propname )
+
+      row = box.row()
+      row.prop( data[0], propname + '_event')
+
+      target = getattr( data[0], propname )
+      if target:#{
+         tipo = target.SR_data.ent_type
+         cls = globals()[ tipo ]
+
+         table = getattr( cls, 'sr_functions', None )
+         if table:#{
+            index = getattr( data[0], propname+'_event')
+            if index in table:
+               row.label( text=table[index] )
+            else:
+               row.label( text="undefined function" )
+         #}
+      #}
+      else:#{
+         row.label( text="..." )
+         row.enabled=False
+      #}
+   #}
+
+   @staticmethod
+   def sr_inspector( layout, data ):#{
+      layout.prop( data[0], 'subtype' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target' )
    #}
 #}
 
@@ -3030,14 +3208,100 @@ class SR_OBJECT_ENT_CCMD(bpy.types.PropertyGroup):
    command: bpy.props.StringProperty(name="Command Line")
 #}
 
-class SR_OBJECT_ENT_CHALLENGE(bpy.types.PropertyGroup):#{
+class SR_OBJECT_ENT_OBJECTIVE(bpy.types.PropertyGroup):#{
    proxima: bpy.props.PointerProperty( \
             type=bpy.types.Object, name="Next", \
-            poll=lambda self,obj: sr_filter_ent_type(obj,['ent_challenge']))
+            poll=lambda self,obj: sr_filter_ent_type(obj,['ent_objective']))
    target: bpy.props.PointerProperty( \
-           type=bpy.types.Object, name="Target", \
-           poll=lambda self,obj: sr_filter_ent_type(obj,\
-                                    ['ent_audio','ent_ccmd']))
+           type=bpy.types.Object, name="Win", \
+           poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target_event: bpy.props.IntProperty( name="Event/Method" )
+   time_limit: bpy.props.FloatProperty( name="Time Limit", default=1.0 )
+   filtrar: bpy.props.EnumProperty( name='Filter',\
+      items=[('0','none',''),
+             (str(0x1),'trick_shuvit',''),
+             (str(0x2),'trick_kickflip',''),
+             (str(0x4),'trick_treflip',''),
+             (str(0x1|0x2|0x4),'trick_any',''),
+             (str(0x8),'flip_back',''),
+             (str(0x10),'flip_front',''),
+             (str(0x8|0x10),'flip_any',''),
+             (str(0x20),'grind_truck_any',''),
+             (str(0x40),'grind_board_any',''),
+             (str(0x20|0x40),'grind_any',''),
+             (str(0x80),'footplant',''),
+             (str(0x100),'passthrough',''),
+             ])
+
+   @staticmethod
+   def sr_inspector( layout, data ):#{
+      layout.prop( data[0], 'proxima' )
+      layout.prop( data[0], 'time_limit' )
+      layout.prop( data[0], 'filtrar' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target' )
+   #}
+#}
+
+class SR_OBJECT_ENT_CHALLENGE(bpy.types.PropertyGroup):#{
+   alias: bpy.props.StringProperty( name="Alias" )
+
+   target: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="On Complete", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target_event: bpy.props.IntProperty( name="Event/Method" )
+   reset: bpy.props.PointerProperty( \
+           type=bpy.types.Object, name="On Reset", \
+           poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   reset_event: bpy.props.IntProperty( name="Event/Method" )
+
+   time_limit: bpy.props.BoolProperty( name="Time Limit" )
+
+   first: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="First Objective", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,['ent_objective']))
+
+   camera: bpy.props.PointerProperty( \
+           type=bpy.types.Object, name="Camera", \
+           poll=lambda self,obj: sr_filter_ent_type(obj,['ent_camera']))
+
+
+   @staticmethod
+   def sr_inspector( layout, data ):#{
+      layout.prop( data[0], 'alias' )
+      layout.prop( data[0], 'camera' )
+      layout.prop( data[0], 'first' )
+      layout.prop( data[0], 'time_limit' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'reset' )
+   #}
+#}
+
+class SR_OBJECT_ENT_RELAY(bpy.types.PropertyGroup):#{
+   target0: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="Target 0", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target1: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="Target 1", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target2: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="Target 2", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+   target3: bpy.props.PointerProperty( \
+            type=bpy.types.Object, name="Target 3", \
+            poll=lambda self,obj: sr_filter_ent_type(obj,SR_TRIGGERABLE))
+
+   target0_event: bpy.props.IntProperty( name="Event" )
+   target1_event: bpy.props.IntProperty( name="Event" )
+   target2_event: bpy.props.IntProperty( name="Event" )
+   target3_event: bpy.props.IntProperty( name="Event" )
+
+   @staticmethod
+   def sr_inspector( layout, data ):#{
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target0' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target1' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target2' )
+      SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target3' )
+   #}
 #}
 
 class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup):
@@ -3057,7 +3321,9 @@ class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup):
    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_objective: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE)
    ent_challenge: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE)
+   ent_relay: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_RELAY)
 
    ent_type: bpy.props.EnumProperty(
       name="Type",
@@ -3134,6 +3400,8 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup):
       ('invisible','Invisible',''),
       ('boundary','Boundary',''),
       ('fxglow','FX Glow',''),
+      ('cubemap','Cubemap',''),
+      ('walking','Walking','')
       ])
 
    surface_prop: bpy.props.EnumProperty(
@@ -3199,6 +3467,18 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup):
          default=Vector((0.0,0.006,0.03)),\
          description="Water colour in the deep bits"\
    )
+   tint: bpy.props.FloatVectorProperty( \
+         name="Tint",\
+         subtype='COLOR',\
+         min=0.0,max=1.0,\
+         size=4,\
+         default=Vector((1.0,1.0,1.0,1.0)),\
+         description="Reflection tint"\
+   )
+
+   cubemap: bpy.props.PointerProperty( \
+               type=bpy.types.Object, name="cubemap", \
+               poll=lambda self,obj: sr_filter_ent_type(obj,['ent_cubemap']))
 #}
 
 # ---------------------------------------------------------------------------- #
@@ -3208,6 +3488,7 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup):
 # ---------------------------------------------------------------------------- #
 
 cv_view_draw_handler = None
+cv_view_pixel_handler = None
 cv_view_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
 cv_view_verts = []
 cv_view_colours = []
@@ -3363,7 +3644,7 @@ def cv_tangent_basis( n, tx, ty ):
 
 # Draw coloured arrow
 #
-def cv_draw_arrow( p0, p1, c0, size=0.15 ):
+def cv_draw_arrow( p0, p1, c0, size=0.25, outline=True ):
 #{
    global cv_view_verts, cv_view_colours
 
@@ -3374,10 +3655,26 @@ def cv_draw_arrow( p0, p1, c0, size=0.15 ):
    tx = Vector((1,0,0))
    ty = Vector((1,0,0))
    cv_tangent_basis( n, tx, ty )
-   
+   tx *= 0.5
+   ty *= 0.5
+
+   if outline:#{
+      cv_draw_lines()
+      gpu.state.line_width_set(1.0)
+   #}
+
    cv_view_verts += [p0,p1, midpt+(tx-n)*size,midpt, midpt+(-tx-n)*size,midpt ]
    cv_view_colours += [c0,c0,c0,c0,c0,c0]
-   #cv_draw_lines()
+   cv_draw_lines()
+
+   if outline:#{
+      gpu.state.line_width_set(3.0)
+      cv_view_verts += [p0,p1,midpt+(tx-n)*size,midpt,midpt+(-tx-n)*size,midpt]
+      b0 = (0,0,0)
+      cv_view_colours += [b0,b0,b0,b0,b0,b0]
+      cv_draw_lines()
+      gpu.state.line_width_set(2.0)
+   #}
 #}
 
 def cv_draw_line_dotted( p0, p1, c0, dots=10 ):
@@ -3700,17 +3997,17 @@ def cv_ent_volume( obj ):
    data = obj.SR_data.ent_volume[0]
 
    if data.subtype == '0':#{
-      cv_draw_ucube( obj.matrix_world, (0,1,0) )
+      cv_draw_ucube( obj.matrix_world, (0,1,0), Vector((0.99,0.99,0.99)) )
 
       if data.target:#{
-         cv_draw_line( obj.location, data.target.location, (0,1,0) )
+         cv_draw_arrow( obj.location, data.target.location, (1,1,1) )
       #}
    #}
    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,1) )
       #}
    #}
 #}
@@ -3929,14 +4226,14 @@ def cv_draw_route( route, dij ):
       path = solve_graph( dij, gi.name, gj.name )
 
       if path:#{
-         cv_draw_arrow(gi.location,dij.points[path[0]],cc,1.5)
-         cv_draw_arrow(dij.points[path[len(path)-1]],gj.location,cc,1.5)
+         cv_draw_arrow(gi.location,dij.points[path[0]],cc,1.5,False)
+         cv_draw_arrow(dij.points[path[len(path)-1]],gj.location,cc,1.5,False)
          for j in range(len(path)-1):#{
             i0 = path[j]
             i1 = path[j+1]
             o0 = dij.points[ i0 ]
             o1 = dij.points[ i1 ]
-            cv_draw_arrow(o0,o1,cc,1.5)
+            cv_draw_arrow(o0,o1,cc,1.5,False)
          #}
       #}
       else:#{
@@ -3945,8 +4242,7 @@ def cv_draw_route( route, dij ):
    #}
 #}
 
-def cv_draw():
-#{
+def cv_draw():#{
    global cv_view_shader
    global cv_view_verts
    global cv_view_colours
@@ -3957,7 +4253,7 @@ def cv_draw():
    cv_view_colours = []
 
    cv_view_shader.bind()
-   gpu.state.depth_mask_set(False)
+   gpu.state.depth_mask_set(True)
    gpu.state.line_width_set(2.0)
    gpu.state.face_culling_set('BACK')
    gpu.state.depth_test_set('LESS')
@@ -3989,6 +4285,51 @@ def cv_draw():
          elif ent_type == 'ent_volume':#{
             cv_ent_volume( obj )
          #}
+         elif ent_type == 'ent_objective':#{
+            data = obj.SR_data.ent_objective[0]
+            if data.proxima:#{
+               cv_draw_arrow( obj.location, data.proxima.location, (1,0.6,0.2) )
+            #}
+            if data.target:
+               cv_draw_arrow( obj.location, data.target.location, (1,1,1) )
+         #}
+         elif ent_type == 'ent_relay':#{
+            data = obj.SR_data.ent_relay[0]
+            if data.target0:
+               cv_draw_arrow( obj.location, data.target0.location, (1,1,1) )
+            if data.target1:
+               cv_draw_arrow( obj.location, data.target1.location, (1,1,1) )
+            if data.target2:
+               cv_draw_arrow( obj.location, data.target2.location, (1,1,1) )
+            if data.target3:
+               cv_draw_arrow( obj.location, data.target3.location, (1,1,1) )
+         #}
+         elif ent_type == 'ent_challenge':#{
+            data = obj.SR_data.ent_challenge[0]
+            if data.target:
+               cv_draw_arrow( obj.location, data.target.location, (1,1,1) )
+            if data.reset:
+               cv_draw_arrow( obj.location, data.reset.location, (0.9,0,0) )
+            if data.first:
+               cv_draw_arrow( obj.location, data.first.location, (1,0.6,0.2) )
+
+            cc1 = (0.4,0.3,0.2)
+            info_cu = Vector((1.2,0.01,0.72))*0.5
+            info_co = Vector((0.0,0.0,0.72))*0.5
+            cv_draw_ucube( obj.matrix_world, cc1, info_cu, info_co)
+            if data.camera:
+               cv_draw_line_dotted( obj.location, data.camera.location, (1,1,1))
+
+            vs = [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
+                  Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
+                  Vector(( 0.1,0.0,0.30))]
+            for v in range(len(vs)):#{
+               vs[v] = obj.matrix_world @ vs[v]
+            #}
+
+            cv_view_verts += [vs[0],vs[1],vs[1],vs[2],vs[3],vs[4]]
+            cv_view_colours += [cc1,cc1,cc1,cc1,cc1,cc1]
+         #}
          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) )
@@ -4053,6 +4394,11 @@ 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 == '3':#{
+               rack = None
+               display = None
+               info = None
+            #}
 
             if rack:
                cv_draw_ucube( rack.matrix_world, cc, rack_cu, rack_co )
@@ -4155,7 +4501,31 @@ def cv_draw():
    #}
 
    cv_draw_lines()
-   return
+#}
+
+def pos3d_to_2d( pos ):#{
+   return view3d_utils.location_3d_to_region_2d( \
+            bpy.context.region, \
+            bpy.context.space_data.region_3d, pos )
+#}
+
+def cv_draw_pixel():#{
+   if not bpy.context.scene.SR_data.gizmos: return
+   blf.size(0,10)
+   blf.color(0, 1.0,1.0,1.0,0.9)
+   blf.enable(0,blf.SHADOW)
+   blf.shadow(0,3,0.0,0.0,0.0,1.0)
+   for obj in bpy.context.collection.objects:#{
+      ent_type = obj_ent_type( obj )
+      
+      if ent_type != 'none':#{
+         co = pos3d_to_2d( obj.location )
+
+         if not co: continue
+         blf.position(0,co[0],co[1],0)
+         blf.draw(0,ent_type)
+      #}
+   #}
 #}
 
 classes = [ SR_INTERFACE, SR_MATERIAL_PANEL,\
@@ -4180,7 +4550,8 @@ classes = [ SR_INTERFACE, SR_MATERIAL_PANEL,\
             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_CCMD,\
-            SR_OBJECT_ENT_CHALLENGE,\
+            SR_OBJECT_ENT_OBJECTIVE,SR_OBJECT_ENT_CHALLENGE,\
+            SR_OBJECT_ENT_RELAY,\
             \
             SR_OBJECT_PROPERTIES, SR_LIGHT_PROPERTIES, SR_BONE_PROPERTIES, 
             SR_MESH_PROPERTIES, SR_MATERIAL_PROPERTIES \
@@ -4207,9 +4578,11 @@ def register():
    bpy.types.Material.SR_data = \
          bpy.props.PointerProperty(type=SR_MATERIAL_PROPERTIES)
 
-   global cv_view_draw_handler
+   global cv_view_draw_handler, cv_view_pixel_handler
    cv_view_draw_handler = bpy.types.SpaceView3D.draw_handler_add(\
       cv_draw,(),'WINDOW','POST_VIEW')
+   cv_view_pixel_handler = bpy.types.SpaceView3D.draw_handler_add(\
+      cv_draw_pixel,(),'WINDOW','POST_PIXEL')
 #}
 
 def unregister():
@@ -4217,8 +4590,9 @@ def unregister():
    for c in classes:
       bpy.utils.unregister_class(c)
 
-   global cv_view_draw_handler
+   global cv_view_draw_handler, cv_view_pixel_handler
    bpy.types.SpaceView3D.draw_handler_remove(cv_view_draw_handler,'WINDOW')
+   bpy.types.SpaceView3D.draw_handler_remove(cv_view_pixel_handler,'WINDOW')
 #}
 
 # ---------------------------------------------------------------------------- #