Wasabi
|
#include <WGeometry.hpp>
Public Member Functions | |
virtual std::string | GetTypeName () const override |
virtual void | SetID (uint32_t newID) override |
virtual void | SetName (std::string newName) override |
WGeometry (Wasabi *const app, uint32_t ID=0) | |
virtual uint32_t | GetVertexBufferCount () const |
virtual W_VERTEX_DESCRIPTION | GetVertexDescription (uint32_t layoutIndex=0) const |
virtual size_t | GetVertexDescriptionSize (uint32_t layoutIndex=0) const |
WError | CreateFromData (void *vb, uint32_t numVerts, void *ib, uint32_t numIndices, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
virtual WError | CreateFromDefaultVerticesData (vector< WDefaultVertex > &default_vertices, vector< uint32_t > &indices, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateCube (float size, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateBox (WVector3 dimensions, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreatePlain (float size, int xsegs, int zsegs, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateRectanglePlain (float sizeX, float sizeZ, int xsegs, int zsegs, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateSphere (float radius, uint32_t vres=12, uint32_t ures=12, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateCone (float radius, float height, uint32_t hsegs, uint32_t csegs, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CreateCylinder (float radius, float height, uint32_t hsegs, uint32_t csegs, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | CopyFrom (WGeometry *const from, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_VB_CPU_READABLE|W_GEOMETRY_CREATE_IB_CPU_READABLE) |
WError | CreateAnimationData (void *animBuf, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_STATIC) |
WError | LoadFromHXM (std::string filename, W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
WError | MapVertexBuffer (void **const vb, W_MAP_FLAGS mapFlags) |
WError | MapIndexBuffer (void **const ib, W_MAP_FLAGS mapFlags) |
WError | MapAnimationBuffer (void **const ab, W_MAP_FLAGS mapFlags) |
void | UnmapVertexBuffer (bool recalculateBoundingBox=true) |
void | UnmapIndexBuffer () |
void | UnmapAnimationBuffer () |
WError | Scale (float mulFactor) |
WError | ScaleX (float mulFactor) |
WError | ScaleY (float mulFactor) |
WError | ScaleZ (float mulFactor) |
WError | ApplyOffset (float x, float y, float z) |
WError | ApplyOffset (WVector3 offset) |
WError | ApplyTransformation (WMatrix mtx) |
bool | Intersect (WVector3 p1, WVector3 p2, WVector3 *pt=nullptr, WVector2 *uv=nullptr, uint32_t *triangleIndex=nullptr) |
WError | Draw (class WRenderTarget *rt, uint32_t numIndices=-1, uint32_t numInstances=1, bool bindAnimation=true) |
WVector3 | GetMinPoint () const |
WVector3 | GetMaxPoint () const |
uint32_t | GetNumVertices () const |
uint32_t | GetNumIndices () const |
bool | IsRigged () const |
virtual bool | Valid () const override |
virtual WError | SaveToStream (WFile *file, std::ostream &outputStream) override |
virtual WError | LoadFromStream (WFile *file, std::istream &inputStream, std::vector< void * > &args, std::string nameSuffix) override |
![]() | |
WFileAsset (class Wasabi *const app, uint32_t ID=0) | |
virtual WError | LoadFromStream (class WFile *file, std::istream &inputStream, vector< void * > &args, std::string nameSuffix)=0 |
![]() | |
WBase (class Wasabi *const app, uint32_t ID=0) | |
uint32_t | GetID () const |
std::string | GetName () const |
class Wasabi * | GetAppPtr () const |
void | AddReference () |
void | RemoveReference () |
Static Public Member Functions | |
static std::string | _GetTypeName () |
static std::vector< void * > | LoadArgs (W_GEOMETRY_CREATE_FLAGS flags=W_GEOMETRY_CREATE_CPU_READABLE) |
Friends | |
class | WGeometryManager |
Additional Inherited Members | |
![]() | |
class Wasabi * | m_app |
uint32_t | m_ID |
std::string | m_name |
A WGeometry is a flexible way to represent any geometry that is needed for rendering or any general computation or usage. WGeometry can be derived such that one can modify the composition of the geometry (the attributes).
A geometry can be made immutable, making it use less memory, at the cost of having several functions not work (functions that require access to the geometry's vertex data).
WGeometry can hold several vertex buffers. By default, Wasabi uses the first buffer to render (with indices) and uses the second buffer (if available) for animation data.
|
static |
Returns "Geometry" string.
WError WGeometry::ApplyOffset | ( | float | x, |
float | y, | ||
float | z | ||
) |
Applies an offset to all vertices in the geometry. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
x | x offset to apply |
y | y offset to apply |
z | z offset to apply |
Applies an offset to all vertices in the geometry. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
offset | Offset to apply |
Applies a transformation matrix to all vertices in the geometry. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
mtx | Transformation matrix to apply |
WError WGeometry::CopyFrom | ( | WGeometry *const | from, |
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_VB_CPU_READABLE|W_GEOMETRY_CREATE_IB_CPU_READABLE |
||
) |
Copy another (non-immutable) geometry.
from | Geometry to copy |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateAnimationData | ( | void * | animBuf, |
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_STATIC |
||
) |
Creates animation data vertex buffer. The geometry must have GetVertexBufferCount() > 1. The buffer will be dynamic if the first vertex buffer (created from a Load*, CreateFromData() or CopyFrom() call) was dynamic, false otherwise. If the geometry of this object is immutable, the the animation buffer will also be.
animBuf | A pointer to the memory to create the animation buffer from, which must be a valid contiguous memory of size GetNumVertices()*GetVertexDescription(1).GetSize() |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateBox | ( | WVector3 | dimensions, |
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a box geometry.
dimensions | Dimensions of the box |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateCone | ( | float | radius, |
float | height, | ||
uint32_t | hsegs, | ||
uint32_t | csegs, | ||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a cone geometry, with csegs segments at the bottom circle and hsegs segments along the cone's height.
radius | Radius of the bottom circle |
height | Height of the cone |
hsegs | Number of segments along the height, minimum is 0 |
csegs | Number of segments at the bottom circle, minimum is 3 |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateCube | ( | float | size, |
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a cube geometry.
If this function is called while the engine parameter "geometryImmutable" (see Wasabi::engineParams) is set to true, then the geometry will be made immutable, regardless of the bDynamic parameter. Immutable geometry cannot have the following function calls work: SaveToWGM(), all map and unmap functions, all scaling functions, all offset functions and Intersect(). Immutable geometry cannot be copied. Immutable geometry uses less memory.
size | Dimension of the cube |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateCylinder | ( | float | radius, |
float | height, | ||
uint32_t | hsegs, | ||
uint32_t | csegs, | ||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a cylinder geometry, with csegs segments at the bottom and top circles and hsegs segments along the cylinder's height.
radius | Radius of the cylinder |
height | Height of the cylinder |
hsegs | Number of segments along the height, minimum is 0 |
csegs | Number of segments at the bottom and top circles, minimum is 3 |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateFromData | ( | void * | vb, |
uint32_t | numVerts, | ||
void * | ib, | ||
uint32_t | numIndices, | ||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a geometry from buffers in memory. The buffers must be formatted such that they match what GetVertexDescription() returns. This function fills up only the first (0th) vertex buffer that is accompanied with an index buffer for rendering use.
If this function is called while the engine parameter "geometryImmutable" (see Wasabi::engineParams) is set to true, then the geometry will be made immutable, regardless of the bDynamic parameter. Immutable geometry cannot have the following function calls work: SaveToWGM(), all map and unmap functions, all scaling functions, all offset functions and Intersect(). Immutable geometry cannot be copied. Immutable geometry uses less memory.
Examples: Create a triangle:
vb | A pointer to the memory containing the vertex data, which must be a valid contiguous memory of size num_verts*GetVertexDescription(0).GetSize() |
numVerts | Number of vertices in vb |
ib | A pointer to the memory containing the index data, which must be a valid contiguous memory of size num_indices*sizeof(uint) |
numIndices | Number of indices in ab |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
|
virtual |
Called by CreateBox, CreateSphere, etc... to convert the given default vertices (of type WDefaultVertex) to the custom type for this geometry. This can be overrided to utilize the Create* functions while using a custom vertex format
WError WGeometry::CreatePlain | ( | float | size, |
int | xsegs, | ||
int | zsegs, | ||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a plain geometry that is segmented. The plain will be split into (xsegs+1)*(zsegs+1) squares, which will have 2 triangles each.
size | Size (dimension) of the plain |
xsegs | Number of segments on the X axis, minimum is 0 |
zsegs | Number of segments on the Z axis, minimum is 0 |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateRectanglePlain | ( | float | sizeX, |
float | sizeZ, | ||
int | xsegs, | ||
int | zsegs, | ||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a plain geometry that is segmented. The plain will be split into (xsegs+1)*(zsegs+1) squares, which will have 2 triangles each.
sizeX | Size (dimension) of the plain on the X axis |
sizeZ | Size (dimension) of the plain on the Z axis |
xsegs | Number of segments on the X axis, minimum is 0 |
zsegs | Number of segments on the Z axis, minimum is 0 |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::CreateSphere | ( | float | radius, |
uint32_t | vres = 12 , |
||
uint32_t | ures = 12 , |
||
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Creates a sphere geometry, with VRes vertical segments and URes horizontal segments.
radius | Radius of the sphere |
vres | Vertical resolution, or number of vertical splits, minimum is 3 |
ures | Horizontal resolution, or number of horizontal splits, minimum is 2 |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::Draw | ( | class WRenderTarget * | rt, |
uint32_t | numIndices = -1 , |
||
uint32_t | numInstances = 1 , |
||
bool | bindAnimation = true |
||
) |
Draw the geometry to the render target. This function will bind the geometry buffer to vertex buffer slot 0 in Vulkan, and will bind the animation buffer (if available and requested) to slot 1. The render target must have its Begin() function called before this function is called.
rt | Render target to draw to |
numIndices | Number of indices to draw, -1 for all. If the geometry has no indices, this is the number of vertices to draw, -1 for all |
numInstances | Number of instances to draw |
bindAnimation | true to bind the animation buffer (if not available, the geometry buffer will be bound twice), false otherwise |
WVector3 WGeometry::GetMaxPoint | ( | ) | const |
Retrieves the point that represents the maximum boundary of the geometry.
WVector3 WGeometry::GetMinPoint | ( | ) | const |
Retrieves the point that represents the minimum boundary of the geometry.
uint32_t WGeometry::GetNumIndices | ( | ) | const |
Retrieves the number of indices in the geometry.
uint32_t WGeometry::GetNumVertices | ( | ) | const |
Retrieves the number of vertices in the geometry.
|
overridevirtual |
This function must be implemented by a child class. This is used for debugging, in which a class should return its name.
Implements WBase.
|
inlinevirtual |
This function should return the number of vertex descriptions that GetVertexDescription() can return, which represents the number of vertex buffers this geometry class can hold.
|
virtual |
Retrieves the vertex description of a vertex buffer. Should return valid descriptions for all layout_index values between 0 and GetVertexBufferCount()-1.
The default vertex description (for default geometry) is:
layoutIndex | Index of the vertex buffer |
|
virtual |
Retrieves the size of the vertex description at the given index.
layoutIndex | Index of the vertex buffer |
bool WGeometry::Intersect | ( | WVector3 | p1, |
WVector3 | p2, | ||
WVector3 * | pt = nullptr , |
||
WVector2 * | uv = nullptr , |
||
uint32_t * | triangleIndex = nullptr |
||
) |
Checks if a ray intersects the geometry. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
p1 | Origin of the ray |
p2 | A vector that points in the same direction as the ray |
pt | A pointer to a 3D vector to be populated with the point of intersection, if any |
uv | A pointer to a 2D vector to be populated with the UV coordinates at the intersection point, if any. If the vertices don't have a an attribute named uv (with at least two components) then this will be the UV coordinates local to the triangle intersected |
triangleIndex | A pointer to an integer to be populated with the index of the triangle that was intersected, if any |
bool WGeometry::IsRigged | ( | ) | const |
Checks if the geometry has an animation vertex buffer.
WError WGeometry::LoadFromHXM | ( | std::string | filename, |
W_GEOMETRY_CREATE_FLAGS | flags = W_GEOMETRY_CREATE_CPU_READABLE |
||
) |
Load a geometry from an HXM file. The geometry in the HXM file may be of a different format, in which case this function will try to fill in the attributes that the two formats share, discarding the rest. If no normal or tangent data are found in the file, but are available in this geometry's description, the function will attempt to fill them in automatically.
filename | Name of the file to load |
flags | Creation flags, see W_GEOMETRY_CREATE_FLAGS |
WError WGeometry::MapAnimationBuffer | ( | void **const | ab, |
W_MAP_FLAGS | mapFlags | ||
) |
Map the animation buffer of this geometry. This will fail if there is no animation data, the geometry is dynamic or if the geometry is immutable.
ab | The address of a pointer to have it point to the mapped memory of the animation vertices |
flags | Map flags (bitwise OR'd), specifying read/write intention |
WError WGeometry::MapIndexBuffer | ( | void **const | ib, |
W_MAP_FLAGS | mapFlags | ||
) |
Map the index buffer of this geometry. This will fail if there is no geometry, the geometry is dynamic or if the geometry is immutable. Indices are stored in 32-bits-per-index (uint32_t).
Examples: Flip this first triangle
ib | The address of a pointer to have it point to the mapped memory of the indices |
flags | Map flags (bitwise OR'd), specifying read/write intention |
WError WGeometry::MapVertexBuffer | ( | void **const | vb, |
W_MAP_FLAGS | mapFlags | ||
) |
Map the vertex buffer of this geometry. This will fail if there is no geometry, the geometry is dynamic or if the geometry is immutable.
Examples: Move the first vertex a bit
vb | The address of a pointer to have it point to the mapped memory of the vertices |
flags | Map flags (bitwise OR'd), specifying read/write intention |
WError WGeometry::Scale | ( | float | mulFactor | ) |
Scale the geometry. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
mulFactor | Scale factor |
WError WGeometry::ScaleX | ( | float | mulFactor | ) |
Scale the geometry on the X axis. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
mulFactor | X scale factor |
WError WGeometry::ScaleY | ( | float | mulFactor | ) |
Scale the geometry on the Y axis. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
mulFactor | Y scale factor |
WError WGeometry::ScaleZ | ( | float | mulFactor | ) |
Scale the geometry on the Z axis. The geometry must be valid and must have an attribute in its geometry buffer named "position". The geometry must be dynamic and not immutable.
mulFactor | Z scale factor |
|
overridevirtual |
|
overridevirtual |
void WGeometry::UnmapAnimationBuffer | ( | ) |
Unmap animation vertices from a previous MapAnimationBuffer() call. If MapAnimationBuffer() was called with bReadOnly == false, the this will apply the changes to the animation data.
void WGeometry::UnmapIndexBuffer | ( | ) |
Unmap indices from a previous MapIndexBuffer() call. If MapIndexBuffer() was called with bReadOnly == false, the this will apply the changes to the geometry.
void WGeometry::UnmapVertexBuffer | ( | bool | recalculateBoundingBox = true | ) |
Unmap vertices from a previous MapVertexBuffer() call. If MapVertexBuffer() was called with bReadOnly == false, the this will apply the changes to the geometry.
recalculateBoundingBox | Whether or not to recalculate the geometry's bounding box information |
|
overridevirtual |
Checks the validity of the geometry. A geometry is valid if it has a vertex and an index buffer.
Implements WBase.