PxCollection Class Referenceabstract

Collection class for serialization. More...

#include <PxCollection.h>

Public Member Functions

virtual void add (PxBase &object, PxSerialObjectId id=PX_SERIAL_OBJECT_ID_INVALID)=0
 Adds a PxBase object to the collection. More...
 
virtual void remove (PxBase &object)=0
 Removes a PxBase member object from the collection. More...
 
virtual bool contains (PxBase &object) const =0
 Returns whether the collection contains a certain PxBase object. More...
 
virtual void addId (PxBase &object, PxSerialObjectId id)=0
 Adds an id to a member PxBase object. More...
 
virtual void removeId (PxSerialObjectId id)=0
 Removes id from a contained PxBase object. More...
 
virtual void add (PxCollection &collection)=0
 Adds all PxBase objects and their ids of collection to this collection. More...
 
virtual void remove (PxCollection &collection)=0
 Removes all PxBase objects of collection from this collection. More...
 
virtual PxU32 getNbObjects () const =0
 Gets number of PxBase objects in this collection. More...
 
virtual PxBasegetObject (PxU32 index) const =0
 Gets the PxBase object of this collection given its index. More...
 
virtual PxU32 getObjects (PxBase **userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const =0
 Copies member PxBase pointers to a user specified buffer. More...
 
virtual PxBasefind (PxSerialObjectId id) const =0
 Looks for a PxBase object given a PxSerialObjectId value. More...
 
virtual PxU32 getNbIds () const =0
 Gets number of PxSerialObjectId names in this collection. More...
 
virtual PxU32 getIds (PxSerialObjectId *userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const =0
 Copies member PxSerialObjectId values to a user specified buffer. More...
 
virtual PxSerialObjectId getId (const PxBase &object) const =0
 Gets the PxSerialObjectId name of a PxBase object within the collection. More...
 
virtual void release ()=0
 Deletes a collection object. More...
 

Protected Member Functions

 PxCollection ()
 
virtual ~PxCollection ()
 

Detailed Description

Collection class for serialization.

A collection is a set of PxBase objects. PxBase objects can be added to the collection regardless of other objects they depend on. Objects may be named using PxSerialObjectId values in order to resolve dependencies between objects of different collections.

Serialization and deserialization only work through collections.

A scene is typically serialized using the following steps:

  1. create a serialization registry
  2. create a collection for scene objects
  3. complete the scene objects (adds all dependent objects, e.g. meshes)
  4. serialize collection
  5. release collection
  6. release serialization registry

For example the code may look like this:

PxPhysics* physics; // The physics
PxScene* scene; // The physics scene
SerialStream s; // The user-defined stream doing the actual write to disk
PxCollection* collection = PxSerialization::createCollection(*scene); // step 2)
PxSerialization::complete(*collection, *registry); // step 3)
PxSerialization::serializeCollectionToBinary(s, *collection, *registry); // step 4)
collection->release(); // step 5)
registry->release(); // step 6)

A scene is typically deserialized using the following steps:

  1. load a serialized collection into memory
  2. create a serialization registry
  3. create a collection by passing the serialized memory block
  4. add collected objects to scene
  5. release collection
  6. release serialization registry

For example the code may look like this:

PxPhysics* physics; // The physics
PxScene* scene; // The physics scene
void* memory128; // a 128-byte aligned buffer previously loaded from disk by the user - step 1)
PxCollection* collection = PxSerialization::createCollectionFromBinary(memory128, *registry); // step 3)
scene->addCollection(*collection); // step 4)
collection->release(); // step 5)
registry->release(); // step 6)
See also
PxBase, PxCreateCollection()

Constructor & Destructor Documentation

◆ PxCollection()

PxCollection::PxCollection ( )
inlineprotected

◆ ~PxCollection()

virtual PxCollection::~PxCollection ( )
inlineprotectedvirtual

Member Function Documentation

◆ add() [1/2]

virtual void PxCollection::add ( PxBase object,
PxSerialObjectId  id = PX_SERIAL_OBJECT_ID_INVALID 
)
pure virtual

Adds a PxBase object to the collection.

Adds a PxBase object to the collection. Optionally a PxSerialObjectId can be provided in order to resolve dependencies between collections. A PxSerialObjectId value of PX_SERIAL_OBJECT_ID_INVALID means the object remains without id. Objects can be added regardless of other objects they require. If the object is already in the collection, the ID will be set if it was PX_SERIAL_OBJECT_ID_INVALID previously, otherwise the operation fails.

Parameters
[in]objectObject to be added to the collection
[in]idOptional PxSerialObjectId id

◆ add() [2/2]

virtual void PxCollection::add ( PxCollection collection)
pure virtual

Adds all PxBase objects and their ids of collection to this collection.

PxBase objects already in this collection are ignored. Object ids need to be conflict free, i.e. the same object may not have two different ids within the two collections.

Parameters
[in]collectionCollection to be added

◆ addId()

virtual void PxCollection::addId ( PxBase object,
PxSerialObjectId  id 
)
pure virtual

Adds an id to a member PxBase object.

If the object is already associated with an id within the collection, the id is replaced. May only be called for objects that are members of the collection. The id needs to be unique within the collection.

Parameters
[in]objectMember PxBase object
[in]idPxSerialObjectId id to be given to the object

◆ contains()

virtual bool PxCollection::contains ( PxBase object) const
pure virtual

Returns whether the collection contains a certain PxBase object.

Parameters
[in]objectPxBase object
Returns
Whether object is contained.

◆ find()

virtual PxBase* PxCollection::find ( PxSerialObjectId  id) const
pure virtual

Looks for a PxBase object given a PxSerialObjectId value.

If there is no PxBase object in the collection with the given id, NULL is returned.

Parameters
[in]idPxSerialObjectId value to look for
Returns
PxBase object with the given id value or NULL

◆ getId()

virtual PxSerialObjectId PxCollection::getId ( const PxBase object) const
pure virtual

Gets the PxSerialObjectId name of a PxBase object within the collection.

The PxBase object needs to be a member of the collection.

Parameters
[in]objectPxBase object to get id for
Returns
PxSerialObjectId name of the object or PX_SERIAL_OBJECT_ID_INVALID if the object is unnamed

◆ getIds()

virtual PxU32 PxCollection::getIds ( PxSerialObjectId userBuffer,
PxU32  bufferSize,
PxU32  startIndex = 0 
) const
pure virtual

Copies member PxSerialObjectId values to a user specified buffer.

Parameters
[out]userBufferArray of PxSerialObjectId values
[in]bufferSizeCapacity of userBuffer
[in]startIndexOffset into list of member PxSerialObjectId values
Returns
number of members PxSerialObjectId values that have been written to the userBuffer

◆ getNbIds()

virtual PxU32 PxCollection::getNbIds ( ) const
pure virtual

Gets number of PxSerialObjectId names in this collection.

Returns
Number of PxSerialObjectId names in this collection

◆ getNbObjects()

virtual PxU32 PxCollection::getNbObjects ( ) const
pure virtual

Gets number of PxBase objects in this collection.

Returns
Number of objects in this collection

◆ getObject()

virtual PxBase& PxCollection::getObject ( PxU32  index) const
pure virtual

Gets the PxBase object of this collection given its index.

Parameters
[in]indexPxBase index in [0, getNbObjects())
Returns
PxBase object at index index

◆ getObjects()

virtual PxU32 PxCollection::getObjects ( PxBase **  userBuffer,
PxU32  bufferSize,
PxU32  startIndex = 0 
) const
pure virtual

Copies member PxBase pointers to a user specified buffer.

Parameters
[out]userBufferArray of PxBase pointers
[in]bufferSizeCapacity of userBuffer
[in]startIndexOffset into list of member PxBase objects
Returns
number of members PxBase objects that have been written to the userBuffer

◆ release()

virtual void PxCollection::release ( )
pure virtual

Deletes a collection object.

This function only deletes the collection object, i.e. the container class. It doesn't delete objects that are part of the collection.

See also
PxCreateCollection()

◆ remove() [1/2]

virtual void PxCollection::remove ( PxBase object)
pure virtual

Removes a PxBase member object from the collection.

Object needs to be contained by the collection.

Parameters
[in]objectPxBase object to be removed

◆ remove() [2/2]

virtual void PxCollection::remove ( PxCollection collection)
pure virtual

Removes all PxBase objects of collection from this collection.

PxBase objects not present in this collection are ignored. Ids of objects which are removed are also removed.

Parameters
[in]collectionCollection to be removed

◆ removeId()

virtual void PxCollection::removeId ( PxSerialObjectId  id)
pure virtual

Removes id from a contained PxBase object.

May only be called for ids that are associated with an object in the collection.

Parameters
[in]idPxSerialObjectId value

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