home *** CD-ROM | disk | FTP | other *** search
/ Freelog 34 / Freelog034.iso / Graphisme3D / City / FILECITY.MCR < prev    next >
Encoding:
Text File  |  1999-02-01  |  9.6 KB  |  162 lines

  1. /*************************************************************************
  2.     FILE OUTPUT CITY GENERATOR MACRO FILE FOR PERSISTENCE OF VISION 3.x
  3. **************************************************************************
  4.  
  5. Created by Chris Colefax, 1 February 1999
  6. NOTE: This file is designed for use with City.inc, eg:
  7.  
  8.       #declare city_output_file = "MYCITY.INC"  // Default is City.fil
  9.       #declare city_macro_file = "FILECITY.MCR"
  10.       #include "CITY.INC"
  11.  
  12.  The file produces the same cities as the default City.mcr file (when the
  13.  same options are used).  As the city is parsed, however, all the objects
  14.  are written to a separate POV file, which can then be included into your
  15.  scene *instead* of City.inc.  This reduces parsing time substantially, and
  16.  is very useful when creating animations or designing building objects (as
  17.  the city doesn't need to be regenerated for every render).
  18.  
  19.  CAUTION: the output file you declare is overwritten every time you use
  20.  CITY.INC with this macro file, so make sure you are using the filename
  21.  you want.
  22.  
  23. *************************************************************************/
  24.  
  25. // CHECK OPTIONS AND ASSIGN DEFAULTS
  26.    #ifndef (city_seed) #local city_seed = 0; #end
  27.    #declare _CT_rand1 = seed(city_seed); // For traffic
  28.    #declare _CT_rand2 = seed(city_seed); // For pavement objects
  29.    #declare _CT_rand3 = seed(city_seed); // For buildings
  30.    #declare _CT_rand4 = seed(city_seed); // For building levels
  31.  
  32.    #ifndef (building_width) #declare building_width = 25; #end
  33.    #ifndef (min_building_height) #declare min_building_height = building_width * .5; #end
  34.    #ifndef (max_building_height) #declare max_building_height = building_width * 2; #end
  35.    #ifndef (building_height_falloff) #declare building_height_falloff = 2; #end
  36.    #ifndef (building_height_turb) #declare building_height_turb = .5; #end
  37.  
  38.    #ifndef (pavement_height) #declare pavement_height = .15; #end
  39.    #ifndef (traffic_spacing) #declare traffic_spacing = 10; #end
  40.    #ifndef (traffic_lanes) #declare traffic_lanes = 1; #end
  41.    #ifndef (traffic_width) #declare traffic_width = 3; #end
  42.    #declare street_width = traffic_width*2*(traffic_lanes + .5);
  43.  
  44.    #ifndef (city_output_file) #declare city_output_file = "CITY.FIL" #end
  45.  
  46.    #ifndef (city_default_objects) #declare city_default_objects = true; #end
  47.    #ifndef (building_types) #declare building_types = 0; #end
  48.  
  49.    #if (city_default_objects)
  50.       #include "DEFAULT.OBJ"
  51.       #if (traffic_spacing > 0) #include "VEHICLES.OBJ" #end
  52.       #include "HOTELS.OBJ" #include "FLATS.OBJ" #include "OFFICES.OBJ"
  53.       #declare _CT_writeincludes = true;
  54.    #else
  55.       #declare _CT_writeincludes = false;
  56.    #end
  57.  
  58. // CITY CREATION MACROS
  59.    #macro city_base (Corner1, Corner2)
  60.       #declare _CT_extents = (abs(city_corner1.x) + abs(city_corner1.z)) / 2;
  61.       #if (debug_progress) #debug concat ("  Opening \"", city_output_file, "\" for city output...\n") #end
  62.       #fopen _CT_file city_output_file write
  63.       #write (_CT_file, "// CITY GENERATOR INCLUDE FILE: File output using FileCity.mcr\n\n")
  64.  
  65.       #if (_CT_writeincludes) #write (_CT_file, "   #ifndef (city_default_objects) #include \"DEFAULT.OBJ\"  ")
  66.          #if (traffic_spacing > 0) #write (_CT_file, "#include \"VEHICLES.OBJ\"  ") #end
  67.          #write (_CT_file, "#include \"HOTELS.OBJ\"  #include \"FLATS.OBJ\"  #include \"OFFICES.OBJ\" #end\n\n")
  68.       #end
  69.  
  70.       #write (_CT_file, "   plane {y, 0 hollow ",
  71.          "clipped_by {box {",<Corner1.x, -.1, Corner1.z>,",",<Corner2.x, .1, Corner2.z>,"}} ",
  72.          "texture {street_texture}}\n")
  73.    #end
  74.  
  75.    #macro city_pavement (Corner1, Corner2)
  76.       #write (_CT_file, "   box {",Corner1,",",Corner2 + y*pavement_height," texture {pavement_texture}}\n")
  77.  
  78.       #ifdef (pavement_objects) #local PSize = Corner2 - Corner1;
  79.       #local V = 0; #while (V < dimension_size(pavement_objects, 1))
  80.          #local P = pavement_object_offsets[V] + rand(_CT_rand2)*pavement_object_turb[V]; #while (P < PSize.x - pavement_object_offsets[V])
  81.             #write (_CT_file, "   object {pavement_objects[",V,"] rotate y*90 translate ",Corner1 + <P, pavement_height, 0>,"} ",
  82.             "object {pavement_objects[",V,"] rotate y*270 translate ",Corner2 + <-P, pavement_height, 0>,"}\n")
  83.          #if (pavement_object_spacings[V] <= 0) #local P = PSize.x; #else
  84.          #local P = P + pavement_object_spacings[V] + rand(_CT_rand2)*pavement_object_turb[V]; #end #end
  85.  
  86.          #local P = pavement_object_offsets[V] + rand(_CT_rand2)*pavement_object_turb[V]; #while (P < PSize.z - pavement_object_offsets[V])
  87.             #write (_CT_file, "   object {pavement_objects[",V,"] translate ",<Corner2.x, pavement_height, Corner1.z + P>,"} ",
  88.             "object {pavement_objects[",V,"] rotate y*180 translate ",<Corner1.x, pavement_height, Corner2.z - P>,"}\n")
  89.          #if (pavement_object_spacings[V] <= 0) #local P = PSize.z; #else #local P = P + pavement_object_spacings[V]; #end #end
  90.       #local V = V + 1; #end #end
  91.    #end
  92.  
  93.    #macro city_traffic ()
  94.       #local V = dimension_size(city_vehicles, 1);
  95.       #if (Direction = 0) #local I = BlockSize.x; #else #local I = BlockSize.z; #end #local I = I + street_width;
  96.       #local L = -traffic_lanes; #while (L <= traffic_lanes)
  97.          #local VD = (L < 0 ? -1 : 1); #local VZ = From.z + traffic_width*VD*(abs(L)-.5);
  98.          #local VX = From.x + street_width + rand(_CT_rand1)*traffic_spacing; #while (VX < To.x - (city_tileable ? 0 : street_width))
  99.             #local VT = int(V*rand(_CT_rand1));
  100.             #write (_CT_file, "   object {city_vehicles[",VT,"] rotate ",y*90*VD," translate ",<VX, 0, VZ>," rotate ",-y*90*Direction,"}\n")
  101.          #local VX = VX + city_vehicle_spacings[VT] + (1 + 2*rand(_CT_rand1))*traffic_spacing;
  102.          #if (mod(VX - From.x, I) < street_width) #local VX = VX + street_width; #end #end
  103.       #local L = L + (L = -1 ? 2 : 1); #end
  104.    #end
  105.  
  106.    #macro city_street (From, To, Direction)
  107.       #if (Direction != 0) #local From = vrotate(From, y*90*Direction); #local To = vrotate(To, y*90*Direction); #end
  108.  
  109.       #ifdef (street_overlay) #write (_CT_file, "   box {",From - <0, 0, street_width*.5>,",",To + <0, (Direction+1)*.001, street_width*.5>,
  110.          " texture {street_overlay scale ",traffic_width," translate ",From,"}",
  111.          " rotate ",-y*90*Direction,"}\n") #end
  112.  
  113.       #if (traffic_spacing > 0 & defined(city_vehicles)) city_traffic () #end
  114.    #end
  115.  
  116.    #macro city_building (Corner1, Corner2, Direction)
  117.       #if (building_types > 0 & defined(building_size))
  118.          #local BCentre = (Corner1 + Corner2)/2;
  119.          #local BHeight = pow(1.2 - (vlength(BCentre) / _CT_extents), building_height_falloff);
  120.          #local BHeight = BHeight + (rand(_CT_rand3) - .5)*building_height_turb;
  121.          #local BHeight = min_building_height + BHeight*(max_building_height - min_building_height);
  122.          #if (BHeight > 0) city_assemble_building (int(building_types*rand(_CT_rand3)), (Corner2-Corner1) + y*BHeight, -y*90*Direction, BCentre + y*pavement_height) #end
  123.       #end
  124.    #end
  125.  
  126.    #macro city_option (Option) (mod(building_options[Type], Option*2) >= Option ? true : false) #end
  127.    #macro city_assemble_building (Type, Size, Rotate, Translate)
  128.       #local Levels = ceil((Size.y / Size.x) / (building_size[Type].y / building_size[Type].x));
  129.       #local LHeight = y*building_size[Type];
  130.       #local Scale = Size/building_size[Type]; #local Scale = <Scale.x, (Scale.x+Scale.z)/2, Scale.z>;
  131.       #local CLevel = 0;
  132.  
  133.       #write (_CT_file, "   union {\n")
  134.          #if (city_option(build_profile)) #write (_CT_file, "   object {building_profile[",Type,"] scale ",<1, Levels, 1>,"}\n") #end
  135.          #if (city_option(build_base)) #write (_CT_file, "   object {building_base[",Type,"]}\n") #local CLevel = 1; #end
  136.          #if (city_option(build_details)) #while (CLevel < Levels)
  137.             #write (_CT_file, "   object {building_details[",Type,"] translate ",LHeight*CLevel,"}\n")
  138.             #local CLevel = CLevel + 1; #end #end
  139.  
  140.          #if (city_option(build_window_profile)) #write (_CT_file, "   object {building_windows[",Type,"] scale ",<1, Levels, 1>," texture {building_window_texture[",Type,"] ",
  141.             "translate ",<int(rand(_CT_rand4)*100)-50, int(rand(_CT_rand4)*100), int(rand(_CT_rand4)*100)-50>*building_window_size[Type],"}}\n") #end
  142.          #if (city_option(build_window_levels)) #local CLevel = 0; #while (CLevel < Levels)
  143.             #write (_CT_file, "   object {building_windows[",Type,"] texture {building_window_texture[",Type,"] ",
  144.             "translate ",<int(rand(_CT_rand4)*100)-50, int(rand(_CT_rand4)*100), int(rand(_CT_rand4)*100)-50>*building_window_size[Type],"} ",
  145.             "translate ",LHeight*CLevel,"}\n")
  146.             #local CLevel = CLevel + 1; #end #end
  147.  
  148.          #if (city_option(build_roof)) #write (_CT_file, "   object {building_roof[",Type,"] translate ",LHeight*Levels,"}\n")
  149.             #else #write (_CT_file, "   sphere {0, 0 pigment {rgb 0}}\n") #end
  150.  
  151.          #if (city_option(build_fit_texture)) #write (_CT_file, "   texture {building_texture[",Type,"]}\n") #end
  152.          #write (_CT_file, "   rotate ",Rotate," scale ",Scale," translate ",Translate,"\n")
  153.          #if (city_option(build_texture)) #write (_CT_file, "   texture {building_texture[",Type,"] scale ",Scale,"}\n") #end
  154.          #write (_CT_file, "   }\n\n")
  155.    #end
  156.  
  157.    #macro city_finish ()
  158.       #if (debug_progress) #debug concat("  Closing \"", city_output_file, "\"...") #end
  159.       #fclose _CT_file  #include city_output_file
  160.       #if (debug_progress) #debug concat("\r  City has been saved to \"", city_output_file, "\"!\n") #end
  161.    #end
  162.