Kanzi Graphics Engine
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
kzu_mesh.h File Reference

Mesh. More...

Enumerations

enum  KzuMeshVertexAttributeSemantic {
  KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_POSITION, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_NORMAL, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_TANGENT, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_TEXTURE_COORDINATE,
  KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_COLOR, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_WEIGHT, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_MATRIX_PALETTE, KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_CUSTOM
}
 Vertex attribute semantic. More...
 
enum  KzuMeshVertexAttributeDataType {
  KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S8, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U8, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S16, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U16,
  KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S32, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U32, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_FLOAT16, KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_FLOAT32
}
 Vertex attribute data type. More...
 

Functions

kzsError kzuMeshCreate (const struct KzuResourceManager *resourceManager, kzString name, struct KzuResourceLoader *loader, struct KzuMesh **out_mesh)
 Creates a mesh that loads the data when needed using the given resource loader. More...
 
kzsError kzuMeshRegisterToFactory (const struct KzuFactory *factory)
 Registers mesh node type to factory. More...
 
kzsError kzuMeshCreateFromMemory (const struct KzuResourceManager *resourceManager, kzString name, kzUint vertexAttributeCount, const kzString *vertexAttributeNames, const enum KzuMeshVertexAttributeSemantic *vertexAttributeSemantics, const enum KzuMeshVertexAttributeDataType *vertexAttributeDataTypes, const kzUint *vertexAttributeDimensions, kzUint vertexCount, const kzByte *vertexData, kzUint clusterCount, const kzUint *clusterIndexCounts, const kzU16 *const *clusterIndices, const enum KzcPrimitiveType *clusterTypes, struct KzuMaterial *const *clusterMaterials, struct KzuMesh **out_mesh)
 Creates a mesh directly from the given data. More...
 
kzsError kzuMeshCreateSphere (const struct KzuResourceManager *resourceManager, kzString name, kzFloat radius, kzUint segmentCount, kzUint rowCount, struct KzuMaterial *material, struct KzuMesh **out_mesh)
 Creates a sphere mesh. More...
 
kzsError kzuMeshCreateBox (const struct KzuResourceManager *resourceManager, kzString name, kzFloat width, kzFloat height, kzFloat depth, struct KzuMaterial *material, struct KzuMesh **out_mesh)
 Creates a box mesh. More...
 
kzsError kzuMeshCreateCopy (const struct KzuResourceManager *resourceManager, kzString name, const struct KzuMesh *sourceMesh, struct KzuMesh **out_mesh)
 Creates a copy of an existing mesh. More...
 
kzsError kzuMeshInitializeFromMemory (struct KzuMesh *mesh, kzUint vertexAttributeCount, const kzString *vertexAttributeNames, const enum KzuMeshVertexAttributeSemantic *vertexAttributeSemantics, const enum KzuMeshVertexAttributeDataType *vertexAttributeDataTypes, const kzUint *vertexAttributeDimensions, kzUint vertexCount, const kzByte *vertexData, kzUint clusterCount, const kzUint *clusterIndexCounts, const kzU16 *const *clusterIndices, const enum KzcPrimitiveType *clusterTypes, struct KzuMaterial *const *clusterMaterials)
 Initializes a mesh with the given data. More...
 
struct KzuGPUResourcekzuMeshToGPUResource (const struct KzuMesh *mesh)
 Converts mesh to GPU resource. More...
 
struct KzuMeshkzuMeshFromGPUResource (const struct KzuGPUResource *gpuResource)
 Converts GPU resource to mesh. More...
 
struct KzuResourcekzuMeshToResource (const struct KzuMesh *mesh)
 Converts mesh to resource. More...
 
struct KzuMeshkzuMeshFromResource (const struct KzuResource *resource)
 Converts resource to mesh. More...
 
struct KzuMeshkzuMeshCastFromResource (const struct KzuResource *resource)
 Casts mesh from resource, KZ_NULL if invalid type. More...
 
kzBool kzuMeshIsRenderable (const struct KzuMesh *mesh)
 Returns true if the mesh is deployed and valid. More...
 
kzsError kzuMeshBind (const struct KzuMesh *mesh, kzUint clusterIndex, const struct KzuShader *shader)
 Binds a cluster of the mesh for rendering. More...
 
kzsError kzuMeshUnbind (struct KzuMesh *mesh, const struct KzuShader *shader)
 Unbinds the mesh from rendering. More...
 
kzsError kzuMeshGetBoundingVolume (const struct KzuMesh *mesh, struct KzuBoundingVolume **out_boundingVolume)
 Gets bounding volume from mesh. More...
 
kzUint kzuMeshGetVertexCount (const struct KzuMesh *mesh)
 Gets the number of vertices in a mesh. More...
 
kzUint kzuMeshGetVertexAttributeCount (const struct KzuMesh *mesh)
 Returns the number of vertex attribute in a mesh. More...
 
kzsError kzuMeshGetVertexAttributeInfo (const struct KzuMesh *mesh, kzUint index, kzString *out_name, enum KzuMeshVertexAttributeSemantic *out_semantic, enum KzuMeshVertexAttributeDataType *out_dataType, kzUint *out_dimension, kzUint *out_offset, kzUint *out_size)
 Returns information about a vertex attribute with the given index. More...
 
kzUint kzuMeshGetVertexSize (const struct KzuMesh *mesh)
 Returns the data size of a single vertex. More...
 
const kzBytekzuMeshGetVertexData (const struct KzuMesh *mesh)
 Returns the vertex data of the mesh. More...
 
kzUint kzuMeshGetClusterCount (const struct KzuMesh *mesh)
 Gets the number of clusters in the mesh. More...
 
kzUint kzuMeshGetIndexCount (const struct KzuMesh *mesh, kzUint clusterIndex)
 Gets the number of indices of a given cluster in a mesh. More...
 
const kzU16kzuMeshGetIndices (const struct KzuMesh *mesh, kzUint clusterIndex)
 Returns the index data of a given cluster in a mesh. More...
 
enum KzcPrimitiveType kzuMeshGetClusterType (const struct KzuMesh *mesh, kzUint clusterIndex)
 Returns the cluster type of a given cluster in a mesh. More...
 
struct KzuMaterialkzuMeshGetMaterial (const struct KzuMesh *mesh, kzUint clusterIndex)
 Gets the material of a given cluster in a mesh. More...
 
kzsError kzuMeshSetMaterial (const struct KzuMesh *mesh, kzUint clusterIndex, struct KzuMaterial *material)
 Sets the material of a given cluster in a mesh. More...
 
kzsError kzuMeshApplyMorph (struct KzuMesh *mesh, const struct KzcMemoryManager *quickMemoryManager)
 Applies morphing by calculating dynamic vertex attributes based on morph properties. More...
 
kzsError kzuMeshApplySkeleton (const struct KzuMesh *mesh, const struct KzuObjectNode *baseNode, const struct KzcMemoryManager *quickMemoryManager, const struct KzcDynamicArray *transformedObjectList)
 Applies mesh skeleton (bones). More...
 
kzsError kzuMeshUpdateBoundingBox (const struct KzuMesh *mesh, struct KzuObjectNode *baseNode, const struct KzcDynamicArray *transformedObjectList, kzBool *out_isSkinned)
 Updates the bounding box of a mesh based on the mesh skeleton and current pose. More...
 
kzUint kzuMeshGetBoneCount (const struct KzuMesh *mesh)
 Returns the number of bones in a mesh skeleton. More...
 
struct KzuObjectNodekzuMeshGetBoneNode (const struct KzuMesh *mesh, kzUint boneIndex)
 Returns the bone node of a given bone in a mesh skeleton. More...
 
struct KzuObjectNodekzuMeshGetBoneChildJoint (const struct KzuMesh *mesh, kzUint boneIndex)
 Returns the child joint node of a given bone in a mesh skeleton. More...
 
kzsError kzuMeshAttach (struct KzuMesh *mesh, struct KzuObjectNode *baseNode)
 Attach bone node for the mesh. More...
 
kzsError kzuMeshDetach (const struct KzuMesh *mesh)
 Detach bone node for the mesh. More...
 
void kzuMeshSetPropertyManager (struct KzuMesh *mesh, struct KzuPropertyManager *propertyManager)
 Sets the property manager of the mesh. More...
 
kzsError kzuMeshGetMappedShaders (const struct KzuMesh *mesh, struct KzcDynamicArray **out_mappedShaders)
 Returns array of shaders having attribute mappings in this mesh. More...
 
kzsError kzuMeshRemoveAttributeMappingForShader (const struct KzuMesh *mesh, const struct KzuShader *shader)
 Removes attribute mapping for the shader. More...
 
kzsError kzuMeshReplaceAttributeMappingForShader (const struct KzuMesh *mesh, const struct KzuShader *shader, const struct KzuShader *newShader)
 Replaces attribute mapping for the shader. More...
 
kzsError kzuMeshSetAttributeMapping (const struct KzuMesh *mesh, const struct KzuShader *shader, kzString shaderAttribute, const struct KzuMesh *targetMesh, kzUint attributeIndex)
 Sets attribute mapping for the shader attribute. More...
 
kzBool kzuMeshGetAttributeMapping (const struct KzuMesh *mesh, const struct KzuShader *shader, kzString shaderAttribute, const struct KzuMesh **out_targetMesh, kzUint *out_attributeIndex)
 Gets attribute mapping for shader attribute. More...
 
kzsError kzuMeshRemoveAttributeMapping (const struct KzuMesh *mesh, const struct KzuShader *shader, kzString shaderAttribute)
 Removes attribute mapping for shader attribute. More...
 

Variables

const KzuResourceType KZU_RESOURCE_TYPE_MESH
 Resource type identifier for mesh. More...
 

Detailed Description

Mesh.

Copyright 2008-2019 by Rightware. All rights reserved.

Enumeration Type Documentation

Vertex attribute semantic.

This specifies the meaning of a vertex attribute.

Enumerator
KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_POSITION 

Position vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_NORMAL 

Normal vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_TANGENT 

Tangent vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_TEXTURE_COORDINATE 

Texture coordinate vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_COLOR 

Color vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_WEIGHT 

Weight vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_MATRIX_PALETTE 

Matrix palette vertex attribute semantic.

KZU_MESH_VERTEX_ATTRIBUTE_SEMANTIC_CUSTOM 

Custom vertex attribute semantic.

Vertex attribute data type.

Enumerator
KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S8 

Signed 8-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U8 

Unsigned 8-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S16 

Signed 16-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U16 

Unigned 16-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_S32 

Signed 32-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_U32 

Unsigned 32-bit integer data type.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_FLOAT16 

16-bit floating point data type.

Not supported by all hardware.

KZU_MESH_VERTEX_ATTRIBUTE_DATA_TYPE_FLOAT32 

Normal 32-bit floating point data type.

Function Documentation

kzsError kzuMeshCreate ( const struct KzuResourceManager resourceManager,
kzString  name,
struct KzuResourceLoader loader,
struct KzuMesh **  out_mesh 
)

Creates a mesh that loads the data when needed using the given resource loader.

kzsError kzuMeshRegisterToFactory ( const struct KzuFactory factory)

Registers mesh node type to factory.

kzsError kzuMeshCreateFromMemory ( const struct KzuResourceManager resourceManager,
kzString  name,
kzUint  vertexAttributeCount,
const kzString vertexAttributeNames,
const enum KzuMeshVertexAttributeSemantic vertexAttributeSemantics,
const enum KzuMeshVertexAttributeDataType vertexAttributeDataTypes,
const kzUint vertexAttributeDimensions,
kzUint  vertexCount,
const kzByte vertexData,
kzUint  clusterCount,
const kzUint clusterIndexCounts,
const kzU16 *const *  clusterIndices,
const enum KzcPrimitiveType clusterTypes,
struct KzuMaterial *const *  clusterMaterials,
struct KzuMesh **  out_mesh 
)

Creates a mesh directly from the given data.

Mesh consists of vertex attributes, vertex data and Clusters.

Each vertex attribute has:

  • Name (e.g. kzPosition), which should match the vertex attribute in the shader.
  • Semantic, which specifies the type of the attribute, e.g. position or normal. This can be used instead of the name to bind the vertex attribute to known Kanzi shader vertex attributes.
  • DataType, which specifies the data format of the attribute, e.g. 32-bit float.
  • Dimension, which specifies the number of elements in the attribute, e.g. 3 for vec3 attributes.

Vertex data is an array of data in the following format:

  • vertexData = <vertex_0><vertex_1>...<vertex_N-1>, where N is vertexCount
  • vertex = <attribute_0><attribute_1>...<attribute_N-1>, where N is vertexAttributeCount
  • attribute = <element_0><element_1>...<element_N-1>, where N is dimension of the attribute
  • element = Data in the format specified by data type of the attribute, e.g. kzFloat.

Each cluster has:

  • IndexCount, which specifies how many vertex indices the cluster has.
  • Indices, which is an array of indices.
  • Type, which specifies how rendering should handle the index data, e.g. each group of 3 vertices to form a triangle.
  • Material, which specifies the material used for rendering the mesh cluster.
kzsError kzuMeshCreateSphere ( const struct KzuResourceManager resourceManager,
kzString  name,
kzFloat  radius,
kzUint  segmentCount,
kzUint  rowCount,
struct KzuMaterial material,
struct KzuMesh **  out_mesh 
)

Creates a sphere mesh.

kzsError kzuMeshCreateBox ( const struct KzuResourceManager resourceManager,
kzString  name,
kzFloat  width,
kzFloat  height,
kzFloat  depth,
struct KzuMaterial material,
struct KzuMesh **  out_mesh 
)

Creates a box mesh.

kzsError kzuMeshCreateCopy ( const struct KzuResourceManager resourceManager,
kzString  name,
const struct KzuMesh sourceMesh,
struct KzuMesh **  out_mesh 
)

Creates a copy of an existing mesh.

The source mesh will be loaded if the data is not yet available.

kzsError kzuMeshInitializeFromMemory ( struct KzuMesh mesh,
kzUint  vertexAttributeCount,
const kzString vertexAttributeNames,
const enum KzuMeshVertexAttributeSemantic vertexAttributeSemantics,
const enum KzuMeshVertexAttributeDataType vertexAttributeDataTypes,
const kzUint vertexAttributeDimensions,
kzUint  vertexCount,
const kzByte vertexData,
kzUint  clusterCount,
const kzUint clusterIndexCounts,
const kzU16 *const *  clusterIndices,
const enum KzcPrimitiveType clusterTypes,
struct KzuMaterial *const *  clusterMaterials 
)

Initializes a mesh with the given data.

Calling this function is safe only from a resource loader passed as an argument to kzuMeshCreate().

See Also
kzuMeshCreate for creating the mesh.
kzuMeshCreateFromMemory for documentation of parameters.
struct KzuGPUResource* kzuMeshToGPUResource ( const struct KzuMesh mesh)

Converts mesh to GPU resource.

struct KzuMesh* kzuMeshFromGPUResource ( const struct KzuGPUResource gpuResource)

Converts GPU resource to mesh.

struct KzuResource* kzuMeshToResource ( const struct KzuMesh mesh)

Converts mesh to resource.

struct KzuMesh* kzuMeshFromResource ( const struct KzuResource resource)

Converts resource to mesh.

struct KzuMesh* kzuMeshCastFromResource ( const struct KzuResource resource)

Casts mesh from resource, KZ_NULL if invalid type.

kzBool kzuMeshIsRenderable ( const struct KzuMesh mesh)

Returns true if the mesh is deployed and valid.

kzsError kzuMeshBind ( const struct KzuMesh mesh,
kzUint  clusterIndex,
const struct KzuShader shader 
)

Binds a cluster of the mesh for rendering.

kzsError kzuMeshUnbind ( struct KzuMesh mesh,
const struct KzuShader shader 
)

Unbinds the mesh from rendering.

kzsError kzuMeshGetBoundingVolume ( const struct KzuMesh mesh,
struct KzuBoundingVolume **  out_boundingVolume 
)

Gets bounding volume from mesh.

kzUint kzuMeshGetVertexCount ( const struct KzuMesh mesh)

Gets the number of vertices in a mesh.

kzUint kzuMeshGetVertexAttributeCount ( const struct KzuMesh mesh)

Returns the number of vertex attribute in a mesh.

kzsError kzuMeshGetVertexAttributeInfo ( const struct KzuMesh mesh,
kzUint  index,
kzString out_name,
enum KzuMeshVertexAttributeSemantic out_semantic,
enum KzuMeshVertexAttributeDataType out_dataType,
kzUint out_dimension,
kzUint out_offset,
kzUint out_size 
)

Returns information about a vertex attribute with the given index.

Any of the output parameters can be KZ_NULL.

See Also
kzuMeshCreateFromMemory
kzUint kzuMeshGetVertexSize ( const struct KzuMesh mesh)

Returns the data size of a single vertex.

This is the sum of all vertex attribute sizes.

const kzByte* kzuMeshGetVertexData ( const struct KzuMesh mesh)

Returns the vertex data of the mesh.

The size of the data is kzuMeshGetVertexCount(mesh) * kzuMeshGetVertexSize(mesh).

See Also
kzuMeshCreateFromMemory
kzUint kzuMeshGetClusterCount ( const struct KzuMesh mesh)

Gets the number of clusters in the mesh.

kzUint kzuMeshGetIndexCount ( const struct KzuMesh mesh,
kzUint  clusterIndex 
)

Gets the number of indices of a given cluster in a mesh.

const kzU16* kzuMeshGetIndices ( const struct KzuMesh mesh,
kzUint  clusterIndex 
)

Returns the index data of a given cluster in a mesh.

enum KzcPrimitiveType kzuMeshGetClusterType ( const struct KzuMesh mesh,
kzUint  clusterIndex 
)

Returns the cluster type of a given cluster in a mesh.

struct KzuMaterial* kzuMeshGetMaterial ( const struct KzuMesh mesh,
kzUint  clusterIndex 
)

Gets the material of a given cluster in a mesh.

kzsError kzuMeshSetMaterial ( const struct KzuMesh mesh,
kzUint  clusterIndex,
struct KzuMaterial material 
)

Sets the material of a given cluster in a mesh.

kzsError kzuMeshApplyMorph ( struct KzuMesh mesh,
const struct KzcMemoryManager quickMemoryManager 
)

Applies morphing by calculating dynamic vertex attributes based on morph properties.

kzsError kzuMeshApplySkeleton ( const struct KzuMesh mesh,
const struct KzuObjectNode baseNode,
const struct KzcMemoryManager quickMemoryManager,
const struct KzcDynamicArray transformedObjectList 
)

Applies mesh skeleton (bones).

kzsError kzuMeshUpdateBoundingBox ( const struct KzuMesh mesh,
struct KzuObjectNode baseNode,
const struct KzcDynamicArray transformedObjectList,
kzBool out_isSkinned 
)

Updates the bounding box of a mesh based on the mesh skeleton and current pose.

kzUint kzuMeshGetBoneCount ( const struct KzuMesh mesh)

Returns the number of bones in a mesh skeleton.

struct KzuObjectNode* kzuMeshGetBoneNode ( const struct KzuMesh mesh,
kzUint  boneIndex 
)

Returns the bone node of a given bone in a mesh skeleton.

struct KzuObjectNode* kzuMeshGetBoneChildJoint ( const struct KzuMesh mesh,
kzUint  boneIndex 
)

Returns the child joint node of a given bone in a mesh skeleton.

kzsError kzuMeshAttach ( struct KzuMesh mesh,
struct KzuObjectNode baseNode 
)

Attach bone node for the mesh.

kzsError kzuMeshDetach ( const struct KzuMesh mesh)

Detach bone node for the mesh.

void kzuMeshSetPropertyManager ( struct KzuMesh mesh,
struct KzuPropertyManager *  propertyManager 
)

Sets the property manager of the mesh.

Warning: This function is deprecated and will be removed in future release.

kzsError kzuMeshGetMappedShaders ( const struct KzuMesh mesh,
struct KzcDynamicArray **  out_mappedShaders 
)

Returns array of shaders having attribute mappings in this mesh.

Caller of this function should delete returned array after use.

kzsError kzuMeshRemoveAttributeMappingForShader ( const struct KzuMesh mesh,
const struct KzuShader shader 
)

Removes attribute mapping for the shader.

Nothing will happen if there is no mapping for this shader

kzsError kzuMeshReplaceAttributeMappingForShader ( const struct KzuMesh mesh,
const struct KzuShader shader,
const struct KzuShader newShader 
)

Replaces attribute mapping for the shader.

Nothing will happen if there is no mapping for this shader

kzsError kzuMeshSetAttributeMapping ( const struct KzuMesh mesh,
const struct KzuShader shader,
kzString  shaderAttribute,
const struct KzuMesh targetMesh,
kzUint  attributeIndex 
)

Sets attribute mapping for the shader attribute.

kzBool kzuMeshGetAttributeMapping ( const struct KzuMesh mesh,
const struct KzuShader shader,
kzString  shaderAttribute,
const struct KzuMesh **  out_targetMesh,
kzUint out_attributeIndex 
)

Gets attribute mapping for shader attribute.

Returns KZ_TRUE if mapping has been found.

kzsError kzuMeshRemoveAttributeMapping ( const struct KzuMesh mesh,
const struct KzuShader shader,
kzString  shaderAttribute 
)

Removes attribute mapping for shader attribute.

Variable Documentation

const KzuResourceType KZU_RESOURCE_TYPE_MESH

Resource type identifier for mesh.