grid based
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index 06d90a4b11d4cb69654c547958f28e6d134a695d..a12850b2b347f02b0391166b8cb90ed191716083 100644 (file)
@@ -255,6 +255,40 @@ class classtype_gate(Structure):
    #}
 #}
 
+class classtype_nonlocal_gate(classtype_gate):
+#{
+   def encode_obj(_,node,node_def):
+   #{
+      node.classtype = 300
+
+      obj = node_def['obj']
+      _.target = encoder_process_pstr( node_def['obj'].cv_data.strp )
+
+      if obj.type == 'MESH':
+      #{
+         _.dims[0] = obj.data.cv_data.v0[0]
+         _.dims[1] = obj.data.cv_data.v0[1]
+         _.dims[2] = obj.data.cv_data.v0[2]
+      #}
+      else:
+      #{
+         _.dims[0] = obj.cv_data.v0[0]
+         _.dims[1] = obj.cv_data.v0[1]
+         _.dims[2] = obj.cv_data.v0[2]
+      #}
+   #}
+
+   @staticmethod
+   def editor_interface( layout, obj ):
+   #{
+      layout.prop( obj.cv_data, "strp", text="Nonlocal ID" )
+
+      mesh = obj.data
+      layout.label( text=F"(i) Data is stored in {mesh.name}" )
+      layout.prop( mesh.cv_data, "v0", text="Gate dimensions" )
+   #}
+#}
+
 # Classtype 3
 #
 #  Purpose: player can reset here, its a safe place
@@ -773,22 +807,71 @@ class classtype_audio(Structure):
 
 # Classtype 200
 # 
-#  Purpose: point light
+#  Purpose: world light
 #
-class classtype_point_light(Structure):
+class classtype_world_light( Structure ):
 #{
    _pack_ = 1
-   _fields_ = [("colour",c_float*4)]
+   _fields_ = [("type",c_uint32),
+               ("colour",c_float*4),
+               ("angle",c_float),
+               ("range",c_float)]
 
    def encode_obj(_, node, node_def):
    #{
       node.classtype = 200
 
-      data = node_def['obj'].data
+      obj  = node_def['obj']
+      data = obj.data
       _.colour[0] = data.color[0]
       _.colour[1] = data.color[1]
       _.colour[2] = data.color[2]
       _.colour[3] = data.energy
+      _.range = data.cutoff_distance # this has to be manually set
+                                     # TODO: At some point, automate a min
+                                     #       threshold value
+
+      if obj.data.type == 'POINT':
+      #{
+         _.type = 0
+         _.angle = 0.0
+      #}
+      elif obj.data.type == 'SPOT':
+      #{
+         _.type = 1
+         _.angle = data.spot_size*0.5
+      #}
+
+      if data.cv_data.bp0:
+         _.type += 2
+   #}
+
+   @staticmethod
+   def editor_interface( layout, obj ):
+   #{
+      pass
+   #}
+#}
+
+# Classtype 201
+# 
+#  Purpose: lighting settings for world
+#
+class classtype_lighting_info(Structure):
+#{
+   _pack_ = 1
+   _fields_ = [("colours",(c_float*3)*3),
+               ("directions",(c_float*2)*3),
+               ("states",c_uint32*3),
+               ("shadow_spread",c_float),
+               ("shadow_length",c_float),
+               ("ambient",c_float*3)]
+
+   def encode_obj(_, node, node_def):
+   #{
+      node.classtype = 201
+
+      # TODO
    #}
 
    @staticmethod
@@ -1264,7 +1347,7 @@ def encoder_build_scene_graph( collection ):
 
    for obj in collection.all_objects:
    #{
-      if obj.parent: continue
+      #if obj.parent: continue
 
       def _extend( p, n, d ):
       #{
@@ -1839,14 +1922,13 @@ def encoder_process_definition( node_def ):
    #{
       obj      = node_def['obj']
       obj_type = obj.type
-      obj_co   = obj.location
+      obj_co   = obj.matrix_world @ Vector((0,0,0))
 
       if obj_type == 'ARMATURE':
          obj_classtype = 'classtype_skeleton'
       elif obj_type == 'LIGHT':
       #{
-         if obj.data.type == 'POINT':
-            obj_classtype = 'classtype_point_light'
+         obj_classtype = 'classtype_world_light'
       #}
       else:
       #{
@@ -2567,6 +2649,31 @@ class CV_MESH_SETTINGS(bpy.types.PropertyGroup):
    v3: bpy.props.FloatVectorProperty(name="v3",size=3)
 #}
 
+class CV_LIGHT_SETTINGS(bpy.types.PropertyGroup):
+#{
+   bp0: bpy.props.BoolProperty( name="bp0" );
+#}
+
+class CV_LIGHT_PANEL(bpy.types.Panel):
+#{
+   bl_label="[Skate Rift]"
+   bl_idname="SCENE_PT_cv_light"
+   bl_space_type='PROPERTIES'
+   bl_region_type='WINDOW'
+   bl_context='data'
+
+   def draw(_,context):
+   #{
+      active_object = context.active_object
+      if active_object == None: return
+
+      if active_object.type != 'LIGHT': return
+
+      data = active_object.data.cv_data
+      _.layout.prop( data, "bp0", text="Only on during night" )
+   #}
+#}
+
 class CV_OBJ_SETTINGS(bpy.types.PropertyGroup):
 #{
    uid: bpy.props.IntProperty( name="" )
@@ -2605,6 +2712,7 @@ class CV_OBJ_SETTINGS(bpy.types.PropertyGroup):
       ('classtype_logic_achievement',"classtype_logic_achievement","",101),
       ('classtype_logic_relay',"classtype_logic_relay","",102),
       ('classtype_spawn_link',"classtype_spawn_link","",150),
+      ('classtype_nonlocal_gate', "classtype_nonlocal_gate", "", 300)
       ])
 #}
 
@@ -2633,7 +2741,7 @@ class CV_BONE_SETTINGS(bpy.types.PropertyGroup):
 
 class CV_BONE_PANEL(bpy.types.Panel):
 #{
-   bl_label="Bone Config"
+   bl_label="[Skate Rift]"
    bl_idname="SCENE_PT_cv_bone"
    bl_space_type='PROPERTIES'
    bl_region_type='WINDOW'
@@ -2926,7 +3034,8 @@ class CV_INTERFACE(bpy.types.Panel):
 classes = [CV_OBJ_SETTINGS,CV_OBJ_PANEL,CV_COMPILE,CV_INTERFACE,\
            CV_MESH_SETTINGS, CV_SCENE_SETTINGS, CV_BONE_SETTINGS,\
            CV_BONE_PANEL, CV_COLLECTION_SETTINGS, CV_COMPILE_THIS,\
-           CV_MATERIAL_SETTINGS, CV_MATERIAL_PANEL ]
+           CV_MATERIAL_SETTINGS, CV_MATERIAL_PANEL, CV_LIGHT_SETTINGS,\
+           CV_LIGHT_PANEL]
 
 def register():
 #{
@@ -2943,6 +3052,7 @@ def register():
          bpy.props.PointerProperty(type=CV_COLLECTION_SETTINGS)
    bpy.types.Material.cv_data = \
          bpy.props.PointerProperty(type=CV_MATERIAL_SETTINGS)
+   bpy.types.Light.cv_data = bpy.props.PointerProperty(type=CV_LIGHT_SETTINGS)
 
    cv_view_draw_handler = bpy.types.SpaceView3D.draw_handler_add(\
       cv_draw,(),'WINDOW','POST_VIEW')