Notifications
Clear all

[Closed] C++ meshDelta FCreateQuad

Hi, I am trying to create a new face using the FCreateQuad but its not showing up. I am using VCreate to get the 4 Verts (which show) and then using that data for the FCreateQuad, but for some odd reason, I can’t get it to work. Here’s my code so far:

void PolyTools::CreateQuad(){
 	ip = GetCOREInterface();
 	t = GetCOREInterface()->GetTime();
 	TriObject* newObj = CreateNewTriObject();
 	UVVert v[4];
 	v[0] = Point3(0, 0, 0);
 	v[1] = Point3(20, 20, 0);
 	v[2] = Point3(20, 20, 5);
 	v[3] = Point3(0, 0, 5);
 	MeshDeltaUser *mdu = GetMeshDeltaUserInterface(newObj);
 	MeshDelta tmd;
 
 	DWORD newV;
 	newV = tmd.VCreate(v, 4);
 	tmd.FCreateQuad(&newV, 0, 0, -1);
 
 	if (mdu) GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);
 	INode *newnode = ip->CreateObjectNode(newObj);
 
 	ip->FlushUndoBuffer();
 	ip->RedrawViews(ip->GetTime());
 }
10 Replies

try to use CreatePolygon instead of FCreateQuad

MeshDelta, MeshDeltaUser, etc. are black boxes. No one knows now how they work, and what really works and what doesn’t. so check first how the sdk samples do this job. usually there is a reason do it some way than otherwise.

Ok I shall have a look at that. Thanks. Ahh that makes sense and I would use a sample, if they had one on FCreateQuad xD

Ok, I have used CreatePolygon and it works, only issues is that it doesn’t use the original Verts ? It just creates new ones for the Polygon which is silly. I’ve looked at the sample code, but from the looks of its, it will do the same thing as mine. How can I get the CreatePolygon to use the Original Verts ?

void PolyTools::CreateQuad(){
 	ip = GetCOREInterface();
 	t = GetCOREInterface()->GetTime();
 	TriObject* newObj = CreateNewTriObject();
 	UVVert v[4];
 	v[0] = Point3(0, 0, 0);
 	v[1] = Point3(20, 20, 0);
 	v[2] = Point3(20, 20, 5);
 	v[3] = Point3(0, 0, 5);
 	MeshDeltaUser *mdu = GetMeshDeltaUserInterface(newObj);
 	MeshDelta tmd (newObj->GetMesh());
 
 	DWORD newV;
 	newV = tmd.VCreate(v, 4);
 	if (mdu) GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);
 
 	int *verts = new int[4];
 	verts[0] = 0;
 	verts[1] = 1;
 	verts[2] = 2;
 	verts[3] = 3;
 
 	tmd.CreatePolygon(newObj->GetMesh(), 4, verts, 0, 0);
 	if (mdu) GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);
 	INode *newnode = ip->CreateObjectNode(newObj);
 
 	ip->FlushUndoBuffer();
 	ip->RedrawViews(ip->GetTime());
 }

Also, as I’m creating the Mesh from scratch, I have to apply the MeshDelta twice to get it to work.

wait a sec… why do make uv verts?

UVVert v[4];

UVVert is a Point3 but you should to keep your code clean…

I have them so I can create the Verts position using VCreate from MeshDelta. If there are no verts, then I can’t use the CreatePolygon function.

Its just the VCreate wanted it as a UVVert. Sorry about my messy code, I normally clean it after its all working ^^

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it’s better to clean it before asking

i don’t have mv studio to test so try it yurself:

void CreateQuad()
{
 	Interface* ip = GetCOREInterface();
 	TimeValue t = GetCOREInterface()->GetTime();
 	TriObject* newObj = CreateNewTriObject();
	Mesh& mesh = newObj->GetMesh();

 	Point3 v[4] = {
		Point3(0, 0, 0),
		Point3(20, 20, 0),
		Point3(20, 20, 5),
		Point3(0, 0, 5)
	};

 	MeshDeltaUser *mdu = GetMeshDeltaUserInterface(newObj);
	if (!mdu) return;

 	MeshDelta tmd(mesh);
 
 	DWORD newV = tmd.VCreate(v, 4);
 	GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);
	tmd.Apply(mesh);

	int vv[4] = { newV, newV+1, newV+2, newV+3 };
 	tmd.CreatePolygon(mesh, 4, vv, 0, 0);
 	GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);
	tmd.Apply(mesh);

 	INode *newnode = ip->CreateObjectNode(newObj);
 
 	//ip->FlushUndoBuffer();
 	ip->RedrawViews(t);
 } 

Thanks, but its gotten worse, now got 16 verts and the poly object created twice instead xD I shall keep working on it, but if you think of anything, let me know and I will clean my code from now on, sorry again

ok… i have amv studio now and it works for me:

void CreateQuad()
{
 	Interface* ip = GetCOREInterface();
 	TimeValue t = GetCOREInterface()->GetTime();
 	TriObject* newObj = CreateNewTriObject();
	Mesh& mesh = newObj->GetMesh();

 	Point3 v[4] = {
		Point3(0, 0, 0),
		Point3(20, 20, 0),
		Point3(20, 20, 5),
		Point3(0, 0, 5)
	};

 	MeshDeltaUser *mdu = GetMeshDeltaUserInterface(newObj);
	if (!mdu) return;

 	MeshDelta tmd(mesh);
 
 	DWORD newV = tmd.VCreate(v, 4);
	DWORD vv[4] = { newV, newV+1, newV+2, newV+3 };
 	tmd.FCreateQuad(vv);
 	GetMeshDeltaUserDataInterface(newObj)->ApplyMeshDelta(tmd, mdu, t);

 	INode *newnode = ip->CreateObjectNode(newObj);
 
 	//ip->FlushUndoBuffer();
 	ip->RedrawViews(ip->GetTime());
 }

Perfect, it works !! Thank you very much