Use Mesh::CreateInfo to describe and create meshes. More...
#include <kanzi/core.ui/platform/graphics_backend/gl/mesh.hpp>
Classes | |
struct | Bone |
Definition of mesh bone, that is used for mesh skinning. More... | |
struct | Cluster |
Parameters for Mesh::Cluster creation. More... | |
struct | Skeleton |
Skeleton is for animating mesh with bones. More... | |
Public Types | |
typedef pair< AbstractPropertyType, Variant > | PropertyEntry |
typedef vector< PropertyEntry > | PropertyContainer |
typedef shared_ptr< Bone > | BoneSharedPtr |
Shared pointer type for Bone. More... | |
Public Types inherited from kanzi::GPUResource | |
enum | MemoryType { GpuOnly, GpuAndRam, RamOnly } |
Memory upload and RAM preservation strategy for GPU resources. More... | |
Public Types inherited from kanzi::PropertyObject | |
typedef intrusive_ptr< AbstractPropertyTypeDescriptor::PropertyStorage > | PropertyStoragePtr |
typedef vector< PropertyStoragePtr > | PropertyStorageContainer |
typedef PropertyStorageContainer::iterator | PropertyStorageIterator |
typedef PropertyStorageContainer::const_iterator | PropertyStorageConstIterator |
typedef PropertyStorageContainer::reverse_iterator | PropertyStorageReverseIterator |
Public Member Functions | |
CreateInfo () | |
Default constructor for mesh create info. More... | |
void | bind (size_t clusterIndex, ShaderProgramSharedPtr shaderProgram) |
Prepares a cluster from the mesh for rendering with the specified shader. More... | |
const KzuBoundingVolume * | getBoundingVolume () const |
Returns the bounding volume of the mesh. More... | |
size_t | getVertexCount () const |
Returns the vertex count of the mesh. More... | |
size_t | getVertexAttributeCount () const |
Gets the number of the vertex attributes in the mesh. More... | |
size_t | getVertexSize () const |
Gets size of one vertex in bytes. More... | |
const void * | getVertexData () const |
Gets raw vertex data. More... | |
size_t | getClusterCount () const |
Gets the number of clusters in the mesh. More... | |
size_t | getClusterIndexCount (size_t clusterIndex) const |
Gets the number of indices in a specified cluster. More... | |
GraphicsPrimitiveType | getClusterPrimitiveType (size_t clusterIndex) const |
Gets the primitive type for the cluster. More... | |
MaterialSharedPtr | getClusterMaterial (size_t clusterIndex) const |
Gets the cluster material. More... | |
void | setClusterMaterial (size_t clusterIndex, MaterialSharedPtr material) |
Sets the cluster material. More... | |
const uint16_t * | getClusterIndexData (size_t clusterIndex) const |
Gets index data for given cluster. More... | |
optional< Matrix4x4 > | updateBoundingBox (Node3D *baseNode, const KzcDynamicArray &transformedObjectList) |
Updates bounding box of mesh with bones from given model. More... | |
size_t | getBoneCount () const |
Gets number of bones in mesh. More... | |
Node3D * | getBoneNode (size_t boneIndex) const |
Gets node for bone. More... | |
Node3D * | getBoneChildJoint (size_t boneIndex) const |
Gets child node for skeletal animation bone. More... | |
void | attach (Node *baseNode) |
Attaches a root node for bone node lookup functions. More... | |
void | detach () |
Detaches root node, making bone node lookups no longer available. More... | |
const vector< int > & | acquireAttributeMap (ShaderProgramSharedPtr shaderProgram) |
Gets attribute map for given shader program. More... | |
void | applySkeleton (Node *baseNode, const KzcDynamicArray *transformedObjectList) |
Applies bone animation, updating matrix palette transformation uniforms. More... | |
const MeshVertexAttribute & | getVertexAttribute (int index) const |
Gets mesh vertex attribute with given mesh attribute index. More... | |
void | bindAttribute (Renderer *renderer, unsigned int shaderAttributeIndex, int meshVertexAttributeIndex) |
Takes one mesh vertex attribute from mesh and makes it usable with (current) shader. More... | |
unsigned int | bindAttributes (ShaderProgramSharedPtr shaderProgram) |
Makes all mesh vertex attributes available with a shader program. More... | |
void | bindIndices (size_t clusterIndex) |
Makes mesh cluster indices available to the next draw call. More... | |
Public Member Functions inherited from kanzi::GPUResource | |
virtual | ~GPUResource () KZ_OVERRIDE |
void | invalidate () |
Notify resource that graphics context was lost and all GPU resources are invalid. More... | |
unsigned int | getGPUMemoryUsage () const |
Renderer * | getRenderer () const |
bool | isDeployed () const |
Public Member Functions inherited from kanzi::Resource | |
KzcMemoryManager * | getMemoryManager () const |
Resource (Domain *domain, string_view name) | |
virtual | ~Resource () |
virtual void | loadFromKZB (const ResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file) |
Function for loading the resource from .KZB. More... | |
virtual void | unloadOverride () |
Unload function for resource. Releases all CPU memory taken by the resource except the resource loader. More... | |
virtual unsigned int | getCPUMemoryUsage () const |
Function for getting the memory usage of a resource. More... | |
void | setKZB (const KzuBinaryDirectory *binaryDirectory, string_view path) |
Set the binary directory and path of the resource. More... | |
const string & | getName () const |
Gets the resource name. More... | |
const string & | getUrl () const |
Gets the resource URL. More... | |
void | setUrl (string_view url) |
Sets the resource URL. More... | |
void | setNotLoaded () |
bool | isFromKZB () const |
void | reload () |
void | reloadFromKzb (KzcInputStream *inputStream, const KzuBinaryFileInfo *file) |
void | reloadFromKzb (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser) |
void | reloadFromFile (string_view filePath) |
void | load () |
void | unload () |
bool | isLoaded () const |
void | kzuResourceLoad_private (const ResourceLoaderThreadContext *threadContext) |
Private function for kzuResourceLoad() with specified thread context. More... | |
void | kzuResourceFinishLoading_private (const ResourceLoaderThreadContext *threadContext) |
Private function for finishing the loading of the resource. More... | |
bool | isKeepAlive () const |
Tells if the resource has keep alive flag set. More... | |
void | setKeepAlive (bool keepAlive) |
Sets the keep alive flag. More... | |
Public Member Functions inherited from kanzi::Object | |
Object (Domain *domain) | |
virtual | ~Object () |
Domain * | getDomain () const |
Returns the domain the object belongs to. More... | |
KzuTaskScheduler * | getTaskScheduler () const |
Returns the task scheduler of the object. More... | |
KzuMessageDispatcher * | getMessageDispatcher () const |
Returns the message dispatcher of the object. More... | |
ResourceManager * | getResourceManager () const |
Returns the resource manager of the object. More... | |
virtual const Metaclass * | getDynamicMetaclass () const KZ_OVERRIDE |
Returns the metaclass of the dynamic type of the object. More... | |
AppliedStyleEntrySharedPtr | applyObjectStyle (kanzi::StyleSharedPtr style) |
Applies a style to an object. More... | |
void | unapplyObjectStyle (AppliedStyleEntrySharedPtr appliedStyleEntry) |
void | applyObjectStyles () |
Apply all styles for an object node. More... | |
void | unapplyObjectStyles () |
Unapplies and removes all applied styles. More... | |
Public Member Functions inherited from kanzi::MetaObject | |
virtual | ~MetaObject () |
bool | isTypeOf (const Metaclass *objectType) const |
Determines if the type of this object is the given type or derived from it. More... | |
Public Member Functions inherited from kanzi::PropertyObject | |
PropertyObject () | |
virtual | ~PropertyObject () |
template<typename DataType > | |
void | setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Traits::ParameterType value) |
Sets the local value of a property. More... | |
void | removeKzbProperties () |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getProperty (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property. More... | |
template<typename DataType > | |
optional< typename PropertyType< DataType >::Traits::ReturnType > | getOptionalProperty (const PropertyType< DataType > &propertyType) const |
Evaluates the property value in the same way as the overload above but does not default to the value in property metadata if there are no inputs to the property value. More... | |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getPropertyBase (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property disregarding modifiers. More... | |
template<typename DataType > | |
void | setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::Traits::ParameterType value) |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getAbstractProperty (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getAbstractPropertyBase (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
optional< typename PropertyType< DataType >::Traits::ReturnType > | getOptionalAbstractProperty (AbstractPropertyType abstractPropertyType) const |
void | setPropertyFlag (AbstractPropertyType propertyType, uint32_t flag) |
bool | isPropertyFlagSet (AbstractPropertyType propertyType, uint32_t flag) const |
void | clearPropertyFlag (AbstractPropertyType propertyType, uint32_t flag) |
bool | hasValue (AbstractPropertyType propertyType) const |
Evaluates whether there are any inputs into the property value. More... | |
bool | hasBaseValue (AbstractPropertyType propertyType) const |
Evaluates whether there are any inputs into the property value, disregarding modifiers. More... | |
bool | hasLocalValue (AbstractPropertyType propertyType) const |
Evaluates whether there is a local value set for the property. More... | |
bool | hasNonClassValue (AbstractPropertyType propertyType) const |
Evaluates whether there is a value of any precedence higher than class default value set for the property. More... | |
void | removeLocalValue (AbstractPropertyType propertyType) |
Removes the local value associated with the property. More... | |
void | copyLocalValue (const PropertyObject &other, AbstractPropertyType propertyType) |
Copies local value of single property from another object. More... | |
void | copyLocalValues (const PropertyObject &other) |
Copies all local values from another object. More... | |
virtual void | onPropertyChanged (AbstractPropertyType propertyType, PropertyNotificationReason reason) |
Virtual function to handle property change notifications. More... | |
template<typename DataType > | |
void | addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, void *owner) |
template<typename DataType > | |
void | removePropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *owner) |
template<typename DataType > | |
void | addPropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner) |
template<typename DataType > | |
void | removePropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner) |
void | validatePropertyModifiers (AbstractPropertyType propertyType) |
template<typename DataType > | |
void | addPropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner) |
template<typename DataType > | |
void | removePropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner) |
template<typename DataType > | |
size_t | getPropertyNotificationHandlerCount (const PropertyType< DataType > &propertyType) |
Gets number of current notification handlers for given property type. More... | |
Static Public Member Functions | |
static MeshSharedPtr | create (Domain *domain, const CreateInfo &createInfo, string_view name) |
Creates a mesh with specified mesh creation parameters. More... | |
static MeshSharedPtr | createSphere (Domain *domain, float radius, unsigned int segmentCount, unsigned int rowCount, string_view name, MaterialSharedPtr material=MaterialSharedPtr()) |
Creates a mesh with a sphere shape in a single cluster. More... | |
static MeshSharedPtr | createBox (Domain *domain, Vector3 size, string_view name, MaterialSharedPtr material=MaterialSharedPtr()) |
Creates a mesh with a box shape in a single cluster. More... | |
static MeshSharedPtr | createPlane (Domain *domain, float width, float height, bool invertU, bool invertV, string_view name, MaterialSharedPtr material=MaterialSharedPtr()) |
Creates a plane shape. More... | |
static ResourceManager::LoadTaskSharedPtr | createLoadTask (string_view name, KzbFile *kzbFile, unique_ptr< ReadOnlyMemoryFile > file) |
Static Public Member Functions inherited from kanzi::Object | |
static const Metaclass * | getStaticMetaclass () |
Returns the metaclass of Object class. More... | |
static PropertyTypeEditorInfoSharedPtr | makeEditorInfo () |
Default implementation that returns empty editor info. More... | |
Static Public Member Functions inherited from kanzi::MetaObject | |
static const Metaclass * | getStaticMetaclass () |
Returns the metaclass of Object class. More... | |
static PropertyTypeEditorInfoSharedPtr | makeEditorInfo () |
Default implementation that returns empty editor info. More... | |
Public Attributes | |
MemoryType | memoryType |
Memory type for the texture. More... | |
vector< Mesh::CreateInfo::Cluster > | clusters |
Clusters. More... | |
Box | boundingBox |
Bounding box for mesh. More... | |
Skeleton | skeleton |
Mesh skeleton for bone animations. More... | |
MeshAttributeCollection | vertexFormat |
Mesh vertex attributes. More... | |
size_t | vertexSize |
Size of one vertex in bytes. This is sum of all mesh vertex attributes sizes. More... | |
size_t | vertexCount |
Number of vertices in the mesh. More... | |
vector< byte > | vertexData |
Vertex buffer data. More... | |
PropertyContainer | properties |
Properties to copy to the mesh. More... | |
struct KANZI_API | CreateInfo |
Friends | |
void | swap (Mesh &mesh1, Mesh &mesh2) |
Additional Inherited Members | |
Protected Types inherited from kanzi::Object | |
typedef vector< AppliedStyleEntrySharedPtr > | AppliedStyleContainer |
Applied style container. More... | |
Protected Attributes inherited from kanzi::Object | |
AppliedStyleContainer | m_appliedStyles |
Listing of applied styles applied to this object. More... | |
Use Mesh::CreateInfo to describe and create meshes.
Mesh stores the geometry data for rendering Model3d nodes.
Vertex and index listings define meshes. Indices refer to vertices which define the faces of a mesh.
To define a mesh, you need:
In Kanzi a mesh can have at most 65536 vertices, a limit set by GLES2. If you need more vertices, create additional meshes.
To create a cube mesh:
Each mesh has one or more clusters. Each cluster has material and primitives. Primitives are typically triangles, they are stored as vertex data and index data.
You can load a mesh resource from a .kzb file or create it with the Mesh::create() function.
Once Mesh has been created with constructor, all primitive data is uploaded to GPU memory and no longer stored in CPU memory in Mesh.
typedef pair<AbstractPropertyType, Variant> kanzi::Mesh::PropertyEntry |
typedef vector<PropertyEntry> kanzi::Mesh::PropertyContainer |
typedef shared_ptr<Bone> kanzi::Mesh::BoneSharedPtr |
Shared pointer type for Bone.
|
explicitprotected |
|
explicit |
Default constructor for mesh create info.
|
static |
Creates a mesh with specified mesh creation parameters.
In order to create a mesh, you will need a Mesh::CreateInfo structure that is filled with mesh creation parameters.
Primitive data (vertex and index data) is always deployed to GPU memory when Mesh is created.
|
static |
Creates a mesh with a sphere shape in a single cluster.
radius | Radius of the sphere |
segmentCount | Number of segments for the shape |
rowCount | Number of rows for the shape |
material | Material pointer for the cluster. If set, leave the materialURL parameter empty. |
materialURL | Resource address for the cluster material. If set, leave material empty. |
|
static |
Creates a mesh with a box shape in a single cluster.
width | Width of the box (size along the x axis) |
height | Height of the box (size along the y axis) |
depth | Depth of the box (size along z axis) |
material | Material pointer for the cluster. If set, leave the materialURL parameter empty. |
materialURL | Resource address for the cluster material. If set, leave the material parameter empty. |
|
static |
Creates a plane shape.
width | Width of the plane (size along the x axis) |
height | Height of the plane (size along the y axis) |
invertU | If true, the first texture coordinate is inverted |
invertV | If true, the second texture coordinate is inverted |
material | Material pointer for the cluster. If set, leave the materialURL parameter empty. |
materialURL | Resource address for the cluster material. If set, leave the material parameter empty. |
void kanzi::Mesh::bind | ( | size_t | clusterIndex, |
ShaderProgramSharedPtr | shaderProgram | ||
) |
Prepares a cluster from the mesh for rendering with the specified shader.
clusterIndex | Which cluster to render. |
shaderProgram | Which ShaderProgram to render with. |
const KzuBoundingVolume* kanzi::Mesh::getBoundingVolume | ( | ) | const |
Returns the bounding volume of the mesh.
|
inline |
Returns the vertex count of the mesh.
|
inline |
Gets the number of the vertex attributes in the mesh.
|
inline |
Gets size of one vertex in bytes.
|
inline |
Gets raw vertex data.
User is responsible for casting the data to proper format for reading.
|
inline |
Gets the number of clusters in the mesh.
size_t kanzi::Mesh::getClusterIndexCount | ( | size_t | clusterIndex | ) | const |
Gets the number of indices in a specified cluster.
clusterIndex | Which cluster to query |
GraphicsPrimitiveType kanzi::Mesh::getClusterPrimitiveType | ( | size_t | clusterIndex | ) | const |
Gets the primitive type for the cluster.
clusterIndex | Which cluster to query |
MaterialSharedPtr kanzi::Mesh::getClusterMaterial | ( | size_t | clusterIndex | ) | const |
Gets the cluster material.
clusterIndex | Which cluster to query |
void kanzi::Mesh::setClusterMaterial | ( | size_t | clusterIndex, |
MaterialSharedPtr | material | ||
) |
Sets the cluster material.
clusterIndex | The cluster for which to set the material |
material | The material to apply to the cluster |
const uint16_t* kanzi::Mesh::getClusterIndexData | ( | size_t | clusterIndex | ) | const |
Gets index data for given cluster.
clusterIndex | Which cluster to query |
optional<Matrix4x4> kanzi::Mesh::updateBoundingBox | ( | Node3D * | baseNode, |
const KzcDynamicArray & | transformedObjectList | ||
) |
Updates bounding box of mesh with bones from given model.
baseNode | Node from which bones are located from. |
transformedObjectList | List of transformed objects, from which bones are retrieved from. |
size_t kanzi::Mesh::getBoneCount | ( | ) | const |
Gets number of bones in mesh.
Node3D* kanzi::Mesh::getBoneNode | ( | size_t | boneIndex | ) | const |
Node3D* kanzi::Mesh::getBoneChildJoint | ( | size_t | boneIndex | ) | const |
void kanzi::Mesh::attach | ( | Node * | baseNode | ) |
Attaches a root node for bone node lookup functions.
baseNode | Root node for bone node lookups. |
void kanzi::Mesh::detach | ( | ) |
Detaches root node, making bone node lookups no longer available.
const vector<int>& kanzi::Mesh::acquireAttributeMap | ( | ShaderProgramSharedPtr | shaderProgram | ) |
Gets attribute map for given shader program.
In attribute map keys to are mesh attribute indices and values are shader attribute indices.
shaderProgram | Shader program. |
void kanzi::Mesh::applySkeleton | ( | Node * | baseNode, |
const KzcDynamicArray * | transformedObjectList | ||
) |
Applies bone animation, updating matrix palette transformation uniforms.
baseNode | Root node for bones. |
transformedObjectList | Transformed nodes. |
const MeshVertexAttribute& kanzi::Mesh::getVertexAttribute | ( | int | index | ) | const |
void kanzi::Mesh::bindAttribute | ( | Renderer * | renderer, |
unsigned int | shaderAttributeIndex, | ||
int | meshVertexAttributeIndex | ||
) |
Takes one mesh vertex attribute from mesh and makes it usable with (current) shader.
unsigned int kanzi::Mesh::bindAttributes | ( | ShaderProgramSharedPtr | shaderProgram | ) |
Makes all mesh vertex attributes available with a shader program.
shaderProgram | Shader program |
void kanzi::Mesh::bindIndices | ( | size_t | clusterIndex | ) |
Makes mesh cluster indices available to the next draw call.
clusterIndex | Index of cluster to prepare. |
|
static |
|
protectedvirtual |
Resource::reloadOverride() implementation.
Reimplemented from kanzi::Resource.
|
protectedvirtual |
Resource::reloadFromKzbOverride() implementation.
Reimplemented from kanzi::Resource.
|
protectedvirtual |
Resource::reloadFromKzbOverride() implementation.
Reimplemented from kanzi::Resource.
|
protectedvirtual |
GPUResource::invalidateOverride() implementation.
Reimplemented from kanzi::GPUResource.
|
protectedvirtual |
GpuResource::isDeployed() implementation.
Implements kanzi::GPUResource.
|
protectedvirtual |
GpuResource::getGPUMemoryUsageOverride() implementation.
Reimplemented from kanzi::GPUResource.
MemoryType kanzi::Mesh::memoryType |
Memory type for the texture.
If Gpu is not included, texture will not be deployed when created. If Ram is not included, texture will not contain images after it has been deployed. Default value is GpuOnly.
vector<Mesh::CreateInfo::Cluster> kanzi::Mesh::clusters |
Clusters.
Box kanzi::Mesh::boundingBox |
Bounding box for mesh.
MeshAttributeCollection kanzi::Mesh::vertexFormat |
Mesh vertex attributes.
size_t kanzi::Mesh::vertexSize |
Size of one vertex in bytes. This is sum of all mesh vertex attributes sizes.
size_t kanzi::Mesh::vertexCount |
Number of vertices in the mesh.
vector<byte> kanzi::Mesh::vertexData |
Vertex buffer data.
PropertyContainer kanzi::Mesh::properties |
Properties to copy to the mesh.
Currently they are not used.
struct KANZI_API kanzi::Mesh::CreateInfo |