Jump to content

Find which bone a vertice belongs to?


Von04
 Share

Recommended Posts

Me and my friend Rick have embarked on a long and tedious process to make a GMF Model Editor. We are actually progressing quite nicely, but have run into a few snags. Does anyone know how to find out which bone a particular vertice is attached to? Thanks in advance.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

We are currently using the GMF/SDK. We have progressed to the point where we can Load/Create a model, modify it, and then save it. It all works fine until we try to save an animation, because we are apparently not attaching the vertices to the correct bones. If anyone else has experimented with this any help would be appreciated.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

We are using c++. Everything seems to save fine except for the animations. Here is our save function.

 

#include "stdafx.h"
#include "gmfsdk.h"
using namespace System;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace Tao::Platform::Windows;
using namespace std;

static int SaveMeshGMF(TMesh mesh,String^ path,TGMFEntity gmfparent=0)	
{
TGMFMesh gmesh;
TGMFSurface	gsurf;
String^ type=gcnew String(GetEntityKey(mesh,"class"));

switch(Convert::ToInt32(GetEntityKey(mesh,"class")))
{
case ENTITY_MESH:
	if(type!="Mesh") break;
	gmesh=GMFMeshCreate(gmfparent);
	GMFNodeSetProperty(gmesh,"name", GetEntityKey(mesh,"name","<None>"));

	for (int s=1; s<Convert::ToInt32(CountSurfaces(mesh)+1);s++)
	{
		TSurface surf=GetSurface(mesh,s);
		gsurf=GMFMeshAddSurface(gmesh);

		int vcount=Convert::ToInt32(CountVertices(surf));
		for(int v=0;v<vcount;v++)
		{
			TVec3 Vertex=GetVertexPosition(surf,v);
			TVec3 VertexN=GetVertexNormal(surf,v);
			TVec4 Color=GetVertexColor(surf,v);
			TVec2 VertexUV=GetVertexTexCoords(surf,v);
			GMFSurfaceAddVertex(gsurf,Vertex.X,Vertex.Y,Vertex.Z,VertexN.X,VertexN.Y,VertexN.Z,VertexUV.X,VertexUV.Y,0.0,0.0,Color.X*255,Color.Y*255,Color.Z*255,Color.W*255);
		   if(AnimationLength(mesh)>0)GMFSurfaceAttachVertex(gsurf,v,gmesh,1);
		}

		int tcount=Convert::ToInt32(CountTriangles(surf));
		for (int t=0;t<tcount;t++)
		{
			GMFSurfaceAddTriangle(gsurf,TriangleVertex(surf,t,0),TriangleVertex(surf,t,1),TriangleVertex(surf,t,2));
		}

		GMFSurfaceCalculateBinormalsAndTangents(gsurf);
		TMaterial gmeshmaterial=GetSurfaceMaterial(surf);
		if(gmeshmaterial)
		{
			str gmeshname=MaterialName(gmeshmaterial);
			if (gmeshname!="")
			{		
				GMFNodeSetProperty (gsurf,"material",gmeshname);
			}
		}
	}

	TVec16 entmat=GetEntityMatrix(mesh); 
	TMat4 bank;
	bank.A0=entmat.A0;
	bank.A1=entmat.A1;
	bank.A2=entmat.A2;
	bank.A3=entmat.A3;
	bank.B0=entmat.B0;
	bank.B1=entmat.B1;
	bank.B2=entmat.B2;
	bank.B3=entmat.B3;
	bank.C0=entmat.C0;
	bank.C1=entmat.C1;
	bank.C2=entmat.C2;
	bank.C3=entmat.C3;
	bank.D0=entmat.D0;
	bank.D1=entmat.D1;
	bank.D2=entmat.D2;
	bank.D3=entmat.D3;
	GMFEntitySetMatrix(gmesh,bank);
}

if(type!="Mesh")
{
	gmesh=GMFBoneCreate(gmfparent);
	TVec3 po=EntityPosition(mesh);
	TVec3 ro=EntityRotation(mesh);
	TVec3 so=EntityScale(mesh);
	GMFNodeSetProperty(gmesh,"name", GetEntityKey(mesh,"name","<None>"));
	GMFEntitySetPositionRotationScale(gmesh,po.X,po.Y,po.Z,ro.X,ro.Y,ro.Z,so.X,so.Y,so.Z);		

	for(int a=0; a < AnimationLength(mesh); a++)
	{
		Animate(mesh,a);
		TVec3 po=EntityPosition(mesh);
		TVec3 ro=EntityRotation(mesh);
		TVec4 qu=EntityQuat(mesh);
		GMFEntityAddQuaternionKey(gmesh,qu.X,qu.Y,qu.Z,qu.W,a);
		GMFEntityAddPositionKey(gmesh, po.X, po.Y, po.Z, a);
		GMFEntityAddRotationKey(gmesh, ro.X, ro.Y, ro.Z, a);
	}
}


for (int c=1;c<CountChildren(mesh)+1;c++)
{		
	SaveMeshGMF(GetChild(mesh,c),path,gmesh);
}


return GMFMeshSaveFile(gmesh,(char*)(void*)Marshal::StringToHGlobalAnsi(path));
};

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...