Exporting objects

Exporting Geometry

The standard procedure for exporting objects to MXS is creating triangle meshes using Cobject::createMesh():

Cmaxwell::Cobject Cmaxwell::createMesh(
                                          const char *pName,           // name of the object
                                          dword nVertexes,             // number of vertices
                                          dword nNormals,              // number of normals
                                          dword nTriangles,            // number of triangles
                                          dword nPositionsPerVertexes  // number of positions per vertex for motion blur (default = 1 for no motion blur, 2 for 2 motion blur substeps, more not yet supported
                                      );

Apart from triangle meshes Maxwell supports defining custom primitives through the engine SDK extension described in a separate section.

Maxwell Render supports geometry stored with either single or double precision. The default is geometry stored with double precision. To allow single precision geometry to be handled, use the following function:

byte Cmaxwell::setSinglePrecisionOfGeometry( void )



Add vertices using:

byte Cmaxwell::setVertex(
                           dword iVertex,   // vertex index_
                           dword iPosition, // vertex pos (0, ...__nPositionsPerVertex--1)
                           Cpoint point     // position_
                         )



Add normals using:

byte Cmaxwell::setNormal(
                           dword iNormal, // normal index
                           dword iPosition, // normal pos (0 ..nPositionsPerVertex-1)
                           Cvector normal // normal XYZ direction
                        )



Add triangles using:

byte Cmaxwell::setTriangle(
                             dword iTriangle, // triangle index
                             dword iVertex1, dword iVertex2, dword iVertex3, // 3 point indexes
                             dword iNormal1, dword iNormal2, dword iNormal3 // 3 normal indexes
                          )



Add a material for the whole object using:

byte setMaterial (Cmaterial material);



There is an alternative way of defining materials. Instead of using setMaterial, materials can be specified at face-level. This is useful for defining “submaterials”:

byte Cmaxwell::setTriangleMaterial(
                                    dword iTriangle,     // triangle index_
                                    Cmaterial material   // material pointer
                                  )



If the material assigned to the mesh contains maps, the mesh will require associated UVW (texture) channels which can be created using:

byte addChannelUVW (dword &iChannel, byte id = 0xFF);

where iChannel is returned as the current added channel. Id is used only if necessary to set IDs for the different channels and use them instead of the channel index.

Finally, for every triangle in the scene and for every UVW channel, the UVW values can be assigned using:

byte Cmaxwell::setTriangleUVW (
                                dword iTriangle, // triangle index
                                dword iChannel, // UVW channel index
                                float u1, float v1, float w1, // uvw value (1 edge)
                                float u2, float v2, float w2, // uvw value (2 edge)
                                float u3, float v3, float w3 // uvw value (3 edge)
                              )


Exporting Attributtes

Cobject has some methods used to apply special attributes to objects. All of them are set to false by default except excludeOfCutPlanes which is set to true.

byte setHide (bool hide);
byte setHideToCamera (bool hide);
byte setHideToReflectionsRefractions (bool hide);
byte setHideToGI (bool hide);
byte excludeOfCutPlanes (bool exclude);

REALFLOW attributes can be set using the function.

byte setRFRKparameters();


Hierarchies

Cobject has the methods

void Cobject::setParent (Cmaxwell::Cobject object)
Cmaxwell::Cobject getParent(void)

to set the scene hierarchy. This is very useful when the user wants to open the scene in Maxwell Studio, because the scene hierarchy is kept.


Instances

Cobject has the following method for creating instances of Cobjects:

Cobject createInstancement (const char *pName, Cobject &object, Cbase &base); //(object must be a mesh, not another instance)

This method returns a Cobject which is an instance (not a mesh). It is only needed to create it with a name, the reference object and a transformation matrix. Then a material can be applied to the Cobject returned with setMaterial (if setMaterial is not used it gets the material of the reference object even if it is different in each triangle, but if setMaterial is used for the instance in the instance, it only supports a material for the whole instance). Other Cobject methods as setHide(), setHideToCamera(), etc are also supported in instances.


Triangle Groups

Triangle groups are very useful to export sub-object info, so the user can recover triangle selections inside Studio. It is only needed to add new triangle groups to the scene using this method:

Cmaxwell::Ccluster newCluster = pScene->addCluster (name);

Then the object that owns this triangle group, the number of triangles and the indexes of these triangles should be specified.

Cmaxwell::Ccluster::addObject (Cmaxwell::Cobject, pTriangles, nTriangles);

To set a material to the whole triangle group at the same time, the following function is used:

Cmaxwell::Ccluster::setMaterial (Cmaxwell::Cmaterial)

which is equivalent to call setTriangleMaterial for each triangle of the group.