Hi. I'm Korean. I can't write English well.
I have a problem. I try to read .ase file exported from 3D MAX and display box mesh with Maya API.
But it can't work. Vertices and Edges are created well. But Faces are not created. I changed shading mode, but result was same..
I can't find example or referrence about creating mesh object with external data(for example, .ase).
Following is my source code.
Help me, please...
[LoadBoxCmd.h]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
double vertices [8][3] = {
{-12.9151f, -43.9114f, 0.0000f},
{42.4354f, -43.9114f, 0.0000f},
{-12.9151f, 4.7970f, 0.0000f},
{42.4354f, 4.7970f, 0.0000f},
{-12.9151f, -43.9114f, 53.8745f},
{42.4354f, -43.9114f, 53.8745f},
{-12.9151f, 4.7970f, 53.8745f},
{42.4354f, 4.7970f, 53.8745f}
};
int face_list[12][3] = {
{0, 2, 3}, {3, 1, 0}, {4, 5, 7},
{7, 6, 4}, {0, 1, 5}, {5, 4, 0},
{1, 3, 7}, {7, 5, 1}, {3, 2, 6},
{6, 7, 3}, {2, 0, 4}, {4, 6, 2}
};
[/LoadBoxCmd.h]
[LoadBoxCmd.cpp]
#include "LoadBoxCmd.h"
class LoadBox : public MPxCommand
{
public:
LoadBox();
virtual ~LoadBox();
MStatus doIt(const MArgList& args);
static void* creator();
private:
int nVertices;
int nPolygons;
};
void* LoadBox::creator()
{
return new LoadBox;
}
LoadBunny::LoadBox()
{
nVertices = 8;
nPolygons = 12;
}
LoadBox::~LoadBox() {}
MStatus LoadBox::doIt(const MArgList &args)
{
MStatus status;
MPointArray arrVertex;
MIntArray arrPolygonCount;
MIntArray arrPolygonConnect;
for(int i = 0; i < nVertices; i++)
{
arrVertex.append(vertices[i][0], vertices[i][1], vertices[i][2], 1);
}
for(int i = 0; i < nPolygons * 3; i += 3)
{
arrPolygonConnect.append(face\_list[i / 3][0]);
arrPolygonConnect.append(face\_list[i / 3][1]);
arrPolygonConnect.append(face\_list[i / 3][2]);
arrPolygonCount.append(3);
}
MFnMesh MeshFn;
MObject Bunny = MeshFn.create(nVertices, nPolygons,
arrVertex, arrPolygonCount, arrPolygonConnect, MObject::kNullObj, &status);
if(MS::kSuccess != status)
{
displayError("Bunny cannot be loaded!!");
return MS::kFailure;
}
cout << "Used polygon : " << MeshFn.numPolygons(&status) << endl;
cout << "Used Vertex : " << MeshFn.numVertices(&status) << endl;
displayInfo("Bunny is loaded!!");
return MS::kSuccess;
}
MStatus initializePlugin(MObject obj)
{
MFnPlugin plugin(obj, "Recre8or", "1.0", "Any");
plugin.registerCommand("LoadBox", LoadBox::creator);
MPxCommand::displayInfo("The LoadBunny plug-in is loaded correctly!");
return MS::kSuccess;
}
MStatus uninitializePlugin(MObject obj)
{
MFnPlugin plugin(obj);
plugin.deregisterCommand("LoadBox");
return MS::kSuccess;
}