Kanzi  3.9.7
Kanzi Engine API
kanzi::Mesh Class Reference

Mesh stores the geometry data for rendering Model3D nodes. More...

#include <kanzi/core.ui/platform/graphics_backend/gl/mesh.hpp>

Inheritance diagram for kanzi::Mesh:
[legend]

Classes

struct  Bone
 Definition of mesh bone that is used for mesh skinning. More...
 
struct  Cluster
 Cluster has a material, primitive type (currently always triangles), and handle for GPU memory buffer where primitive indices are stored. More...
 
struct  CreateInfo
 Use Mesh::CreateInfo to describe and create meshes. More...
 
class  MappedBuffer
 Mapped buffer is a container for GPU memory that is mapped into CPU memory. More...
 
struct  Skeleton
 Skeleton is for animating mesh with bones. More...
 

Public Types

typedef shared_ptr< BoneBoneSharedPtr
 Shared pointer type for Bone. More...
 
typedef unique_ptr< MappedBufferMappedBufferPtr
 
using SkeletonRuntime = Skeleton
 
using SkeletonRuntimeSharedPtr = shared_ptr< SkeletonRuntime >
 
- 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 PropertyStorageContainer::const_iterator PropertyStorageConstIterator
 
typedef vector< PropertyStoragePtrPropertyStorageContainer
 
typedef PropertyStorageContainer::iterator PropertyStorageIterator
 
typedef intrusive_ptr< AbstractPropertyTypeDescriptor::PropertyStoragePropertyStoragePtr
 
typedef PropertyStorageContainer::reverse_iterator PropertyStorageReverseIterator
 

Public Member Functions

const vector< int > & acquireAttributeMap (ShaderProgramSharedPtr shaderProgram)
 Gets attribute map for given shader program. More...
 
void applySkeleton (Renderer &renderer, Node &baseNode, ShaderProgramSharedPtr shaderProgram)
 Applies bone animation, updating matrix palette transformation uniforms. More...
 
void attachSkeleton (Model3D *model)
 Attaches the mesh skeleton runtime to the node. More...
 
void bind (Renderer &renderer, size_t clusterIndex, ShaderProgramSharedPtr shaderProgram)
 Prepares a cluster from the mesh for rendering with the specified shader. More...
 
void bindAttribute (Renderer &renderer, unsigned int shaderAttributeIndex, size_t meshVertexAttributeIndex)
 Takes one mesh vertex attribute from mesh and makes it usable with (current) shader. More...
 
unsigned int bindAttributes (Renderer &renderer, ShaderProgramSharedPtr shaderProgram)
 Makes all mesh vertex attributes available with a shader program. More...
 
void bindIndices (Renderer &renderer, size_t clusterIndex)
 Makes mesh cluster indices available to the next draw call. More...
 
void detachSkeleton (Model3D *model)
 Detaches the mesh skeleton runtime from the node. More...
 
Box getBoundingBox () const
 Returns the bounding box of a mesh. 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...
 
span< const bytegetClusterIndexData (size_t clusterIndex) const
 Gets index data for given cluster. More...
 
IndexBufferType getClusterIndexType (size_t clusterIndex) const
 Gets the index type for the cluster. More...
 
MaterialSharedPtr getClusterMaterial (size_t clusterIndex) const
 Gets the cluster material. More...
 
GraphicsPrimitiveType getClusterPrimitiveType (size_t clusterIndex) const
 Gets the primitive type for the cluster. More...
 
GPUBuffer::NativeHandle getNativeIndexBufferHandle (size_t clusterIndex)
 Gets the native handle for index data of the cluster. More...
 
GPUBuffer::NativeHandle getNativeInstanceBufferHandle ()
 Gets the native handle for the instance data of the mesh. More...
 
GPUBuffer::NativeHandle getNativeVertexBufferHandle ()
 Gets the native handle for vertex data of the mesh. More...
 
const SkeletongetSkeleton () const
 Returns the skeleton of the mesh. More...
 
const MeshVertexAttributegetVertexAttribute (unsigned int index) const
 Gets a vertex attribute by its index. More...
 
size_t getVertexAttributeCount () const
 Gets the number of the vertex attributes in the mesh. More...
 
optional< unsigned int > getVertexAttributeIndex (VertexAttribute::Semantic semantic) const
 Gets a vertex attribute index by semantic. More...
 
optional< unsigned int > getVertexAttributeIndex (VertexAttribute::Semantic semantic, unsigned int index) const
 Gets a vertex attribute index by semantic and semantic index. More...
 
size_t getVertexCount () const
 Returns the vertex count of the mesh. More...
 
span< const bytegetVertexData () const
 Gets raw vertex data. More...
 
size_t getVertexSize () const
 Gets size of one vertex in bytes. More...
 
MappedBufferPtr mapIndexData (size_t clusterIndex)
 Maps the index data of a cluster in the mesh on the GPU to a CPU memory region. More...
 
MappedBufferPtr mapInstanceData ()
 Maps the instance data of the mesh on the GPU to a CPU memory region. More...
 
MappedBufferPtr mapVertexData ()
 Maps the vertex data of the mesh on the GPU to a CPU memory region. More...
 
void setClusterMaterial (size_t clusterIndex, MaterialSharedPtr material)
 Sets the cluster material. More...
 
void setClusterPrimitiveType (size_t clusterIndex, GraphicsPrimitiveType primitiveType)
 Sets the primitive type for the cluster. More...
 
void setIndexData (size_t clusterIndex, ConstByteSpan data)
 Sets the index data of a cluster in the mesh. More...
 
void setIndexSubData (size_t clusterIndex, ConstByteSpan data, unsigned int offset)
 Sets a section of the index data of a cluster in the mesh. More...
 
void setInstanceData (ConstByteSpan data)
 Sets the instance data of the mesh. More...
 
void setInstanceSubData (ConstByteSpan data, unsigned int offset)
 Sets a section of the instance data of the mesh. More...
 
void setVertexData (ConstByteSpan data)
 Sets the vertex data of the mesh. More...
 
void setVertexSubData (ConstByteSpan data, unsigned int offset)
 Sets a section of the vertex data of the mesh. More...
 
optional< Matrix4x4updateSkeletonTransformation (Model3D &model)
 Updates bounding box of mesh with bones from given model and root transformation of the skeleton. More...
 
- Public Member Functions inherited from kanzi::GPUResource
void destroy ()
 Destroys a GPU resource. More...
 
unsigned int getGPUMemoryUsage () const
 
RenderergetRenderer () const
 
void invalidate ()
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
bool isDeployed () const
 
 ~GPUResource () override
 
- Public Member Functions inherited from kanzi::Resource
virtual unsigned int getCPUMemoryUsage () const
 Function for getting the memory usage of a resource. More...
 
const string & getName () const
 Gets the resource name. More...
 
const string & getUrl () const
 Gets the resource URL. More...
 
bool isKeepAlive () const
 Tells if the resource has keep alive flag set. More...
 
void reload ()
 
void reloadFromFile (string_view filePath)
 
void reloadFromKzb (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser)
 
void setKeepAlive (bool keepAlive)
 Sets the keep alive flag. More...
 
void setUrl (string_view url)
 Sets the resource URL. More...
 
 ~Resource () override
 Destructor. More...
 
- Public Member Functions inherited from kanzi::Object
AppliedStyleEntrySharedPtr applyObjectStyle (kanzi::StyleSharedPtr style)
 Applies a style to an object. More...
 
void applyObjectStyles ()
 Apply all styles for an object node. More...
 
DomaingetDomain () const
 Returns the domain the object belongs to. More...
 
const MetaclassgetDynamicMetaclass () const override
 Returns the metaclass of the dynamic type of the object. More...
 
MainLoopSchedulergetMainLoopScheduler () const
 Returns the MainLoopScheduler instance of the associated Domain. More...
 
detail::MessageDispatcher * getMessageDispatcher () const
 Returns the message dispatcher of the object. More...
 
ResourceManagergetResourceManager () const
 Returns the resource manager of the object. More...
 
ScriptingContextSharedPtr getScriptingContext () const
 Gets the scripting context of the object. More...
 
 Object (Domain *domain)
 
void setScriptingContext (ScriptingContextSharedPtr context)
 Sets the scripting context of the object. More...
 
void unapplyObjectStyle (AppliedStyleEntrySharedPtr appliedStyleEntry)
 
void unapplyObjectStyles ()
 Unapplies and removes all applied styles. More...
 
 ~Object () override
 
- Public Member Functions inherited from kanzi::MetaObject
bool isTypeOf (const Metaclass *objectType) const
 Determines if the type of this object is the given type or derived from it. More...
 
virtual ~MetaObject ()
 
- Public Member Functions inherited from kanzi::PropertyObject
template<typename DataType >
void addPropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner)
 
template<typename DataType >
void addPropertyModifierWithoutNotifyingHandlers (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner)
 Adds a property modifier without notifying handlers. More...
 
template<typename DataType >
void addPropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner)
 
template<typename DataType >
void addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, void *ownerPointer)
 
template<typename DataType >
void addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, AbstractPropertyTypeDescriptor::ValueSourceOwner *owner)
 
PropertyStorageContainer::iterator beginPropertyStorage ()
 Returns the begin iterator to the internal property storage container. More...
 
PropertyStorageContainer::const_iterator beginPropertyStorage () const
 Returns the begin iterator to the internal property storage container. More...
 
void clearPropertyFlag (AbstractPropertyType propertyType, uint32_t flag)
 
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...
 
PropertyStorageContainer::iterator endPropertyStorage ()
 Returns the end iterator to the internal property storage container. More...
 
PropertyStorageContainer::const_iterator endPropertyStorage () const
 Returns the end iterator to the internal property storage container. More...
 
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
 
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 >
optional< typename PropertyType< DataType >::Traits::ReturnType > getOptionalPropertyBase (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property disregarding modifiers, 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 getProperty (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property type. 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 >
size_t getPropertyNotificationHandlerCount (const PropertyType< DataType > &propertyType) const
 Gets number of current notification handlers for given property type. 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...
 
bool hasValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value. More...
 
bool isPropertyFlagSet (AbstractPropertyType propertyType, uint32_t flag) const
 
virtual void onPropertyChanged (AbstractPropertyType propertyType, PropertyNotificationReason reason)
 Virtual function to handle property change notifications. More...
 
 PropertyObject ()
 
void removeKzbProperties (flat_set< AbstractPropertyType > *keepProperties)
 Remove all KZB properties that are not included in a given set. More...
 
void removeKzbProperties ()
 Remove all KZB properties. More...
 
template<typename DataType >
void removeLocalPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *ownerPointer)
 
void removeLocalValue (AbstractPropertyType propertyType)
 Removes the local value associated with the property. More...
 
template<typename DataType >
void removePropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner)
 
template<typename DataType >
void removePropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner)
 
template<typename DataType >
void removePropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *ownerPointer)
 
template<typename DataType >
void setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::Traits::ParameterType value)
 
template<typename DataType >
void setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Traits::ParameterType value)
 Sets the local value of a property type. More...
 
void setPropertyFlag (AbstractPropertyType propertyType, uint32_t flag)
 
KZ_DEPRECATED void validatePropertyModifiers (AbstractPropertyType propertyType)
 Validates property modifiers and notifies handlers. More...
 
void validatePropertyModifiersAndNotifyHandlers (AbstractPropertyType propertyType)
 Validates property modifiers and notifies handlers. More...
 
virtual ~PropertyObject ()
 

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 createBox (Domain *domain, Vector3 size, unsigned int subdivisions, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a mesh with a box shape in a single cluster. More...
 
static MeshSharedPtr createIcosphere (Domain *domain, float radius, unsigned int subdivisions, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a mesh with a sphere shape in a single cluster. More...
 
static ResourceManager::LoadTaskSharedPtr createLoadTask (string_view name, KzbFile *kzbFile, ReadOnlyMemoryFilePtr file)
 
static MeshSharedPtr createPlane (Domain *domain, float width, float height, unsigned int subdivisions, bool invertU, bool invertV, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a plane shape. More...
 
static MeshSharedPtr createQuadsphere (Domain *domain, float radius, unsigned int subdivisions, string_view name, MaterialSharedPtr material=MaterialSharedPtr())
 Creates a mesh with a sphere shape in a single cluster. 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 Public Member Functions inherited from kanzi::Object
static const MetaclassgetStaticMetaclass ()
 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 MetaclassgetStaticMetaclass ()
 Returns the metaclass of Object class. More...
 
static PropertyTypeEditorInfoSharedPtr makeEditorInfo ()
 Default implementation that returns empty editor info. More...
 

Protected Member Functions

void destroyOverride () override
 GPUResource::destroyOverride() implementation. More...
 
unsigned int getCPUMemoryUsageOverride () const override
 Resource::getCPUMemoryUsageOverride() implementation. More...
 
unsigned int getGPUMemoryUsageOverride () const override
 GpuResource::getGPUMemoryUsageOverride() implementation. More...
 
void invalidateOverride () override
 GPUResource::invalidateOverride() implementation. More...
 
bool isDeployedOverride () const override
 GpuResource::isDeployed() implementation. More...
 
 Mesh (Domain *domain, const CreateInfo &createInfo, string_view name)
 
void reloadFromKzbOverride (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser) override
 Resource::reloadFromKzbOverride() implementation. More...
 
void reloadOverride () override
 Resource::reloadOverride() implementation. More...
 
- Protected Member Functions inherited from kanzi::GPUResource
 GPUResource (Domain *domain, string_view name="")
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::Resource
virtual void reloadFromFileOverride (string_view filePath)
 
 Resource (Domain *domain, string_view name)
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::Object
void initialize ()
 
void onCopy (const Object &other)
 
- Protected Member Functions inherited from kanzi::MetaObject
void initialize ()
 
 MetaObject ()
 
- Protected Member Functions inherited from kanzi::PropertyObject
AbstractPropertyTypeDescriptor::ValueSourceEntryacquireLocalValueSourceEntry (AbstractPropertyTypeDescriptor &descriptor, PropertyStoragePtr &propertyStorage)
 Acquires a local value source entry that is free for the assignment of a value. More...
 
AbstractPropertyTypeDescriptor::ModifierStorageacquireModifierStorage (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage)
 
AbstractPropertyTypeDescriptor::NotificationStorageacquireNotificationStorage (AbstractPropertyTypeDescriptor &descriptor)
 
PropertyStoragePtr acquirePropertyStorage (AbstractPropertyTypeDescriptor &descriptor)
 
template<typename DataType >
void addPropertyModifierBase (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner, bool notify)
 Adds a property modifier entry to the property modifier stack and validates them. More...
 
void addPropertyValueSource (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::ValueSource *valueSource, PropertyValuePrecedence precedence, void *ownerPointer)
 Internally adds a property value source. More...
 
void addPropertyValueSource (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::ValueSource *valueSource, PropertyValuePrecedence precedence, AbstractPropertyTypeDescriptor::ValueSourceOwner *owner)
 Internally adds a property value source. More...
 
AbstractPropertyTypeDescriptor::ValueSourceEntryconstructLocalValueSourceEntry (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::PropertyStorage &propertyStorage)
 
PropertyStoragePtr constructPropertyStorage (AbstractPropertyTypeDescriptor &descriptor)
 
void copyLocalValue (const AbstractPropertyTypeDescriptor::PropertyStorage &otherPropertyStorage)
 Copy local value from property storage. More...
 
AbstractPropertyTypeDescriptor::ModifierStoragefindModifierStorage (AbstractPropertyTypeDescriptor &descriptor)
 
AbstractPropertyTypeDescriptor::NotificationStoragefindNotificationStorage (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::PropertyStoragefindPropertyStorage (AbstractPropertyTypeDescriptor &descriptor) const
 Gets the property storage for given property type descriptor. More...
 
PropertyStoragePtr findPropertyStoragePtr (AbstractPropertyTypeDescriptor &descriptor) const
 Gets property storage intrusive pointer which you can use to hold a reference until the end of the operation. More...
 
AbstractPropertyTypeDescriptorfindPropertyTypeDescriptorByNameAndDataType (string_view name, PropertyDataType dataType) const
 Finds a property type descriptor by name and data type. More...
 
AbstractPropertyTypeDescriptorfindPropertyTypeDescriptorByQualifiedNameAndDataType (string_view qualifiedName, PropertyDataType dataType) const
 Like findPropertyTypeDescriptorByNameAndDataType, but only searches by matching with qualified names. More...
 
AbstractPropertyTypeDescriptorfindPropertyTypeDescriptorByUnqualifiedNameAndDataType (string_view unqualifiedName, PropertyDataType dataType) const
 Like findPropertyTypeDescriptorByNameAndDataType, but only searches by matching with unqualified names. More...
 
AbstractPropertyTypeDescriptor::ValueSourcegetClassValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetFinalValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetNonClassValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 
AbstractPropertyTypeDescriptor::ValueSourcegetTopValueSource (AbstractPropertyTypeDescriptor &descriptor) const
 Gets the top-level value source for a given property descriptor. More...
 
virtual void notifyPropertyHandlers (PropertyStoragePtr &storagePtr, PropertyNotificationReason reason)
 Notifies all property handlers on a property storage. More...
 
void onCopy (const PropertyObject &other)
 
void removeLocalValue (AbstractPropertyTypeDescriptor &descriptor, PropertyStoragePtr &propertyStorage)
 Removes a local value from the given property storage. More...
 
void removePropertyValueSource (AbstractPropertyTypeDescriptor &descriptor, AbstractPropertyTypeDescriptor::ValueSource *valueSource, void *owner)
 Removes a property value source. More...
 
void validatePropertyModifiers (PropertyStoragePtr &propertyStorage)
 Validates property modifiers without notifying handlers. More...
 
void validatePropertyModifiersAndNotifyHandlers (PropertyStoragePtr &propertyStorage)
 Validates property modifiers and notifies handlers. More...
 

Friends

void swap (Mesh &mesh1, Mesh &mesh2)
 

Additional Inherited Members

- Protected Types inherited from kanzi::Object
typedef vector< AppliedStyleEntrySharedPtrAppliedStyleContainer
 Applied style container. More...
 
- Protected Attributes inherited from kanzi::Object
AppliedStyleContainer m_appliedStyles
 Listing of applied styles applied to this object. More...
 

Detailed Description

Mesh stores the geometry data for rendering Model3D nodes.

A mesh has one or more clusters. Each cluster has material and primitives. Primitives are typically triangles stored as vertex data and index data.

You can load a mesh resource from a kzb file or use the Mesh::create() function to create a mesh.

After you create a Mesh with the constructor, Kanzi uploads all primitive data to GPU memory instead of storing the data in CPU memory in the Mesh.

See also
Mesh::CreateInfo

Member Typedef Documentation

typedef shared_ptr<Bone> kanzi::Mesh::BoneSharedPtr

Shared pointer type for Bone.

Constructor & Destructor Documentation

kanzi::Mesh::Mesh ( Domain domain,
const CreateInfo createInfo,
string_view  name 
)
explicitprotected

Member Function Documentation

static MeshSharedPtr kanzi::Mesh::create ( Domain domain,
const CreateInfo createInfo,
string_view  name 
)
static

Creates a mesh with specified mesh creation parameters.

To create a mesh, you need a Mesh::CreateInfo structure.

When you create a Mesh, Kanzi deploys the primitive vertex and index data to GPU memory.

Parameters
domainDomain for the mesh.
createInfoMesh creation parameters.
nameName of the mesh.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createSphere ( Domain domain,
float  radius,
unsigned int  segmentCount,
unsigned int  rowCount,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a sphere shape in a single cluster.

Parameters
domainThe domain to which the mesh belongs.
radiusRadius of the sphere
segmentCountNumber of segments for the shape
rowCountNumber of rows for the shape
nameName of the mesh.
materialMaterial pointer for the cluster.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createIcosphere ( Domain domain,
float  radius,
unsigned int  subdivisions,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a sphere shape in a single cluster.

Parameters
domainThe domain to which the mesh belongs.
radiusRadius of the sphere.
subdivisionsNumber of subdivision to apply.
nameName of the mesh.
materialMaterial pointer for the cluster.
Returns
Mesh shared pointer.
Since
Kanzi 3.9.4
static MeshSharedPtr kanzi::Mesh::createQuadsphere ( Domain domain,
float  radius,
unsigned int  subdivisions,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a sphere shape in a single cluster.

Parameters
domainThe domain to which the mesh belongs.
radiusRadius of the sphere.
subdivisionsNumber of subdivision to apply.
nameName of the mesh.
materialMaterial pointer for the cluster.
Returns
Mesh shared pointer.
Since
Kanzi 3.9.4
static MeshSharedPtr kanzi::Mesh::createBox ( Domain domain,
Vector3  size,
unsigned int  subdivisions,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a mesh with a box shape in a single cluster.

Parameters
domainThe domain to which the mesh belongs.
sizeSize of the box.
subdivisionsAmount of subdivision to apply.
nameName of the mesh.
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
Returns
Mesh shared pointer.
static MeshSharedPtr kanzi::Mesh::createPlane ( Domain domain,
float  width,
float  height,
unsigned int  subdivisions,
bool  invertU,
bool  invertV,
string_view  name,
MaterialSharedPtr  material = MaterialSharedPtr() 
)
static

Creates a plane shape.

Parameters
domainThe domain to which the mesh belongs.
widthWidth of the plane, that is, the size along the x axis.
heightHeight of the plane, that is, the size along the y axis.
subdivisionsAmount of subdivision to apply.
invertUWhether to invert the first texture coordinate.
invertVWhether to invert the second texture coordinate.
nameName of the mesh.
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
Returns
Mesh shared pointer.
void kanzi::Mesh::bind ( Renderer renderer,
size_t  clusterIndex,
ShaderProgramSharedPtr  shaderProgram 
)

Prepares a cluster from the mesh for rendering with the specified shader.

Parameters
rendererRenderer to use.
clusterIndexWhich cluster to render.
shaderProgramWhich ShaderProgram to render with.
Box kanzi::Mesh::getBoundingBox ( ) const

Returns the bounding box of a mesh.

Returns
Bounding box for the mesh.
size_t kanzi::Mesh::getVertexCount ( ) const
inline

Returns the vertex count of the mesh.

Returns
Number of vertices in mesh.
size_t kanzi::Mesh::getVertexAttributeCount ( ) const
inline

Gets the number of the vertex attributes in the mesh.

Returns
Number of vertex attributes in mesh.
const MeshVertexAttribute& kanzi::Mesh::getVertexAttribute ( unsigned int  index) const
inline

Gets a vertex attribute by its index.

The vertex attribute index must be valid.

Parameters
indexIndex to access.
Returns
Vertex attribute
Since
Kanzi 3.9.7
optional<unsigned int> kanzi::Mesh::getVertexAttributeIndex ( VertexAttribute::Semantic  semantic) const
inline

Gets a vertex attribute index by semantic.

Parameters
semanticSemantic to use.
Returns
Vertex attribute index. If there is no matching semantic, returns nullopt.
Since
Kanzi 3.9.7
optional<unsigned int> kanzi::Mesh::getVertexAttributeIndex ( VertexAttribute::Semantic  semantic,
unsigned int  index 
) const
inline

Gets a vertex attribute index by semantic and semantic index.

Parameters
semanticSemantic to use.
indexSemantic index to use.
Returns
Vertex attribute index. If there is no matching semantic and index, returns nullopt.
Since
Kanzi 3.9.7
size_t kanzi::Mesh::getVertexSize ( ) const
inline

Gets size of one vertex in bytes.

Returns
Size of vertex in bytes.
span<const byte> kanzi::Mesh::getVertexData ( ) const
inline

Gets raw vertex data.

User is responsible for casting the data to proper format for reading.

Returns
Raw vertex data. If data is not preserved in RAM, the returned span is empty.
size_t kanzi::Mesh::getClusterCount ( ) const
inline

Gets the number of clusters in the mesh.

Returns
Number of clusters in the mesh.
size_t kanzi::Mesh::getClusterIndexCount ( size_t  clusterIndex) const

Gets the number of indices in a specified cluster.

Parameters
clusterIndexThe cluster to query.
Returns
Number of indices in the cluster.
GraphicsPrimitiveType kanzi::Mesh::getClusterPrimitiveType ( size_t  clusterIndex) const

Gets the primitive type for the cluster.

Parameters
clusterIndexThe cluster to query.
Returns
The primitive type for the cluster.
void kanzi::Mesh::setClusterPrimitiveType ( size_t  clusterIndex,
GraphicsPrimitiveType  primitiveType 
)

Sets the primitive type for the cluster.

Parameters
clusterIndexThe cluster to query.
primitiveTypeThe primitive type for the cluster.
Since
Kanzi 3.9.6
IndexBufferType kanzi::Mesh::getClusterIndexType ( size_t  clusterIndex) const

Gets the index type for the cluster.

Parameters
clusterIndexThe cluster to query.
Returns
The index type for the cluster.
MaterialSharedPtr kanzi::Mesh::getClusterMaterial ( size_t  clusterIndex) const

Gets the cluster material.

Parameters
clusterIndexThe cluster to query.
Returns
The material for the cluster.
void kanzi::Mesh::setClusterMaterial ( size_t  clusterIndex,
MaterialSharedPtr  material 
)

Sets the cluster material.

Parameters
clusterIndexThe cluster for which to set the material.
materialThe material to apply to the cluster.
span<const byte> kanzi::Mesh::getClusterIndexData ( size_t  clusterIndex) const

Gets index data for given cluster.

Make sure to cast the data to the correct format for reading. Use getClusterIndexType() to get the correct format.

Parameters
clusterIndexThe cluster to query.
Returns
Raw cluster index data. If data is not preserved in RAM, the returned span is empty.
optional<Matrix4x4> kanzi::Mesh::updateSkeletonTransformation ( Model3D model)

Updates bounding box of mesh with bones from given model and root transformation of the skeleton.

Parameters
modelNode to update.
Returns
If skinning is enabled for the mesh, armature root transform, otherwise empty optional.
const Skeleton& kanzi::Mesh::getSkeleton ( ) const
inline

Returns the skeleton of the mesh.

Returns
The skeleton of the mesh. If the mesh is not skinned, the skeleton has zero bones.
void kanzi::Mesh::attachSkeleton ( Model3D model)

Attaches the mesh skeleton runtime to the node.

Parameters
modelRoot node for the bone lookups.
void kanzi::Mesh::detachSkeleton ( Model3D model)

Detaches the mesh skeleton runtime from the node.

Parameters
modelRoot node for the bone lookups.
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.

Parameters
shaderProgramShader program.
Returns
Attribute map (mesh attribute index -> shader attribute index).
void kanzi::Mesh::applySkeleton ( Renderer renderer,
Node baseNode,
ShaderProgramSharedPtr  shaderProgram 
)

Applies bone animation, updating matrix palette transformation uniforms.

Parameters
rendererRenderer to use.
baseNodeRoot node for bones.
shaderProgramShader program in use.
void kanzi::Mesh::bindAttribute ( Renderer renderer,
unsigned int  shaderAttributeIndex,
size_t  meshVertexAttributeIndex 
)

Takes one mesh vertex attribute from mesh and makes it usable with (current) shader.

Parameters
rendererRenderer.
shaderAttributeIndexShader attribute index. This is the target, where attribute data is directed.
meshVertexAttributeIndexMesh attribute index. This is the source, where attibute data is taken from.
unsigned int kanzi::Mesh::bindAttributes ( Renderer renderer,
ShaderProgramSharedPtr  shaderProgram 
)

Makes all mesh vertex attributes available with a shader program.

Parameters
rendererRenderer.
shaderProgramShader program.
Returns
Bitfield: nth bit indicates that nth shader attribute was sourced from the mesh.
void kanzi::Mesh::bindIndices ( Renderer renderer,
size_t  clusterIndex 
)

Makes mesh cluster indices available to the next draw call.

Parameters
rendererRenderer.
clusterIndexIndex of cluster to prepare.
MappedBufferPtr kanzi::Mesh::mapVertexData ( )

Maps the vertex data of the mesh on the GPU to a CPU memory region.

Returns
Unique pointer to the mapped buffer if the mapping succeeded, nullptr if failed.
void kanzi::Mesh::setVertexData ( ConstByteSpan  data)

Sets the vertex data of the mesh.

Parameters
dataData to set to as vertex buffer data.
void kanzi::Mesh::setVertexSubData ( ConstByteSpan  data,
unsigned int  offset 
)

Sets a section of the vertex data of the mesh.

Parameters
dataData to set to as vertex buffer data.
offsetByte offset from the start of the vertex data where to start the newly set data.
MappedBufferPtr kanzi::Mesh::mapIndexData ( size_t  clusterIndex)

Maps the index data of a cluster in the mesh on the GPU to a CPU memory region.

Parameters
clusterIndexIndex of the cluster whose index data to map.
Returns
Unique pointer to the mapped buffer if the mapping succeeded, nullptr if failed.
void kanzi::Mesh::setIndexData ( size_t  clusterIndex,
ConstByteSpan  data 
)

Sets the index data of a cluster in the mesh.

This is a synchronous call to copy the data to the GPU.

Parameters
clusterIndexIndex of the cluster whose index data to map.
dataData to set to set as a buffer index data.
void kanzi::Mesh::setIndexSubData ( size_t  clusterIndex,
ConstByteSpan  data,
unsigned int  offset 
)

Sets a section of the index data of a cluster in the mesh.

Parameters
clusterIndexIndex of the cluster whose index data to map.
dataData to set to set as a buffer index data.
offsetByte offset from the start of the index data where to start the newly set data.
MappedBufferPtr kanzi::Mesh::mapInstanceData ( )

Maps the instance data of the mesh on the GPU to a CPU memory region.

Returns
If the mapping succeeds, returns a unique pointer to the mapped buffer. If the mapping fails, returns a nullptr.
Since
Kanzi 3.9.6
void kanzi::Mesh::setInstanceData ( ConstByteSpan  data)

Sets the instance data of the mesh.

Parameters
dataData to set as the instance buffer data.
Since
Kanzi 3.9.6
void kanzi::Mesh::setInstanceSubData ( ConstByteSpan  data,
unsigned int  offset 
)

Sets a section of the instance data of the mesh.

Parameters
dataData to set as the instance buffer data.
offsetByte offset from the start of the instance data where to start the newly set data.
Since
Kanzi 3.9.6
static ResourceManager::LoadTaskSharedPtr kanzi::Mesh::createLoadTask ( string_view  name,
KzbFile kzbFile,
ReadOnlyMemoryFilePtr  file 
)
static
GPUBuffer::NativeHandle kanzi::Mesh::getNativeVertexBufferHandle ( )
inline

Gets the native handle for vertex data of the mesh.

Returns
Native vertex buffer handle if available, otherwise GPUBuffer::NativeHandleInvalid.
Since
Kanzi 3.9.6
GPUBuffer::NativeHandle kanzi::Mesh::getNativeIndexBufferHandle ( size_t  clusterIndex)
inline

Gets the native handle for index data of the cluster.

Parameters
clusterIndexIndex of the cluster whose index buffer to get.
Returns
Native index buffer handle if available, otherwise GPUBuffer::NativeHandleInvalid.
Since
Kanzi 3.9.6
GPUBuffer::NativeHandle kanzi::Mesh::getNativeInstanceBufferHandle ( )
inline

Gets the native handle for the instance data of the mesh.

Returns
Native vertex buffer handle if available, otherwise GPUBuffer::NativeHandleInvalid.
Since
Kanzi 3.9.6
void kanzi::Mesh::reloadOverride ( )
overrideprotectedvirtual

Resource::reloadOverride() implementation.

Reimplemented from kanzi::Resource.

void kanzi::Mesh::reloadFromKzbOverride ( KzbFile kzbFile,
ReadOnlyMemoryFile file,
KzbMemoryParser parser 
)
overrideprotectedvirtual

Resource::reloadFromKzbOverride() implementation.

Reimplemented from kanzi::Resource.

void kanzi::Mesh::invalidateOverride ( )
overrideprotectedvirtual

GPUResource::invalidateOverride() implementation.

Reimplemented from kanzi::GPUResource.

void kanzi::Mesh::destroyOverride ( )
overrideprotectedvirtual

GPUResource::destroyOverride() implementation.

Reimplemented from kanzi::GPUResource.

bool kanzi::Mesh::isDeployedOverride ( ) const
overrideprotectedvirtual

GpuResource::isDeployed() implementation.

Implements kanzi::GPUResource.

unsigned int kanzi::Mesh::getGPUMemoryUsageOverride ( ) const
overrideprotectedvirtual

GpuResource::getGPUMemoryUsageOverride() implementation.

Reimplemented from kanzi::GPUResource.

unsigned int kanzi::Mesh::getCPUMemoryUsageOverride ( ) const
overrideprotectedvirtual

Resource::getCPUMemoryUsageOverride() implementation.

Reimplemented from kanzi::Resource.

Friends And Related Function Documentation

void swap ( Mesh mesh1,
Mesh mesh2 
)
friend

The documentation for this class was generated from the following file: