Skip to content

Commit dee4cd6

Browse files
committed
bam2egg: support exposed joints properly
Also, don't use structured tag unless it seems necessary to preserve the structure
1 parent ba9ea06 commit dee4cd6

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

panda/src/egg2pg/eggSaver.cxx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "modelNode.h"
5353
#include "animBundleNode.h"
5454
#include "animChannelMatrixXfmTable.h"
55+
#include "characterJointEffect.h"
5556
#include "characterJoint.h"
5657
#include "character.h"
5758
#include "string_utils.h"
@@ -155,6 +156,16 @@ convert_node(const WorkingNodePath &node_path, EggGroupNode *egg_parent,
155156
convert_character_node(DCAST(Character, node), node_path, egg_parent, has_decal);
156157

157158
} else {
159+
// Is this a ModelNode that represents an exposed joint? If so, skip it,
160+
// as we'll take care of it when building the joint hierarchy.
161+
if (node->get_type() == ModelNode::get_class_type()) {
162+
ModelNode *model_node = (ModelNode *)node;
163+
if (model_node->get_preserve_transform() == ModelNode::PT_net &&
164+
model_node->has_effect(CharacterJointEffect::get_class_type())) {
165+
return;
166+
}
167+
}
168+
158169
// Just a generic node.
159170
EggGroup *egg_group = new EggGroup(node->get_name());
160171
egg_parent->add_child(egg_group);
@@ -354,6 +365,17 @@ convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent, Charac
354365
EggGroup *joint = new EggGroup(bundleNode->get_name());
355366
joint->add_matrix4(transformd);
356367
joint->set_group_type(EggGroup::GT_joint);
368+
369+
// Is this joint exposed?
370+
NodePathCollection coll = character_joint->get_net_transforms();
371+
for (size_t i = 0; i < coll.size(); ++i) {
372+
const NodePath &np = coll[i];
373+
if (np.get_name() == bundleNode->get_name() && np.node()->is_of_type(ModelNode::get_class_type())) {
374+
joint->set_dcs_type(EggGroup::DC_net);
375+
break;
376+
}
377+
}
378+
357379
joint_group = joint;
358380
egg_parent->add_child(joint_group);
359381
if (joint_map != NULL) {
@@ -384,16 +406,33 @@ convert_character_node(Character *node, const WorkingNodePath &node_path,
384406

385407
// A sequence node gets converted to an ordinary EggGroup, we only apply the
386408
// appropriate switch attributes to turn it into a sequence.
387-
// We have to use DT_structured since it is the only mode that preserves the
388-
// node hierarchy, including LODNodes and CollisionNodes that may be under
389-
// this Character node.
390409
EggGroup *egg_group = new EggGroup(node->get_name());
391-
egg_group->set_dart_type(EggGroup::DT_structured);
392410
egg_parent->add_child(egg_group);
393411
apply_node_properties(egg_group, node);
394412

395413
CharacterJointMap joint_map;
396-
recurse_nodes(node_path, egg_group, has_decal, &joint_map);
414+
bool is_structured = false;
415+
416+
int num_children = node->get_num_children();
417+
for (int i = 0; i < num_children; i++) {
418+
PandaNode *child = node->get_child(i);
419+
convert_node(WorkingNodePath(node_path, child), egg_parent, has_decal, &joint_map);
420+
421+
TypeHandle type = child->get_type();
422+
if (child->get_num_children() > 0 ||
423+
(type != GeomNode::get_class_type() && type != ModelNode::get_class_type())) {
424+
is_structured = true;
425+
}
426+
}
427+
428+
// We have to use DT_structured if it is necessary to preserve any node
429+
// hierarchy, such as LODNodes and CollisionNodes that may be under this
430+
// Character node.
431+
if (is_structured) {
432+
egg_group->set_dart_type(EggGroup::DT_structured);
433+
} else {
434+
egg_group->set_dart_type(EggGroup::DT_default);
435+
}
397436

398437
// turn it into a switch.. egg_group->set_switch_flag(true);
399438

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy