read camera from metascene
authorhgn <hgodden00@gmail.com>
Fri, 13 Dec 2024 01:52:42 +0000 (01:52 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 13 Dec 2024 01:52:42 +0000 (01:52 +0000)
content_skaterift/metascenes/test_scene.ms
skaterift_blender/sr_mdl.py
skaterift_blender/sr_metascene.py
src/metascene.c
src/metascene.h
src/skaterift.c

index 3f9eba06222265404e283f327d080c1b1a4a99f3..838c7f2c462b3bc3ac62a5db46ac5c6971e4141d 100644 (file)
Binary files a/content_skaterift/metascenes/test_scene.ms and b/content_skaterift/metascenes/test_scene.ms differ
index 16cdaea9f70730541e74e9b4e1cc8d8673731dbc..79c2be9b664943fb48ba902e5ae0986ddd1b6d25 100644 (file)
@@ -611,7 +611,7 @@ def _mdl_compiler_compile_entities():
             cam.co[1] = trans.co[1]
             cam.co[2] = trans.co[2]
 
-            cam.fov = obj.data.angle * 45.0
+            cam.fov = obj.data.angle_y * 57.2958
             sr_ent_push(cam)
          #}
          elif ent_type == 'ent_gate': #{
index 94e587a3bcb0d5dc34019b41b2796d54f1dc42cc..34f46ab9941d6d5926a734655133aa677dd0d026 100644 (file)
@@ -239,6 +239,12 @@ def _metascene_compile_action_curves( out_strip, action ):
          mul = [1,1,-1][ index ]
       #}
 
+      if name == 'rotation_euler':
+      #{
+         index = [1,0,2][ index ]
+         mul = -1
+      #}
+
       id = F"{name}:{index}"
       print( F"      Appending curve '{id}'" )
       
@@ -433,6 +439,17 @@ def _sr_export_metascene( path ):
    for marker in bpy.context.scene.timeline_markers:
    #{
       print( F"Marker {marker.name}: {marker.camera}" )
+      out_strip = ms_strip()
+      out_strip.data_start = 0
+      out_strip.data_count = 0
+      out_strip.data_mode = 2
+      out_strip.offset = marker.frame
+      out_strip.length = 0
+      out_strip.pstr_name = _af_pack_string( marker.name )
+      out_strip.pstr_internal_name = 0
+      out_strip.instance_id = 0xffffffff
+      out_strip.object_id = sr_entity_id( marker.camera )
+      _ms_compiler.strips.append( out_strip )
    #}
 
    _ms_compiler.strips.sort( key=lambda s: s.offset )
index b3a932ff2e8501f209e415a48c9a2288d76230c4..40eed04a28c6f7dac84309bde1b9278bd800103b 100644 (file)
@@ -85,6 +85,8 @@ struct
    samplers[32];
    u32 active_samplers;
 
+   ent_camera *active_camera;
+
    u32 strip;
    f32 time;
 }
@@ -498,6 +500,11 @@ f32 explicit_bezier( f32 A[2], f32 B[2], f32 C[2], f32 D[2], f32 x )
          + A[1] * (-1.0f*t3 + 3.0f*t2 - 3.0f*tc + 1.0f);
 }
 
+ent_camera *_cutscene_active_camera(void)
+{
+   return _cutscene.active_camera;
+}
+
 void cutscene_update( f32 delta )
 {
    _cutscene.time += delta;
@@ -544,6 +551,24 @@ void cutscene_update( f32 delta )
          continue;
       }
 
+      if( strip->data_mode == 2 )
+      {
+         if( strip->object_id )
+         {
+            struct cs_asoc asoc;
+            _cutscene_get_strip_asoc( strip, &asoc );
+
+            VG_ASSERT( asoc.entity_type == k_ent_camera );
+            ent_camera *cam = 
+               af_arritm( &_cutscene.meta.cameras, asoc.entity_index );
+
+            _cutscene.active_camera = cam;
+         }
+         else
+            _cutscene.active_camera = NULL;
+      }
+      else
+      {
       if( strip->instance_id == 0xffffffff )
       {
          /* internal link */
@@ -611,7 +636,8 @@ void cutscene_update( f32 delta )
             samp->override = asoc.override;
          }
       }
-      
+      }
+
       _cutscene.strip ++;
    }
 
@@ -685,75 +711,6 @@ void cutscene_update( f32 delta )
 
          if( kl && kr )
          {
-#if 0
-            f32 A = kl->co[0],
-                D = kr->co[0],
-                L = D-A,
-                B = (kl->r[0] - A) / L,
-                C = (kr->l[0] - A) / L,
-                a = 1.0f + 3.0f*B - 3.0f*C,
-                b = -6.0f*B + 3.0f*C,
-                c = 3.0f*B,
-                d = -(t - A) / L;
-
-/* ILLINOIS */
-            f32 fa = d,
-                fb = a+b+c+d,
-                xMin = 0.0f,
-                xMax = 1.0f,
-                e,x1;
-
-            for( u32 j=0; j<6; j ++ )
-            {
-               x1 = xMax - fb*(xMax-xMin)/(fb-fa);
-               e  = x1*x1*x1*a + x1*x1*b + x1*c + d;
-
-               if( fabsf(e) < 0.0001f )
-                  break;
-
-               if( fb*e < 0.0f )
-               {
-                  xMin = xMax;
-                  fa = fb;
-               }
-               else
-                  fa = fa*0.5f;
-
-               xMax = x1;
-               fb = e;
-            }
-            
-/* BISECTION */
-#if 0
-            /* One day I will have my revenge on cubics I swear */
-            f32 x1 = 0.5f,
-                xMin = 0.0f,
-                xMax = 1.0f,
-                e;
-            for( u32 j=0; j<16; j ++ )
-            {
-               e = x1*x1*x1*a + x1*x1*b + x1*c + d;
-               if( e > 0.0f ) xMax = x1;
-               else           xMin = x1;
-               x1 = (xMin+xMax)*0.5f;
-            }
-#endif
-
-            if( samp->curves.semantic == CS_LOCATION+1 )
-               vg_info( "convergence: %.9f\n", e );
-
-            f32 x2 = x1*x1,
-                x3 = x2*x1,
-                Ay = kl->co[1],
-                By = kl->r[1],
-                Cy = kr->l[1],
-                Dy = kr->co[1],
-                y =    Dy*x3 
-                     + Cy*(-3.0f*x3 + 3.0f*x2) 
-                     + By*( 3.0f*x3 - 6.0f*x2 + 3.0f*x1)
-                     + Ay*(-x3      + 3.0f*x2 - 3.0f*x1 + 1.0f );
-#endif
-
             *samp->curves.target = 
                explicit_bezier( kl->co, kl->r, kr->l, kr->co, t );
          }
@@ -761,6 +718,13 @@ void cutscene_update( f32 delta )
          {
             *samp->curves.target = kl->co[1];
          }
+
+         if( samp->curves.semantic == CS_FOV )
+         {
+            f32 mm  = *samp->curves.target,
+                fov = 2.0f * 57.2957795f * atanf( (36.0f*0.5f) / mm );
+            *samp->curves.target = fov;
+         }
       }
    }
 
@@ -797,6 +761,23 @@ static void cb_cutscene_view( ui_context *ctx, ui_rect rect,
    for( u32 i=0; i<af_arrcount(&_cutscene.meta.strips); i ++ )
    {
       ms_strip *strip = af_arritm(&_cutscene.meta.strips, i );
+
+      if( strip->data_mode == 2 )
+      {
+         ui_rect box = { root[0] + strip->offset, root[1], 1, rect[3]-16 };
+         ui_fill( ctx, box, 0xff00ff00 );
+
+         box[1] += box[3] -16;
+         box[2] = 200;
+         box[3] = 16;
+
+         if( ui_clip( rect, box, box ) )
+         {
+            ui_text( ctx, box, af_str( &_cutscene.meta.af, strip->pstr_name ),
+                     1, k_ui_align_middle_left, 0 );
+         }
+         continue;
+      }
       
       u32 layer = 0;
       for( u32 k=0; k<VG_ARRAY_LEN(usage); k ++ )
index 45e19b6bca552cdc8f61baa0cdccb1ce79033891..86b4990a31423f92733ac90e4962c4db72678e1f 100644 (file)
@@ -78,3 +78,4 @@ void metascene_load( ms_context *ms, const char *path, void *alloc );
 void cutscene_init(void);
 void cutscene_render( world_instance *world, vg_camera *cam );
 void cutscene_update( f32 delta );
+ent_camera *_cutscene_active_camera(void);
index cc1e89b59b2dd3dc1dcd930f9d48fa722f874232..7bd4103aa9b3ba9497b2b6c82a7ffa8040f6a6e3 100644 (file)
@@ -493,6 +493,10 @@ static void skaterift_composite_maincamera(void)
       }
    }
 
+   ent_camera *cs_cam = _cutscene_active_camera();
+   if( cs_cam )
+      ent_camera_unpack( cs_cam, &g_render.cam );
+
    vg_camera_update_transform( &g_render.cam );
    vg_camera_update_view( &g_render.cam );
    vg_camera_update_projection( &g_render.cam );