THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/06/2003 at 07:31, xxxxxxxx wrote:
You mean you can't read my mind? Maybe the next version of the SDK will include that... Here is some code. I am skipping a lot, but I will try and put the pertinent parts in. Also, remember Im really not much of a programmer, so any help is appreciated.
It is a menu plugin. At the beginning of the execute function, I define most of the variable that are being used:
BaseObject *object ; //holds the object being exported
BaseObject *cameraob; //holds the camera object
Vector position; //holds the position of the object
Vector lightcolor; //holds the color of the light
Real intensity; //holds the intensity of the light
Vector sphererad; //stores the radius of hte primitive sphere
Matrix cameramatrix; //holds the cameras matrix
Matrix objectmatrix; //holds the objects matrix
Vector mv0, mv1, mv2, mv3 = 0; //used to save the Transform line in the RIB file
BaseContainer data; //container to hold object container
Vector objectcolor; //hold the color of the object
BaseTag *ptag = NULL;
BaseChannel *channel = NULL; //holds the channel of the material
BaseContainer chcontainer; //the container of the channel
String shaderinfo; //holds any custom shader defined with the RMShader tag plugin
String outputfilename;
Bool ok; //did the export get cancelled...
Filename fn; //holds the filename of the exported file
RenderData *rd = NULL; //holds the render data (resolution, etc)
BaseContainer rdc; //Render Data container
Then, after setting up the export file and writing some preliminary info to it, I get the camera:
//Camera Options
Real fov;
cameraob = doc->SearchObject("RenderCamera");
if (!cameraob)
{
MessageDialog("Render camera not found. Looking for camera named RenderCamera.");
a_file.close();
return;
}
fov = Deg(2 * atan((cameraob->GetAperture()/ 2) / cameraob->GetFocus()));
a_file<<"#Camera options\n";
cameramatrix = !cameraob->GetMgn();
mv0 = cameramatrix.v1;
mv1 = cameramatrix.v2;
mv2 = cameramatrix.v3;
mv3 = cameramatrix.off;
This code works if I comment out the code later on in the source dealing with exporting polygon objects. In fact, I found out last night that it is just the part of the code exporting quads that messes the camera data up, if I leave in the exporting of triangles, everything works. In between the camera export code and the code below is the code for exporting the light data, and all the vraious primities that are supported. Here is the polygon code:
else if (object->GetType() == Opolygon)
{
GePrint("Exporting: " + object->GetName());
Vector p;
Vector *padr = NULL;
Polygon *polyadr=NULL;
LONG i,j,k,pcnt,ptcnt,polycount;
LONG *dadr=NULL;
Vector normal;
Neighbor n;
Vector scale = object->GetScale();
UVWStruct uv;
//General Stuff
a_file<<"#" << GetText(object->GetName()) << "\n";
a_file<<"AttributeBegin\n";
if (objectcolor != NULL) a_file<<"Color [" << GetText(RealToString(objectcolor.x)) << " " << GetText(RealToString(objectcolor.y)) << " " << GetText(RealToString(objectcolor.z)) << "]\n";
objectmatrix = object->GetMgn();
mv0 = objectmatrix.v1;
mv1 = objectmatrix.v2;
mv2 = objectmatrix.v3;
mv3 = objectmatrix.off;
if (shaderinfo != "")
a_file<<GetText(shaderinfo) << "\n";
else
a_file<<"Surface \"plastic\"\n";
a_file<<"Transform [" << GetText(RealToString(mv0.x)) << " " << GetText(RealToString(mv0.y)) << " " << GetText(RealToString(mv0.z)) << " 0 " << GetText(RealToString(mv1.x)) << " " << GetText(RealToString(mv1.y)) << " " << GetText(RealToString(mv1.z)) << " 0 " << GetText(RealToString(mv2.x)) << " " << GetText(RealToString(mv2.y)) << " " << GetText(RealToString(mv2.z)) << " 0 " << GetText(RealToString(mv3.x/100)) << " " << GetText(RealToString(mv3.y/100)) << " " << GetText(RealToString(mv3.z/100)) << " 1]\n";
//polygon count and polygon address
polyadr = static_cast<PolygonObject*>(object)->GetPolygon();
pcnt = static_cast<PolygonObject*>(object)->GetPolygonCount();
//point count and point address
ptcnt = static_cast<PointObject*>(object)->GetPointCount();
padr = static_cast<PointObject*>(object)->GetPoint();
//initial normal gathering variables
Vector normals = NULL;
long dcnt;
n.Init(ptcnt,polyadr,pcnt,NULL);
//Get UV tag if there is one
ptag = object->GetTag(Tuvw);
//main polygon export loop
for (i=0; i<pcnt; i++)
{
if (polyadr[i].c == polyadr[i].d) //triangle
{
a_file<<"Polygon \"P\" [";
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].a].x/100) + " " + RealToString(scale.y*padr[polyadr[i].a].y/100) + " " + RealToString(scale.z*padr[polyadr[i].a].z/100) + " ");
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].b].x/100) + " " + RealToString(scale.y*padr[polyadr[i].b].y/100) + " " + RealToString(scale.z*padr[polyadr[i].b].z/100) + " ");
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].c].x/100) + " " + RealToString(scale.y*padr[polyadr[i].c].y/100) + " " + RealToString(scale.z*padr[polyadr[i].c].z/100) + " ");
a_file<<"] \"N\" [";
//normal for point 1
normals = NULL;
n.GetPointPolys(polyadr[i].a,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
//normal for point 2
normals = NULL;
n.GetPointPolys(polyadr[i].b,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
//normal for point 3
normals = NULL;
n.GetPointPolys(polyadr[i].c,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
a_file<<"] ";
if (ptag)
{
a_file<<"\"st\" [";
uv = static_cast<UVWTag*>(ptag)->Get(i);
a_file<<GetText(RealToString(uv.a.x) + " " + RealToString(uv.a.y)+ " " + RealToString(uv.b.x)+ " " + RealToString(uv.b.y)+ " " + RealToString(uv.c.x)+ " " + RealToString(uv.c.y) + " ");
a_file<<"]\n";
}
}
else //quad
{
a_file<<"Polygon \"P\" [";
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].a].x/100) + " " + RealToString(scale.y*padr[polyadr[i].a].y/100) + " " + RealToString(scale.z*padr[polyadr[i].a].z/100) + " ");
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].b].x/100) + " " + RealToString(scale.y*padr[polyadr[i].b].y/100) + " " + RealToString(scale.z*padr[polyadr[i].b].z/100) + " ");
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].c].x/100) + " " + RealToString(scale.y*padr[polyadr[i].c].y/100) + " " + RealToString(scale.z*padr[polyadr[i].c].z/100) + " ");
a_file<<GetText(RealToString(scale.x*padr[polyadr[i].d].x/100) + " " + RealToString(scale.y*padr[polyadr[i].d].y/100) + " " + RealToString(scale.z*padr[polyadr[i].d].z/100) + " ");
a_file<<"] \"N\" [";
//normal for point 1
normals = NULL;
n.GetPointPolys(polyadr[i].a,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
//normal for point 2
normals = NULL;
n.GetPointPolys(polyadr[i].b,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
//normal for point 3
normals = NULL;
n.GetPointPolys(polyadr[i].c,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
//normal for point 4
normals = NULL;
n.GetPointPolys(polyadr[i].d,&dadr,&dcnt);
for(k=0;k<dcnt;k++)
{
normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));
}
normals = !((normals)/k);
a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");
a_file<<"] ";
if (ptag) //object has UV coordinates
{
a_file<<"\"st\" [";
uv = static_cast<UVWTag*>(ptag)->Get(i);
a_file<<GetText(RealToString(uv.a.x) + " " + RealToString(uv.a.y)+ " " + RealToString(uv.b.x)+ " " + RealToString(uv.b.y)+ " " + RealToString(uv.c.x)+ " " + RealToString(uv.c.y) + " " + RealToString(uv.d.x)+ " " + RealToString(uv.d.y) + " ");
a_file<<"]\n";
}
}