Message 1 of 5
Plugin returns negative coordinates
Not applicable
06-02-2009
04:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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....
Any help would be greatly appreciated
I am using MAX7 + SDK
Thanks in advance
Jack
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(int i = 0; i < msfMesh.numVerts; i++)
{
Vertex vtx;
Point3 pnt = mesh->getVert(i)
vtx = pnt.x; vtx = pnt.y; vtx = pnt.z; <<<<< here is the problem!!!
fwrite(vtx, sizeof(Vertex), 1, stream)
}
// write texture vertices
for(i = 0; i < msfMesh.numTVerts; i++)
{
TexVtx tv;
UVVert uvw = mesh->getTVert(i)
tv = uvw.x; tv = uvw.y;
fwrite(tv, sizeof(TexVtx), 1, stream)
}
// write faces
for(i = 0; i < msfMesh.numFaces; i++)
{
MSF_Face msfFace;
memset(&msfFace, 0, sizeof(MSF_Face))
// extract face information
msfFace.verts = mesh->faces.v;
msfFace.verts = mesh->faces.v;
msfFace.verts = mesh->faces.v;
if(msfMesh.numTVerts > 0)
{
// extract texture face information
msfFace.tverts = mesh->tvFace.t;
msfFace.tverts = mesh->tvFace.t;
msfFace.tverts = mesh->tvFace.t;
}
// write our face structure
fwrite(&msfFace, sizeof(MSF_Face), 1, stream)
}
// delete the mesh if needDel is true
if(needDel) mesh->DeleteThis()
count = 1;
}
// recurse children
for(int i = 0; i < node->NumberOfChildren() i++)
{
count += RecursiveWriteMesh(
node->GetChildNode(i),
stream, time)
}
return count;
}
// ========================================================
int ExpUtil::RecursiveWriteDummy(
INode *node,
FILE *stream,
TimeValue time)
{
int count = 0;
// Filter out dummy objects
if(IsNodeValid(node, DUMMY_CLASS_ID))
{
MSF_Dummy msfDummy;
memset(&msfDummy, 0, sizeof(MSF_Light))
// get the node name
strncpy(msfDummy.name,
node->GetName(),
sizeof(msfDummy.name))
// get the objects matrix and store
Matrix3 tm = node->GetObjectTM(time)
MatrixToArr(tm, msfDummy.tm)
// write our dummy object
fwrite(&msfDummy, sizeof(MSF_Dummy), 1, stream)
count = 1;
}
// recurse children
for(int i = 0; i < node->NumberOfChildren() i++)
{
count += RecursiveWriteDummy(
node->GetChildNode(i),
stream, time)
}
return count;
}
Any help would be greatly appreciated
I am using MAX7 + SDK
Thanks in advance
Jack