Blame view

ios/cocos2d/cocos/3d/CCMeshSkin.h 3.56 KB
520389e3   xiaoyu   接入cocos源码,编译未通过,继续修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /****************************************************************************
   Copyright (c) 2014-2016 Chukong Technologies Inc.
   Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  
   http://www.cocos2d-x.org
  
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
  
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
  
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
   ****************************************************************************/
  
  #ifndef __CCMESHSKIN_H__
  #define __CCMESHSKIN_H__
  
  #include "3d/CCBundle3DData.h"
  #include "base/CCRef.h"
  #include "base/CCVector.h"
  #include "math/CCMath.h"
  #include <vector>
  
  NS_CC_BEGIN
  
  /**
   * @addtogroup _3d
   * @{
   */
  
  class Bone3D;
  class Skeleton3D;
  
  /**
   * @brief MeshSkin, A class maintain a collection of bones that affect Mesh vertex.
   * And it is responsible for computing matrix palettes that used by skin mesh rendering.
   * @js NA
   * @lua NA
   */
  class CC_DLL MeshSkin: public Ref
  {
      friend class Mesh;
  public:
      
      /**create a new meshskin if do not want to share meshskin*/
      static MeshSkin* create(Skeleton3D* skeleton, const std::string& filename, const std::string& name);
      
      static MeshSkin* create(Skeleton3D* skeleton, const std::vector<std::string>& boneNames, const std::vector<Mat4>& invBindPose);
      
      /**get total bone count, skin bone + node bone*/
      ssize_t getBoneCount() const;
      
      /**get bone*/
      Bone3D* getBoneByIndex(unsigned int index) const;
      Bone3D* getBoneByName(const std::string& id) const;
      
      /**get bone index*/
      int getBoneIndex(Bone3D* bone) const;
      
      /**compute matrix palette used by gpu skin*/
      Vec4* getMatrixPalette();
      
      /**getSkinBoneCount() * 3*/
      ssize_t getMatrixPaletteSize() const;
  
      /**getSkinBoneCount() * 3 * sizeof(Vec4) */
      ssize_t getMatrixPaletteSizeInBytes() const;
      
      /**get root bone of the skin*/
      Bone3D* getRootBone() const;
      
  CC_CONSTRUCTOR_ACCESS:
      
      MeshSkin();
      
      ~MeshSkin();
      
      /**remove all bones*/
      void removeAllBones();
      
      /**add skin bone*/
      void addSkinBone(Bone3D* bone);
      
      /** get inverse bind pose */
      const Mat4& getInvBindPose(const Bone3D* bone);
      
  protected:
      
      Vector<Bone3D*>    _skinBones; // bones with skin
      std::vector<Mat4>  _invBindPoses; //inverse bind pose of bone
  
      Bone3D* _rootBone;
      Skeleton3D*     _skeleton; //skeleton the skin referred
      
      // Pointer to the array of palette matrices.
      // This array is passed to the vertex shader as a uniform.
      // Each 4x3 row-wise matrix is represented as 3 Vec4's.
      // The number of Vec4's is (_skinBones.size() * 3).
      std::vector<Vec4> _matrixPalette;
  };
  
  // end of 3d group
  /// @}
  
  NS_CC_END
  
  #endif // __CCSKIN_H__