Introduction

The Alias API provides developers with access to Alias' internal data. This is done through two products based on the Alias API, OpenModel and OpenAlias. Alias OpenModel (OM) provides a programmer's interface to the Alias wire file (our proprietary data files), while OpenAlias (OA) provides a programmer's interface to the Alias application.

What is the Alias API?

The Alias API is a set of C++ classes that define an interface to the data structures in an Alias wire file (OpenModel) or within Alias (OpenAlias).

The Alias API is written in C++ and is supplied as C++ classes. An interface for C programmers is provided as a source code example of the API. However, since this reduces the utility of the API we encourage developers to use the C++ API. Most of the discussion in this document is intended for C++ programmers and we assume that you understand the C++ concepts of classes and inheritance.

The components of the API are:

What Can the Alias API Do?

A brief list of some of the possibilities includes

What Can't the Alias API Do?

The Alias API does not give access to all functions in Alias. You do not have access to functions such as birail. However, with each release we provide more functionality to the API programmer. Note that new classes and new methods within existing classes are listed at the end of this document.

At this time, there is a C interface of the Alias API. It is provided as source code. Due to the dependencies on C++, not all features of the API are available through the C interface, and as a result, developers are encouraged to use the C++ interface.

Who needs OpenModel?

The Alias wire file format is a binary format and is therefore not modifiable without proprietary knowledge of Alias data structures. We have therefore provided a library that insulates developers from the details of the file format and from any future changes in the file format. Since a library is available to read, write, and query wire files, developers do not need to make software changes to accommodate wire file changes. Re-linking with a new wire file library is sufficient.

With this library, you can:

Who needs OpenAlias?

If C++ developers want to interact with data internal to the interactive Alias package, then OpenAlias is for them. With OpenAlias it is possible to:

OpenModel versus OpenAlias

Deciding whether to use OpenModel or OpenAlias is largely a simple matter of deciding whether instantaneous response is a concern. OpenModel allows for the development of stand-alone applications which can operate on several files one after another, or can be launched from a script, and therefore requiring little interaction with a user.

OpenAlias on the other hand is meant for developers who need instant feedback or wish to integrate new custom features into Alias. The results of using a plug-in appear immediately on the screen.

Still unsure? If so, then it is likely best to start developing plug-ins. OpenAlias generally provides a tighter integration with Alias providing a greater number of possible solutions to design decisions.

General Usage

The body of this document assumes a knowledge of the Alias interactive software. The Alias package is far to complex to explain adequately in these pages, so the Alias manual should be at hand for any unfamiliar terms.

Where do I start?

Within the API there is an object called the "Universe", which contains all geometry, lights, cameras and clusters for a model, as well as animation and rendering data. Developers can use the Alias API to change the universe and its contents.

Understanding the Alias universe and the class hierarchy is the best way to get started.

Documentation Notes

In the documentation, the characters "<", ">" and "|" are used to indicate how an argument is used by a method.

< indicates that an argument is used as input into the method

> indicates that an argument is used as output

| indicates that an argument is used for both input and output by a method.

The Alias Universe

The universe is a static class that can access all objects in a wire file or within Alias. The main feature of the universe is that it has a pointer to a tree-like data structure which is called a directed acyclic graph (DAG). All geometry, light, camera and cluster information is stored in this DAG. The DAG is composed of nodes called DAG nodes.

This diagram illustrates an example model. Arrows indicate that a class references the class that it is pointing to. Double sided arrows indictate a two way reference.

The topmost DAG node is called the "world". In this example, the world node (returned by AlUniverse::firstDagNode()) has three group nodes as its "children" and an AlFaceNode as a sibling. Notice that two group nodes are instances. They both refer to the same curve node. NULL nodes (nothing below them) created in the Alias interactive package are retrieved as AlDagNodes.

There are several classes derived from the DAG node class that refer specifically to objects that contain geometry, light, camera or cluster information. (When a DAG node "refers" to an object, it means that the DAG node has the object as a child object.) For instance, a camera node is a DAG node that only refers to a camera object. A light node is a DAG node that only refers to a light object. Combinations such as these tend to be created at the same time, manipulated together, and deleted at the same time. Whenever a DAG node is created, it is inserted into the world position. After creating a DAG node, the method AlUniverse::firstDagNode() will return this node. Please note that is it possible for other creation routines (such as texture creation) to insert nodes into the world position as the first node.

Cameras

Above, we see three camera nodes and their camera object. The nodes represent the camera's eye, view, and up positions. To create this combination, it would be necessary to instantiate and create an AlOrthographicCamera or an AlPerspectiveCamera. When they are first created, the camera nodes are siblings under an AlGroupNode.

Lights

This diagram shows a light and its three light DAG nodes, grouped under a common group node. To create this structure it would be necessary to instantiate and create one of the several different light types. The three light nodes (the position, look at, and up DAG nodes) are created automatically. The three light DAG nodes will be grouped under a common group node. All of the different light types make use of the position DAG node; however, only the AlSpotLight makes use of the look at and up nodes.

Curves and Faces

Some objects have child objects as well. For example the AlCurve class has AlCurveCVs or children classes.

Here we see a curve DAG node, its curve object, and control vertices (CVs). To create this entire structure, first instantiate and create an AlCurve, then instantiate and create an AlCurveNode object. Note that if an AlCurve is created and not associated with an AlCurveNode, it doesn't become part of the universe. In this case, if the pointer to the AlCurve is lost, the AlCurve becomes wasted memory.

A face is similar to a curve. Here we see a face DAG node, its face objects and their control vertices (CVs). A face must have at least one face object. To create a face, instantiate and create an AlFaceNode. As with curves, if the pointer to an AlFace is lost without first being associated with an AlFaceNode, the AlFace becomes wasted memory.

A face is similar to a curve. Here we see a face DAG node, its face objects and their control vertices (CVs). A face must have at least one face object. To create a face, instantiate and create an AlFaceNode. As with curves, if the pointer to an AlFace is lost without first being associated with an AlFaceNode, the AlFace becomes wasted memory.

Surfaces

Surfaces like curves have child classes, but surfaces are far more complex and have a far greater number of child classes, including trim classes. There are also surface methods which allow you to project a curve onto the surface, create a curve-on-surface, and other methods which allow you to trim the surface using the curves on the surface.

Above is a surface node, its surface object and associated objects for control vertices (CVs) and curve-on-surface's. To create a surface/surface node pair, first instantiate and create an AlSurface, then instantiate and create a surface node. The surface CVs are created automatically. To create a curve-on-surface, instantiate and set the data of an AlCurveOnSurface object, then add it to an AlSurface. You cannot insert or delete individual CVs. Make sure you create a surface node for each surface that you create; a surface without a surface node is not added to the universe, and if the pointer is lost, the surface would become wasted memory.

Clusters

Some objects rather than having a child object, refer to other objects in the universe. In particular the AlSetMember and AlClusterMember classes refer to objects which are components of the set or cluster respectively.

Here we have a cluster DAG node, its cluster object and cluster members. To create this structure, instantiate and create an AlCluster object. It is not possible to create or delete individual AlClusterMember objects instead, they are created or deleted when objects are added to or removed from the cluster.

Sets

This diagram shows some sets and their set members. A set has no DAG node and is not in the DAG; to get the global list of sets, use the AlUniverse::firstSet() method. To create a set, instantiate and create an AlSet and add members to the set. As with cluster members it is not possible to create or delete individual AlSetMember objects instead, they are created when objects are added to or removed from the set.

Animation and Rendering

Animation and rendering information can also be accessed through the universe. For example, the list of all the channels, actions or shaders in the universe can be traversed. However, this information is also accessible through the objects that use this information. For example, surfaces and faces will have access to the list of shaders and animated objects they use - for example, a CV, light or texture will have access to the channels that animate it. The diagrams below show an animation and rendering example respectively of the relationship between objects that refer to each other. In these figures, all objects are represented in a rectangular box.

This diagram shows a CV on a surface animated by a motion path and timing curve. To create this structure, instantiate and create an AlMotionAction using an AlCurveNode above the desired motion path curve; instantiate and create an AlChannel with the AlSurfaceCV to animate, the X, Y, or Z parameter of the CV to animate, and the newly-created AlMotionAction; now use the applyWarp() method of the AlChannel, which will create the AlParamAction as a timing curve. Access the two AlKeyframes through the AlParamAction, and change the timing of the animation by using the setLocation() method of the AlKeyframe.

This diagram shows a surface with two shaders, the first shader having two textures. To create this structure, first create a surface. Then create the two shaders with AlShader::create(). To one of them add textures with AlShader::addTexture() and then add the shaders to the surface with AlSurface::assignShader() for the first one and AlSurface::layerShader() for the second one.

Class Hierarchy

All but a few objects in the API are derived from a base class called "AlObject". By deriving all object classes from a common base class, most things can be treated as AlObjects until you need to know otherwise.

To find the type of an AlObject, you can query the type or use the safe type casting methods described later in this document. The class hierarchy is shown in the following diagrams.

Here we see many of the classes of the Alias API and their class derivations. Notice that the AlObject class is the base class.

Here we see class hierarchies for some of the more complex classes.

Wrappers

The objects which make up the API (C++ classes) are wrappers on internal Alias data, whether read in from a file, or running the interactive package. These wrappers can be thought of as a method to indirectly access the data. Access to the data is done through methods contained in the wrapper classes. This provides a clean, and consistent view of the data and hides its internal representation.

Wrappers are only allocated when necessary. This means that developers using the API are responsible for deleting wrappers when they are not needed any longer.

New Versus Reused Wrappers

All methods which return a pointer to an object return a new wrapper, except for the casting methods (i.e. AlObject::asLightNodePtr()). Methods are provided to reuse wrappers when sets of data are processed as a group. These include any method whose name ends in "D" which (i.e. AlSurface::nextShaderD()), and any iterator (i.e. AlIterator).

Implementation Details

There are some coding concepts unique to the Alias API. The API separates the operations of instantiation and creation. Developers must initialize the universe before doing anything else. Since most objects are derived from the AlObject base class, safe type casting must be used to convert a base object to a derived object. Deleting objects and wrappers requires extra care.

Instantiation and Creation

The creation of an object often involves both instantiation and initialization. The initialization part, if it's simple, can be put in the constructor of a class. However, if the initialization involves an operation that could fail (for instance, memory allocation could fail), then the constructor is inadequate to convey failure. To address this, the API uses "create" methods to perform initialization because they return useful status codes. The following is an example of how an object should be created, and returns NULL if creation was unsuccessful.

// instantiaion
AlAmbientLight *ambientLight = new AlAmbientLight;
if (ambientLight == NULL) {
return NULL;
}
// creation
statusCode status = ambientLight->create();
switch(status) {
case sSuccess:
break;
case sInsufficientMemory:
default:
delete ambientLight; // Remember to free the memory
return NULL;
}

Safe Type Casting

Type casting a pointer from a derived class to a base class is inherent to C++. Type casting a pointer from a base class to a derived class is not safe and could possibly point to the incorrect data. The Alias API provides methods to achieve this "down casting". The example programs, especially the DAG traversal functions, show how down casting is used.

For instance, if class derivation is AlObject->AlLight->AlAmbientLight, where the AlObject class is the base class, and AlAmbientLight is the most derived class, the following code shows how down casting is performed:

AlAmbientLight *ambientLightPtr = objectPtr->asAmbientLightPtr();
if (ambientLightPtr != NULL) {
// then we know the object is an ambient light
}
Note that it is not necessary to first cast the object to an AlLight. Also note that a new wrapper is not allocated when using the casting methods. In this way these methods can be thought of as regular casts.

Deletion

Be very careful when deleting objects from the universe. Some complex objects are closely linked and behave as a single entity. This includes objects such as camera nodes and camera objects. When a member of the group is deleted, the other members will also be deleted. For instance, when one of the three camera nodes is deleted, the other two nodes will also be deleted automatically. Alternatively, if a camera node is deleted, its camera (and other camera nodes) are deleted. Since the camera nodes are often siblings, developers should be careful that they are not left with a pointer that refers to a deleted object. An advantage to wrappers is that they can be invalidated, meaning that the internal object they reference may be deleted, but the wrapper remains with the knowledge that it is not valid. Methods of an invalid wrapper will fail gracefully avoiding concerns about dereferencing dangling pointers.

Core dumps

If a core dump happens, it could mean one of the following:

Limitations

Comparing Pointers

It is not possible to compare wrapper pointers to see if the wrapper objects are the same. Any number of different wrapper objects may reference the same Alias data internally. It is necessary to use AlIsEqual() to compare objects. This will compare the Alias objects to which the wrappers point. It is a true test of equality between Alias objects.

In addition, checking a pointer for NULL is not sufficient for determining its validity. It is possible that through interaction with Alias, a developer may delete an object, causing any associated wrappers to become invalid, lest they point to freed memory. AlIsValid()should be used on objects that may have become invalidated since they were last referenced. All classes implicitly perform validity checks on instances, so a member function called on an invalid object will simply fail.

Allocation of Input Values

As a rule, the API developer is not responsible for allocation of arguments to functions. For instance, if a function takes a string as an argument, that string will be duplicated by the API. The developer may then deallocate the string. The exceptions to this rule are blind data (user defined and only accessible through the API) and comments. Blind data is not copied on input. Rather, a pointer to the user's buffer is kept in the Alias object. As long as a reference exists from Alias to that blind data, the developer should avoid deleting the associated buffer. Note that when the wire file is stored, the blind data is copied into the wire file. When a wire file is retrieved, any blind data will then be copied into a newly allocated buffer. This has the same effect as creating duplicates of any shared blind data. As a general rule it is not a good idea to allow objects to share blind data.

Allocation of Return Values

There has been some confusion in the past over which functions allocate their return values and which functions return pointers to existing data. As of the Version 7 release, we have taken care to keep the treatment of return values consistent. For example, all functions that return strings now return "const char *" references to Alias data. We believe this approach to be more general - it does not force the developer to perform extra memory management if it is not necessary. If this returned string is required for future reference, then it is up to the developer to make a copy.

A Few Simple Rules for Return Values

While the allocation of return values may change and although there may be some exceptional cases, here are some rules of thumb to remember.

Reserved Types for Blind Data

User-types 0 to 9999 are reserved for Alias|Wavefront plug-in development. User-types 10000 to 12999 are currently reserved for third-party plug-in development. Contact Alias|Wavefront if you would like to have a block of user-types reserved for your plug-in applications.





aliasdocs@aw.sgi.com
Copyright © 1996, Alias|Wavefront, a Silicon Graphics Company. All rights reserved.