Plugin returns negative coordinates

Plugin returns negative coordinates

Anonymous
Not applicable
392 Views
4 Replies
Message 1 of 5

Plugin returns negative coordinates

Anonymous
Not applicable
Hello,
I am trying out a plugin which comes from a book...
I put a breakpoint to check the vertex coordinate, it always returns some negative
coordinates. However, in my scene and a very simple scene just consists of a box and a plane (have been converted to editable Mesh (also tried Editable Poly), there are nothing in that range...
What strange to me is 3ds max always shows some symmetrical information about the mesh
For example
Vert 1 X coordiate = 10.0
On the other end of the mesh
it has -10.0

I am really unpleased, but tried to rewrite from scratch... but the same thing happens...
Here's the code... Would you mind taking the time to check for me? Have been looking at it for days....


// ========================================================
// ExpUtil.cpp
// Scene Export Utility
// Copyrite ?000, Simon Feltman
// --------------------------------------------------------
#include "ExpUtil.h"
#include "MSF.h"

#define EXPUTIL_CLASS_ID Class_ID(0x39d70798, 0x2b220e8b)

// ========================================================
void PointToArr(const Point3 &pnt, float arr)
{
arr = pnt.x;
arr = pnt.y;
arr = pnt.z;
}

// ========================================================
void MatrixToArr(const Matrix3 &tm, float arr)
{
}

// ========================================================
bool IsNodeValid(INode *node, int cid)
{
// don't use root or hidden nodes.
if(node->IsRootNode() || node->IsNodeHidden())
return false;

Object *obj = node->EvalWorldState(0).obj;
if(obj && obj->CanConvertToType(Class_ID(cid, 0)))
return true;

return false;
}

// ========================================================
class ExpUtil : public UtilityObj
{
public:
HWND hPanel;
IUtil *iu;
Interface *ip;

int RecursiveWriteMesh(
INode *node,
FILE *stream,
TimeValue time)

int RecursiveWriteDummy(
INode *node,
FILE *stream,
TimeValue time)

int RecursiveWriteLight(
INode *node,
FILE *stream,
TimeValue time)

int RecursiveWriteCamera(
INode *node,
FILE *stream,
TimeValue time)

void DoExport()

void BeginEditParams(Interface *ip, IUtil *iu)
void EndEditParams(Interface *ip, IUtil *iu)

void Init(HWND hWnd)
void Destroy(HWND hWnd)

void DeleteThis() { }

//Constructor/Destructor
ExpUtil()
~ExpUtil()
};

static ExpUtil theExpUtil;

// ========================================================
class ExpUtilClassDesc : public ClassDesc2
{
public:
int IsPublic() {
return 1;
}
void* Create(BOOL loading = FALSE) {
return &theExpUtil;
}
const TCHAR* ClassName() {
return GetString(IDS_CLASS_NAME)
}
SClass_ID SuperClassID() {
return UTILITY_CLASS_ID;
}
Class_ID ClassID() {
return EXPUTIL_CLASS_ID;
}
const TCHAR* Category() {
return GetString(IDS_CATEGORY)
}
const TCHAR* InternalName() {
return _T("ExpUtil")
}
HINSTANCE HInstance() {
return hInstance;
}

char *GetRsrcString(long l) { return "hello"; }
};

static ExpUtilClassDesc ExpUtilDesc;

ClassDesc2* GetExpUtilDesc() {
return &ExpUtilDesc;
}

// ========================================================
// For use with GetRenderMesh
class NullView : public View
{
public:
Point2 ViewToScreen(Point3 p) {
return Point2(p.x,p.y)
}
NullView() {
worldToView.IdentityMatrix()
screenW = 640.0f; screenH = 480.0f;
}
};
static NullView nullView;

// ========================================================
static BOOL CALLBACK ExpUtilDlgProc(
HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
theExpUtil.Init(hWnd)
break;

case WM_DESTROY:
theExpUtil.Destroy(hWnd)
break;

case WM_COMMAND:
// Filter out when the IDC_DOEXPORT button is hit.
if(LOWORD(wParam) == IDC_DOEXPORT)
theExpUtil.DoExport()
break;

case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
theExpUtil.ip->RollupMouseMessage(
hWnd, msg, wParam, lParam)
break;

default:
return FALSE;
}
return TRUE;
}

// ========================================================
ExpUtil::ExpUtil()
{
iu = NULL;
ip = NULL;
hPanel = NULL;
}
ExpUtil::~ExpUtil() {}

// ========================================================
void ExpUtil::BeginEditParams(Interface *ip,
IUtil *iu)
{
this->iu = iu;
this->ip = ip;
hPanel = ip->AddRollupPage(
hInstance,
MAKEINTRESOURCE(IDD_PANEL),
ExpUtilDlgProc,
GetString(IDS_PARAMS),
0)
}

// ========================================================
void ExpUtil::EndEditParams(Interface *ip, IUtil *iu)
{
this->iu = NULL;
this->ip = NULL;
ip->DeleteRollupPage(hPanel)
hPanel = NULL;
}

// ========================================================
void ExpUtil::Init(HWND hWnd) {}
void ExpUtil::Destroy(HWND hWnd) {}

// ========================================================
// Function will recurse all nodes filtering only meshes
int ExpUtil::RecursiveWriteMesh(
INode *node,
FILE *stream,
TimeValue time)
{
int count = 0;

// Filter out geometry objects.
if(IsNodeValid(node, TRIOBJ_CLASS_ID))
{
// get a snapshot of the same mesh the renderer uses
BOOL needDel = FALSE;
ObjectState os = node->EvalWorldState(time)
Mesh *mesh = ((TriObject*)os.obj)->GetRenderMesh(
time, node, nullView, needDel)

MSF_Mesh msfMesh;
memset(&msfMesh, 0, sizeof(MSF_Mesh))

// get the node name and color
strncpy(msfMesh.name, node->GetName(),
sizeof(msfMesh.name))
msfMesh.rgb = node->GetWireColor()

// get vert, tvert, and face counts
msfMesh.numVerts = mesh->getNumVerts()
msfMesh.numTVerts = mesh->getNumTVerts()
msfMesh.numFaces = mesh->getNumFaces()

// write the mesh header
fwrite(&msfMesh, sizeof(MSF_Mesh), 1, stream)

// write vertices
for&#40;int i = 0; i < msfMesh.numVerts; i++&#41;
{
Vertex vtx;
Point3 pnt = mesh->getVert&#40;i&#41;
vtx = pnt.x; vtx = pnt.y; vtx = pnt.z; <<<<< here is the problem!!!
fwrite&#40;vtx, sizeof&#40;Vertex&#41;, 1, stream&#41;
}

// write texture vertices
for&#40;i = 0; i < msfMesh.numTVerts; i++&#41;
{
TexVtx tv;
UVVert uvw = mesh->getTVert&#40;i&#41;
tv = uvw.x; tv = uvw.y;
fwrite&#40;tv, sizeof&#40;TexVtx&#41;, 1, stream&#41;
}

// write faces
for&#40;i = 0; i < msfMesh.numFaces; i++&#41;
{
MSF_Face msfFace;
memset&#40;&msfFace, 0, sizeof&#40;MSF_Face&#41;&#41;

// extract face information
msfFace.verts = mesh->faces.v;
msfFace.verts = mesh->faces.v;
msfFace.verts = mesh->faces.v;

if&#40;msfMesh.numTVerts > 0&#41;
{
// extract texture face information
msfFace.tverts = mesh->tvFace.t;
msfFace.tverts = mesh->tvFace.t;
msfFace.tverts = mesh->tvFace.t;
}

// write our face structure
fwrite&#40;&msfFace, sizeof&#40;MSF_Face&#41;, 1, stream&#41;
}

// delete the mesh if needDel is true
if&#40;needDel&#41; mesh->DeleteThis&#40;&#41;

count = 1;
}

// recurse children
for&#40;int i = 0; i < node->NumberOfChildren&#40;&#41; i++&#41;
{
count += RecursiveWriteMesh&#40;
node->GetChildNode&#40;i&#41;,
stream, time&#41;
}

return count;
}

// ========================================================
int ExpUtil::RecursiveWriteDummy&#40;
INode *node,
FILE *stream,
TimeValue time&#41;
{
int count = 0;

// Filter out dummy objects
if&#40;IsNodeValid&#40;node, DUMMY_CLASS_ID&#41;&#41;
{
MSF_Dummy msfDummy;
memset&#40;&msfDummy, 0, sizeof&#40;MSF_Light&#41;&#41;

// get the node name
strncpy&#40;msfDummy.name,
node->GetName&#40;&#41;,
sizeof&#40;msfDummy.name&#41;&#41;

// get the objects matrix and store
Matrix3 tm = node->GetObjectTM&#40;time&#41;
MatrixToArr&#40;tm, msfDummy.tm&#41;

// write our dummy object
fwrite&#40;&msfDummy, sizeof&#40;MSF_Dummy&#41;, 1, stream&#41;
count = 1;
}

// recurse children
for&#40;int i = 0; i < node->NumberOfChildren&#40;&#41; i++&#41;
{
count += RecursiveWriteDummy&#40;
node->GetChildNode&#40;i&#41;,
stream, time&#41;
}

return count;
}



Any help would be greatly appreciated
I am using MAX7 + SDK
Thanks in advance
Jack
0 Likes
393 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Just out of curiosity &#40;I know nothing about the SDK&#41; is your test cube located at the origin &#40;0,0,0&#41; ?
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Melting Point,
Thanks for your reply. Actually, I have moved the test cube around...
I also checked every vertex coordinate, but they all fall in a positive range.
One thing I noticed about is all objects have a unknown scene root checked with properties
Is it where the problem lies?
Thanks
Jack
0 Likes
Message 4 of 5

Anonymous
Not applicable
I have selected "World" from the top combo box before dragging out a box..
It was still the same.
Any further thoughts?
Sorry about it because I don't know how to work with MAX
Thanks
JAc
0 Likes
Message 5 of 5

Anonymous
Not applicable
I guess the only other question I have is, does it export usable data? I mean, your exporting it for something right, so does it import into the &#40;game engine?&#41; and if so, is the shape maintained, but in the wrong spot?

You said you moved the cube around, did the values change? or always remain the same? If they're the same, then it would sound like the pivot was being used as the parent. But again since I don't know the SDK, I can't help much, but there must be a way to get the world space coordinates of a mesh.
0 Likes