Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
HeightFieldShapeSettings Class Referencefinal

Class that constructs a HeightFieldShape. More...

#include <HeightFieldShape.h>

Inheritance diagram for HeightFieldShapeSettings:
ShapeSettings SerializableObject RefTarget< ShapeSettings >

Public Member Functions

 HeightFieldShapeSettings ()=default
 Default constructor for deserialization. More...
 
 HeightFieldShapeSettings (const float *inSamples, Vec3Arg inOffset, Vec3Arg inScale, uint32 inSampleCount, const uint8 *inMaterialIndices=nullptr, const PhysicsMaterialList &inMaterialList=PhysicsMaterialList())
 
virtual ShapeResult Create () const override
 Create a shape according to the settings specified by this object. More...
 
void DetermineMinAndMaxSample (float &outMinValue, float &outMaxValue, float &outQuantizationScale) const
 
uint32 CalculateBitsPerSampleForError (float inMaxError) const
 
virtual ShapeResult Create () const =0
 Create a shape according to the settings specified by this object. More...
 
- Public Member Functions inherited from SerializableObject
virtual ~SerializableObject ()=default
 Constructor. More...
 
- Public Member Functions inherited from RefTarget< ShapeSettings >
 RefTarget ()=default
 Constructor. More...
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us More...
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator. More...
 
uint32 GetRefCount () const
 Get current refcount of this object. More...
 
void AddRef () const
 Add or release a reference to this object. More...
 
void Release () const
 

Public Attributes

Vec3 mOffset = Vec3::sZero()
 
Vec3 mScale = Vec3::sReplicate(1.0f)
 
uint32 mSampleCount = 0
 
uint32 mBlockSize = 2
 
uint32 mBitsPerSample = 8
 
Array< float > mHeightSamples
 
Array< uint8mMaterialIndices
 
PhysicsMaterialList mMaterials
 The materials of square at (x, y) is: mMaterials[mMaterialIndices[x + y * (mSampleCount - 1)]]. More...
 
- Public Attributes inherited from ShapeSettings
uint64 mUserData = 0
 User data (to be used freely by the application) More...
 

Additional Inherited Members

- Public Types inherited from ShapeSettings
using ShapeResult = Result< Ref< Shape > >
 
- Static Public Member Functions inherited from RefTarget< ShapeSettings >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 
- Protected Attributes inherited from ShapeSettings
ShapeResult mCachedResult
 
- Protected Attributes inherited from RefTarget< ShapeSettings >
atomic< uint32mRefCount
 Current reference count. More...
 
- Static Protected Attributes inherited from RefTarget< ShapeSettings >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded. More...
 

Detailed Description

Class that constructs a HeightFieldShape.

Constructor & Destructor Documentation

◆ HeightFieldShapeSettings() [1/2]

HeightFieldShapeSettings::HeightFieldShapeSettings ( )
default

Default constructor for deserialization.

◆ HeightFieldShapeSettings() [2/2]

HeightFieldShapeSettings::HeightFieldShapeSettings ( const float *  inSamples,
Vec3Arg  inOffset,
Vec3Arg  inScale,
uint32  inSampleCount,
const uint8 inMaterialIndices = nullptr,
const PhysicsMaterialList inMaterialList = PhysicsMaterialList() 
)

Create a height field shape of inSampleCount * inSampleCount vertices. The height field is a surface defined by: inOffset + inScale * (x, inSamples[y * inSampleCount + x], y). where x and y are integers in the range x and y e [0, inSampleCount - 1]. inSampleCount: inSampleCount / mBlockSize must be a power of 2 and minimally 2. inSamples: inSampleCount^2 vertices. inMaterialIndices: (inSampleCount - 1)^2 indices that index into inMaterialList.

Member Function Documentation

◆ CalculateBitsPerSampleForError()

uint32 HeightFieldShapeSettings::CalculateBitsPerSampleForError ( float  inMaxError) const

Given mBlockSize, mSampleCount and mHeightSamples, calculate the amount of bits needed to stay below absolute error inMaxError

Parameters
inMaxErrorMaximum allowed error in mHeightSamples after compression (note that this does not take mScale.Y into account)
Returns
Needed bits per sample in the range [1, 8].

◆ Create()

ShapeSettings::ShapeResult HeightFieldShapeSettings::Create ( ) const
overridevirtual

Create a shape according to the settings specified by this object.

Implements ShapeSettings.

◆ DetermineMinAndMaxSample()

void HeightFieldShapeSettings::DetermineMinAndMaxSample ( float &  outMinValue,
float &  outMaxValue,
float &  outQuantizationScale 
) const

Determine the minimal and maximal value of mHeightSamples (will ignore cNoCollisionValue)

Parameters
outMinValueThe minimal value fo mHeightSamples or FLT_MAX if no samples have collision
outMaxValueThe maximal value fo mHeightSamples or -FLT_MAX if no samples have collision
outQuantizationScale(value - outMinValue) * outQuantizationScale quantizes a height sample to 16 bits

Member Data Documentation

◆ mBitsPerSample

uint32 HeightFieldShapeSettings::mBitsPerSample = 8

How many bits per sample to use to compress the height field. Can be in the range [1, 8]. Note that each sample is compressed relative to the min/max value of its block of mBlockSize * mBlockSize pixels so the effective precision is higher. Also note that increasing mBlockSize saves more memory than reducing the amount of bits per sample.

◆ mBlockSize

uint32 HeightFieldShapeSettings::mBlockSize = 2

The heightfield is divided in blocks of mBlockSize * mBlockSize * 2 triangles and the acceleration structure culls blocks only, bigger block sizes reduce memory consumption but also reduce query performance. Sensible values are [2, 8], does not need to be a power of 2. Note that at run-time we'll perform one more grid subdivision, so the effective block size is half of what is provided here.

◆ mHeightSamples

Array<float> HeightFieldShapeSettings::mHeightSamples

◆ mMaterialIndices

Array<uint8> HeightFieldShapeSettings::mMaterialIndices

◆ mMaterials

PhysicsMaterialList HeightFieldShapeSettings::mMaterials

The materials of square at (x, y) is: mMaterials[mMaterialIndices[x + y * (mSampleCount - 1)]].

◆ mOffset

Vec3 HeightFieldShapeSettings::mOffset = Vec3::sZero()

The height field is a surface defined by: mOffset + mScale * (x, mHeightSamples[y * mSampleCount + x], y). where x and y are integers in the range x and y e [0, mSampleCount - 1].

◆ mSampleCount

uint32 HeightFieldShapeSettings::mSampleCount = 0

◆ mScale

Vec3 HeightFieldShapeSettings::mScale = Vec3::sReplicate(1.0f)

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