Shockwave 3D§ Data Out

Once the information from the authoring tool has been converted into the Shockwave 3D§ database, its display and writing to disk is handled automatically, including issues such as file format, compression, and streaming.

Writing the Shockwave 3D Database to a .W3D file

To write a Shockwave 3D database to disk:

  1. Create and initialize an IFXWriteManager object.

  2. Use the IFXWriteManager::SetQualityFactor() method to set geometry and animation resources quality levels (range 0 to 1000). Texture compression levels are set in the STextureSourceInfo structure that is populated and passed into the IFXCompressedTextureSource::SetRawImage() method. Note that low values represent high compression, high values represent low compression.

  3. Create an IFXWriteBuffer object and get the IFXStdio interface from it.

  4. Open the output file with the IFXStdio interface.

  5. Mark the scenegraph for writing.

  6. Write out the Shockwave 3D database using the IFXWriteManager::Write() method.

  7. Close the output file with IFXStdio

  8. Release all the resources requested.

The scene is exported to disk into a file (.w3d format) that can be read and manipulated by Macromedia Director§.

Viewing the Shockwave 3D Database

To view the contents of the Shockwave 3D database, create an instance of the S3DPreview class (after making the appropriate modifications to support the authoring tool) and call the S3DPreview::Render() method after the scene is written to disk. This will display the scenegraph as it will be written to disk (including compression artifacts) to give a visual verification of the export. To maintain maximum compatibility, the S3DPreview class uses a software renderer for the preview window. This means that the scene will render particularly slowly when the application is linked in debug mode.

Note: Always make sure to write the scene to disk before viewing it with the S3DPreview class, otherwise you will not be able to see how compression will effect the data.

The hardest part of writing an exporter is collecting the skeletal animation data. To help debug this phase, look at the S3DPreview::Render() method for the three large blocks of code that have been commented out with the lines "Begin useful debug code" at their head, and the one block that reads "Begin debug code." Keep in mind that none of these debug features will work until the section of code that reads "Begin debug code" is uncommented.

Note: These debugging features require that the exporter be linked against the OpenGL libraries, and that the system has hardware OpenGL acceleration. Any other configuration will cause the application to fail.

To view the bounding volumes and display the models in wireframe mode (to view imbedded bones), uncomment the first block. Of particular interest is the IFXSceneGraph::BONES flag, which will show any bones as they animate. Coordinate axes in the scene will be represented with the following colors: Red = X-axis, Green = Y-axis, Blue = Z-axis. Mesh vertices will be colored with the color of the bone(s) that control them. Bone(s) of the same color should be near these vertices, not on the other side of the model.

To debug bones even more fully, uncomment the second and third blocks also. These blocks of code will force all skeletal models into reference mode, which is the pose that the bones and meshes were in when this data was compiled into the IFXModelResource. To successfully export skeletal animation, all meshes and skeletons should register perfectly in reference mode. Mesh and bones must have the same relative scale, rotation, and position, with absolute different positions in space.

Another helpful feature for debugging bones involves some scene navigation that has been built into the S3DPreview class when it is compiled in debug mode. Looking at the model from a number of angles can be helpful when trying to figure out why a skeleton and a mesh don't line up. Navigation in the preview window works using the following controls:

Rotation

Dolly

Pan

Note: When navigating through a scene, remember that only the parts of models that are in front of the camera will be rendered. Parts of models that penetrate the camera plane and are behind the camera will not render, resulting in visual artifacts ("black holes" or "tearing") in the model. This is particularly noticeable when dollying an orthographic camera forward, since the lack of perspective effects does not hide the models as the camera passes them. Dolly the camera back, and the visual artifacts will disappear.

§See asterisked (*) statement at Legal Information © 2001 Intel Corporation.