cropping
[csRadar.git] / vmf.h
diff --git a/vmf.h b/vmf.h
index 4793e0bda61af53b28c06a4bc521193369c9bc0a..d2bbbd214dd21b85c74a2edf2f429481f28a67d1 100644 (file)
--- a/vmf.h
+++ b/vmf.h
@@ -101,27 +101,20 @@ void solidgen_ctx_free( vmf_solid *ctx )
 }
 
 // Compute bounds of solid gen ctx
-void solidgen_bounds( vmf_solid *ctx, u32 start, u32 end, v3f min, v3f max )
+void solidgen_bounds( vmf_solid *ctx, boxf box )
 {
        v3f mine = { INFINITY, INFINITY, INFINITY };
        v3f maxe = {-INFINITY,-INFINITY,-INFINITY };
 
-       for( int i = start; i < end; i ++ )
+       for( int i = 0; i < csr_sb_count( ctx->verts ); i ++ )
        {
                vmf_vert *vert = ctx->verts + i;
-               float *co = vert->co;
-               
-               mine[0] = fminf( mine[0], co[0] );
-               mine[1] = fminf( mine[1], co[1] );
-               mine[2] = fminf( mine[2], co[2] );
-               
-               maxe[0] = fmaxf( maxe[0], co[0] );
-               maxe[1] = fmaxf( maxe[1], co[1] );
-               maxe[2] = fmaxf( maxe[2], co[2] );
+               v3_minv( mine, vert->co, mine );
+               v3_maxv( maxe, vert->co, maxe );
        }
        
-       v3_copy( mine, min );
-       v3_copy( maxe, max );
+       v3_copy( mine, box[0] );
+       v3_copy( maxe, box[1] );
 }
 
 struct
@@ -831,3 +824,37 @@ void vmf_entity_transform( vdf_node *ent, m4x3f mat )
        // Scale
        m4x3_scale( mat, scale );
 }
+
+u32 vmf_visgroup_id( vdf_node *root, const char *name )
+{
+       vdf_node *dict = vdf_next( root, "visgroups", NULL );
+       
+       if( dict )
+       {
+               vdf_foreach( dict, "visgroup", group )
+               {
+                       if( !strcmp( kv_get( group, "name", "" ), name ) )
+                       {
+                               return kv_get_int( group, "visgroupid", 0 );
+                       }
+               }
+       }
+       
+       return 0;
+}
+
+int vmf_visgroup_match( vdf_node *ent, u32 target )
+{
+       vdf_node *editor = vdf_next( ent, "editor", NULL );
+       
+       if( editor )
+       {
+               kv_foreach( editor, "visgroupid", groupe )
+               {
+                       if( target == atoi( groupe ) )
+                               return 1;
+               }
+       }
+       
+       return 0;
+}