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 > NonCopyable

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
 
- Public Member Functions inherited from ShapeSettings
virtual ShapeResult Create () const =0
 Create a shape according to the settings specified by this object. More...
 
void ClearCachedResult ()
 
- Public Member Functions inherited from SerializableObject
virtual ~SerializableObject ()=default
 Constructor. More...
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 
- 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
 
float mMinHeightValue = FLT_MAX
 Artificial minimal value of mHeightSamples, used for compression and can be used to update the terrain after creating with lower height values. If there are any lower values in mHeightSamples, this value will be ignored. More...
 
float mMaxHeightValue = -FLT_MAX
 Artificial maximum value of mHeightSamples, used for compression and can be used to update the terrain after creating with higher height values. If there are any higher values in mHeightSamples, this value will be ignored. More...
 
uint32 mBlockSize = 2
 
uint32 mBitsPerSample = 8
 
Array< float > mHeightSamples
 An array of mSampleCount^2 height samples. Samples are stored in row major order, so the sample at (x, y) is at index y * mSampleCount + x. More...
 
Array< uint8mMaterialIndices
 An array of (mSampleCount - 1)^2 material indices. More...
 
PhysicsMaterialList mMaterials
 The materials of square at (x, y) is: mMaterials[mMaterialIndices[x + y * (mSampleCount - 1)]]. More...
 
float mActiveEdgeCosThresholdAngle = 0.996195f
 
- 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 minimally 2 and a power of 2 is the most efficient in terms of performance and storage. 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 of mHeightSamples or FLT_MAX if no samples have collision
outMaxValueThe maximal value of mHeightSamples or -FLT_MAX if no samples have collision
outQuantizationScale(value - outMinValue) * outQuantizationScale quantizes a height sample to 16 bits

Member Data Documentation

◆ mActiveEdgeCosThresholdAngle

float HeightFieldShapeSettings::mActiveEdgeCosThresholdAngle = 0.996195f

Cosine of the threshold angle (if the angle between the two triangles is bigger than this, the edge is active, note that a concave edge is always inactive). Setting this value too small can cause ghost collisions with edges, setting it too big can cause depenetration artifacts (objects not depenetrating quickly). Valid ranges are between cos(0 degrees) and cos(90 degrees). The default value is cos(5 degrees).

◆ 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

An array of mSampleCount^2 height samples. Samples are stored in row major order, so the sample at (x, y) is at index y * mSampleCount + x.

◆ mMaterialIndices

Array<uint8> HeightFieldShapeSettings::mMaterialIndices

An array of (mSampleCount - 1)^2 material indices.

◆ mMaterials

PhysicsMaterialList HeightFieldShapeSettings::mMaterials

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

◆ mMaxHeightValue

float HeightFieldShapeSettings::mMaxHeightValue = -FLT_MAX

Artificial maximum value of mHeightSamples, used for compression and can be used to update the terrain after creating with higher height values. If there are any higher values in mHeightSamples, this value will be ignored.

◆ mMinHeightValue

float HeightFieldShapeSettings::mMinHeightValue = FLT_MAX

Artificial minimal value of mHeightSamples, used for compression and can be used to update the terrain after creating with lower height values. If there are any lower values in mHeightSamples, this value will be ignored.

◆ 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: