[sdk] Set pivot on a mesh


#1

Is there a way to set the pivot point of a mesh ?

How would I do the following on a mesh ?

Matrix3 ntm = originalNode->GetNodeTM(ip->GetTime());
newNode->SetNodeTM(ip->GetTime(), ntm);
newNode->SetObjOffsetPos(originalNode->GetObjOffsetPos());
newNode->SetObjOffsetRot(originalNode->GetObjOffsetRot());
newNode->SetObjOffsetScale(originalNode->GetObjOffsetScale());

Guillermo


#2

Figure it out.

Point3 center = (node->pos) * Inverse(tm);

Matrix3 tmpTM;
tmpTM = ScaleMatrix(Point3(1, 1, 1));
tmpTM.RotateX(0.0f);
tmpTM.RotateY(0.0f);
tmpTM.RotateZ(0.0f);

... Do any other transformations..

tmpTM.SetTrans(Point3(center.x, (center.y + (objectSize * .5f)), center.z));

#3

I thought I had resolved my problem but I’m not, I have tried everything I can think of, But I haven’t found a solution, Obviously I don’t know enough.

Can some one please suggest a way to do this ?

Please look at the following image

There were 3 things I wanted to do. Align them first to the surface (done), then to the grow vector (done) and the last which i haven’t been able to do is to rotate them like the ones in the red circle which I rotate them manually inside max.

This is what I’m doing now.

// Align to the adhesion vector
Quat alignAvec;
Matrix3 alignRotAdheVec;
alignRotAdheVec.IdentityMatrix();

alignRotAdheVec.SetRow(2, Normalize(node->adhesionVector));						
alignRotAdheVec.SetRow(0, Point3(0, 1, 0) ^ alignRotAdheVec.GetRow(2));			
alignRotAdheVec.SetRow(1, alignRotAdheVec.GetRow(2) ^ alignRotAdheVec.GetRow(0));	

alignAvec = Quat(alignRotAdheVec*tm);
alignAvec.MakeMatrix(alignRotAdheVec);

tmpTM *= alignRotAdheVec;

/////////////////////////////////////

// Align to the grow direction
// Function came from Math.cpp in the CAT samples
RotateMatrixToAlignWithVector(tmpTM, Normalize(node->primaryDir), Y);

///////////////////////////////////

//  Here is were I'm stuck at the moment, I'm trying to rotate the squares by some predefined amounts 
//  along the grow direction
// I Guess I need to modify the Matrix so the rotations happens at the bottom of the square but I dont know how.
std::vector<float> theAngles = { -80.0f, -70.0f, -60.0f, -50.0f, 50.0f, 60.0f, 70.0f, 80.0f };
float vAngle = theAngles.at(rangeRandomInt(0, 7));
RotateMatrix(tmpTM, AngAxis(Normalize(node->adhesionVector), DegToRad(vAngle)));

// and last set the location of the quad
// I tried to set the offset here but it does not happens in local space so the quads end up off the correct center.
tmpTM.SetTrans(center);

Any help really apreciated.
Guillermo


#4

you are lost a little … look at:
INode::Move
INode::Rotate
INode::Scale

and specially a their pivMode option


#5

Hi DenisT,

I can’t since I don’t have an INode, Just a Mesh that was created by converting a Plane to a Tri then a Mesh.


#6

Just a mesh doesn’t have pivot. The Pivot is a thing of Node only. That means we talk about something else.


#7

I know the INode does not has a pivot, That’s what i’m trying to replicate on a mesh. Trying to rotate the mesh about an specific point but i haven’t find a way to do it, I’m guessing it has to do we the matrix but i don’t know how.


#8

You have to rotate the verts of the mesh about your point.
Maxscript version for editable poly:

(
angle = 45 
vertsToMove = $.selectedVerts

selCenter = [0,0,0]
for v in vertsToMove do selCenter += polyop.getvert $ v.index
selCenter /= vertsToMove.count

transform_mat = transMatrix selCenter
rot_mat = (rotateZMatrix angle) * transform_mat 

for v in vertsToMove do 
(
	in coordsys transform_mat vertex_position = (polyop.getVert $ v.index) 
	polyop.setVert $ v.index (vertex_position * rot_mat ) 
)
)

#9

Thanks miauu,

I will see if i can make this work on c++


#10

Hi miauu,

I finally got some time to work on this again.

I was having a hard time understanding how the code works but i found this post by bobo How to rotate subobjects using script ?
it has some comments so it was easier to understand plus it works in local space., AN was able to get it to work in maxscript but Unfortunately I have not been able to reproduce that effect in c++

Do you have a sample on doing that on c++ ?

Thanks,