Browse Source

fix bounds when flattening actors

David Rose 17 years ago
parent
commit
384a2570a8

+ 4 - 0
panda/src/chan/partBundle.cxx

@@ -188,6 +188,10 @@ apply_transform(const TransformState *transform) {
     bool inserted = _applied_transforms.insert(AppliedTransforms::value_type(transform, new_bundle)).second;
     nassertr(inserted, new_bundle);
   }
+  
+  // Make sure the new transform gets immediately applied to all of
+  // the joints.
+  new_bundle->force_update();
 
   return new_bundle;
 }

+ 4 - 0
panda/src/chan/partBundleNode.cxx

@@ -57,6 +57,10 @@ apply_attribs_to_vertices(const AccumulatedAttribs &attribs, int attrib_types,
       PT(PartBundle) new_bundle = bundle->apply_transform(attribs._transform);
       update_bundle(handle, new_bundle);
     }
+
+    // Make sure the Geom bounding volumes get recomputed due to this
+    // update.
+    r_mark_geom_bounds_stale(Thread::get_current_thread());
   }
 }
 

+ 16 - 0
panda/src/gobj/geomVertexData.cxx

@@ -1060,6 +1060,22 @@ animate_vertices(bool force, Thread *current_thread) const {
   return cdataw->_animated_vertices;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GeomVertexData::clear_animated_vertices
+//       Access: Published
+//  Description: Removes the cache of animated vertices computed by a
+//               previous call to animate_vertices() within the same
+//               frame.  This will force the next call to
+//               animate_vertices() to recompute these values from
+//               scratch.  Normally it is not necessary to call this.
+////////////////////////////////////////////////////////////////////
+void GeomVertexData::
+clear_animated_vertices() {
+  CDWriter cdata(_cycler, true);
+  cdata->_animated_vertices_modified.clear();
+  cdata->_animated_vertices.clear();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomVertexData::bytewise_copy
 //       Access: Private, Static

+ 1 - 0
panda/src/gobj/geomVertexData.h

@@ -150,6 +150,7 @@ PUBLISHED:
   CPT(GeomVertexData) reverse_normals() const;
 
   CPT(GeomVertexData) animate_vertices(bool force, Thread *current_thread) const;
+  void clear_animated_vertices();
 
   PT(GeomVertexData) 
     replace_column(InternalName *name, int num_components,

+ 24 - 0
panda/src/pgraph/geomNode.cxx

@@ -832,6 +832,30 @@ do_premunge(GraphicsStateGuardianBase *gsg,
   CLOSE_ITERATE_CURRENT_AND_UPSTREAM(_cycler);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GeomNode::r_mark_geom_bounds_stale
+//       Access: Protected, Virtual
+//  Description: Recursively calls Geom::mark_bounds_stale() on every
+//               Geom at this node and below.
+////////////////////////////////////////////////////////////////////
+void GeomNode::
+r_mark_geom_bounds_stale(Thread *current_thread) {
+  OPEN_ITERATE_CURRENT_AND_UPSTREAM(_cycler, current_thread) {
+    CDStageWriter cdata(_cycler, pipeline_stage, current_thread);
+
+    GeomList::iterator gi;
+    PT(GeomList) geoms = cdata->modify_geoms();
+    for (gi = geoms->begin(); gi != geoms->end(); ++gi) {
+      GeomEntry &entry = (*gi);
+      entry._geom.get_read_pointer()->mark_bounds_stale();
+    }
+  }
+  CLOSE_ITERATE_CURRENT_AND_UPSTREAM(_cycler);
+  mark_internal_bounds_stale();
+
+  PandaNode::r_mark_geom_bounds_stale(current_thread);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::compute_internal_bounds
 //       Access: Protected, Virtual

+ 1 - 0
panda/src/pgraph/geomNode.h

@@ -100,6 +100,7 @@ public:
                    GeomTransformer &transformer);
 
 protected:
+  virtual void r_mark_geom_bounds_stale(Thread *current_thread);
   virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
                                        int &internal_vertices,
                                        int pipeline_stage,

+ 23 - 0
panda/src/pgraph/pandaNode.cxx

@@ -2641,6 +2641,29 @@ force_bounds_stale(int pipeline_stage, Thread *current_thread) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PandaNode::r_mark_geom_bounds_stale
+//       Access: Protected, Virtual
+//  Description: Recursively calls Geom::mark_bounds_stale() on every
+//               Geom at this node and below.
+////////////////////////////////////////////////////////////////////
+void PandaNode::
+r_mark_geom_bounds_stale(Thread *current_thread) {
+  Children children = get_children(current_thread);
+
+  int i;
+  for (i = 0; i < children.get_num_children(); i++) {
+    PandaNode *child = children.get_child(i);
+    child->r_mark_geom_bounds_stale(current_thread);
+  }
+
+  Stashed stashed = get_stashed(current_thread);
+  for (i = 0; i < stashed.get_num_stashed(); i++) {
+    PandaNode *child = stashed.get_stashed(i);
+    child->r_mark_geom_bounds_stale(current_thread);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaNode::compute_internal_bounds
 //       Access: Protected, Virtual

+ 2 - 0
panda/src/pgraph/pandaNode.h

@@ -308,6 +308,8 @@ protected:
   void force_bounds_stale(int pipeline_stage, Thread *current_thread);
   INLINE void mark_internal_bounds_stale(int pipeline_stage, Thread *current_thread);
 
+  virtual void r_mark_geom_bounds_stale(Thread *current_thread);
+
   virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
                                        int &internal_vertices,
                                        int pipeline_stage,