disambiguate get_transform2d() and get_transform3d()

This commit is contained in:
David Rose 2005-07-20 23:37:10 +00:00
parent 201213e3d5
commit 923a4086d8
21 changed files with 78 additions and 56 deletions

View File

@ -1113,7 +1113,7 @@ adjust_under() {
// Our own transform also affects our node frame. // Our own transform also affects our node frame.
_node_frame = _node_frame =
new MatrixFrame(get_transform() * get_node_frame()); new MatrixFrame(get_transform3d() * get_node_frame());
_node_frame_inv = _node_frame_inv =
new MatrixFrame(invert(get_node_frame())); new MatrixFrame(invert(get_node_frame()));
_vertex_to_node = _vertex_to_node =
@ -1175,7 +1175,7 @@ r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
mat1.set_row(3, LVector3d(0.0, 0.0, 0.0)); mat1.set_row(3, LVector3d(0.0, 0.0, 0.0));
inv1.set_row(3, LVector3d(0.0, 0.0, 0.0)); inv1.set_row(3, LVector3d(0.0, 0.0, 0.0));
internal_set_transform(inv1 * get_transform() * mat); internal_set_transform(inv1 * get_transform3d() * mat);
EggGroupNode::r_transform(mat1, inv1, to_cs); EggGroupNode::r_transform(mat1, inv1, to_cs);
} else { } else {

View File

@ -1037,7 +1037,7 @@ r_apply_texmats(EggTextureCollection &textures) {
// We've got a texture with a matrix applied. Save the matrix, // We've got a texture with a matrix applied. Save the matrix,
// and get a new texture without the matrix. // and get a new texture without the matrix.
LMatrix4d mat = texture->get_transform(); LMatrix4d mat = texture->get_transform3d();
EggTexture new_texture(*texture); EggTexture new_texture(*texture);
new_texture.clear_transform(); new_texture.clear_transform();
EggTexture *unique = textures.create_unique_texture(new_texture, ~0); EggTexture *unique = textures.create_unique_texture(new_texture, ~0);
@ -1056,7 +1056,7 @@ r_apply_texmats(EggTextureCollection &textures) {
EggVertex new_vertex(*vertex); EggVertex new_vertex(*vertex);
PT(EggVertexUV) new_uv_obj = new EggVertexUV(*uv_obj); PT(EggVertexUV) new_uv_obj = new EggVertexUV(*uv_obj);
TexCoord3d uvw = uv_obj->get_uvw() * mat; TexCoord3d uvw = uv_obj->get_uvw() * mat;
if (uv_obj->has_w() || !texture->is_transform_2d()) { if (uv_obj->has_w() || texture->has_transform3d()) {
new_uv_obj->set_uvw(uvw); new_uv_obj->set_uvw(uvw);
} else { } else {
new_uv_obj->set_uv(TexCoordd(uvw[0], uvw[1])); new_uv_obj->set_uv(TexCoordd(uvw[0], uvw[1]));

View File

@ -323,7 +323,7 @@ is_equivalent_to(const EggTexture &other, int eq) const {
} }
if (has_transform() && other.has_transform()) { if (has_transform() && other.has_transform()) {
if (!get_transform().almost_equal(other.get_transform(), 0.0001)) { if (!get_transform3d().almost_equal(other.get_transform3d(), 0.0001)) {
return false; return false;
} }
} }
@ -399,7 +399,7 @@ sorts_less_than(const EggTexture &other, int eq) const {
} }
if (has_transform() && other.has_transform()) { if (has_transform() && other.has_transform()) {
int compare = get_transform().compare_to(other.get_transform()); int compare = get_transform3d().compare_to(other.get_transform3d());
if (compare != 0) { if (compare != 0) {
return compare < 0; return compare < 0;
} }

View File

@ -160,7 +160,8 @@ add_matrix4(const LMatrix4d &mat) {
// Access: Public // Access: Public
// Description: Returns true if the transform is nonempty, false if // Description: Returns true if the transform is nonempty, false if
// it is empty (no transform components have been // it is empty (no transform components have been
// added). // added). This is true for either a 2-d or a 3-d
// transform.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool EggTransform:: INLINE bool EggTransform::
has_transform() const { has_transform() const {
@ -168,57 +169,74 @@ has_transform() const {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTransform::is_transform_2d // Function: EggTransform::has_transform2d
// Access: Public // Access: Public
// Description: Returns true if the transform is specified as a 2-d // Description: Returns true if the transform is specified as a 2-d
// transform, e.g. with a 3x3 matrix, or false if it is // transform, e.g. with a 3x3 matrix, or false if it is
// specified as a 3-d transform, with a 4x4 matrix. // specified as a 3-d transform (with a 4x4 matrix), or
// not specified at all.
// //
// Normally, EggTextures have a 2-d matrix (but // Normally, EggTextures have a 2-d matrix (but
// occasionally they use a 3-d matrix), and EggGroups // occasionally they use a 3-d matrix), and EggGroups
// always have a 3-d matrix. // always have a 3-d matrix.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool EggTransform:: INLINE bool EggTransform::
is_transform_2d() const { has_transform2d() const {
return _is_transform_2d; return has_transform() && _is_transform_2d;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTransform::set_transform_2d // Function: EggTransform::set_transform2d
// Access: Public // Access: Public
// Description: Sets the overall transform as a 3x3 matrix. This // Description: Sets the overall transform as a 3x3 matrix. This
// completely replaces whatever componentwise transform // completely replaces whatever componentwise transform
// may have been defined. // may have been defined.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void EggTransform:: INLINE void EggTransform::
set_transform_2d(const LMatrix3d &mat) { set_transform2d(const LMatrix3d &mat) {
internal_set_transform(mat); internal_set_transform(mat);
transform_changed(); transform_changed();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTransform::set_transform // Function: EggTransform::has_transform3d
// Access: Public
// Description: Returns true if the transform is specified as a 3-d
// transform, e.g. with a 4x4 matrix, or false if it is
// specified as a 2-d transform (with a 2x2 matrix), or
// not specified at all.
//
// Normally, EggTextures have a 3-d matrix (but
// occasionally they use a 3-d matrix), and EggGroups
// always have a 3-d matrix.
////////////////////////////////////////////////////////////////////
INLINE bool EggTransform::
has_transform3d() const {
return has_transform() && !_is_transform_2d;
}
////////////////////////////////////////////////////////////////////
// Function: EggTransform::set_transform3d
// Access: Public // Access: Public
// Description: Sets the overall transform as a 4x4 matrix. This // Description: Sets the overall transform as a 4x4 matrix. This
// completely replaces whatever componentwise transform // completely replaces whatever componentwise transform
// may have been defined. // may have been defined.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void EggTransform:: INLINE void EggTransform::
set_transform(const LMatrix4d &mat) { set_transform3d(const LMatrix4d &mat) {
internal_set_transform(mat); internal_set_transform(mat);
transform_changed(); transform_changed();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTransform::get_transform_2d // Function: EggTransform::get_transform2d
// Access: Public // Access: Public
// Description: Returns the overall transform as a 3x3 matrix. It is // Description: Returns the overall transform as a 3x3 matrix. It is
// only valid to call this if is_transform_2d() has // an error to call this if has_transform3d() is true.
// returned true.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE LMatrix3d EggTransform:: INLINE LMatrix3d EggTransform::
get_transform_2d() const { get_transform2d() const {
nassertr(is_transform_2d(), LMatrix3d::ident_mat()); nassertr(!has_transform3d(), LMatrix3d::ident_mat());
const LMatrix4d &t = _transform; const LMatrix4d &t = _transform;
return LMatrix3d(t(0, 0), t(0, 1), t(0, 3), return LMatrix3d(t(0, 0), t(0, 1), t(0, 3),
t(1, 0), t(1, 1), t(1, 3), t(1, 0), t(1, 1), t(1, 3),
@ -226,12 +244,15 @@ get_transform_2d() const {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTransform::get_transform // Function: EggTransform::get_transform3d
// Access: Public // Access: Public
// Description: Returns the overall transform as a 4x4 matrix. // Description: Returns the overall transform as a 4x4 matrix. It is
// valid to call this even if has_transform2d() is true;
// in this case, the 3x3 transform will be expanded to a
// 4x4 matrix.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE const LMatrix4d &EggTransform:: INLINE const LMatrix4d &EggTransform::
get_transform() const { get_transform3d() const {
return _transform; return _transform;
} }

View File

@ -57,11 +57,12 @@ PUBLISHED:
INLINE void add_matrix4(const LMatrix4d &mat); INLINE void add_matrix4(const LMatrix4d &mat);
INLINE bool has_transform() const; INLINE bool has_transform() const;
INLINE bool is_transform_2d() const; INLINE bool has_transform2d() const;
INLINE void set_transform_2d(const LMatrix3d &mat); INLINE void set_transform2d(const LMatrix3d &mat);
INLINE void set_transform(const LMatrix4d &mat); INLINE bool has_transform3d() const;
INLINE LMatrix3d get_transform_2d() const; INLINE void set_transform3d(const LMatrix4d &mat);
INLINE const LMatrix4d &get_transform() const; INLINE LMatrix3d get_transform2d() const;
INLINE const LMatrix4d &get_transform3d() const;
INLINE bool transform_is_identity() const; INLINE bool transform_is_identity() const;
enum ComponentType { enum ComponentType {

View File

@ -253,7 +253,7 @@ build_joint_hierarchy(EggNode *egg_node, PartGroup *part, int index) {
// it to single-precision. // it to single-precision.
LMatrix4d matd; LMatrix4d matd;
if (egg_group->has_transform()) { if (egg_group->has_transform()) {
matd = egg_group->get_transform(); matd = egg_group->get_transform3d();
} else { } else {
matd = LMatrix4d::ident_mat(); matd = LMatrix4d::ident_mat();
} }

View File

@ -2040,7 +2040,7 @@ make_vertex_data(const EggRenderState *render_state,
BakeInUVs::const_iterator buv = render_state->_bake_in_uvs.find(iname); BakeInUVs::const_iterator buv = render_state->_bake_in_uvs.find(iname);
if (buv != render_state->_bake_in_uvs.end()) { if (buv != render_state->_bake_in_uvs.end()) {
// If we are to bake in a texture matrix, do so now. // If we are to bake in a texture matrix, do so now.
uvw = uvw * (*buv).second->get_transform(); uvw = uvw * (*buv).second->get_transform3d();
} }
gvw.set_data3f(LCAST(float, uvw)); gvw.set_data3f(LCAST(float, uvw));
@ -2055,7 +2055,7 @@ make_vertex_data(const EggRenderState *render_state,
TexCoord3d duvw = morph.get_offset(); TexCoord3d duvw = morph.get_offset();
if (buv != render_state->_bake_in_uvs.end()) { if (buv != render_state->_bake_in_uvs.end()) {
TexCoord3d new_uvw = orig_uvw + duvw; TexCoord3d new_uvw = orig_uvw + duvw;
duvw = (new_uvw * (*buv).second->get_transform()) - uvw; duvw = (new_uvw * (*buv).second->get_transform3d()) - uvw;
} }
gvw.add_data3f(LCAST(float, duvw)); gvw.add_data3f(LCAST(float, duvw));

View File

@ -171,7 +171,7 @@ fill_state(EggPrimitive *egg_prim) {
// with a different transform, it will increase // with a different transform, it will increase
// tex_mats[uv_name].size() to at least 2, indicating we can't // tex_mats[uv_name].size() to at least 2, indicating we can't
// bake in the texture matrix. // bake in the texture matrix.
tex_mats[uv_name][egg_tex->get_transform()].push_back(&def); tex_mats[uv_name][egg_tex->get_transform3d()].push_back(&def);
} }
} }
} }

View File

@ -441,7 +441,7 @@ apply_node_properties(EggGroup *egg_group, PandaNode *node) {
} else if (transform->has_mat()) { } else if (transform->has_mat()) {
// Otherwise, we store the raw matrix. // Otherwise, we store the raw matrix.
const LMatrix4f &mat = transform->get_mat(); const LMatrix4f &mat = transform->get_mat();
egg_group->set_transform(LCAST(double, mat)); egg_group->set_transform3d(LCAST(double, mat));
} }
any_applied = true; any_applied = true;
} }

View File

@ -39,7 +39,7 @@ EggJointNodePointer(EggObject *object) {
// Quietly insist that the joint has a transform, for neatness. If // Quietly insist that the joint has a transform, for neatness. If
// it does not, give it the identity transform. // it does not, give it the identity transform.
if (!_joint->has_transform()) { if (!_joint->has_transform()) {
_joint->set_transform(LMatrix4d::ident_mat()); _joint->set_transform3d(LMatrix4d::ident_mat());
} }
} }
} }
@ -74,7 +74,7 @@ get_num_frames() const {
LMatrix4d EggJointNodePointer:: LMatrix4d EggJointNodePointer::
get_frame(int n) const { get_frame(int n) const {
nassertr(n == 0, LMatrix4d::ident_mat()); nassertr(n == 0, LMatrix4d::ident_mat());
return _joint->get_transform(); return _joint->get_transform3d();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -91,7 +91,7 @@ get_frame(int n) const {
void EggJointNodePointer:: void EggJointNodePointer::
set_frame(int n, const LMatrix4d &mat) { set_frame(int n, const LMatrix4d &mat) {
nassertv(n == 0); nassertv(n == 0);
_joint->set_transform(mat); _joint->set_transform3d(mat);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -180,7 +180,7 @@ do_rebuild() {
return false; return false;
} }
_joint->set_transform(_rebuild_frames[0]); _joint->set_transform3d(_rebuild_frames[0]);
_rebuild_frames.clear(); _rebuild_frames.clear();
return true; return true;
} }

View File

@ -240,7 +240,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) {
} }
if (!componentwise_ok) { if (!componentwise_ok) {
egg_group->set_transform(flt_bead->get_transform()); egg_group->set_transform3d(flt_bead->get_transform());
} }
} }
} }

View File

@ -450,9 +450,9 @@ apply_transform(EggTransform *egg_transform, FltBead *flt_node) {
if (components_ok) { if (components_ok) {
// Verify that the transform was computed correctly. // Verify that the transform was computed correctly.
if (!flt_node->get_transform().almost_equal(egg_transform->get_transform())) { if (!flt_node->get_transform().almost_equal(egg_transform->get_transform3d())) {
nout << "Incorrect transform! Expected:\n"; nout << "Incorrect transform! Expected:\n";
egg_transform->get_transform().write(nout, 2); egg_transform->get_transform3d().write(nout, 2);
nout << "Computed:\n"; nout << "Computed:\n";
flt_node->get_transform().write(nout, 2); flt_node->get_transform().write(nout, 2);
nout << "\n"; nout << "\n";
@ -462,7 +462,7 @@ apply_transform(EggTransform *egg_transform, FltBead *flt_node) {
if (!components_ok) { if (!components_ok) {
// Just store the overall transform. // Just store the overall transform.
flt_node->set_transform(egg_transform->get_transform()); flt_node->set_transform(egg_transform->get_transform3d());
} }
} }

View File

@ -36,7 +36,7 @@ make_egg() {
// If we have a nonzero pivot point, that's a translation // If we have a nonzero pivot point, that's a translation
// transform. // transform.
LPoint3d translate = LCAST(double, _layer->_pivot); LPoint3d translate = LCAST(double, _layer->_pivot);
_egg_group->set_transform(LMatrix4d::translate_mat(translate)); _egg_group->set_transform3d(LMatrix4d::translate_mat(translate));
_egg_group->set_group_type(EggGroup::GT_instance); _egg_group->set_group_type(EggGroup::GT_instance);
} }
} }

View File

@ -679,7 +679,7 @@ convert_char_chan(double start_frame, double end_frame, double frame_inc,
} }
get_joint_transform(node_desc->get_dag_path(), tgroup); get_joint_transform(node_desc->get_dag_path(), tgroup);
EggXfmSAnim *anim = _tree.get_egg_anim(node_desc); EggXfmSAnim *anim = _tree.get_egg_anim(node_desc);
if (!anim->add_data(tgroup->get_transform())) { if (!anim->add_data(tgroup->get_transform3d())) {
mayaegg_cat.error() mayaegg_cat.error()
<< "Invalid transform on " << node_desc->get_name() << "Invalid transform on " << node_desc->get_name()
<< " frame " << frame.value() << ".\n"; << " frame " << frame.value() << ".\n";
@ -1055,7 +1055,7 @@ get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group) {
ident_mat.setToIdentity(); ident_mat.setToIdentity();
if (!mat.isEquivalent(ident_mat, 0.0001)) { if (!mat.isEquivalent(ident_mat, 0.0001)) {
egg_group->set_transform egg_group->set_transform3d
(LMatrix4d(mat[0][0], mat[0][1], mat[0][2], mat[0][3], (LMatrix4d(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[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],
@ -2430,7 +2430,7 @@ apply_texture_properties(EggTexture &tex, const MayaShaderColorDef &color_def) {
LMatrix3d mat = color_def.compute_texture_matrix(); LMatrix3d mat = color_def.compute_texture_matrix();
if (!mat.almost_equal(LMatrix3d::ident_mat())) { if (!mat.almost_equal(LMatrix3d::ident_mat())) {
tex.set_transform_2d(mat); tex.set_transform2d(mat);
} }
} }
@ -2470,7 +2470,7 @@ compare_texture_properties(EggTexture &tex,
m(1, 0), m(1, 1), 0.0, m(1, 2), m(1, 0), m(1, 1), 0.0, m(1, 2),
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
m(2, 0), m(2, 1), 0.0, m(2, 2)); m(2, 0), m(2, 1), 0.0, m(2, 2));
if (!mat4.almost_equal(tex.get_transform())) { if (!mat4.almost_equal(tex.get_transform3d())) {
okflag = false; okflag = false;
} }

View File

@ -86,8 +86,8 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) {
_egg_data = data; _egg_data = data;
_tref_name = egg_tex->get_name(); _tref_name = egg_tex->get_name();
if (_egg_tex->has_transform() && egg_tex->is_transform_2d()) { if (_egg_tex->has_transform2d()) {
_tex_mat = _egg_tex->get_transform_2d(); _tex_mat = _egg_tex->get_transform2d();
if (!_inv_tex_mat.invert_from(_tex_mat)) { if (!_inv_tex_mat.invert_from(_tex_mat)) {
_inv_tex_mat = LMatrix3d::ident_mat(); _inv_tex_mat = LMatrix3d::ident_mat();
} }
@ -474,7 +474,7 @@ update_egg() {
// Compose the new texture matrix with whatever matrix was already // Compose the new texture matrix with whatever matrix was already
// there, if any. // there, if any.
_egg_tex->set_transform_2d(_tex_mat * new_tex_mat); _egg_tex->set_transform2d(_tex_mat * new_tex_mat);
// Finally, go back and actually adjust the UV's to match what we // Finally, go back and actually adjust the UV's to match what we
// claimed they could be. // claimed they could be.

View File

@ -487,7 +487,7 @@ get_transform(SAA_Scene *scene, EggGroup *egg_group, bool global) {
matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3], matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3],
matrix[3][0], matrix[3][1], matrix[3][2], matrix[3][3]); matrix[3][0], matrix[3][1], matrix[3][2], matrix[3][3]);
if (!m4d.almost_equal(LMatrix4d::ident_mat(), 0.0001)) { if (!m4d.almost_equal(LMatrix4d::ident_mat(), 0.0001)) {
egg_group->set_transform(m4d); egg_group->set_transform3d(m4d);
softegg_cat.spam() << "set transform in egg_group\n"; softegg_cat.spam() << "set transform in egg_group\n";
} }
} }

View File

@ -377,7 +377,7 @@ vrml_transform(const VrmlNode *node, EggGroup *group,
} }
if (any_transform) { if (any_transform) {
group->set_transform(local_transform); group->set_transform3d(local_transform);
} }
LMatrix4d next_transform = local_transform * net_transform; LMatrix4d next_transform = local_transform * net_transform;

View File

@ -94,7 +94,7 @@ create_hierarchy(XFileToEggConverter *converter) {
EggGroup *joint = (*ti).second._joint; EggGroup *joint = (*ti).second._joint;
if (anim_table->empty() && joint != (EggGroup *)NULL) { if (anim_table->empty() && joint != (EggGroup *)NULL) {
// If there's no animation data, assign the rest transform. // If there's no animation data, assign the rest transform.
anim_table->add_data(joint->get_transform()); anim_table->add_data(joint->get_transform3d());
} }
anim_table->optimize(); anim_table->optimize();
} }

View File

@ -160,7 +160,7 @@ add_group(EggGroup *egg_group, XFileNode *x_parent) {
// Set the transform on the frame, if we have one. // Set the transform on the frame, if we have one.
if (egg_group->has_transform()) { if (egg_group->has_transform()) {
x_frame->add_FrameTransformMatrix(egg_group->get_transform()); x_frame->add_FrameTransformMatrix(egg_group->get_transform3d());
} }
if (!recurse_nodes(egg_group, x_frame)) { if (!recurse_nodes(egg_group, x_frame)) {

View File

@ -437,7 +437,7 @@ convert_transform(XFileDataNode *obj, EggGroupNode *egg_parent) {
if (egg_parent->is_of_type(EggGroup::get_class_type())) { if (egg_parent->is_of_type(EggGroup::get_class_type())) {
EggGroup *egg_group = DCAST(EggGroup, egg_parent); EggGroup *egg_group = DCAST(EggGroup, egg_parent);
egg_group->set_transform(mat); egg_group->set_transform3d(mat);
} else { } else {
xfile_cat.error() xfile_cat.error()

View File

@ -60,8 +60,8 @@ set_from_egg(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
if (egg_prim->has_texture()) { if (egg_prim->has_texture()) {
// Check if there's a texture matrix on the texture. // Check if there's a texture matrix on the texture.
EggTexture *egg_tex = egg_prim->get_texture(); EggTexture *egg_tex = egg_prim->get_texture();
if (egg_tex->has_transform() && egg_tex->is_transform_2d()) { if (egg_tex->has_transform2d()) {
uv = uv * egg_tex->get_transform_2d(); uv = uv * egg_tex->get_transform2d();
} }
} }