Jump to content


* - - - - 1 votes

Calling API Objects from LibObj File


  • Please log in to reply
1 reply to this topic

#1 IBtheSarge

IBtheSarge

    First Class Member

  • Moderator
  • PipPipPipPipPipPipPipPip
  • 10,718 posts
  • Location:Central Florida

Posted 30 March 2006 - 02:06 PM

To call (place) API objects that you have placed in a LibObjs file is rather simple.  You need AFCAD, SCASM and Wordpad; your work should be done in, and saved into, the same directory in which the API, SCA and LibObj files are located.  So, that being said:

=====================================================

Step 1:  Open WordPad and create the following lines of code:  
;*****************
; START OF CODE
;*****************

Set( buf 100 )
Set( areamx 64 )
Set( linbuf 64 )
Set( ppperr 2000 )

Header( 1 N60:51:33.8012 N60:51:13.4549 W161:20:34.1047 W161:21:24.9706 )

LatRange( N60:51:13.4549 N60:51:33.8012 )

; api name 
Macro( C:\MYOBJECTS\mybox.API N060:51:25.0320 W161:21:10.6088 20 0.1000000015 180.0 0 0 0 0 10000 0.0 0 v2= 100 0 0 0 0 0 0 )

;**************
; END OF CODE
;**************
Note the spacing, characters, and character count for each line.  Your code must be EXACTLY like this in those respects; you'll change data for your purposes, but it must still match the above code.

Step 2:  Edit the data above to place one of the APIs in your working directory.  The first thing that needs to be changed is the Header( information.  This line contains the boundaries of the airport area into which you are going to place the object.  It consists of the lat/lon for two points -- the farthest north and west corner of the airport area, and the farthest south and east corner of the airport area.  Open AFCAD, open the airport where you're going to place the object(s), and find those two points; write down both sets of lat/lon.

We need to convert the AFCAD lat/lon format (dd:mm.mmmm) to the format SCASM needs to place the object (dd:mm:ss.ssss).  It's a simple process.  Pretend one of your latitudes is N85* 27.38' -- clearly, that won't work in the above code ... we need seconds as well.  No problem, simple math:  85 is degrees, 27 is minutes, and to get seconds all we need to do is multiply .38 by 60.  We get 22.8 -- those are the seconds -- giving us N085:27:22.8000 for the converted latitude.  Do the conversion for both sets (write them down, of course ... even a photographic memory can produce blurred images at times :D )

Now we need to plug-in the converted coordinates IN THE CORRECT ORDER.  Let's use

N46:58:06.8400
W67:53:59.9400
for the most northern/most western coordinates, and

N46:55:59.9340
W67:52:38.8980
as the most southern/most eastern coordinates.

The first coordinate in
Header( 1 N60:51:33.8012 N60:51:13.4549 W161:20:34.1047 W161:21:24.9706 )
is the northern most latitude, or N46:58:06.8400 (of our replacement coordinates).
The second coodinate is the southern most latitude, or N46:55:59.9340
The third coordinate is the eastern most longitude, or W67:52:38.8980
The fourth coordinate is the western most longitude, or W67:53:59.9400

Word of caution -- one individual earlier came up with an easy way to remember it as being LARGE SMALL SMALL LARGE.  That's fine, if you're only going to place objects in the northern latitudes and western longitudes.  It does NOT hold true if you're placing objects in southern latitudes and/or eastern longitudes.  Regardless of the numbers, remember that it is both latitudes first and both longitudes second, in the order TOP BOTTOM BOTTOM TOP.

The next line
LatRange( N60:51:13.4549 N60:51:33.8012 )
is simply a repeat of the latitudes, southern most latitude first (N46:55:59.9340) and then the northern most latitude (N46:58:06.8400).  Don't ask me why it has to be repeated, nor why it's the reverse of the Header( line.  It's an FS9 thing; that's the way FS9 wants to see the data and if it isn't exactly like that, the object will never appear.

The line
; api object
is an information line consisting of a semi-colon, a space, and whatever you want to call the object you're about to place.  If you will place more than one copy of the object in the scenery, this is a good place to keep track of what you've done, such as ; Fighter Hangar 1 and ; Fighter Hanagr 2 for the next placement.

Now comes the fun line .... it's where you actually place the object, and there are several things that need to be changed:

Macro( C:\MYOBJECTS\mybox.API N060:51:25.0320 W161:21:10.6088 20 0.1000000015 180.0 0 0 0 0 10000 0.0 0 v2= 100 0 0 0 0 0 0 )

First of all, you need the FULL PATH to the API object you are going to place.  If your working directory is D:\WorkAPI and the name of the API is FtrHgr_TI.api, then your would replace C:\MYOBJECTS\mybox.API with your path of D:\WorkAPI\FtrHgr_TI.api.

Macro( D:\WorkAPI\FtrHgr_TI.api N060:51:25.0320 W161:21:10.6088 20 0.1000000015 180.0 0 0 0 0 10000 0.0 0 v2= 100 0 0 0 0 0 0 )

Next are the coordinates for the CENTER of the object you want to place.  Locate the spot on the AFCAD screen of your airport where you want the object to be centered.  Write down the lat/lon, convert to the dd:mm:ss.ssss format, and then replace N060:51:25.0320 W161:21:10.6088with your coordinates.  Notice that the latitude has gained an extra character and is now in the format ddd:mm:ss.ssss -- no problem, just stick a "0" in there.

Macro( D:\WorkAPI\FtrHgr_TI.api N046:56:25.0320 W067:53:10.6088 20 0.1000000015 180.0 0 0 0 0 10000 0.0 0 v2= 100 0 0 0 0 0 0 )

Set the heading of the object; which way do you want it to face?  the format is ddd.d so even if it's a whole number (180) enter it as 180.0.

Macro( D:\WorkAPI\FtrHgr_TI.api N046:56:25.0320 W067:53:10.6088 20 0.1000000015 180.0 0 0 0 0 10000 0.0 0 v2= 100 0 0 0 0 0 0 )

Here's where you get to make another adjustment that can make the framerates more friendly.  This item is the distance, in meters, from your airplane that the object will be drawn.  10,000m is roughly 6.2 miles.  It is my experience that while it might be nice to see SOME of the structures from that distance, it is absolutely ridiculous to be able to see the ILS transmitter for the runway you are going to land on from that distance.  Remember -- the more FS9 has to draw, the more system resources it grabs to draw the objects.  If you can close the distance to the object before FS9 draws it, then some of the objects to the rear will be out of range and FS9 will unload them, then load the new objects as they come in range.  Since (for purposes of this tutorial) we're dealing with a fighter hangar, I think 4 miles out would be plenty enough time for FS9 to draw it.  So, change this item to 6437.376.  That ILS transmitter could wait until you are the length of the runway away from it (for a 10,000 ft runway, you would change this item to 3048; it would come into view at the departure end of the runway just as you touchdown on the approach end.

Your modified line should look something like this now:

Macro( D:\WorkAPI\FtrHgr_TI.api N046:56:25.0320 W067:53:10.6088 20 0.1000000015 180.0 0 0 0 0 6437.376 0.0 0 v2= 100 0 0 0 0 0 0 )

If this is the only object you intend to place, you're finished modifying the file.  If you intend to place additional objects, simply repeat
Macro( D:\WorkAPI\FtrHgr_TI.api N046:56:25.0320 W067:53:10.6088 20 0.1000000015 180.0 0 0 0 0 6437.376 0.0 0 v2= 100 0 0 0 0 0 0 )
as many times as you need to, changing the data for each object you wish to place.  Just make sure the file ends with
;**************
; END OF CODE
;**************
so you have a reference point each time you modify the file.  Also notice that there is a blank line between the last placement code and the ending comment lines.

Step 5:  On Wordpad's toolbar, "File" then "Save As" and point Wordpad to the directory in which SCASM, the library objects file, and your object API/SCA files are located.  Give the file a unique name (I usually use the ICAO of the airport and another identifier, like KPSN_MilObjs) and click "Save."  This is another file you will need to rename so you can change the extension to SCA.

Once you have changed the extension, drag-and-drop the SCA file onto the SCASM icon, wait a few seconds, and -- if you've done it right -- a BGL file will appear with the same name as the SCA file (i.e., KPSM_MilObjs.BGL).  All you need to do is place the BGL file in your airport's Scenery folder, and any textures that the objects require in your airport's Texture folder.

=====================================================

NOTE -- Why should you invest the time to create a LibraryObjects file, then write/compile placement XML for those objects?  The answer is simple -- framerate.  When you place objects with programs like FSSC, the info given to FS9 is per object.  If you place an object that is 100 polygons five times into a scenery, FS9 is given 500 polygons to draw (100 per appearance of the object).  Using a LibraryObjects file and XML to place that same object, you can place it 100 times and FS9 will only load the initial 100 polygons, not 10,000 polygons.  It reads the initial call and then only reads the changed coordinates and facings to mirror the object in the other 99 locations.  That saves a lot of system resources, leaving them free for performance instead of hogging them to display objects in sceneries.

Edited by sarge, 30 March 2006 - 06:43 PM.


#2 Jon

Jon

    Administrator

  • Admin
  • PipPipPipPipPipPip
  • 3,140 posts
  • Location:South Carolina, USA

Posted 05 April 2006 - 09:23 PM

Added to Knowledge Base