mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
always recenter transforms on rotate pivot
This commit is contained in:
parent
0cc3ed8706
commit
a182469159
@ -670,47 +670,8 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A special case: if the group is a billboard, we center the
|
// Billboards always get the transform set.
|
||||||
// transform on the rotate pivot and ignore whatever transform might
|
if (egg_group->get_billboard_type() == EggGroup::BT_none) {
|
||||||
// be there.
|
|
||||||
if (egg_group->get_billboard_type() != EggGroup::BT_none) {
|
|
||||||
MFnTransform transform(transformNode, &status);
|
|
||||||
if (!status) {
|
|
||||||
status.perror("MFnTransform constructor");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MPoint pivot = transform.rotatePivot(MSpace::kObject, &status);
|
|
||||||
if (!status) {
|
|
||||||
status.perror("Can't get rotate pivot");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to convert the pivot to world coordinates.
|
|
||||||
// Unfortunately, Maya can only tell it to us in local
|
|
||||||
// coordinates.
|
|
||||||
MMatrix mat = dag_path.inclusiveMatrix(&status);
|
|
||||||
if (!status) {
|
|
||||||
status.perror("Can't get coordinate space for pivot");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LMatrix4d n2w(mat[0][0], mat[0][1], mat[0][2], mat[0][3],
|
|
||||||
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
|
||||||
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
|
||||||
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
|
|
||||||
LPoint3d p3d(pivot[0], pivot[1], pivot[2]);
|
|
||||||
p3d = p3d * n2w;
|
|
||||||
|
|
||||||
if (egg_group->get_parent() != (EggGroupNode *)NULL) {
|
|
||||||
// Now convert the pivot point into the group's parent's space.
|
|
||||||
p3d = p3d * egg_group->get_parent()->get_vertex_frame_inv();
|
|
||||||
}
|
|
||||||
|
|
||||||
egg_group->clear_transform();
|
|
||||||
egg_group->add_translate(p3d);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (_transform_type) {
|
switch (_transform_type) {
|
||||||
case TT_all:
|
case TT_all:
|
||||||
break;
|
break;
|
||||||
@ -732,9 +693,9 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
|||||||
case TT_invalid:
|
case TT_invalid:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Extract the matrix from the dag path, and convert it to the local
|
// Extract the matrix from the dag path.
|
||||||
// frame.
|
|
||||||
MMatrix mat = dag_path.inclusiveMatrix(&status);
|
MMatrix mat = dag_path.inclusiveMatrix(&status);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
status.perror("Can't get transform matrix");
|
status.perror("Can't get transform matrix");
|
||||||
@ -744,10 +705,36 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
|||||||
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
||||||
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
||||||
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
|
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
|
||||||
|
|
||||||
|
// Maya has a rotate pivot, separate from its transform. Usually we
|
||||||
|
// care more about the rotate pivot than we do about the transform,
|
||||||
|
// so get the rotate pivot too.
|
||||||
|
MFnTransform transform(transformNode, &status);
|
||||||
|
if (!status) {
|
||||||
|
status.perror("MFnTransform constructor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MPoint pivot = transform.rotatePivot(MSpace::kObject, &status);
|
||||||
|
if (!status) {
|
||||||
|
status.perror("Can't get rotate pivot");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to convert the pivot to world coordinates. (Maya can
|
||||||
|
// only tell it to us in local coordinates.)
|
||||||
|
LPoint3d p3d(pivot[0], pivot[1], pivot[2]);
|
||||||
|
p3d = p3d * m4d;
|
||||||
|
|
||||||
|
// Now recenter the matrix about the pivot point.
|
||||||
|
m4d.set_row(3, p3d);
|
||||||
|
|
||||||
|
// Convert the recentered matrix into the group's space and store
|
||||||
|
// it.
|
||||||
m4d = m4d * egg_group->get_node_frame_inv();
|
m4d = m4d * egg_group->get_node_frame_inv();
|
||||||
if (!m4d.almost_equal(LMatrix4d::ident_mat(), 0.0001)) {
|
if (!m4d.almost_equal(LMatrix4d::ident_mat(), 0.0001)) {
|
||||||
egg_group->add_matrix(m4d);
|
egg_group->add_matrix(m4d);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user