AnimEngine
GltfDataViewer.h
1 #pragma once
2 #ifndef GLTF_DATA_VIEWER_HAS_BEEN_INCLUDED_
3 #define GLTF_DATA_VIEWER_HAS_BEEN_INCLUDED_
4 
5 #include "GltfCommon.h"
6 #include <algorithm>
7 
8 namespace gltf{
9 
10 template <typename ResultT, typename ElemT = ResultT>
12 {
13  public:
14  virtual const ResultT operator[](size_t aIndex) const = 0;
15  virtual const ResultT at(size_t aIndex) const = 0;
16 
17  virtual const gltf::TypePair& internalTypeInfo() const noexcept = 0;
18 
19  inline size_t size() const noexcept {return(mSize);}
20 
21  protected:
22  size_t mSize = 0;
23 };
24 
25 // Hide implementation within internal namespace
26 namespace _internal{
27 
28 template <typename ResultT, typename ElemT, gltf::DataType T_dataType, gltf::ComponentType T_compType>
30 {
31  public:
32  GltfDataAdaptorInternalImplementation(const gltf::DataAccessBundle& aDataAccBundle, int aSkipStride = -1)
33  : mDataAccBundle(aDataAccBundle), mSkipStride(aSkipStride)
34  {
35  GltfDataAdaptorInterface<ResultT, ElemT>::mSize = mDataAccBundle.accessor.count;
36  }
37 
38  virtual const ResultT operator[](size_t aIndex) const override;
39  virtual const ResultT at(size_t aIndex) const override;
40  virtual const gltf::TypePair& internalTypeInfo() const noexcept override {return(mTypeInfo);}
41 
42  protected:
43 
44  const gltf::TypePair mTypeInfo = {T_dataType, T_compType};
45 
46  DataAccessBundle mDataAccBundle;
47 
48  int mSkipStride = -1; // Optional skip stride used when it's desirable to skip over a number of elements on each access.
49 };
50 
52 template <typename ResultT, typename ElemT = std::false_type>
53 GltfDataAdaptorInterface<ResultT, ElemT>* get_adaptor_implementation(const gltf::DataAccessBundle& aDataAccBundle, int aSkipStride = -1);
54 
55 } // end namespace gltf::_internal
56 
57 template <typename ResultT, typename ElemT = ResultT>
58 class GltfDataAdaptor : virtual public GltfDataAdaptorInterface<ResultT, ElemT>
59 {
60  public:
61 
62  using result_t = ResultT;
63  using element_t = ElemT;
64 
65  GltfDataAdaptor(){}
66  GltfDataAdaptor(const gltf::DataAccessBundle& aDataAccBundle, int aSkipStride = -1);
67 
68  bool isValid() const noexcept {return(_mInternalAdaptor != nullptr);}
69 
70  virtual const ResultT operator[](size_t aIndex) const override {
71  return(_mInternalAdaptor->operator[](aIndex));
72  }
73  virtual const ResultT at(size_t aIndex) const override {
74  return(_mInternalAdaptor->at(aIndex));
75  }
76  virtual const gltf::TypePair& internalTypeInfo() const noexcept override {
77  return(_mInternalAdaptor->internalTypeInfo());
78  }
79 
80  void fillVector(std::vector<ResultT>& aOutVector){
81  size_t size = _mInternalAdaptor->size();
82  aOutVector.reserve(size);
83  for(size_t idx = 0; idx < size; ++idx){
84  aOutVector.emplace_back(operator[](idx));
85  }
86  }
87 
88  protected:
89 
91  _mInternalAdaptor = aAdaptorInterface;
92  if(_mInternalAdaptor != nullptr) GltfDataAdaptorInterface<ResultT, ElemT>::mSize = _mInternalAdaptor->size();
93  }
94 
95  std::shared_ptr<GltfDataAdaptorInterface<ResultT, ElemT>> _mInternalAdaptor = nullptr;
96 };
97 
98 } // end namespace gltf
99 
100 #include "GltfDataViewer.inl"
101 
102 
103 #endif
Definition: GltfDataViewer.h:11
Definition: GltfCommon.h:58
Definition: GltfCommon.h:15
Definition: GltfDataViewer.h:58
Definition: GltfCommon.h:24