Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

AsciiModelWriter Class Reference

Inheritance diagram for AsciiModelWriter:

Inheritance graph
Collaboration diagram for AsciiModelWriter:

Collaboration graph
List of all members.

Public Member Functions

 AsciiModelWriter (ostream &)
virtual bool write (const Model &)
 ~AsciiModelWriter ()

Private Member Functions

void writeGroup (const Mesh::PrimitiveGroup &)
void writeMaterial (const Mesh::Material &)
void writeMesh (const Mesh &)
void writeVertexDescription (const Mesh::VertexDescription &)
void writeVertices (const void *vertexData, uint32 nVertices, uint32 stride, const Mesh::VertexDescription &desc)

Private Attributes

ostream & out

Constructor & Destructor Documentation

AsciiModelWriter::AsciiModelWriter ostream &   ) 
 

Definition at line 751 of file modelfile.cpp.

00751                                                 :
00752     out(_out)
00753 {
00754 }

AsciiModelWriter::~AsciiModelWriter  ) 
 

Definition at line 757 of file modelfile.cpp.

00758 {
00759 }


Member Function Documentation

bool AsciiModelWriter::write const Model  )  [virtual]
 

Implements ModelWriter.

Definition at line 763 of file modelfile.cpp.

References CEL_MODEL_HEADER_ASCII, out, writeMaterial(), and writeMesh().

00764 {
00765     out << CEL_MODEL_HEADER_ASCII << "\n\n";
00766 
00767     for (uint32 matIndex = 0; model.getMaterial(matIndex); matIndex++)
00768     {
00769         writeMaterial(*model.getMaterial(matIndex));
00770         out << '\n';
00771     }
00772 
00773     for (uint32 meshIndex = 0; model.getMesh(meshIndex); meshIndex++)
00774     {
00775         writeMesh(*model.getMesh(meshIndex));
00776         out << '\n';
00777     }
00778 
00779     return true;
00780 }

void AsciiModelWriter::writeGroup const Mesh::PrimitiveGroup  )  [private]
 

Definition at line 784 of file modelfile.cpp.

References out.

Referenced by writeMesh().

00785 {
00786     switch (group.prim)
00787     {
00788     case Mesh::TriList:
00789         out << "trilist"; break;
00790     case Mesh::TriStrip:
00791         out << "tristrip"; break;
00792     case Mesh::TriFan:
00793         out << "trifan"; break;
00794     case Mesh::LineList:
00795         out << "linelist"; break;
00796     case Mesh::LineStrip:
00797         out << "linestrip"; break;
00798     case Mesh::PointList:
00799         out << "points"; break;
00800     default:
00801         return;
00802     }
00803     
00804     out << ' ' << group.materialIndex << ' ' << group.nIndices << '\n';
00805 
00806     // Print the indices, twelve per line
00807     for (uint32 i = 0; i < group.nIndices; i++)
00808     {
00809         out << group.indices[i];
00810         if (i % 12 == 11 || i == group.nIndices - 1)
00811             out << '\n';
00812         else
00813             out << ' ';
00814     }
00815 }

void AsciiModelWriter::writeMaterial const Mesh::Material  )  [private]
 

Definition at line 967 of file modelfile.cpp.

References DefaultDiffuse(), DefaultEmissive(), DefaultOpacity, DefaultSpecular(), DefaultSpecularPower, ResourceManager< T >::getResourceInfo(), GetTextureManager(), InvalidResource, out, and TextureInfo::source.

Referenced by write().

00968 {
00969     out << "material\n";
00970     if (material.diffuse != DefaultDiffuse)
00971     {
00972         out << "diffuse " <<
00973             material.diffuse.red() << ' ' <<
00974             material.diffuse.green() << ' ' <<
00975             material.diffuse.blue() << '\n';
00976     }
00977 
00978     if (material.emissive != DefaultEmissive)
00979     {
00980         out << "emissive " <<
00981             material.emissive.red() << ' ' <<
00982             material.emissive.green() << ' ' <<
00983             material.emissive.blue() << '\n';
00984     }
00985 
00986     if (material.specular != DefaultSpecular)
00987     {
00988         out << "specular " <<
00989             material.specular.red() << ' ' <<
00990             material.specular.green() << ' ' <<
00991             material.specular.blue() << '\n';
00992     }
00993 
00994     if (material.specularPower != DefaultSpecularPower)
00995         out << "specpower " << material.specularPower << '\n';
00996 
00997     if (material.opacity != DefaultOpacity)
00998         out << "opacity " << material.opacity << '\n';
00999 
01000     for (int i = 0; i < Mesh::TextureSemanticMax; i++)
01001     {
01002         const TextureInfo* texInfo = GetTextureManager()->getResourceInfo(material.maps[i]);
01003         if (texInfo != NULL)
01004         {
01005             switch (Mesh::TextureSemantic(i))
01006             {
01007             case Mesh::DiffuseMap:
01008                 out << "texture0";
01009                 break;
01010             case Mesh::NormalMap:
01011                 out << "normalmap";
01012                 break;
01013             case Mesh::SpecularMap:
01014                 out << "specularmap";
01015                 break;
01016             case Mesh::EmissiveMap:
01017                 out << "emissivemap";
01018                 break;
01019             default:
01020                 assert(0);
01021             }
01022             
01023             out << " \"" << texInfo->source << "\"\n";
01024         }
01025     }
01026 
01027 #if 0
01028     if (material.maps[Mesh::DiffuseMap] != InvalidResource)
01029     {
01030         const TextureInfo* texInfo = GetTextureManager()->getResourceInfo(material.tex0);
01031         if (texInfo != NULL)
01032             out << "texture0 \"" << texInfo->source << "\"\n";
01033     }
01034 
01035     if (material.tex1 != InvalidResource)
01036     {
01037         const TextureInfo* texInfo = GetTextureManager()->getResourceInfo(material.tex1);
01038         if (texInfo != NULL)
01039             out << "texture1 \"" << texInfo->source << "\"\n";
01040     }
01041 #endif
01042 
01043 
01044     out << "end_material\n";
01045 }

void AsciiModelWriter::writeMesh const Mesh  )  [private]
 

Definition at line 819 of file modelfile.cpp.

References out, writeGroup(), writeVertexDescription(), and writeVertices().

Referenced by write().

00820 {
00821     out << "mesh\n";
00822 
00823     if (!mesh.getName().empty())
00824         out << "# " << mesh.getName() << '\n';
00825 
00826     writeVertexDescription(mesh.getVertexDescription());
00827     out << '\n';
00828 
00829     writeVertices(mesh.getVertexData(),
00830                   mesh.getVertexCount(),
00831                   mesh.getVertexStride(),
00832                   mesh.getVertexDescription());
00833     out << '\n';
00834 
00835     for (uint32 groupIndex = 0; mesh.getGroup(groupIndex); groupIndex++)
00836     {
00837         writeGroup(*mesh.getGroup(groupIndex));
00838         out << '\n';
00839     }
00840 
00841     out << "end_mesh\n";
00842 }

void AsciiModelWriter::writeVertexDescription const Mesh::VertexDescription  )  [private]
 

Definition at line 894 of file modelfile.cpp.

References out.

Referenced by writeMesh().

00895 {
00896     out << "vertexdesc\n";
00897     for (uint32 attr = 0; attr < desc.nAttributes; attr++)
00898     {
00899         // We should never have a vertex description with invalid
00900         // fields . . .
00901 
00902         switch (desc.attributes[attr].semantic)
00903         {
00904         case Mesh::Position:
00905             out << "position";
00906             break;
00907         case Mesh::Color0:
00908             out << "color0";
00909             break;
00910         case Mesh::Color1:
00911             out << "color1";
00912             break;
00913         case Mesh::Normal:
00914             out << "normal";
00915             break;
00916         case Mesh::Tangent:
00917             out << "tangent";
00918             break;
00919         case Mesh::Texture0:
00920             out << "texcoord0";
00921             break;
00922         case Mesh::Texture1:
00923             out << "texcoord1";
00924             break;
00925         case Mesh::Texture2:
00926             out << "texcoord2";
00927             break;
00928         case Mesh::Texture3:
00929             out << "texcoord3";
00930             break;
00931         default:
00932             assert(0);
00933             break;
00934         }
00935 
00936         out << ' ';
00937 
00938         switch (desc.attributes[attr].format)
00939         {
00940         case Mesh::Float1:
00941             out << "f1";
00942             break;
00943         case Mesh::Float2:
00944             out << "f2";
00945             break;
00946         case Mesh::Float3:
00947             out << "f3";
00948             break;
00949         case Mesh::Float4:
00950             out << "f4";
00951             break;
00952         case Mesh::UByte4:
00953             out << "ub4";
00954             break;
00955         default:
00956             assert(0);
00957             break;
00958         }
00959 
00960         out << '\n';
00961     }
00962     out << "end_vertexdesc\n";
00963 }

void AsciiModelWriter::writeVertices const void *  vertexData,
uint32  nVertices,
uint32  stride,
const Mesh::VertexDescription desc
[private]
 

Definition at line 846 of file modelfile.cpp.

References out.

Referenced by writeMesh().

00850 {
00851     const unsigned char* vertex = reinterpret_cast<const unsigned char*>(vertexData);
00852 
00853     out << "vertices " << nVertices << '\n';
00854     for (uint32 i = 0; i < nVertices; i++, vertex += stride)
00855     {
00856         for (uint32 attr = 0; attr < desc.nAttributes; attr++)
00857         {
00858             const unsigned char* ubdata = vertex + desc.attributes[attr].offset;
00859             const float* fdata = reinterpret_cast<const float*>(ubdata);
00860 
00861             switch (desc.attributes[attr].format)
00862             {
00863             case Mesh::Float1:
00864                 out << fdata[0];
00865                 break;
00866             case Mesh::Float2:
00867                 out << fdata[0] << ' ' << fdata[1];
00868                 break;
00869             case Mesh::Float3:
00870                 out << fdata[0] << ' ' << fdata[1] << ' ' << fdata[2];
00871                 break;
00872             case Mesh::Float4:
00873                 out << fdata[0] << ' ' << fdata[1] << ' ' <<
00874                        fdata[2] << ' ' << fdata[3];
00875                 break;
00876             case Mesh::UByte4:
00877                 out << (int) ubdata[0] << ' ' << (int) ubdata[1] << ' ' <<
00878                        (int) ubdata[2] << ' ' << (int) ubdata[3];
00879                 break;
00880             default:
00881                 assert(0);
00882                 break;
00883             }
00884 
00885             out << ' ';
00886         }
00887 
00888         out << '\n';
00889     }
00890 }


Member Data Documentation

ostream& AsciiModelWriter::out [private]
 

Definition at line 133 of file modelfile.cpp.

Referenced by write(), writeGroup(), writeMaterial(), writeMesh(), writeVertexDescription(), and writeVertices().


The documentation for this class was generated from the following file:
Generated on Sat Jan 14 22:33:06 2006 for Celestia by  doxygen 1.4.1