Blame view

ios/cocos2d/cocos/3d/CCMeshVertexIndexData.h 5.11 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  /****************************************************************************
   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.
   ****************************************************************************/
  #pragma once
  
  #include <string>
  #include <vector>
  
  #include "3d/CCBundle3DData.h"
  #include "3d/CCAABB.h"
  #include "3d/CC3DProgramInfo.h"
  
  #include "base/CCRef.h"
  #include "base/CCVector.h"
  #include "math/CCMath.h"
  #include "renderer/CCMeshCommand.h"
  
  
  NS_CC_BEGIN
  
  /**
   * @addtogroup _3d
   * @{
   */
  
  class MeshVertexData;
  
  /**
   * the MeshIndexData class.
   * @brief the MeshIndexData contain all of the indices data which mesh need.
   * @js NA
   * @lua NA
   */
  class CC_DLL MeshIndexData : public Ref
  {
  public:
      /** create  */
      static MeshIndexData* create(const std::string& id, MeshVertexData* vertexData, backend::Buffer* indexbuffer, const AABB& aabb);
      
      /**get index buffer*/
      backend::Buffer* getIndexBuffer() const { return _indexBuffer; }
  
      /**get vertex buffer*/
      backend::Buffer* getVertexBuffer() const;
      
      /**get vertex data*/
      const MeshVertexData* getMeshVertexData() const { return _vertexData; }
      
      /** aabb getter and setter */
      void setAABB(const AABB& aabb) { _aabb = aabb; }
      const AABB& getAABB() const { return _aabb; }
      
      /** id setter and getter */
      void setId(const std::string& id) { _id = id; }
      const std::string& getId() const { return _id; }
      
      /**primitive type setter & getter*/
      MeshCommand::PrimitiveType getPrimitiveType() const { return _primitiveType; }
      void   setPrimitiveType(MeshCommand::PrimitiveType primitive) { _primitiveType = primitive; }
      
      void setIndexData(const MeshData::IndexArray& indexdata);
      
  CC_CONSTRUCTOR_ACCESS:
      MeshIndexData();
      virtual ~MeshIndexData();
      
  protected:
      backend::Buffer*    _indexBuffer = nullptr; //index buffer
      MeshVertexData*     _vertexData = nullptr; //vertex buffer, weak ref
      AABB                _aabb; // original aabb of the submesh
      std::string         _id; //id
      MeshCommand::PrimitiveType   _primitiveType = MeshCommand::PrimitiveType::TRIANGLE;
      MeshData::IndexArray _indexData;
  
      friend class MeshVertexData;
      friend class Sprite3D;
  #if CC_ENABLE_CACHE_TEXTURE_DATA
      EventListenerCustom* _backToForegroundListener = nullptr;
  #endif
  };
  
  /**
   * the MeshVertexData class.
   * @brief the MeshVertexData contain all of the vertices data which mesh need.
   */
  class CC_DLL MeshVertexData : public Ref
  {
      friend class Sprite3D;
      friend class Mesh;
  public:
      /**create*/
      static MeshVertexData* create(const MeshData& meshdata);
      
      /** get vertexbuffer */
      backend::Buffer* getVertexBuffer() const { return _vertexBuffer; }
      
      /** get attributes count */
      ssize_t getMeshVertexAttribCount() const { return _attribs.size(); }
      
      /** get attribute by index */
      const MeshVertexAttrib& getMeshVertexAttrib(ssize_t index) const { return _attribs[index]; }
      
      /** get index data count */
      ssize_t getMeshIndexDataCount() const { return _indexs.size(); }
      /** get index data by index */
      MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indexs.at(index); }
      /** get index data by id */
      MeshIndexData* getMeshIndexDataById(const std::string& id) const;
      
      ssize_t getSizePerVertex() const { return _sizePerVertex; }
  
      /**has vertex attribute?*/
      //TODO: will be removed!
      bool hasVertexAttrib(shaderinfos::VertexKey attrib) const;
  
      void setVertexData(const std::vector<float> &vertexData);
      
  CC_CONSTRUCTOR_ACCESS:
      MeshVertexData();
      virtual ~MeshVertexData();
  
  protected:
      
      backend::Buffer* _vertexBuffer = nullptr; // vertex buffer
      ssize_t  _sizePerVertex = -1;
      Vector<MeshIndexData*> _indexs; //index data
      std::vector<MeshVertexAttrib> _attribs; //vertex attributes
      
      int _vertexCount = 0; //vertex count
      std::vector<float> _vertexData;
  #if CC_ENABLE_CACHE_TEXTURE_DATA
      EventListenerCustom* _backToForegroundListener = nullptr;
  #endif
  };
  
  // end of 3d group
  /// @}
  
  NS_CC_END