From: hgn Date: Fri, 13 Dec 2024 01:52:42 +0000 (+0000) Subject: read camera from metascene X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=5237c1e543acd67d8e4696c1fccc56bf4eb359db;p=carveJwlIkooP6JGAAIwe30JlM.git read camera from metascene --- diff --git a/content_skaterift/metascenes/test_scene.ms b/content_skaterift/metascenes/test_scene.ms index 3f9eba0..838c7f2 100644 Binary files a/content_skaterift/metascenes/test_scene.ms and b/content_skaterift/metascenes/test_scene.ms differ diff --git a/skaterift_blender/sr_mdl.py b/skaterift_blender/sr_mdl.py index 16cdaea..79c2be9 100644 --- a/skaterift_blender/sr_mdl.py +++ b/skaterift_blender/sr_mdl.py @@ -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': #{ diff --git a/skaterift_blender/sr_metascene.py b/skaterift_blender/sr_metascene.py index 94e587a..34f46ab 100644 --- a/skaterift_blender/sr_metascene.py +++ b/skaterift_blender/sr_metascene.py @@ -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 ) diff --git a/src/metascene.c b/src/metascene.c index b3a932f..40eed04 100644 --- a/src/metascene.c +++ b/src/metascene.c @@ -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; idata_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