Overte C++ Documentation
ModelMath.h
1 //
2 // ModelMath.h
3 // model-baker/src/model-baker
4 //
5 // Created by Sabrina Shanman on 2019/01/07.
6 // Copyright 2019 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #include <hfm/HFM.h>
13 
14 #include "BakerTypes.h"
15 
16 namespace baker {
17  template<typename T>
18  const T& safeGet(const std::vector<T>& data, size_t i) {
19  static T t;
20 
21  if (data.size() > i) {
22  return data[i];
23  } else {
24  return t;
25  }
26  }
27 
28  template<typename T>
29  const T& safeGet(const QVector<T>& data, int i) {
30  static T t;
31 
32  if (i >= 0 && data.size() > i) {
33  return data[i];
34  } else {
35  return t;
36  }
37  }
38 
39  // Returns a reference to the normal at the specified index, or nullptr if it cannot be accessed
40  using NormalAccessor = std::function<glm::vec3*(int index)>;
41 
42  // Assigns a vertex to outVertex given the lookup index
43  using VertexSetter = std::function<void(int index, glm::vec3& outVertex)>;
44 
45  void calculateNormals(const hfm::Mesh& mesh, NormalAccessor normalAccessor, VertexSetter vertexAccessor);
46 
47  // firstIndex, secondIndex: the vertex indices to be used for calculation
48  // outVertices: should be assigned a 2 element array containing the vertices at firstIndex and secondIndex
49  // outTexCoords: same as outVertices but for texture coordinates
50  // outNormal: reference to the normal of this triangle
51  //
52  // Return value: pointer to the tangent you want to be calculated
53  using IndexAccessor = std::function<glm::vec3*(int firstIndex, int secondIndex, glm::vec3* outVertices, glm::vec2* outTexCoords, glm::vec3& outNormal)>;
54 
55  void calculateTangents(const hfm::Mesh& mesh, IndexAccessor accessor);
56 };
A single mesh (with optional blendshapes).
Definition: HFM.h:239