+ else if( pnode->classtype == k_classtype_car_path )
+ {
+ struct classtype_car_path *p = mdl_get_entdata( mworld, pnode );
+ traffic_node *tn = &world.traffic[ world.traffic_count ];
+ tn->mn_next = NULL;
+ tn->mn_next1 = NULL;
+
+ if( p->target ) tn->mn_next = mdl_node_from_id( mworld, p->target );
+ if( p->target1 ) tn->mn_next1 = mdl_node_from_id( mworld, p->target1 );
+
+ m4x3f transform;
+ mdl_node_transform( pnode, transform );
+ m3x3_mulv( transform, (v3f){1.0f,0.0f,0.0f}, tn->h );
+ v3_copy( transform[3], tn->co );
+
+ pnode->sub_uid = world.traffic_count ++;
+ }
+ else if( pnode->classtype == k_classtype_instance )
+ {
+ struct classtype_instance *inst = mdl_get_entdata( mworld, pnode );
+ pnode->sub_uid = 0;
+
+ int cached = 0;
+ for( int i=0; i<world.instance_cache_count; i++ )
+ {
+ struct instance_cache *cache = &world.instance_cache[i];
+ if( inst->pstr_file == cache->pstr_file )
+ {
+ cached = 1;
+ pnode->sub_uid = i+1;
+ break;
+ }
+ }
+
+ if( !cached )
+ {
+ world.instance_cache = buffer_reserve(
+ world.instance_cache, world.instance_cache_count,
+ &world.instance_cache_cap, 1,
+ sizeof(struct instance_cache) );
+
+ struct instance_cache *cache =
+ &world.instance_cache[world.instance_cache_count];
+
+ const char *filename = mdl_pstr(mworld, inst->pstr_file);
+
+ cache->pstr_file = inst->pstr_file;
+ cache->mdl = mdl_load( filename );
+
+ if( cache->mdl )
+ {
+ world.instance_cache_count ++;
+ pnode->sub_uid = world.instance_cache_count;
+ mdl_link_materials( mworld, cache->mdl );
+ vg_success( "Cached %s\n", filename );
+ }
+ else
+ {
+ vg_warn( "Failed to cache %s\n", filename );
+ }
+ }
+ }
+ }
+
+ world.instance_cache = buffer_fix( world.instance_cache,
+ world.instance_cache_count,
+ &world.instance_cache_cap,
+ sizeof( struct instance_cache ) );
+
+#if 0
+ traffic_finalize( world.traffic, world.traffic_count );
+ for( int i=0; i<vg_list_size(world.van_man); i++ )
+ world.van_man[i].current =&world.traffic[vg_randint(world.traffic_count)];
+#endif
+
+ /*
+ * Compile meshes into the world scenes
+ */
+ scene_init( &world.geo );
+
+ u32 mat_surf = 0,
+ mat_surf_oob = 0,
+ mat_vertex_blend = 0,
+ mat_alphatest = 0,
+ mat_graffiti = 0,
+ mat_subworld = 0,
+ mat_terrain = 0;
+
+ for( int i=1; i<mworld->material_count; i++ )
+ {
+ mdl_material *mat = mdl_material_from_id( mworld, i );
+ const char *mat_name = mdl_pstr( mworld, mat->pstr_name );
+
+ if( !strcmp( "surf", mat_name ))
+ mat_surf = i;
+ else if( !strcmp( "surf_oob", mat_name ))
+ mat_surf_oob = i;
+ else if( !strcmp( "vertex_blend", mat_name ))
+ mat_vertex_blend = i;
+ else if( !strcmp( "alphatest", mat_name ))
+ mat_alphatest = i;
+ else if( !strcmp( "graffitibox", mat_name ))
+ mat_graffiti = i;
+ else if( !strcmp( "terrain", mat_name ) )
+ mat_terrain = i;