All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kanzi::Mesh Class Reference

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

#include <kanzi/graphics_3d/mesh.hpp>

Inheritance diagram for kanzi::Mesh:
kanzi::GPUResource kanzi::Resource kanzi::Object

Public Member Functions

 Mesh (Domain *domain, string_view name="")
 
virtual ~Mesh () KZ_OVERRIDE
 
void createBoundingVolume ()
 Update bounding volume for the mesh. More...
 
void initializeFromMemory (unsigned int vertexAttributeCount, const kzString *vertexAttributeNames, const VertexAttribute::Semantic *vertexAttributeSemantics, const GraphicsDataType *vertexAttributeDataTypes, const unsigned int *vertexAttributeDimensions, unsigned int vertexCount, const kzByte *vertexData, unsigned int clusterCount, const unsigned int *clusterIndexCounts, const kzU16 *const *clusterIndices, const GraphicsPrimitiveType *clusterTypes, MaterialSharedPtr const *clusterMaterials)
 Creates a mesh from the data provided in the parameters. More...
 
void generateSphere (float radius, unsigned int segmentCount, unsigned int rowCount, MaterialSharedPtr material=MaterialSharedPtr(), kzString materialURL="")
 Populates a mesh with a sphere shape in a single cluster. More...
 
void generateBox (float width, float height, float depth, MaterialSharedPtr material=MaterialSharedPtr(), kzString materialURL="")
 Populates a mesh with a box shape in a single cluster. More...
 
void generatePlane (float width, float height, bool invertU, bool invertV, MaterialSharedPtr material=MaterialSharedPtr(), kzString materialURL="")
 Generates a plane shape. More...
 
void bind (unsigned int clusterIndex, ShaderSharedPtr shader)
 Prepares a cluster from the mesh for rendering with the specified shader. More...
 
void unbind (ShaderSharedPtr shader)
 Cleans up the rendering preparations done in the bind() function. More...
 
KzuBoundingVolumeSharedPtr getBoundingVolume ()
 Returns the bounding volume of the mesh. More...
 
unsigned int 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...
 
void getVertexAttributeInfo (unsigned int index, string &out_name, VertexAttribute::Semantic *out_semantic, GraphicsDataType *out_dataType, unsigned int *out_dimension, unsigned int *out_offset, unsigned int *out_size)
 Gets the information about the specific vertex attribute in the mesh. More...
 
unsigned int getVertexSize () const
 Gets the vertex size. More...
 
const kzBytegetVertexData () const
 Gets the pointer to the vertex data. More...
 
unsigned int getClusterCount () const
 Gets the number of clusters in the mesh. More...
 
unsigned int getIndexCount (unsigned int clusterIndex) const
 Gets the number of indices in a specified cluster. More...
 
const kzU16getIndices (unsigned int clusterIndex) const
 Gets the index data in the specified cluster. More...
 
GraphicsPrimitiveType getClusterType (unsigned int clusterIndex) const
 Gets the primitive type for the cluster. More...
 
MaterialgetMaterial (unsigned int clusterIndex) const
 Gets the cluster material. More...
 
void setMaterial (unsigned int clusterIndex, MaterialSharedPtr material)
 Sets the cluster material. More...
 
bool updateBoundingBox (Node3D *baseNode, const KzcDynamicArray *transformedObjectList)
 
size_t getBoneCount () const
 
Node3DgetBoneNode (size_t boneIndex) const
 
Node3DgetBoneChildJoint (size_t boneIndex) const
 
void attach (Node *baseNode)
 
void detach ()
 
bool isRenderable () const
 
void setPrimitiveVertexAttributes ()
 
void loadVertices (KzcInputStream *inputStream, bool halfFloatSupported)
 
void loadDataFromKZB (const KzuResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file)
 
void loadPrimitiveFromKZB (const KzuResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file)
 Loads mesh primitive from KZB. More...
 
int acquireAttributeIndex (StringToAttributeIndexSharedPtr attributeMap, const string &shaderAttributeName)
 
vector< int > const & acquireAttributeMap (ShaderSharedPtr shader)
 
void interpolateMorphTargets ()
 
void applySkeleton (Node *baseNode, const KzcDynamicArray *transformedObjectList)
 
VertexAttribute const & getVertexAttribute (int index) const
 
void bindAttribute (Renderer *renderer, unsigned int shaderAttributeIndex, int meshVertexAttributeIndex)
 Binds the vertex buffer and sets the vertex attribute pointer. More...
 
unsigned int bindAttributes (ShaderSharedPtr shader)
 
void bindIndices (unsigned int clusterIndex)
 
void bindMorphAttributes (Morph *morph)
 
void removeAttributeMapping (ShaderSharedPtr shader, const string &shaderAttribute)
 
void prepareMorph ()
 
virtual void loadFromKZB (const KzuResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file) KZ_OVERRIDE
 Function for loading the resource from .KZB. More...
 
virtual void finishLoadingOverride (const KzuResourceLoaderThreadContext *threadContext) KZ_OVERRIDE
 Function for finishing the loading of the resource. More...
 
virtual void unloadOverride () KZ_OVERRIDE
 Unload function for resource. More...
 
virtual unsigned int getCPUMemoryUsage () const KZ_OVERRIDE
 Function for getting the memory usage of a resource. More...
 
virtual void freeCommonData () KZ_OVERRIDE
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
- Public Member Functions inherited from kanzi::GPUResource
virtual ~GPUResource () KZ_OVERRIDE
 
void deploy ()
 Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. More...
 
void undeploy ()
 Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. More...
 
void invalidate ()
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
unsigned int getGPUMemoryUsage () const
 
RenderergetRenderer () const
 
bool getDeployOnLoad () const
 Returns true if GPUResource is automatically deployed when loaded. More...
 
void setDeployOnLoad (bool value)
 Sets GPUResource automatic deployment on loade on or orr. More...
 
bool isDeployed () const
 
void deployed ()
 
void undeployed ()
 
- Public Member Functions inherited from kanzi::Resource
KzcMemoryManagergetMemoryManager () const
 
 Resource (Domain *domain, string_view name)
 
virtual ~Resource ()
 
void setKZB (const KzuBinaryDirectory *binaryDirectory, kzString path)
 
void setLoaded ()
 
kzString getName () const
 Accessor. More...
 
void load ()
 
void unload ()
 
bool isLoaded () const
 
void kzuResourceLoad_private (const KzuResourceLoaderThreadContext *threadContext)
 Private function for kzuResourceLoad() with specified thread context. More...
 
void kzuResourceFinishLoading_private (const KzuResourceLoaderThreadContext *threadContext)
 Private function for finishing the loading of the resource. More...
 
KzuResourceLoadingStrategy getLoadingStrategy () const
 
void setLoadingStrategy (KzuResourceLoadingStrategy loadingStrategy)
 
bool getKeepAlive () 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 ()
 
DomaingetDomain () const
 Returns the domain the object belongs to. More...
 
KzuPropertyManager * getPropertyManager () const
 Returns the property manager of the object. More...
 
KzuTaskSchedulergetTaskScheduler () const
 Returns the task scheduler of the object. More...
 
KzuMessageDispatchergetMessageDispatcher () const
 Returns the message dispatcher of the object. More...
 
ResourceManagergetResourceManager () const
 Returns the resource manager of the object. More...
 
virtual const MetaclassgetDynamicMetaclass () const
 Returns the metaclass of the dynamic type of the object. More...
 
bool isTypeOf (const Metaclass *objectType) const
 Determines if the type of this object is the given type or derived from it. More...
 
template<typename DataType >
void setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType value)
 Sets the local value of a property. More...
 
void setProperty (const PropertyType< ResourceID > &propertyType, ResourceSharedPtr value)
 Sets the local value of a resource id property with a resource pointer. More...
 
template<typename DataType >
DataType getProperty (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property. More...
 
template<typename DataType >
bool getProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType &value) 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 >
void setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType value)
 
void setAbstractProperty (AbstractPropertyType abstractPropertyType, ResourceSharedPtr value)
 
template<typename DataType >
DataType getAbstractProperty (AbstractPropertyType abstractPropertyType) const
 
template<typename DataType >
bool getAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType &value) const
 
bool hasValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value. More...
 
bool hasLocalValue (AbstractPropertyType propertyType) const
 Evaluates whether there is a local value set for the property. More...
 
void removeLocalValue (AbstractPropertyType propertyType)
 Removes the local value associated with the property. More...
 
void copyLocalValues (const Object &other)
 Copies all local values from another object. More...
 
virtual void onPropertyChanged (AbstractPropertyType propertyType, KzuPropertyNotificationReason reason)
 Virtual function to handle property change notifications. More...
 
AppliedStyleEntryapplyObjectStyle (kanzi::StyleSharedPtr style)
 Applies a style to an object. More...
 
void unapplyObjectStyle (AppliedStyleEntry *appliedStyleEntry)
 
void applyObjectStyles ()
 Apply all styles for an object node. More...
 
void unapplyObjectStyles ()
 Unapplies and removes all applied styles. More...
 

Static Public Member Functions

static MeshSharedPtr create (Domain *domain, string_view name="")
 
- 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...
 

Protected Member Functions

virtual void deployOverride () KZ_OVERRIDE
 Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy() More...
 
virtual void undeployOverride () KZ_OVERRIDE
 Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy() More...
 
virtual void invalidateOverride () KZ_OVERRIDE
 Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate() More...
 
virtual unsigned int getGPUMemoryUsageOverride () const KZ_OVERRIDE
 
- Protected Member Functions inherited from kanzi::GPUResource
 GPUResource (Domain *domain, string_view name="")
 
- Protected Member Functions inherited from kanzi::Resource
KzuResourceLoadState getLoadState ()
 Access. More...
 
- Protected Member Functions inherited from kanzi::Object
void initialize ()
 
void onCopy (const Object &other)
 

Additional Inherited Members

- Protected Types inherited from kanzi::Object
typedef vector
< AppliedStyleEntry * > 
AppliedStyleContainer
 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.

Each mesh has one or more clusters. Each cluster has vertex data, index data, and a material.

You can load a mesh from a .kzb file or create it with the createEmpty() function.

Constructor & Destructor Documentation

kanzi::Mesh::Mesh ( Domain domain,
string_view  name = "" 
)
explicit
virtual kanzi::Mesh::~Mesh ( )
virtual

Member Function Documentation

static MeshSharedPtr kanzi::Mesh::create ( Domain domain,
string_view  name = "" 
)
static
void kanzi::Mesh::createBoundingVolume ( )

Update bounding volume for the mesh.

void kanzi::Mesh::initializeFromMemory ( unsigned int  vertexAttributeCount,
const kzString vertexAttributeNames,
const VertexAttribute::Semantic vertexAttributeSemantics,
const GraphicsDataType vertexAttributeDataTypes,
const unsigned int *  vertexAttributeDimensions,
unsigned int  vertexCount,
const kzByte vertexData,
unsigned int  clusterCount,
const unsigned int *  clusterIndexCounts,
const kzU16 *const *  clusterIndices,
const GraphicsPrimitiveType clusterTypes,
MaterialSharedPtr const *  clusterMaterials 
)

Creates a mesh from the data provided in the parameters.

Parameters
vertexAttributeCountNumber of vertex attributes
vertexAttributeNamesArray of vertex attribute names
vertexAttributeSemanticsArray of vertex attribute semantics
vertexAttributeDataTypesArray of vertex attribute data types
vertexAttributeDimensionsArray of vertex attribute dimensions
vertexCountNumber of vertices
vertexDataVertex data, vertexCount formatted by vertex attributes
clusterCountNumber of clusters
clusterIndexCountsArray of cluster index counts
clusterIndicesArray of pointers to cluster index data
clusterTypesArray of cluster primitive type
void kanzi::Mesh::generateSphere ( float  radius,
unsigned int  segmentCount,
unsigned int  rowCount,
MaterialSharedPtr  material = MaterialSharedPtr(),
kzString  materialURL = "" 
)

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

Parameters
radiusRadius of the sphere
segmentCountNumber of segments for the shape
rowCountNumber of rows for the shape
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave material empty.
void kanzi::Mesh::generateBox ( float  width,
float  height,
float  depth,
MaterialSharedPtr  material = MaterialSharedPtr(),
kzString  materialURL = "" 
)

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

Parameters
widthWidth of the box (size along the x axis)
heightHeight of the box (size along the y axis)
depthDepth of the box (size along z axis)
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave the material parameter empty.
void kanzi::Mesh::generatePlane ( float  width,
float  height,
bool  invertU,
bool  invertV,
MaterialSharedPtr  material = MaterialSharedPtr(),
kzString  materialURL = "" 
)

Generates a plane shape.

Parameters
widthWidth of the plane (size along the x axis)
heightHeight of the plane (size along the y axis)
invertUIf true, the first texture coordinate is inverted
invertVIf true, the second texture coordinate is inverted
materialMaterial pointer for the cluster. If set, leave the materialURL parameter empty.
materialURLResource address for the cluster material. If set, leave the material parameter empty.
void kanzi::Mesh::bind ( unsigned int  clusterIndex,
ShaderSharedPtr  shader 
)

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

After the cluster is rendered, call the unbind() function.

Parameters
clusterIndexWhich cluster to render
shaderWhich shader to render with
void kanzi::Mesh::unbind ( ShaderSharedPtr  shader)

Cleans up the rendering preparations done in the bind() function.

Parameters
shaderThe shader used in the bind() function
KzuBoundingVolumeSharedPtr kanzi::Mesh::getBoundingVolume ( )

Returns the bounding volume of the mesh.

unsigned int kanzi::Mesh::getVertexCount ( ) const

Returns the vertex count of the mesh.

size_t kanzi::Mesh::getVertexAttributeCount ( ) const

Gets the number of the vertex attributes in the mesh.

void kanzi::Mesh::getVertexAttributeInfo ( unsigned int  index,
string &  out_name,
VertexAttribute::Semantic out_semantic,
GraphicsDataType out_dataType,
unsigned int *  out_dimension,
unsigned int *  out_offset,
unsigned int *  out_size 
)

Gets the information about the specific vertex attribute in the mesh.

Parameters
indexWhich vertex attribute to query
out_nameName of the vertex attribute
out_semanticSemantic of the vertex attribute
out_dataTypeData type of the vertex attribute
out_dimensionDimension of the vertex attribute
out_offsetOffset of the vertex data for the vertex attribute
out_sizeSize of the vertex attribute
unsigned int kanzi::Mesh::getVertexSize ( ) const

Gets the vertex size.

const kzByte* kanzi::Mesh::getVertexData ( ) const

Gets the pointer to the vertex data.

unsigned int kanzi::Mesh::getClusterCount ( ) const

Gets the number of clusters in the mesh.

unsigned int kanzi::Mesh::getIndexCount ( unsigned int  clusterIndex) const

Gets the number of indices in a specified cluster.

Parameters
clusterIndexWhich cluster to query
Returns
Number of indices in the cluster
const kzU16* kanzi::Mesh::getIndices ( unsigned int  clusterIndex) const

Gets the index data in the specified cluster.

Parameters
clusterIndexWhich cluster to query
Returns
The pointer to the index data in the cluster.
GraphicsPrimitiveType kanzi::Mesh::getClusterType ( unsigned int  clusterIndex) const

Gets the primitive type for the cluster.

Parameters
clusterIndexWhich cluster to query
Returns
The primitive type for the cluster.
Material* kanzi::Mesh::getMaterial ( unsigned int  clusterIndex) const

Gets the cluster material.

Parameters
clusterIndexWhich cluster to query
Returns
The material for the cluster.
void kanzi::Mesh::setMaterial ( unsigned int  clusterIndex,
MaterialSharedPtr  material 
)

Sets the cluster material.

Parameters
clusterIndexThe cluster for which to set the material
materialThe material to apply to the cluster
bool kanzi::Mesh::updateBoundingBox ( Node3D baseNode,
const KzcDynamicArray transformedObjectList 
)
size_t kanzi::Mesh::getBoneCount ( ) const
Node3D* kanzi::Mesh::getBoneNode ( size_t  boneIndex) const
Node3D* kanzi::Mesh::getBoneChildJoint ( size_t  boneIndex) const
void kanzi::Mesh::attach ( Node baseNode)
void kanzi::Mesh::detach ( )
bool kanzi::Mesh::isRenderable ( ) const
void kanzi::Mesh::setPrimitiveVertexAttributes ( )
void kanzi::Mesh::loadVertices ( KzcInputStream inputStream,
bool  halfFloatSupported 
)
void kanzi::Mesh::loadDataFromKZB ( const KzuResourceLoaderThreadContext threadContext,
KzcInputStream inputStream,
const KzuBinaryFileInfo file 
)
void kanzi::Mesh::loadPrimitiveFromKZB ( const KzuResourceLoaderThreadContext threadContext,
KzcInputStream inputStream,
const KzuBinaryFileInfo file 
)

Loads mesh primitive from KZB.

int kanzi::Mesh::acquireAttributeIndex ( StringToAttributeIndexSharedPtr  attributeMap,
const string &  shaderAttributeName 
)
vector<int> const& kanzi::Mesh::acquireAttributeMap ( ShaderSharedPtr  shader)
void kanzi::Mesh::interpolateMorphTargets ( )
void kanzi::Mesh::applySkeleton ( Node baseNode,
const KzcDynamicArray transformedObjectList 
)
VertexAttribute const& kanzi::Mesh::getVertexAttribute ( int  index) const
void kanzi::Mesh::bindAttribute ( Renderer renderer,
unsigned int  shaderAttributeIndex,
int  meshVertexAttributeIndex 
)

Binds the vertex buffer and sets the vertex attribute pointer.

unsigned int kanzi::Mesh::bindAttributes ( ShaderSharedPtr  shader)
void kanzi::Mesh::bindIndices ( unsigned int  clusterIndex)
void kanzi::Mesh::bindMorphAttributes ( Morph morph)
void kanzi::Mesh::removeAttributeMapping ( ShaderSharedPtr  shader,
const string &  shaderAttribute 
)
void kanzi::Mesh::prepareMorph ( )
virtual void kanzi::Mesh::loadFromKZB ( const KzuResourceLoaderThreadContext threadContext,
KzcInputStream inputStream,
const KzuBinaryFileInfo file 
)
virtual

Function for loading the resource from .KZB.

This function is called when loading the data from .KZB file. Implementations should call super class loadFromKZB before reading anything else from inputStream. This function is called from arbitrary loading threads. The parameter threadContext contains thread safe memory manager and a thread specific Property manager which can be locked with the threadLock in the threadContext. This function may not access resource manager or the UIDomain due to race conditions.

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::finishLoadingOverride ( const KzuResourceLoaderThreadContext threadContext)
virtual

Function for finishing the loading of the resource.

This function is called in the main thread after loading the data. Implementations should call super class finishLoading first. The parameter threadContext contains thread safe memory manager and the property manager that was used for loading the resource, which can be locked with the threadLock in the threadContext.

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::unloadOverride ( )
virtual

Unload function for resource.

Releases all memory taken by the resource except the resource loader.

Reimplemented from kanzi::GPUResource.

virtual unsigned int kanzi::Mesh::getCPUMemoryUsage ( ) const
virtual

Function for getting the memory usage of a resource.

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::freeCommonData ( )
virtual

Notify resource that graphics context was lost and all GPU resources are invalid.

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::deployOverride ( )
protectedvirtual

Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy()

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::undeployOverride ( )
protectedvirtual

Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy()

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Mesh::invalidateOverride ( )
protectedvirtual

Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate()

Reimplemented from kanzi::GPUResource.

virtual unsigned int kanzi::Mesh::getGPUMemoryUsageOverride ( ) const
protectedvirtual

Reimplemented from kanzi::GPUResource.


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