cubemaps
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index f9b8f6925120eb57da1fd0760681f93d44153e7a..349dbe038b00040efc87d5eb9b71d576358d0671 100644 (file)
@@ -54,6 +54,8 @@ def get_entity_enum_id( alias ):
       #}
    #}
 
+   if alias == 'ent_cubemap': return 21
+
    return 0
 #}
 
@@ -484,11 +486,23 @@ class ent_relay(Structure):#{
    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 ):
 #{
    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
 #}
 
@@ -753,8 +767,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: 
@@ -783,6 +796,7 @@ def sr_compile_material( mat ):
    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
@@ -829,14 +843,19 @@ 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 in ['standard', 'standard_cutout', 'terrain_blend', \
+                             'vertex_blend', 'fxglow', 'cubemap' ]: #{
       if 'tex_diffuse' in inf: 
          m.tex_diffuse = sr_compile_texture(inf['tex_diffuse'])
    #}
@@ -1865,6 +1884,16 @@ def sr_compile( collection ):
             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 )
+         #}
       #}
    #}
 
@@ -2410,6 +2439,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" )
+      #}
    #}
 #}
 
@@ -3309,6 +3343,7 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup):
       ('invisible','Invisible',''),
       ('boundary','Boundary',''),
       ('fxglow','FX Glow',''),
+      ('cubemap','Cubemap','')
       ])
 
    surface_prop: bpy.props.EnumProperty(
@@ -3374,6 +3409,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']))
 #}
 
 # ---------------------------------------------------------------------------- #