FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
mesh.h
Go to the documentation of this file.
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPL_MESH_H
16 #define FPL_MESH_H
17 
18 #include <vector>
19 
20 #include "fplbase/config.h" // Must come first.
21 
22 #include "fplbase/asset.h"
23 #include "fplbase/async_loader.h"
24 #include "fplbase/handles.h"
25 #include "fplbase/material.h"
26 #include "fplbase/render_state.h"
27 #include "fplbase/shader.h"
28 #include "mathfu/constants.h"
29 
30 namespace fplbase {
31 
32 /// @file
33 /// @addtogroup fplbase_mesh
34 /// @{
35 
36 class Renderer;
37 struct MeshImpl;
38 
39 /// @brief An array of these enums defines the format of vertex data.
40 enum Attribute {
41  kEND = 0, ///< @brief The array must always be terminated by one of these.
42  kPosition3f,
43  kNormal3f,
44  kTangent4f,
45  kTexCoord2f,
46  kTexCoordAlt2f, ///< @brief Second set of UVs for use with e.g. lightmaps.
47  kColor4ub,
48  kBoneIndices4ub,
49  kBoneWeights4ub,
50 };
51 
52 /// @class Mesh
53 /// @brief Abstraction for a set of indices, used for rendering.
54 ///
55 /// A mesh instance contains a VBO and one or more IBO's.
56 class Mesh : public AsyncAsset {
57  public:
58  enum Primitive {
59  kTriangles,
60  kTriangleStrip,
61  kTriangleFan,
62  kLines,
63  kPoints,
64  };
65 
66  typedef std::function<Material *(const char *filename)> MaterialLoaderFn;
67 
68  /// @brief Initialize a Mesh from a file asynchronously.
69  ///
70  /// Asynchronously create mesh from a file if filename is valid.
71  /// Otherwise, if filename is null, need to call LoadFromMemory to init
72  /// manually.
73  Mesh(const char *filename = nullptr,
74  MaterialLoaderFn material_loader_fn = nullptr,
75  Primitive primitive = kTriangles);
76 
77  /// @brief Initialize a Mesh by creating one VBO, and no IBO's.
78  Mesh(const void *vertex_data, size_t count, size_t vertex_size,
79  const Attribute *format, mathfu::vec3 *max_position = nullptr,
80  mathfu::vec3 *min_position = nullptr, Primitive primitive = kTriangles);
81 
82  ~Mesh();
83 
84  /// @brief Initialize a Mesh by creating one VBO, and no IBO's.
85  virtual void LoadFromMemory(const void *vertex_data, size_t count,
86  size_t vertex_size, const Attribute *format,
87  mathfu::vec3 *max_position = nullptr,
88  mathfu::vec3 *min_position = nullptr);
89 
90  /// @brief Loads and unpacks the Mesh from 'filename_' and 'data_'.
91  virtual void Load();
92 
93  /// @brief Creates a mesh from 'data_'.
94  virtual bool Finalize();
95 
96  /// @brief Whether this object loaded and finalized correctly. Call after
97  /// Finalize has been called (by AssetManager::TryFinalize).
98  bool IsValid();
99 
100  /// @brief Add an index buffer object to be part of this mesh
101  ///
102  /// Create one IBO to be part of this mesh. May be called more than once.
103  ///
104  /// @param indices The indices to be included in the IBO.
105  /// @param count The number of indices.
106  /// @param mat The material associated with the IBO.
107  /// @param is_32_bit Specifies that the indices are 32bit. Default 16bit.
108  /// @param primitive How the triangles are assembled from the indices.
109  void AddIndices(const void *indices, int count, Material *mat,
110  bool is_32_bit = false);
111 
112  /// @brief Set the bones used by an animated mesh.
113  ///
114  /// If mesh is animated set the transform from a bone's parent space into
115  /// the bone's local space. Optionally record the bone names, too, for
116  /// debugging.
117  /// The shader only accesses a bone if at least one vertex is weighted to it.
118  /// So, we don't have to pass every bone transform up to the shader. Instead,
119  /// we compact the bone transforms by passing only those in
120  /// shader_bone_indices.
121  ///
122  /// @param bone_transforms Array of bones to be used.
123  /// @param bone_parents Array that contains, for each bone, the index of its
124  /// parent.
125  /// @param bone_names Array containing the names of the bones.
126  /// @param num_bones The number of bones in the given array.
127  /// @param shader_bone_indices The indices of bones used by the shader.
128  /// @param num_shader_bones The number of bones in the shader bones array.
129  void SetBones(const mathfu::AffineTransform *bone_transforms,
130  const uint8_t *bone_parents, const char **bone_names,
131  size_t num_bones, const uint8_t *shader_bone_indices,
132  size_t num_shader_bones);
133 
134  /// @brief Convert bone transforms for consumption by a skinning shader.
135  ///
136  /// Vertices are stored in object space, but we need to manipulate them
137  /// in bone space, so the shader transform multiplies the inverse of the
138  /// default bone transform. See default_bone_transform_inverses_ for details.
139  ///
140  /// @param bone_transforms Array of bone transforms, in object space.
141  /// Length num_bones(). ith element represents the
142  /// tranformation of the ith skeleton bone to its
143  /// animated position.
144  /// @param shader_transforms Output array of transforms, one for each bone
145  /// that has vertices weighted to it. Bones without
146  /// any weighted vertices are pruned.
147  /// Length num_shader_bones().
148  void GatherShaderTransforms(const mathfu::AffineTransform *bone_transforms,
149  mathfu::AffineTransform *shader_transforms) const;
150 
151  /// @brief Render the mesh.
152  ///
153  /// Call to have the mesh render itself. Uniforms must have been set before
154  /// calling this. For instanced rendering, pass in a value >1 (needs OpenGL
155  /// ES 3.0 to work).
156  ///
157  /// @param renderer The renderer object to be used.
158  /// @param ignore_material Whether to ignore the meshes defined material.
159  /// @param instances The number of instances to be rendered.
160  void Render(Renderer &renderer, bool ignore_material = false,
161  size_t instances = 1);
162 
163  /// @brief Render the mesh, itself, into stereoscopic viewports.
164  /// @param renderer The renderer object to be used.
165  /// @param shader The shader object to be used.
166  /// @param viewport An array with two elements (left and right parameters) for
167  /// the viewport.
168  /// @param mvp An array with two elements (left and right parameters) for the
169  /// Model View Projection (MVP) matrix.
170  /// @param camera_position An array with two elements (left and right
171  /// parameters) for camera position.
172  /// @param ignore_material Whether to ignore the meshes defined material.
173  /// @param instances The number of instances to be rendered.
174  void RenderStereo(Renderer &renderer, const Shader *shader,
175  const Viewport *viewport, const mathfu::mat4 *mvp,
176  const mathfu::vec3 *camera_position,
177  bool ignore_material = false, size_t instances = 1);
178 
179  /// @brief Get the material associated with the IBO at the given index.
180  ///
181  /// @param i The index of the IBO.
182  /// @return Returns the material of the corresponding IBO.
183  Material *GetMaterial(int i) { return indices_[i].mat; }
184 
185  /// @brief Define the vertex buffer format.
186  ///
187  /// `format` must have length <= kMaxAttributes, including `kEND`.
188  ///
189  /// @param format Array of attributes to set the format to, delimitted with
190  /// `kEND`.
191  void set_format(const Attribute *format);
192 
193  /// @brief Renders the given vertex and index data directly.
194  ///
195  /// Renders primitives using vertex and index data directly in local memory.
196  /// This is a convenient alternative to creating a Mesh instance for small
197  /// amounts of data, or dynamic data.
198  ///
199  /// @param primitive The type of primitive to render the data as.
200  /// @param index_count The total number of indices.
201  /// @param format The vertex buffer format, following the same rules as
202  /// described in set_format().
203  /// @param vertex_size The size of an individual vertex.
204  /// @param vertices The array of vertices.
205  /// @param indices The array of indices into the vertex array.
206  static void RenderArray(Primitive primitive, int index_count,
207  const Attribute *format, int vertex_size,
208  const void *vertices, const unsigned short *indices);
209 
210  /// @brief Renders the given vertex data directly.
211  ///
212  /// Renders primitives using vertex data directly in local memory. This is a
213  /// convenient alternative to creating a Mesh instance for small amounts of
214  /// data, or dynamic data.
215  ///
216  /// @param primitive The type of primitive to render the data as.
217  /// @param vertex_count The total number of vertices.
218  /// @param format The vertex buffer format, following the same rules as
219  /// described in set_format().
220  /// @param vertex_size The size of an individual vertex.
221  /// @param vertices The array of vertices.
222  static void RenderArray(Primitive primitive, int vertex_count,
223  const Attribute *format, int vertex_size,
224  const void *vertices);
225 
226  /// @brief Convenience method for rendering a Quad.
227  ///
228  /// bottom_left and top_right must have their X coordinate be different, but
229  /// either Y or Z can be the same.
230  ///
231  /// @param bottom_left The bottom left coordinate of the Quad.
232  /// @param top_right The bottom left coordinate of the Quad.
233  /// @param tex_bottom_left The texture coordinates at the bottom left.
234  /// @param tex_top_right The texture coordinates at the top right.
235  static void RenderAAQuadAlongX(
236  const mathfu::vec3 &bottom_left, const mathfu::vec3 &top_right,
237  const mathfu::vec2 &tex_bottom_left = mathfu::vec2(0, 0),
238  const mathfu::vec2 &tex_top_right = mathfu::vec2(1, 1));
239 
240  /// @brief Convenience method for rendering a Quad with nine patch settings.
241  ///
242  /// In the patch_info, the user can define nine patch settings
243  /// as vec4(x0, y0, x1, y1) where
244  /// (x0,y0): top-left corner of stretchable area in UV coordinate.
245  /// (x1,y1): bottom-right corner of stretchable area in UV coordinate.
246  ///
247  /// @param bottom_left The bottom left coordinate of the Quad.
248  /// @param top_right The top right coordinate of the Quad.
249  /// @param texture_size The size of the texture used by the patches.
250  /// @param patch_info Defines how the patches are set up.
251  static void RenderAAQuadAlongXNinePatch(const mathfu::vec3 &bottom_left,
252  const mathfu::vec3 &top_right,
253  const mathfu::vec2i &texture_size,
254  const mathfu::vec4 &patch_info);
255 
256  /// @brief Compute normals and tangents given position and texcoords.
257  ///
258  /// The template type should be a struct with at least the following fields:
259  /// mathfu::vec3_packed pos;
260  /// mathfu::vec2_packed tc;
261  /// mathfu::vec3_packed norm;
262  /// mathfu::vec4_packed tangent;
263  ///
264  /// @param vertices The vertices to computes the information for.
265  /// @param indices The indices that make up the mesh.
266  /// @param numverts The number of vertices in the vertex array.
267  /// @param numindices The number of indices in the index array.
268  template <typename T>
269  static void ComputeNormalsTangents(T *vertices, const unsigned short *indices,
270  int numverts, int numindices) {
271  std::unique_ptr<mathfu::vec3[]> binormals(new mathfu::vec3[numverts]);
272 
273  // set all normals to 0, as we'll accumulate
274  for (int i = 0; i < numverts; i++) {
275  vertices[i].norm = mathfu::kZeros3f;
276  vertices[i].tangent = mathfu::kZeros4f;
277  binormals[i] = mathfu::kZeros3f;
278  }
279  // Go through each triangle and calculate tangent space for it, then
280  // contribute results to adjacent triangles.
281  // For a description of the math see e.g.:
282  // http://www.terathon.com/code/tangent.html
283  for (int i = 0; i < numindices; i += 3) {
284  auto &v0 = vertices[indices[i + 0]];
285  auto &v1 = vertices[indices[i + 1]];
286  auto &v2 = vertices[indices[i + 2]];
287  // The cross product of two vectors along the triangle surface from the
288  // first vertex gives us this triangle's normal.
289  auto q1 = mathfu::vec3(v1.pos) - mathfu::vec3(v0.pos);
290  auto q2 = mathfu::vec3(v2.pos) - mathfu::vec3(v0.pos);
291  auto norm = normalize(cross(q1, q2));
292  // Contribute the triangle normal into all 3 verts:
293  v0.norm = mathfu::vec3(v0.norm) + norm;
294  v1.norm = mathfu::vec3(v1.norm) + norm;
295  v2.norm = mathfu::vec3(v2.norm) + norm;
296  // Similarly create uv space vectors:
297  auto uv1 = mathfu::vec2(v1.tc) - mathfu::vec2(v0.tc);
298  auto uv2 = mathfu::vec2(v2.tc) - mathfu::vec2(v0.tc);
299  float m = 1 / (uv1.x * uv2.y - uv2.x * uv1.y);
300  auto tangent = mathfu::vec4((uv2.y * q1 - uv1.y * q2) * m, 0);
301  auto binorm = (uv1.x * q2 - uv2.x * q1) * m;
302  v0.tangent = mathfu::vec4(v0.tangent) + tangent;
303  v1.tangent = mathfu::vec4(v1.tangent) + tangent;
304  v2.tangent = mathfu::vec4(v2.tangent) + tangent;
305  binormals[indices[i + 0]] = binorm;
306  binormals[indices[i + 1]] = binorm;
307  binormals[indices[i + 2]] = binorm;
308  }
309  // Normalize per vertex tangent space constributions, and pack tangent /
310  // binormal into a 4 component tangent.
311  for (int i = 0; i < numverts; i++) {
312  auto norm = mathfu::vec3(vertices[i].norm);
313  auto tangent = mathfu::vec4(vertices[i].tangent);
314  // Renormalize all 3 axes:
315  norm = normalize(norm);
316  tangent = mathfu::vec4(normalize(tangent.xyz()), 0);
317  binormals[i] = normalize(binormals[i]);
318  tangent = mathfu::vec4(
319  // Gram-Schmidt orthogonalize xyz components:
320  normalize(tangent.xyz() - norm * dot(norm, tangent.xyz())),
321  // The w component is the handedness, set as difference between the
322  // binormal we computed from the texture coordinates and that from the
323  // cross-product:
324  dot(cross(norm, tangent.xyz()), binormals[i]));
325  vertices[i].norm = norm;
326  vertices[i].tangent = tangent;
327  }
328  }
329 
330  enum {
331  kAttributePosition,
332  kAttributeNormal,
333  kAttributeTangent,
334  kAttributeTexCoord,
335  kAttributeTexCoordAlt,
336  kAttributeColor,
337  kAttributeBoneIndices,
338  kAttributeBoneWeights,
339  };
340 
341  /// @brief Compute the byte size for a vertex from given attributes.
342  ///
343  /// @param attributes The array of attributes describing the vertex.
344  /// @param end The attribute to treat as the end of the array.
345  /// @return Returns the byte size based on the given attributes.
346  static size_t VertexSize(const Attribute *attributes, Attribute end = kEND);
347 
348  /// @brief Get the minimum position of an AABB about the mesh.
349  ///
350  /// @return Returns the minimum position of the mesh.
351  const mathfu::vec3 &min_position() const { return min_position_; }
352  /// @brief Get the maximum position of an AABB about the mesh.
353  ///
354  /// @return Returns the maximum position of the mesh.
355  const mathfu::vec3 &max_position() const { return max_position_; }
356  /// @brief The defines parents of each bone.
357  ///
358  /// @return Returns an array of indices of each bone's parent.
359  const uint8_t *bone_parents() const { return bone_parents_.data(); }
360  /// @brief Array of names for each bone.
361  ///
362  /// @return Returns the array of names for each bone, of length num_bones().
363  const std::string *bone_names() const { return bone_names_.data(); }
364  /// @brief The array of default bone transform inverses.
365  ///
366  /// @return Returns the array of default bone transform inverses.
367  const mathfu::AffineTransform *default_bone_transform_inverses() const {
368  return default_bone_transform_inverses_;
369  }
370  /// @brief The number of bones in the mesh.
371  ///
372  /// @return Returns the number of bones.
373  size_t num_bones() const { return bone_parents_.size(); }
374  /// @brief The indices of bones used by the shader.
375  ///
376  /// @return Returns an array of indices of bones used by the shader.
377  const uint8_t *shader_bone_indices() const {
378  return &shader_bone_indices_[0];
379  }
380  /// @brief The number of bones used by the shader.
381  ///
382  /// @return Returns the number of bones used by the shader.
383  size_t num_shader_bones() const { return shader_bone_indices_.size(); }
384 
385  /// @brief The number of vertices in the VBO.
386  ///
387  /// @return Returns the number of vertices in the VBO.
388  size_t num_vertices() const { return num_vertices_; }
389 
390  /// @brief The total number of indices in all IBOs.
391  ///
392  /// @return Returns the total number of indices across all IBOs.
393  size_t CalculateTotalNumberOfIndices() const;
394 
395  /// @brief Holder for data that can be turned into a mesh.
397  const void *vertex_data;
398  std::vector<uint8_t> owned_vertex_data;
399  size_t count;
400  size_t vertex_size;
401  std::vector<Attribute> format;
402  bool has_skinning;
403 
405  : vertex_data(nullptr), count(0), vertex_size(0), has_skinning(false) {}
406  };
407 
408  /// @brief: Load vertex data from a FlatBuffer into CPU memory first.
409  void ParseInterleavedVertexData(const void *meshdef_buffer,
410  InterleavedVertexData *ivd);
411 
412  MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
413 
414  private:
415  // Disallow copies because of pointers bone_transforms_ and
416  // bone_global_transforms_. Feel free to implement copy or move operators
417  // if required.
418  Mesh(const Mesh &);
419  Mesh &operator=(const Mesh &);
420 
421  // Free all resources in the platform-independent data (i.e. everything
422  // outside of the impl_ class). Implemented in mesh_common.cc.
423  void Clear();
424 
425  // Free all resources in the platform-dependent data (i.e. everything in the
426  // impl_ class). Implemented in platform-dependent code.
427  void ClearPlatformDependent();
428 
429  // Init mesh from MeshDef FlatBuffer.
430  bool InitFromMeshDef(const void *meshdef_buffer);
431 
432  // Backend-specific create and destroy calls. These just call new and delete
433  // on the platform-specific MeshImpl structs.
434  static MeshImpl *CreateMeshImpl();
435  static void DestroyMeshImpl(MeshImpl *impl);
436 
437  // Backend-specific way to get underlying primitive flag.
438  static uint32_t GetPrimitiveTypeFlags(Mesh::Primitive primitive);
439 
440  static const int kMaxAttributes = 9;
441 
442  struct Indices {
443  Indices()
444  : count(0),
445  ibo(InvalidBufferHandle()),
446  mat(nullptr),
447  index_type(0),
448  indexBufferMem(InvalidDeviceMemoryHandle()) {}
449  int count;
450  BufferHandle ibo;
451  Material *mat;
452  uint32_t index_type;
453  DeviceMemoryHandle indexBufferMem;
454  };
455 
456  MeshImpl *impl_;
457  std::vector<Indices> indices_;
458  uint32_t primitive_;
459  size_t vertex_size_;
460  size_t num_vertices_;
461  Attribute format_[kMaxAttributes];
462  mathfu::vec3 min_position_;
463  mathfu::vec3 max_position_;
464 
465  // The default bone positions, in object space, inverted. Length NumBones().
466  // Used when skinning.
467  //
468  // The vertex transform is,
469  //
470  // mvp * bone_transforms_[i] * default_bone_transform_inverses_[i]
471  //
472  // where bone_transforms_[i] is the placement of bone i relative to
473  // the root of the object. So, when the bone is in its default position,
474  // bone_transforms_[i] * default_bone_transform_inverses_[i] = Identity
475  // which makes sense.
476  //
477  // How to think of this: default_bone_transform_inverses_[i] maps the
478  // vertex from object space into bone space. That is, it gives the
479  // coordinates of the vertex relative to bone i. Then bone_transforms_[i]
480  // maps the bone back into object space, in its animated location.
481  //
482  // Note that vector<AffineTransform> is not possible on Visual Studio 2010
483  // because it doesn't support vectors of aligned types, so we use a raw
484  // pointer instead.
485  mathfu::AffineTransform *default_bone_transform_inverses_;
486  std::vector<uint8_t> bone_parents_;
487  std::vector<std::string> bone_names_;
488  std::vector<uint8_t> shader_bone_indices_;
489 
490  // Function to load material by filename.
491  MaterialLoaderFn material_loader_fn_;
492 };
493 
494 /// @}
495 } // namespace fplbase
496 
497 #endif // FPL_MESH_H
const mathfu::vec3 & min_position() const
Get the minimum position of an AABB about the mesh.
Definition: mesh.h:351
static void RenderAAQuadAlongX(const mathfu::vec3 &bottom_left, const mathfu::vec3 &top_right, const mathfu::vec2 &tex_bottom_left=mathfu::vec2(0, 0), const mathfu::vec2 &tex_top_right=mathfu::vec2(1, 1))
Convenience method for rendering a Quad.
size_t num_bones() const
The number of bones in the mesh.
Definition: mesh.h:373
void RenderStereo(Renderer &renderer, const Shader *shader, const Viewport *viewport, const mathfu::mat4 *mvp, const mathfu::vec3 *camera_position, bool ignore_material=false, size_t instances=1)
Render the mesh, itself, into stereoscopic viewports.
const std::string * bone_names() const
Array of names for each bone.
Definition: mesh.h:363
The array must always be terminated by one of these.
Definition: mesh.h:41
void GatherShaderTransforms(const mathfu::AffineTransform *bone_transforms, mathfu::AffineTransform *shader_transforms) const
Convert bone transforms for consumption by a skinning shader.
Attribute
An array of these enums defines the format of vertex data.
Definition: mesh.h:40
size_t CalculateTotalNumberOfIndices() const
The total number of indices in all IBOs.
void AddIndices(const void *indices, int count, Material *mat, bool is_32_bit=false)
Add an index buffer object to be part of this mesh.
const mathfu::AffineTransform * default_bone_transform_inverses() const
The array of default bone transform inverses.
Definition: mesh.h:367
size_t num_shader_bones() const
The number of bones used by the shader.
Definition: mesh.h:383
void set_format(const Attribute *format)
Define the vertex buffer format.
Abstraction for a set of indices, used for rendering.
Definition: mesh.h:56
Represents a shader consisting of a vertex and pixel shader.
Definition: shader.h:42
const std::string & filename() const
The name of the file associated with the resource.
Definition: async_loader.h:107
Mesh(const char *filename=nullptr, MaterialLoaderFn material_loader_fn=nullptr, Primitive primitive=kTriangles)
Initialize a Mesh from a file asynchronously.
const mathfu::vec3 & max_position() const
Get the maximum position of an AABB about the mesh.
Definition: mesh.h:355
Collections of textures used for rendering multi-texture models.
Definition: material.h:37
Second set of UVs for use with e.g. lightmaps.
Definition: mesh.h:46
virtual void Load()
Loads and unpacks the Mesh from 'filename_' and 'data_'.
size_t num_vertices() const
The number of vertices in the VBO.
Definition: mesh.h:388
static void ComputeNormalsTangents(T *vertices, const unsigned short *indices, int numverts, int numindices)
Compute normals and tangents given position and texcoords.
Definition: mesh.h:269
void Render(Renderer &renderer, bool ignore_material=false, size_t instances=1)
Render the mesh.
Material * GetMaterial(int i)
Get the material associated with the IBO at the given index.
Definition: mesh.h:183
void ParseInterleavedVertexData(const void *meshdef_buffer, InterleavedVertexData *ivd)
: Load vertex data from a FlatBuffer into CPU memory first.
static void RenderAAQuadAlongXNinePatch(const mathfu::vec3 &bottom_left, const mathfu::vec3 &top_right, const mathfu::vec2i &texture_size, const mathfu::vec4 &patch_info)
Convenience method for rendering a Quad with nine patch settings.
const uint8_t * shader_bone_indices() const
The indices of bones used by the shader.
Definition: mesh.h:377
virtual void LoadFromMemory(const void *vertex_data, size_t count, size_t vertex_size, const Attribute *format, mathfu::vec3 *max_position=nullptr, mathfu::vec3 *min_position=nullptr)
Initialize a Mesh by creating one VBO, and no IBO's.
void SetBones(const mathfu::AffineTransform *bone_transforms, const uint8_t *bone_parents, const char **bone_names, size_t num_bones, const uint8_t *shader_bone_indices, size_t num_shader_bones)
Set the bones used by an animated mesh.
mathfu::recti Viewport
Specifies the region of the surface to be used for rendering.
Definition: renderer_common.h:23
Holder for data that can be turned into a mesh.
Definition: mesh.h:396
const uint8_t * bone_parents() const
The defines parents of each bone.
Definition: mesh.h:359
static void RenderArray(Primitive primitive, int index_count, const Attribute *format, int vertex_size, const void *vertices, const unsigned short *indices)
Renders the given vertex and index data directly.
Renderer is the main API class for rendering commands.
Definition: renderer.h:310
bool IsValid()
Whether this object loaded and finalized correctly. Call after Finalize has been called (by AssetMana...
static size_t VertexSize(const Attribute *attributes, Attribute end=kEND)
Compute the byte size for a vertex from given attributes.
Definition: handles.h:24
Definition: async_loader.h:48
virtual bool Finalize()
Creates a mesh from 'data_'.