Skip to content

Commit 06b40c1

Browse files
committed
fix flt2egg transform order, add -C option
1 parent 3063689 commit 06b40c1

File tree

8 files changed

+36
-12
lines changed

8 files changed

+36
-12
lines changed

pandatool/src/flt/fltTransformRotateAboutPoint.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ recompute_matrix() {
9595

9696
_matrix =
9797
LMatrix4d::translate_mat(-_center) *
98-
LMatrix4d::rotate_mat(_angle, normalize(axis), CS_zup_right) *
98+
LMatrix4d::rotate_mat(_angle, axis, CS_zup_right) *
9999
LMatrix4d::translate_mat(_center);
100100
}
101101
}

pandatool/src/fltegg/fltToEggConverter.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
////////////////////////////////////////////////////////////////////
4949
FltToEggConverter::
5050
FltToEggConverter() {
51+
_compose_transforms = false;
5152
}
5253

5354
////////////////////////////////////////////////////////////////////
@@ -57,7 +58,8 @@ FltToEggConverter() {
5758
////////////////////////////////////////////////////////////////////
5859
FltToEggConverter::
5960
FltToEggConverter(const FltToEggConverter &copy) :
60-
SomethingToEggConverter(copy)
61+
SomethingToEggConverter(copy),
62+
_compose_transforms(copy._compose_transforms)
6163
{
6264
}
6365

@@ -156,7 +158,7 @@ convert_flt(const FltHeader *flt_header) {
156158
// they're assigned to (for instance, to apply a transparency or
157159
// something).
158160

159-
FltToEggLevelState state;
161+
FltToEggLevelState state(this);
160162
state._egg_parent = _egg_data;
161163
convert_record(_flt_header, state);
162164

pandatool/src/fltegg/fltToEggConverter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class FltToEggConverter : public SomethingToEggConverter {
6767
virtual bool convert_file(const Filename &filename);
6868
bool convert_flt(const FltHeader *flt_header);
6969

70+
// Set this true to store transforms in egg files as the fully
71+
// composed matrix, or false (the default) to keep them decomposed
72+
// into elemental operations.
73+
bool _compose_transforms;
74+
7075
private:
7176
void cleanup();
7277

pandatool/src/fltegg/fltToEggLevelState.I

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
// Description:
2323
////////////////////////////////////////////////////////////////////
2424
INLINE FltToEggLevelState::
25-
FltToEggLevelState() {
25+
FltToEggLevelState(FltToEggConverter *converter) :
26+
_converter(converter)
27+
{
2628
_flt_object = (FltObject *)NULL;
2729
_egg_parent = (EggGroupNode *)NULL;
2830
}
@@ -35,7 +37,8 @@ FltToEggLevelState() {
3537
INLINE FltToEggLevelState::
3638
FltToEggLevelState(const FltToEggLevelState &copy) :
3739
_flt_object(copy._flt_object),
38-
_egg_parent(copy._egg_parent)
40+
_egg_parent(copy._egg_parent),
41+
_converter(copy._converter)
3942
{
4043
// We don't bother to copy the _parents map.
4144
}
@@ -49,5 +52,6 @@ INLINE void FltToEggLevelState::
4952
operator = (const FltToEggLevelState &copy) {
5053
_flt_object = copy._flt_object;
5154
_egg_parent = copy._egg_parent;
55+
_converter = copy._converter;
5256
// We don't bother to copy the _parents map.
5357
}

pandatool/src/fltegg/fltToEggLevelState.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
////////////////////////////////////////////////////////////////////
1818

1919
#include "fltToEggLevelState.h"
20+
#include "fltToEggConverter.h"
2021
#include "fltTransformTranslate.h"
2122
#include "fltTransformRotateAboutPoint.h"
2223
#include "fltTransformRotateAboutEdge.h"
@@ -134,7 +135,7 @@ get_synthetic_group(const string &name,
134135

135136
////////////////////////////////////////////////////////////////////
136137
// Function: FltToEggLevelState::set_transform
137-
// Access: Public, Static
138+
// Access: Public
138139
// Description: Sets up the group to reflect the transform indicated
139140
// by the given record, if any.
140141
////////////////////////////////////////////////////////////////////
@@ -144,7 +145,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) {
144145
egg_group->set_group_type(EggGroup::GT_instance);
145146

146147
int num_steps = flt_bead->get_num_transform_steps();
147-
bool componentwise_ok = true;
148+
bool componentwise_ok = !_converter->_compose_transforms;
148149

149150
if (num_steps == 0) {
150151
componentwise_ok = false;
@@ -154,8 +155,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) {
154155
// don't know how to interpret, just store the whole transform
155156
// matrix in the egg file.
156157
egg_group->clear_transform();
157-
158-
for (int i = 0; i < num_steps && componentwise_ok; i++) {
158+
for (int i = num_steps -1; i >= 0 && componentwise_ok; i--) {
159159
const FltTransformRecord *step = flt_bead->get_transform_step(i);
160160
if (step->is_exact_type(FltTransformTranslate::get_class_type())) {
161161
const FltTransformTranslate *trans;
@@ -166,7 +166,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) {
166166

167167
} else if (step->is_exact_type(FltTransformRotateAboutPoint::get_class_type())) {
168168
const FltTransformRotateAboutPoint *rap;
169-
DCAST_INTO_V(rap, step);
169+
DCAST_INTO_V(rap, step);
170170
if (!IS_NEARLY_ZERO(rap->get_angle())) {
171171
if (!rap->get_center().almost_equal(LVector3d::zero())) {
172172
egg_group->add_translate(-rap->get_center());

pandatool/src/fltegg/fltToEggLevelState.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FltObject;
2626
class FltBead;
2727
class EggGroupNode;
2828
class EggGroup;
29+
class FltToEggConverter;
2930

3031
////////////////////////////////////////////////////////////////////
3132
// Class : FltToEggLevelState
@@ -34,7 +35,7 @@ class EggGroup;
3435
////////////////////////////////////////////////////////////////////
3536
class FltToEggLevelState {
3637
public:
37-
INLINE FltToEggLevelState();
38+
INLINE FltToEggLevelState(FltToEggConverter *converter);
3839
INLINE FltToEggLevelState(const FltToEggLevelState &copy);
3940
INLINE void operator = (const FltToEggLevelState &copy);
4041
~FltToEggLevelState();
@@ -43,7 +44,7 @@ class FltToEggLevelState {
4344
const FltBead *transform_bead,
4445
FltGeometry::BillboardType type = FltGeometry::BT_none);
4546

46-
static void set_transform(const FltBead *flt_bead, EggGroup *egg_group);
47+
void set_transform(const FltBead *flt_bead, EggGroup *egg_group);
4748

4849
const FltObject *_flt_object;
4950
EggGroupNode *_egg_parent;
@@ -60,6 +61,8 @@ class FltToEggLevelState {
6061

6162
typedef pmap<LMatrix4d, ParentNodes *> Parents;
6263
Parents _parents;
64+
65+
FltToEggConverter *_converter;
6366
};
6467

6568
#include "fltToEggLevelState.I"

pandatool/src/fltprogs/fltToEgg.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ FltToEgg() :
4848
"Specify the coordinate system of the input " + _format_name +
4949
" file. Normally, this is z-up.");
5050

51+
add_option
52+
("C", "", 0,
53+
"Compose node transforms into a single matrix before writing them to "
54+
"the egg file, instead of writing them as individual scale, rotate, and "
55+
"translate operations",
56+
&FltToEgg::dispatch_none, &_compose_transforms);
57+
5158
_coordinate_system = CS_zup_right;
5259
}
5360

@@ -82,6 +89,7 @@ run() {
8289
converter.set_egg_data(&_data, false);
8390
converter.set_texture_path_convert(_texture_path_convert, _make_rel_dir);
8491
converter.set_model_path_convert(_model_path_convert, _make_rel_dir);
92+
converter._compose_transforms = _compose_transforms;
8593

8694
if (!converter.convert_flt(header)) {
8795
nout << "Errors in conversion.\n";

pandatool/src/fltprogs/fltToEgg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class FltToEgg : public SomethingToEgg {
3636
FltToEgg();
3737

3838
void run();
39+
40+
bool _compose_transforms;
3941
};
4042

4143
#endif

0 commit comments

Comments
 (0)