void ssgCullAndDraw ( ssgRoot *root ) ;This call deals with the entire process of rendering the database. Your application need only call ssgInit(), build a database, create a current context and call ssgCullAndDraw using the root node of that database.
int ssgIsect ( ssgRoot *root, sgSphere *s, sgMat4 m, ssgHit **results ) ; int ssgHOT ( ssgRoot *root, sgVec3 s, sgMat4 m, ssgHit **results ) ; int ssgLOS ( ssgRoot *root, sgVec3 s, sgMat4 m, ssgHit **results ) ;These three calls implement various ways to test the database for collisions, weapon impacts and such like. In each case, the search for a collision starts at 'root', and the database is transformed by the matrix 'm' before the test is evaluated - hence, 'm' is ususally the inverse of the matrix describing the test object's location.
ie: ssgHit *results ; int num_hits = ssgIsect ( root, &sphere, mat, &results ) ; for ( int i = 0 ; i < num_hits ; i++ ) { ssgHit *h = &(results [ i ]) ; /* Do something with 'h' */ }Remember, you must finish using the results array before you do another ssgIsect/ssgHOT/ssgLOS because all three functions share the same results array.
An ssgHit looks like this:
class ssgHit { ssgLeaf *leaf ; int triangle ; sgVec4 plane ; sgMat4 matrix ; ssgHit () int getNumPathEntries () ; ssgEntity *getPathEntry ( int i ) ; } ;The 'leaf' member points at the leaf node that impacted the sphere. The 'triangle' member tells you which triangle within the leaf did the impacting. The 'plane' member contains the plane equation of the impacting triangle and the 'matrix' element tells you the net result of concatenating all the transform nodes from the root to the leaf to the matrix you provided in the ssgIsect call.
It's possible for there to be multiple paths through the scene graph to the leaf node. Sometimes you'll need to look back up the tree to see nodes above the one that we actually impacted with. Hence, you can read all the ssgEntities that were traversed on the path from the root down to the leaf. Calling the 'getNumPathEntries' function to find the number of nodes along the path - and then 'getPathEntry(n)' to get the n'th entry in the path. The 'root' node will always be the zeroth entry in the path - and the leaf node will always be the last.
ssgLight *ssgGetLight ( int i ) ;...to get the i'th light should you need to manipulate it.
class ssgLight { int isOn () ; void on () ; void off () ; void setPosition ( const sgVec3 pos ) ; void setPosition ( float x, float y, float z ) ; void setColour ( GLenum which , const sgVec4 colour ) ; void setColour ( GLenum which , float r, float g, float b ) ; void setHeadlight ( int head ) ; int isHeadlight () ; void setSpotlight ( int spot ) ; int isSpotlight () ; void setSpotDirection ( const sgVec3 dir ) ; void setSpotDirection ( float x, float y, float z ) ; void setSpotDiffusion ( float exponent, float cutoff = 90.0f ) ; void setSpotAttenuation ( float constant, float linear, float quadratic ) ; } ;Each light can be turned on or off - or tested to see if it's on or off.
Lights are positioned with 'setPosition()' - which can be relative to the origin of the world - or relative to the SSG camera (in 'headlight' mode).
If the 'spotlight' mode is enabled, then the light intensity has a certain distribution and attenuation. These parameters can be set with the 'setSpotXxx' methods. Otherwise, the light source is considered to be directional, or infinitely far away (in the direction of its position). The 'spotlight' mode is initially disabled.
int ssgGetNumTexelsLoaded () ;(Bear in mind that a texel could be 16 or 32 bits depending on the hardware - and with MIPmapping enabled, 25% of the texels will be in the MIPmaps - so ssgGetNumTexelsLoaded will return a larger number than the total of the sizes of the input images might suggest.
At time or writing, there are MANY loaders for SSG:
typedef ssgBranch *(*ssgHookFunc)(char *) ; ssgEntity *ssgLoad ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadSSG ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadAC ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoad3ds ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ...etc...Minimally, all you need to do is to call ssgLoadAC/ssgLoad3ds with the name of the file to load. However, most file formats (AC3D's and 3Dstudio's included) lack many desirable features, and it is also often necessary to store application-specific information in the file.
SSG's loaders will decode the comment fields found in the nodes of many common file formats and pass these onto the application via 'hookfunc'. This function should decode the string and construct whatever kind of SSG node it considers appropriate.
Similarly, the application may wish to embellish the ssgState of a loaded node - and since state information rarely has a comment field in most file formats, we pass the texture filename instead and expect the application to construct the entire ssgState:
void ssgSetAppStateCallback ( ssgState *(*cb)(char *) ) ;One common problem with file loaders is that it's often possible to refer to a second file from inside the first - but the path to that file is often not adequately defined by the original file. Hence, the application can specify a file path to be prepended to all model or texture file names.
void ssgModelPath ( char *path ) ; void ssgTexturePath ( char *path ) ;You can only supply one path. If you need additional features, use the function
ulFindFile
(for more see util-library-doc).
The last three functions simply set values in the _ssgCurrentOptions
(type ssgLoaderOptions), for example:
inline void ssgModelPath ( const char *path ) { _ssgCurrentOptions -> setModelDir ( path ) ; }For more on ssgLoaderOptions see also the next page of this doc.
Some loaders for file formats that use texture formats not supported by ssg use this functions to find textures:
void ssgFindOptConvertTexture( char * filepath, char * tfname )It finds and optionally (= if necessary) converts the texture. This is only really implemented for Windo$ :-(, for all others it should just be the two lines you will find in the comment. I didn't test it, that's the reason I commented it out. But it will warn you when you have to convert something, so even for non-Windo$-users the new function is already a step forward. For the actual conversion, at first I wanted to use GIMP. So, in Deja, I looked for "+gimp +convert +batch" and similar strings. I found several people asking, but almost all the answer were to use ImageMagick instead. ImageMagick is free as in beer. Also, the docs I got with the newest gimp is extremely sparse :-(. Therefore, I tried ImageMagick and this worked straight away. You should find ImageMagick under
http://www.wizards.dupont.com/cristy/ImageMagick.html
Plib uses the ImageMagick application "convert". Since there are other convert.exe-programs on my computer, I had to copy the ImageMagick stuff into the directory of my plib-application, so that it uses the correct convert.exe.
Most file formats contain considerable numbers of redundant nodes (because of the way people build using these tools). This function walks a database sub-tree multiplying out any ssgTransform nodes and replacing them with ssgBranch'ed - unless they have userdata associated with them. Any branch nodes with zero kids are deleted - any with just one kid are eliminated and the child node pushed up one level.
void ssgFlatten ( ssgEntity *ent ) ;It's important for 3D performance to optimise triangles into triangle strips or fans. Since most file formats don't record strip/fan information, it's useful to call:
void ssgStripify ( ssgEntity *ent ) ;
To write a model file from SSG, you can either call a writer function that is specific to the format of the file you wish to save - or you can call 'ssgSave' - which parses the filename extension and calls the appropriate format-specific writer.
Saving into ssg-format is done with these functions:
int ssgSave ( char *fname, ssgEntity *ent ) ; int ssgSaveSSG ( char *fname, ssgEntity *ent ) ;This returns TRUE if the operation worked - FALSE if it failed. You will also find writers for the 3DS, AC, ASE, ATG, DXF, M, OBJ, OFF, QHI, TRI and X formats.
Feature | 3DS load |
AC load |
AC save |
ASE load/ save |
ATG load/ save |
DXF load |
DXF save |
FLT load |
M load |
M save |
MD2 load |
OBJ load |
OBJ save |
OFF load/ save |
SSG load/ save |
Strip load |
TRI load/ save |
X load |
IV load |
VRML1 load |
Filled polys | E | E | E | E | E | E | E(5) | E | E | D | ? | E | E | E | E | E | E | E | E | |
# sides | n | 3 | 3 | n | 3,4(4) | 3 | n | n? | 3 | n | n(4) | 3? | n | 3,4 | 3,4 | |||||
Lines | A | D | C | C | A(?) | E | E | A | A | A | ? | E | E | A? | E | A | A | B | B | |
Points | A | A | A | C | A(?) | A | A | B | A | A | ? | A | A | A | E | A | A | B | B | |
Sub objects | E | E | D | E | A(?) | A | A | E | A | A | ? | C-D | C-D | A | E | A | E | E | E | |
Hierarchie | A | E | D | E | A(?) | A | A | E | A | A | ? | C | C | A | E | A | C | E | E | |
DAG | A | A | A | A | A(?) | A | A | E | A | A | ? | A | A | A | E | A | A(?) | E | E | |
Colours | E | E | D | E | ? | E | E | D(1) | A | A | ? | D | C | A | E | A | E | B | B | |
Textures | D | E | D | E | E | A | A | E | A | A | ? | D | C | B | E | A | E | E | E | |
Texture coord. | D | E | D | E | E | A | A | E | A | A | ? | E | C | B | E | A | E | E | E | |
Texture coord. per face AND vertex |
D(?) | D(?) | D(?) | E | E | A | A | A | A | A | ? | E | C | B(?) | A | A | C | E | E | |
Texture per face | D(?) | - | A | E | A | A | E | A | A | ? | A | A | B(?) | A | A | C | B | A | ||
Transparency | D | D | D | D | A(?) | A | A | E | A | A | ? | A? | A? | B(?) | E | A | E | B | B | |
Animation | B | A | A | E | A | A | A | B(2) | A | A | ? | A? | A? | A | E | A | B or C | B | A | |
Billboards | A | A | A | A | A | A | E | A | A | ? | A | A | A | E | A | A | B | A | ||
LOD | A | A | A | A | A | A | E | A | A | ? | A | A | A | E | A | A | B | B | ||
Other switches | A | A | A | A | A | A | D | A | A | ? | A | A | A | E | A | A | D | D | ||
A=Ascii or B=Binary |
B | A | A | A | A | A | A | B | A | A | B | A | A | A | B | ? | A | A+B(3) | A | A |
<= previous = | Return to SSG Index | = next => |
Steve J. Baker. <sjbaker1@airmail.net> |