Skip to content

Commit f524f00

Browse files
committed
Merge branch 'release/1.10.x'
2 parents fd5ec07 + 1b67931 commit f524f00

File tree

8 files changed

+130
-26
lines changed

8 files changed

+130
-26
lines changed

direct/src/gui/DirectScrolledList.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def scrollTo(self, index, centered=0):
210210
numItemsVisible = self["numItemsVisible"]
211211
numItemsTotal = len(self["items"])
212212
if(centered):
213-
self.index = index - (numItemsVisible/2)
213+
self.index = index - (numItemsVisible // 2)
214214
else:
215215
self.index = index
216216

panda/src/egg2pg/eggSaver.cxx

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,61 @@ convert_anim_node(AnimBundleNode *node, const WorkingNodePath &node_path,
345345
*/
346346
void EggSaver::
347347
convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent, CharacterJointMap *joint_map) {
348+
convert_character_bundle(bundleNode, egg_parent, joint_map, nullptr);
349+
}
350+
351+
/**
352+
* Converts the indicated Character Bundle to the corresponding Egg joints
353+
* structure.
354+
*/
355+
void EggSaver::
356+
convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent,
357+
CharacterJointMap *joint_map, const CharacterJoint *parent_joint) {
348358
int num_children = bundleNode->get_num_children();
349359

360+
const CharacterJoint *character_joint = nullptr;
361+
350362
EggGroupNode *joint_group = egg_parent;
351363
if (bundleNode->is_of_type(CharacterJoint::get_class_type())) {
352-
CharacterJoint *character_joint = DCAST(CharacterJoint, bundleNode);
364+
character_joint = DCAST(CharacterJoint, bundleNode);
353365

354-
LMatrix4 transformf;
355-
character_joint->get_transform(transformf);
356-
LMatrix4d transformd(LCAST(double, transformf));
357366
EggGroup *joint = new EggGroup(bundleNode->get_name());
358-
joint->add_matrix4(transformd);
359367
joint->set_group_type(EggGroup::GT_joint);
368+
369+
// The default_value originally passed to the CharacterJoint is what is used
370+
// for skinning. However, the _default_value can be changed after joint
371+
// construction (such as via a <DefaultPose>), so we can't just pull the
372+
// current _default_value.
373+
//
374+
// We have to instead work back from the _initial_net_transform_inverse,
375+
// which is computed at construction time from the original default_value:
376+
//
377+
// _net_transform = default_value * parent_joint->_net_transform;
378+
// _initial_net_transform_inverse = invert(_net_transform);
379+
//
380+
// So we should be able to reconstruct the original default_value like so:
381+
//
382+
// default_value = invert(_initial_net_transform_inverse)
383+
// * parent_joint->_initial_net_transform_inverse;
384+
//
385+
LMatrix4d net_transform = invert(LCAST(double, character_joint->_initial_net_transform_inverse));
386+
if (parent_joint != nullptr) {
387+
if (parent_joint->_initial_net_transform_inverse != character_joint->_initial_net_transform_inverse) {
388+
LMatrix4d parent_inverse = LCAST(double, parent_joint->_initial_net_transform_inverse);
389+
joint->add_matrix4(net_transform * parent_inverse);
390+
}
391+
} else if (!net_transform.is_identity()) {
392+
joint->add_matrix4(net_transform);
393+
}
394+
395+
// The joint's _default_value, if different, goes into a <DefaultPose>.
396+
LMatrix4d default_pose = LCAST(double, character_joint->_default_value);
397+
if (default_pose != joint->get_transform3d()) {
398+
EggTransform transform;
399+
transform.add_matrix4(LCAST(double, default_pose));
400+
joint->set_default_pose(transform);
401+
}
402+
360403
joint_group = joint;
361404
egg_parent->add_child(joint_group);
362405
if (joint_map != nullptr) {
@@ -373,7 +416,7 @@ convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent, Charac
373416

374417
for (int i = 0; i < num_children ; i++) {
375418
PartGroup *partGroup= bundleNode->get_child(i);
376-
convert_character_bundle(partGroup, joint_group, joint_map);
419+
convert_character_bundle(partGroup, joint_group, joint_map, character_joint);
377420
}
378421

379422
}
@@ -707,6 +750,7 @@ convert_primitive(const GeomVertexData *vertex_data,
707750
const LMatrix4 &net_mat, EggGroupNode *egg_parent,
708751
CharacterJointMap *joint_map) {
709752
GeomVertexReader reader(vertex_data);
753+
const GeomVertexFormat *format = vertex_data->get_format();
710754

711755
// Make a zygote that will be duplicated for each primitive.
712756
PT(EggPrimitive) egg_prim;
@@ -765,14 +809,14 @@ convert_primitive(const GeomVertexData *vertex_data,
765809
// Check for a texture.
766810
const TextureAttrib *ta;
767811
if (net_state->get_attrib(ta)) {
768-
EggTexture *egg_tex = get_egg_texture(ta->get_texture());
812+
for (size_t i = 0; i < ta->get_num_on_stages(); ++i) {
813+
TextureStage *tex_stage = ta->get_on_stage(i);
769814

770-
if (egg_tex != nullptr) {
771-
TextureStage *tex_stage = ta->get_on_stage(0);
772-
if (tex_stage != nullptr) {
815+
EggTexture *egg_tex = get_egg_texture(ta->get_on_texture(tex_stage));
816+
if (egg_tex != nullptr) {
773817
switch (tex_stage->get_mode()) {
774818
case TextureStage::M_modulate:
775-
if (has_color_off == true) {
819+
if (has_color_off == true && i == 0) {
776820
egg_tex->set_env_type(EggTexture::ET_replace);
777821
} else {
778822
egg_tex->set_env_type(EggTexture::ET_modulate);
@@ -793,12 +837,44 @@ convert_primitive(const GeomVertexData *vertex_data,
793837
case TextureStage::M_blend_color_scale:
794838
egg_tex->set_env_type(EggTexture::ET_blend_color_scale);
795839
break;
840+
case TextureStage::M_modulate_glow:
841+
egg_tex->set_env_type(EggTexture::ET_modulate_glow);
842+
break;
843+
case TextureStage::M_modulate_gloss:
844+
egg_tex->set_env_type(EggTexture::ET_modulate_gloss);
845+
break;
846+
case TextureStage::M_normal:
847+
egg_tex->set_env_type(EggTexture::ET_normal);
848+
break;
849+
case TextureStage::M_normal_height:
850+
egg_tex->set_env_type(EggTexture::ET_normal_height);
851+
break;
852+
case TextureStage::M_glow:
853+
egg_tex->set_env_type(EggTexture::ET_glow);
854+
break;
855+
case TextureStage::M_gloss:
856+
egg_tex->set_env_type(EggTexture::ET_gloss);
857+
break;
858+
case TextureStage::M_height:
859+
egg_tex->set_env_type(EggTexture::ET_height);
860+
break;
861+
case TextureStage::M_selector:
862+
egg_tex->set_env_type(EggTexture::ET_selector);
863+
break;
864+
case TextureStage::M_normal_gloss:
865+
egg_tex->set_env_type(EggTexture::ET_normal_gloss);
866+
break;
796867
default:
797868
break;
798869
}
799-
}
800870

801-
egg_prim->set_texture(egg_tex);
871+
const InternalName *name = tex_stage->get_texcoord_name();
872+
if (name != nullptr && name != InternalName::get_texcoord()) {
873+
egg_tex->set_uv_name(name->get_basename());
874+
}
875+
876+
egg_prim->add_texture(egg_tex);
877+
}
802878
}
803879
}
804880

@@ -863,10 +939,15 @@ convert_primitive(const GeomVertexData *vertex_data,
863939
color[3] * color_scale[3]));
864940
}
865941

866-
if (vertex_data->has_column(InternalName::get_texcoord())) {
867-
reader.set_column(InternalName::get_texcoord());
942+
for (size_t ti = 0; ti < format->get_num_texcoords(); ++ti) {
943+
const InternalName *texcoord_name = format->get_texcoord(ti);
944+
reader.set_column(texcoord_name);
868945
LTexCoord uv = reader.get_data2();
869-
egg_vert.set_uv(LCAST(double, uv));
946+
if (texcoord_name == InternalName::get_texcoord()) {
947+
egg_vert.set_uv(LCAST(double, uv));
948+
} else {
949+
egg_vert.set_uv(texcoord_name->get_basename(), LCAST(double, uv));
950+
}
870951
}
871952

872953
EggVertex *new_egg_vert = _vpool->create_unique_vertex(egg_vert);

panda/src/egg2pg/eggSaver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class EXPCL_PANDA_EGG2PG EggSaver {
7878
void convert_character_node(Character *node, const WorkingNodePath &node_path,
7979
EggGroupNode *egg_parent, bool has_decal);
8080
void convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent, CharacterJointMap *jointMap);
81+
void convert_character_bundle(PartGroup *bundleNode, EggGroupNode *egg_parent,
82+
CharacterJointMap *jointMap,
83+
const CharacterJoint *parent_joint);
8184
void convert_collision_node(CollisionNode *node, const WorkingNodePath &node_path,
8285
EggGroupNode *egg_parent, bool has_decal,
8386
CharacterJointMap *joint_map);

panda/src/express/referenceCount.I

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ ref_if_nonzero() const {
317317
return true;
318318
}
319319

320+
/**
321+
* Atomically decreases the reference count of this object if it is one.
322+
* Do not use this. This exists only to implement a special case with the
323+
* state cache.
324+
* @return false if the reference count was decremented to zero.
325+
*/
326+
INLINE bool ReferenceCount::
327+
unref_if_one() const {
328+
#ifdef _DEBUG
329+
nassertr(test_ref_count_integrity(), 0);
330+
nassertr(_ref_count > 0, 0);
331+
#endif
332+
return (AtomicAdjust::compare_and_exchange(_ref_count, 1, 0) != 1);
333+
}
334+
320335
/**
321336
* This global helper function will unref the given ReferenceCount object, and
322337
* if the reference count reaches zero, automatically delete it. It can't be

panda/src/express/referenceCount.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class EXPCL_PANDA_EXPRESS ReferenceCount : public MemoryBase {
6464
INLINE void weak_unref();
6565

6666
INLINE bool ref_if_nonzero() const;
67+
INLINE bool unref_if_one() const;
6768

6869
protected:
6970
bool do_test_ref_count_integrity() const;

panda/src/pgraph/renderAttrib.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,15 @@ garbage_collect() {
209209

210210
do {
211211
RenderAttrib *attrib = (RenderAttrib *)_attribs.get_key(si);
212-
if (attrib->get_ref_count() == 1) {
212+
if (!attrib->unref_if_one()) {
213213
// This attrib has recently been unreffed to 1 (the one we added when
214214
// we stored it in the cache). Now it's time to delete it. This is
215215
// safe, because we're holding the _attribs_lock, so it's not possible
216216
// for some other thread to find the attrib in the cache and ref it
217-
// while we're doing this.
217+
// while we're doing this. Also, we've just made sure to unref it to 0,
218+
// to ensure that another thread can't get it via a weak pointer.
218219
attrib->release_new();
219-
unref_delete(attrib);
220+
delete attrib;
220221

221222
// When we removed it from the hash map, it swapped the last element
222223
// with the one we just removed. So the current index contains one we

panda/src/pgraph/renderState.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,15 +925,17 @@ garbage_collect() {
925925
}
926926
}
927927

928-
if (state->get_ref_count() == 1) {
928+
if (!state->unref_if_one()) {
929929
// This state has recently been unreffed to 1 (the one we added when
930930
// we stored it in the cache). Now it's time to delete it. This is
931931
// safe, because we're holding the _states_lock, so it's not possible
932932
// for some other thread to find the state in the cache and ref it
933-
// while we're doing this.
933+
// while we're doing this. Also, we've just made sure to unref it to 0,
934+
// to ensure that another thread can't get it via a weak pointer.
935+
934936
state->release_new();
935937
state->remove_cache_pointers();
936-
state->cache_unref();
938+
state->cache_unref_only();
937939
delete state;
938940

939941
// When we removed it from the hash map, it swapped the last element

panda/src/pgraph/transformState.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,15 +1195,16 @@ garbage_collect() {
11951195
}
11961196
}
11971197

1198-
if (state->get_ref_count() == 1) {
1198+
if (!state->unref_if_one()) {
11991199
// This state has recently been unreffed to 1 (the one we added when
12001200
// we stored it in the cache). Now it's time to delete it. This is
12011201
// safe, because we're holding the _states_lock, so it's not possible
12021202
// for some other thread to find the state in the cache and ref it
1203-
// while we're doing this.
1203+
// while we're doing this. Also, we've just made sure to unref it to 0,
1204+
// to ensure that another thread can't get it via a weak pointer.
12041205
state->release_new();
12051206
state->remove_cache_pointers();
1206-
state->cache_unref();
1207+
state->cache_unref_only();
12071208
delete state;
12081209

12091210
// When we removed it from the hash map, it swapped the last element

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