rom
10-09-2007, 08:57 AM
Hi all,:thumbsup:
I am writing a custom binary exporter for modeler in order to synchronize
mesh data between lightwave and a game engine.
have a working version.
however ...
while looping polygons
and their assosiated points
i am having trouble
finding the absolute index of a point identifier,(as an integer)
within the context of all the points in the object.
I am able to retrieve the point identifier
and get the position data of the point.
i need a method to retieve the point index of a point identifier
in the context of the global point array.
I searched the docs and not been able to find the answer
it's probably staring me in the face
please see commented code for what i am trying to achieve
hope some one can point me in the right direction
:help:
//-----------------------------------------
// LScript Modeler template
//
// custom binary exporter
@version 2.2
@warnings
@script modeler
// global values go here
mesh;
//_______________________________
// this is causing massive overhead
// need to find better way of getting point index
getPointIndex : point // TAGGED FOR FACTOR OUT
{
for(i=1;i<=pointcount();i++ )
{
if(point == mesh.points[i])
{
return i;
}
}
return 0;
}
main
{
editbegin();
mesh = Mesh(1); // just layer 1 for now
pntCnt = pointcount();
polyCount = mesh.polygonCount(1);
// create the custom .bin file at the same path as the object filename
filename = string(mesh.filename,".bin");
file = File(filename,"wb") || error("can't create file");
file.close();
file = File(filename,"rb+") || error("cant open file");
// file header
file.writeInt(pntCnt);
file.writeInt(polyCount);
// write out points
file.offset(64,FROMSTART);
for(i=1;i <= pntCnt;i++)
{
lastPntPos = pointinfo(mesh.points[i]);
file.writeVector(lastPntPos);
}
// write polys :
// for now asuming mesh is trippled
// i need an int[3] of point indices referencing the global point array ?
p=1;
foreach(poly, polyCount )
{
v=1;
thisPoly = mesh.polygons[p];
pi=1;
pointIndices;
foreach(point , thisPoly.pointCount)
{
//triPoints;
thisPoint = thisPoly.points[pi];
// here i need index referencing the global point array.
// as poly count increases
// using getPointIndex() SEE getPointIndex : point
// is geometrically more expensive
// TAGGED TO FACTOR OUT
file.writeInt( getPointIndex( thisPoint ) );
// i would like to do as in next comment
// foreach(index ,pointIndices)
//{
// file.writeInt(index);
//}
pi++;
}
p++;
}
file.close();
editend();
reqbegin("<Requester Title>");
c0 = ctlinteger("Integer Control",1);
c1 = ctlnumber("Number Control",1.0);
c2 = ctlstring("String Control","my string");
c3 = ctlcheckbox("Checkbox Control",true);
c4 = ctlpopup("Popup control",1,@"Item 1","Item 2","Item 3"@);
c5 = ctlchoice("Choice Control",1,@"X","Y","Z"@);
//return if !reqpost();
//ureturn if !reqopen("keepOpen");
// get requester control values here
reqend();
// processing code goes here
}
I am writing a custom binary exporter for modeler in order to synchronize
mesh data between lightwave and a game engine.
have a working version.
however ...
while looping polygons
and their assosiated points
i am having trouble
finding the absolute index of a point identifier,(as an integer)
within the context of all the points in the object.
I am able to retrieve the point identifier
and get the position data of the point.
i need a method to retieve the point index of a point identifier
in the context of the global point array.
I searched the docs and not been able to find the answer
it's probably staring me in the face
please see commented code for what i am trying to achieve
hope some one can point me in the right direction
:help:
//-----------------------------------------
// LScript Modeler template
//
// custom binary exporter
@version 2.2
@warnings
@script modeler
// global values go here
mesh;
//_______________________________
// this is causing massive overhead
// need to find better way of getting point index
getPointIndex : point // TAGGED FOR FACTOR OUT
{
for(i=1;i<=pointcount();i++ )
{
if(point == mesh.points[i])
{
return i;
}
}
return 0;
}
main
{
editbegin();
mesh = Mesh(1); // just layer 1 for now
pntCnt = pointcount();
polyCount = mesh.polygonCount(1);
// create the custom .bin file at the same path as the object filename
filename = string(mesh.filename,".bin");
file = File(filename,"wb") || error("can't create file");
file.close();
file = File(filename,"rb+") || error("cant open file");
// file header
file.writeInt(pntCnt);
file.writeInt(polyCount);
// write out points
file.offset(64,FROMSTART);
for(i=1;i <= pntCnt;i++)
{
lastPntPos = pointinfo(mesh.points[i]);
file.writeVector(lastPntPos);
}
// write polys :
// for now asuming mesh is trippled
// i need an int[3] of point indices referencing the global point array ?
p=1;
foreach(poly, polyCount )
{
v=1;
thisPoly = mesh.polygons[p];
pi=1;
pointIndices;
foreach(point , thisPoly.pointCount)
{
//triPoints;
thisPoint = thisPoly.points[pi];
// here i need index referencing the global point array.
// as poly count increases
// using getPointIndex() SEE getPointIndex : point
// is geometrically more expensive
// TAGGED TO FACTOR OUT
file.writeInt( getPointIndex( thisPoint ) );
// i would like to do as in next comment
// foreach(index ,pointIndices)
//{
// file.writeInt(index);
//}
pi++;
}
p++;
}
file.close();
editend();
reqbegin("<Requester Title>");
c0 = ctlinteger("Integer Control",1);
c1 = ctlnumber("Number Control",1.0);
c2 = ctlstring("String Control","my string");
c3 = ctlcheckbox("Checkbox Control",true);
c4 = ctlpopup("Popup control",1,@"Item 1","Item 2","Item 3"@);
c5 = ctlchoice("Choice Control",1,@"X","Y","Z"@);
//return if !reqpost();
//ureturn if !reqopen("keepOpen");
// get requester control values here
reqend();
// processing code goes here
}