GteSkinController.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <LowLevel/GteArray2.h>
11 #include <Graphics/GteController.h>
13 #include <Mathematics/GteVector4.h>
14 #include <functional>
15 #include <memory>
16 
17 namespace gte
18 {
19 
20 class Node;
21 
23 {
24 public:
25  // Construction and destruction. The numbers of vertices and bones are
26  // fixed for the lifetime of the object. The controlled object must
27  // have a vertex buffer with 'numVertices' elements, with 3D (x,y,z) or
28  // 4D (x,y,z,1) positions, and the bind of positions is in unit 0. The
29  // post-update function is used to allow a graphics engine object to copy
30  // the modified vertex buffer to graphics memory.
31  typedef std::function<void(std::shared_ptr<VertexBuffer> const&)> Updater;
32  virtual ~SkinController();
33  SkinController(int numVertices, int numBones, Updater const& postUpdate);
34 
35  // Member access. After calling the constructor, you must set the data
36  // using these functions. The bone array uses weak pointers to avoid
37  // reference-count cycles in the scene graph.
38  inline int GetNumVertices() const;
39  inline int GetNumBones() const;
40  inline std::vector<std::weak_ptr<Node>>& GetBones();
41  inline Array2<float>& GetWeights();
42  inline Array2<Vector4<float>>& GetOffsets();
43 
44  // The animation update. The application time is in milliseconds.
45  virtual bool Update(double applicationTime);
46 
47 protected:
48  // On the first call to Update(...), the position channel and stride
49  // are extracted from mObject's vertex buffer. This is a deferred
50  // construction, because we do not know mObject when SkinController
51  // is constructed.
52  void OnFirstUpdate();
53 
54  int mNumVertices; // nv
55  int mNumBones; // nb
56  std::vector<std::weak_ptr<Node>> mBones; // bones[nb]
57  Array2<float> mWeights; // weight[nv][nb], index b+nb*v
58  Array2<Vector4<float>> mOffsets; // offset[nv][nb], index b+nb*v
60  char* mPosition;
61  unsigned int mStride;
62  bool mFirstUpdate, mCanUpdate;
63 };
64 
65 
67 {
68  return mNumVertices;
69 }
70 
71 inline int SkinController::GetNumBones() const
72 {
73  return mNumBones;
74 }
75 
76 inline std::vector<std::weak_ptr<Node>>& SkinController::GetBones()
77 {
78  return mBones;
79 }
80 
82 {
83  return mWeights;
84 }
85 
87 {
88  return mOffsets;
89 }
90 
91 }
Array2< float > mWeights
std::vector< std::weak_ptr< Node > > mBones
Array2< Vector4< float > > & GetOffsets()
int GetNumBones() const
Array2< Vector4< float > > mOffsets
std::function< void(std::shared_ptr< VertexBuffer > const &)> Updater
std::vector< std::weak_ptr< Node > > & GetBones()
Array2< float > & GetWeights()
int GetNumVertices() const
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01