#include <maya/MIOStream.h>
#include <maya/MGlobal.h>
#include <maya/MIntArray.h>
#include <maya/MFnSet.h>
#include <maya/MItDependencyGraph.h>
#include <maya/MDagPath.h>
#include <maya/MFnMesh.h>
#include <maya/MPlug.h>
#include <maya/MIOStream.h>
#include <time.h>
#include <maya/MItMeshPolygon.h>
#include "polyRawWriter.h"
#define DELIMITER "\t"
#define SHAPE_DIVIDER "*******************************************************************************\n"
#define HEADER_LINE "===============================================================================\n"
#define LINE "-------------------------------------------------------------------------------\n"
polyWriter(dagPath, status),
fHeadUVSet(NULL)
{
}
polyRawWriter::~polyRawWriter()
{
if (NULL != fHeadUVSet) delete fHeadUVSet;
}
MStatus polyRawWriter::extractGeometry()
{
}
}
unsigned int uvSetCount = uvSetNames.
length();
unsigned int i;
UVSet* currUVSet = NULL;
for (i = 0; i < uvSetCount; i++ ) {
if (0 == i) {
currUVSet = new UVSet;
fHeadUVSet = currUVSet;
} else {
currUVSet->next = new UVSet;
currUVSet = currUVSet->next;
}
currUVSet->name = uvSetNames[i];
currUVSet->next = NULL;
if (
MStatus::kFailure == fMesh->getUVs(currUVSet->uArray, currUVSet->vArray, &currUVSet->name)) {
}
}
}
MStatus polyRawWriter::writeToFile(ostream& os)
{
os << SHAPE_DIVIDER;
os << "Shape: " << fMesh->partialPathName() << "\n";
os << SHAPE_DIVIDER;
os << "\n";
}
}
}
}
}
}
}
}
}
os << "\n\n";
}
MStatus polyRawWriter::outputFaces(ostream& os)
{
unsigned int faceCount = fMesh->numPolygons();
if (0 == faceCount) {
}
os << "Faces: " << faceCount << "\n";
os << HEADER_LINE;
os << "Format: Index|Vertex Indices\n";
os << LINE;
unsigned int i;
for (i = 0; i < faceCount; i++) {
os << i << DELIMITER;
unsigned int indexCount = fMesh->polygonVertexCount(i, &status);
}
status = fMesh->getPolygonVertices (i, indexArray);
}
unsigned int j;
for (j = 0; j < indexCount; j++) {
os << indexArray[j] << " ";
}
os << "\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputVertices(ostream& os)
{
unsigned int vertexCount = fVertexArray.length();
unsigned i;
if (0 == vertexCount) {
}
os << "Vertices: " << vertexCount << "\n";
os << HEADER_LINE;
os << "Format: Vertex|(x, y, z)\n";
os << LINE;
for (i = 0; i < vertexCount; i++) {
os << i << DELIMITER << "("
<< fVertexArray[i].x << ", "
<< fVertexArray[i].y << ", "
<< fVertexArray[i].z << ")\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputVertexInfo(ostream& os)
{
unsigned int faceCount = fMesh->numPolygons();
unsigned i, j, indexCount;
os << "Vertex Info:\n";
os << HEADER_LINE;
os << "Format: Face|faceVertexIndex|vertexIndex|normalIndex|colorIndex|";
UVSet* currUVSet;
for (currUVSet = fHeadUVSet; currUVSet != NULL; currUVSet = currUVSet->next) {
os << "| UV_" << currUVSet->name;
}
os << "\n";
os << LINE;
int colorIndex, uvID;
for (i = 0; i < faceCount; i++) {
indexCount = fMesh->polygonVertexCount(i, &status);
}
status = fMesh->getPolygonVertices (i, indexArray);
}
status = fMesh->getFaceNormalIds (i, normalIndexArray);
}
for (j = 0; j < indexCount; j++) {
status = fMesh->getFaceVertexColorIndex(i, j, colorIndex);
os << i << DELIMITER << j << DELIMITER << indexArray[j] << DELIMITER
<< normalIndexArray[j] << DELIMITER << colorIndex << DELIMITER;
for (currUVSet = fHeadUVSet; currUVSet != NULL; currUVSet = currUVSet->next) {
status = fMesh->getPolygonUVid(i, j, uvID, &currUVSet->name);
}
os << DELIMITER << uvID;
}
os << "\n";
}
os << "\n";
}
os << "\n";
}
MStatus polyRawWriter::outputNormals(ostream& os)
{
unsigned int normalCount = fNormalArray.length();
if (0 == normalCount) {
}
os << "Normals: " << normalCount << "\n";
os << HEADER_LINE;
os << "Format: Index|[x, y, z]\n";
os << LINE;
unsigned int i;
for (i = 0; i < normalCount; i++) {
os << i << DELIMITER << "["
<< fNormalArray[i].x << ", "
<< fNormalArray[i].y << ", "
<< fNormalArray[i].z << "]\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputTangents(ostream& os)
{
unsigned int tangentCount = fTangentArray.length();
if (0 == tangentCount) {
}
os << "Tangents: " << tangentCount << "\n";
os << HEADER_LINE;
os << "Format: Index|[x, y, z]\n";
os << LINE;
unsigned int i;
for (i = 0; i < tangentCount; i++) {
os << i << DELIMITER << "["
<< fTangentArray[i].x << ", "
<< fTangentArray[i].y << ", "
<< fTangentArray[i].z << "]\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputBinormals(ostream& os)
{
unsigned int binormalCount = fBinormalArray.length();
if (0 == binormalCount) {
}
os << "Binormals: " << binormalCount << "\n";
os << HEADER_LINE;
os << "Format: Index|[x, y, z]\n";
os << LINE;
unsigned int i;
for (i = 0; i < binormalCount; i++) {
os << i << DELIMITER << "["
<< fBinormalArray[i].x << ", "
<< fBinormalArray[i].y << ", "
<< fBinormalArray[i].z << "]\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputColors(ostream& os)
{
unsigned int colorCount = fColorArray.length();
if (0 == colorCount) {
}
os << "Colors: " << colorCount << "\n";
os << HEADER_LINE;
os << "Format: Index|R G B A\n";
os << LINE;
unsigned int i;
for (i = 0; i < colorCount; i++) {
os << i << DELIMITER
<< fColorArray[i].r << " "
<< fColorArray[i].g << " "
<< fColorArray[i].b << " "
<< fColorArray[i].a << "\n";
}
os << "\n\n";
}
MStatus polyRawWriter::outputUVs(ostream& os)
{
UVSet* currUVSet;
unsigned int i, uvCount;
for (currUVSet = fHeadUVSet; currUVSet != NULL; currUVSet = currUVSet->next) {
if (currUVSet->name == fCurrentUVSetName) {
os << "Current ";
}
os << "UV Set: " << currUVSet->name << "\n";
uvCount = currUVSet->uArray.length();
os << "UV Count: " << uvCount << "\n";
os << HEADER_LINE;
os << "Format: Index|(u, v)\n";
os << LINE;
for (i = 0; i < uvCount; i++) {
os << i << DELIMITER << "(" << currUVSet->uArray[i] << ", " << currUVSet->vArray[i] << ")\n";
}
os << "\n";
}
os << "\n";
}
{
unsigned int i;
unsigned int faceCount = faces.
length();
os << "Set: " << setName << "\n";
os << HEADER_LINE;
os << "Faces: ";
for (i = 0; i < faceCount; i++) {
os << faces[i] << " ";
}
os << "\n";
if (textureName == "") {
textureName = "none";
}
os << "Texture File: " << textureName << "\n";
os << "\n\n";
}