OpenSceneGraph 3.6.5
RigGeometry
Go to the documentation of this file.
1/* -*-c++-*-
2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version. The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * OpenSceneGraph Public License for more details.
13*/
14
15#ifndef OSGANIMATION_RIGGEOMETRY_H
16#define OSGANIMATION_RIGGEOMETRY_H
17
18#include <osgAnimation/Export>
19#include <osgAnimation/Skeleton>
22#include <osg/Geometry>
23
24namespace osgAnimation
25{
26 // The idea is to compute a bounding box with a factor x of the first step we compute the bounding box
28 {
29 public:
30 RigComputeBoundingBoxCallback(double factor = 2.0): _computed(false), _factor(factor) {}
31
33 osg::Drawable::ComputeBoundingBoxCallback(rhs, copyop),
34 _computed(false),
35 _factor(rhs._factor) {}
36
38
39 void reset() { _computed = false; }
40
41 virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const;
42 protected:
43 mutable bool _computed;
44 double _factor;
46 };
47
48
50 {
51 public:
52
54
56
58
59 inline void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
60 inline const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get(); }
62
63 inline const Skeleton* getSkeleton() const { return _root.get(); }
64 inline Skeleton* getSkeleton() { return _root.get(); }
65 // will be used by the update callback to init correctly the rig mesh
66 inline void setSkeleton(Skeleton* root) { _root = root; }
67
68 void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state; }
70
72
73 // set implementation of rig method
77
78 void update();
79
81
83
85
86 inline osg::Geometry* getSourceGeometry() { return _geometry.get(); }
87 inline const osg::Geometry* getSourceGeometry() const { return _geometry.get(); }
88 inline void setSourceGeometry(osg::Geometry* geometry) { _geometry = geometry; }
89
91
93 {
97 {
98 if (_root.valid())
99 return;
100 _root = dynamic_cast<osgAnimation::Skeleton*>(&node);
101 traverse(node);
102 }
103 };
104
105 protected:
106
110
115
116 };
117
118
120 {
122
124 osg::Object(org, copyop),
125 osg::Callback(org, copyop),
126 osg::DrawableUpdateCallback(org, copyop) {}
127
129
130 virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw)
131 {
132 RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
133 if(!geom)
134 return;
135 if(!geom->getSkeleton() && !geom->getParents().empty())
136 {
138 if(geom->getParents().size() > 1)
139 osg::notify(osg::WARN) << "A RigGeometry should not have multi parent ( " << geom->getName() << " )" << std::endl;
140 geom->getParents()[0]->accept(finder);
141
142 if(!finder._root.valid())
143 {
144 osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeometry ( " << geom->getName() << " )" << std::endl;
145 return;
146 }
148 geom->setSkeleton(finder._root.get());
149 }
150
151 if(!geom->getSkeleton())
152 return;
153
154 if(geom->getNeedToComputeMatrix())
156
157 if(geom->getSourceGeometry())
158 {
159 osg::Drawable::UpdateCallback * up = dynamic_cast<osg::Drawable::UpdateCallback*>(geom->getSourceGeometry()->getUpdateCallback());
160 if(up)
161 up->update(nv, geom->getSourceGeometry());
162 }
163
164 geom->update();
165 }
166 };
167}
168
169#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
@ WARN
Definition Notify:33
BoundingBoxd BoundingBox
Definition BoundingBox:257
Matrixd Matrix
Definition Matrix:27
std::ostream & notify(void)
Definition Notify:80
The osgAnimation library provides general purpose utility classes for animation.
Definition Action:34
Callback()
Definition Callback:38
DrawableUpdateCallback()
Definition Callback:300
virtual void update(osg::NodeVisitor *, osg::Drawable *)
do customized update code.
Definition Callback:315
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Pure virtual base class for drawable geometry.
Definition Drawable:89
DrawableUpdateCallback UpdateCallback
Definition Drawable:344
Callback to allow users to override the default computation of bounding volume.
Definition Drawable:162
ComputeBoundingBoxCallback()
Definition Drawable:163
Definition Geometry:31
const ParentList & getParents() const
Get the parent list of node.
Definition Node:173
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
@ TRAVERSE_PARENTS
Definition NodeVisitor:88
void traverse(Node &node)
Method for handling traversal of a nodes.
Definition NodeVisitor:274
NodeVisitor(TraversalMode tm=TRAVERSE_NONE)
Object()
Construct an object.
Definition Object:69
const std::string & getName() const
Get the name of object.
Definition Object:213
Smart pointer for observed objects, that automatically set pointers to them to null when they are del...
Definition observer_ptr:39
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
void reset()
Definition RigGeometry:39
RigComputeBoundingBoxCallback(double factor=2.0)
Definition RigGeometry:30
META_Object(osgAnimation, RigComputeBoundingBoxCallback)
virtual osg::BoundingBox computeBound(const osg::Drawable &drawable) const
RigComputeBoundingBoxCallback(const RigComputeBoundingBoxCallback &rhs, const osg::CopyOp &copyop)
Definition RigGeometry:32
double _factor
Definition RigGeometry:44
osg::BoundingBox _boundingBox
Definition RigGeometry:45
bool _computed
Definition RigGeometry:43
Definition RigGeometry:50
osg::Geometry * getSourceGeometry()
Definition RigGeometry:86
osg::ref_ptr< osg::Geometry > _geometry
Definition RigGeometry:107
osg::observer_ptr< Skeleton > _root
Definition RigGeometry:113
META_Object(osgAnimation, RigGeometry)
osg::Matrix _invMatrixFromSkeletonToGeometry
Definition RigGeometry:112
void copyFrom(osg::Geometry &from)
void setNeedToComputeMatrix(bool state)
Definition RigGeometry:68
osg::Matrix _matrixFromSkeletonToGeometry
Definition RigGeometry:111
void buildVertexInfluenceSet()
Definition RigGeometry:80
const Skeleton * getSkeleton() const
Definition RigGeometry:63
void setInfluenceMap(VertexInfluenceMap *vertexInfluenceMap)
Definition RigGeometry:59
osg::ref_ptr< RigTransform > _rigTransformImplementation
Definition RigGeometry:108
VertexInfluenceMap * getInfluenceMap()
Definition RigGeometry:61
Skeleton * getSkeleton()
Definition RigGeometry:64
const osg::Matrix & getMatrixFromSkeletonToGeometry() const
osg::ref_ptr< VertexInfluenceMap > _vertexInfluenceMap
Definition RigGeometry:109
bool _needToComputeMatrix
Definition RigGeometry:114
RigTransform * getRigTransformImplementation()
Definition RigGeometry:74
void setSkeleton(Skeleton *root)
Definition RigGeometry:66
const osg::Geometry * getSourceGeometry() const
Definition RigGeometry:87
bool getNeedToComputeMatrix() const
Definition RigGeometry:69
const osg::Matrix & getInvMatrixFromSkeletonToGeometry() const
void setSourceGeometry(osg::Geometry *geometry)
Definition RigGeometry:88
const RigTransform * getRigTransformImplementation() const
Definition RigGeometry:76
const VertexInfluenceMap * getInfluenceMap() const
Definition RigGeometry:60
RigGeometry(const RigGeometry &b, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
void setRigTransformImplementation(RigTransform *rig)
Definition RigGeometry:75
osg::ref_ptr< Skeleton > _root
Definition RigGeometry:94
void apply(osg::Transform &node)
Definition RigGeometry:96
UpdateRigGeometry()
Definition RigGeometry:121
META_Object(osgAnimation, UpdateRigGeometry)
virtual void update(osg::NodeVisitor *nv, osg::Drawable *drw)
do customized update code.
Definition RigGeometry:130
UpdateRigGeometry(const UpdateRigGeometry &org, const osg::CopyOp &copyop)
Definition RigGeometry:123
Definition RigTransform:26
virtual bool prepareData(RigGeometry &)
to call manually when a skeleton is reacheable from the rig in order to prepare technic data before r...
Definition RigTransform:38
Definition Skeleton:26
Definition VertexInfluence:52
#define OSGANIMATION_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.