Kemena3D
Loading...
Searching...
No Matches
kemena::kObject Class Reference

Base scene-graph node. More...

#include <kobject.h>

Inheritance diagram for kemena::kObject:

Public Member Functions

 kObject (kObject *parentNode=nullptr)
 Constructs a kObject and optionally attaches it to a parent.
virtual ~kObject ()
 Destroys the object.
kObjectgetParent ()
 Returns the parent node.
void setParent (kObject *newParent)
 Reparents this object under newParent.
void detachFromParent ()
 Removes this object from its parent's children list.
void setParentKeepTransform (kObject *newParent)
 Reparents this object while keeping its world transform.
std::vector< kObject * > getChildren ()
 Returns the list of direct children.
std::vector< kScript > & getScripts ()
 Returns a mutable reference to the list of attached scripts.
void addScript (const kScript &script)
 Appends a script descriptor to this object.
void removeScript (const kString &uuid)
 Removes the script with the given UUID from this object.
std::vector< kParticle > & getParticles ()
 Returns a mutable reference to the list of attached particle systems.
void addParticle (const kParticle &particle)
 Appends a particle system descriptor to this object.
void removeParticle (const kString &uuid)
 Removes the particle system with the given UUID from this object.
std::vector< kAudioSource > & getAudioSources ()
 Returns a mutable reference to the list of attached audio sources.
void addAudioSource (const kAudioSource &source)
 Appends an audio source descriptor to this object.
void removeAudioSource (const kString &uuid)
 Removes the audio source with the given UUID from this object.
std::vector< kAudioListener > & getAudioListeners ()
 Returns a mutable reference to the list of audio listener components (0 or 1).
void addAudioListener (const kAudioListener &listener)
 Attaches an audio listener descriptor to this object.
void removeAudioListener (const kString &uuid)
 Removes the audio listener with the given UUID from this object.
bool getHasPhysicsDesc () const
 Returns true if this object has a physics body descriptor configured.
void setHasPhysicsDesc (bool val)
 Sets whether this object has a physics body descriptor.
kPhysicsObjectDescgetPhysicsDesc ()
 Returns a mutable reference to the physics body descriptor.
bool getHasCharacterDesc () const
 Returns true if this object has a character controller configured.
void setHasCharacterDesc (bool val)
 Sets whether this object has a character controller descriptor.
kCharacterControllerDescgetCharacterDesc ()
 Returns a mutable reference to the character controller descriptor.
bool getHasNavMeshDesc () const
 Returns true if this object carries a navigation surface.
void setHasNavMeshDesc (bool val)
 Sets whether this object carries a navigation surface.
kNavMeshDescgetNavMeshDesc ()
 Returns a mutable reference to the navigation surface descriptor.
kNodeType getType ()
 Returns the scene-graph node type tag.
void setType (kNodeType newType)
 Sets the node type tag.
bool getActive ()
 Returns whether this object is active (visible/processed).
void setActive (bool newActive)
 Activates or deactivates the object.
bool getStatic ()
 Returns whether this object is marked as static (immobile geometry).
void setStatic (bool newStatic)
 Marks the object as static or dynamic.
bool getDebugMode ()
 Returns whether editor debug visualization is enabled.
void setDebugMode (bool newMode)
 Enables or disables editor debug visualization for this object.
unsigned int getId ()
 Returns the numeric identifier of this object.
void setId (unsigned int newId)
 Sets the numeric identifier.
kString getUuid ()
 Returns the UUID kString of this object.
void setUuid (kString newUuid)
 Sets the UUID kString.
kString getName ()
 Returns the display name of this object.
void setName (kString newName)
 Sets the display name.
kString getPrefabRef () const
 Returns the prefab asset UUID this object is an instance of, or empty.
void setPrefabRef (const kString &ref)
 Sets the prefab asset UUID this object is an instance of.
kString getTemplateUuid () const
 Returns the UUID of the corresponding node in the prefab template.
void setTemplateUuid (const kString &uuid)
 Sets the corresponding template UUID for this prefab instance node.
kVec3 getPosition ()
 Returns the local position.
virtual void setPosition (kVec3 newPosition)
 Sets the local position.
kQuat getRotation ()
 Returns the local rotation as a quaternion.
kVec3 getRotationEuler ()
 Returns the local rotation as Euler angles in degrees.
virtual void setRotation (kQuat newRotation)
 Sets the local rotation from a quaternion.
kVec3 getScale ()
 Returns the local scale.
virtual void setScale (kVec3 newScale)
 Sets the local scale.
kVec3 calculateRight ()
 Computes the local right (+X) direction in world space.
kVec3 calculateForward ()
 Computes the local forward (-Z) direction in world space.
kVec3 calculateUp ()
 Computes the local up (+Y) direction in world space.
void rotate (kVec3 rotationAxis, float angularSpeed)
 Rotates the object around an axis by a given angular speed.
kVec3 getGlobalPosition ()
 Returns the world-space position derived from the world transform.
kQuat getGlobalRotation ()
 Returns the world-space rotation derived from the world transform.
kVec3 getGlobalScale ()
 Returns the world-space scale derived from the world transform.
void setMaterial (kMaterial *newMaterial, bool setChildren=true)
 Assigns a material to this object and optionally its children.
kMaterialgetMaterial ()
 Returns the assigned material.
void setMaterialUuid (const kString &uuid)
 Sets the source asset UUID of the assigned material.
kString getMaterialUuid () const
 Returns the source asset UUID of the assigned material.
void setImportChild (bool v)
 Marks this node as an import-derived sub-mesh.
bool getImportChild () const
 Whether this node is an import-derived sub-mesh (see setImportChild).
void calculateModelMatrix ()
 Recomputes the local and world-space model matrices.
kMat4 getModelMatrixWorld ()
 Returns the world-space model matrix.
kMat4 getModelMatrixLocal ()
 Returns the local model matrix (relative to the parent).
virtual void draw ()
 Draws the object.
virtual json serialize ()
 Serialises the object to a JSON value.
virtual void deserialize (json data)
 Restores the object state from a JSON value.
void attachPhysics (kPhysicsObject *physicsObj)
 Attaches a physics body to this object.
void detachPhysics ()
 Detaches the physics body without destroying it.
kPhysicsObjectgetPhysicsObject ()
 Returns the attached physics body, or nullptr if none is attached.
void syncFromPhysics ()
 Copies the physics body's current position and rotation into this object's local transform.
void attachCharacter (kCharacterController *character)
 Attaches a runtime character controller to this object.
void detachCharacter ()
 Detaches the character controller without destroying it.
kCharacterControllergetCharacterController ()
 Returns the attached character controller, or nullptr.
void syncFromCharacter ()
 Copies the character controller's position into this object's local transform. Call once per frame after the physics update.

Detailed Description

Base scene-graph node.

Every entity in the world hierarchy — meshes, lights, cameras, and plain empty objects — derives from kObject. It manages parent/child relationships, a local and world-space transform, an optional material, and a list of attached AngelScript scripts.

Constructor & Destructor Documentation

◆ kObject()

kemena::kObject::kObject ( kObject * parentNode = nullptr)

Constructs a kObject and optionally attaches it to a parent.

Parameters
parentNodeParent to attach to, or nullptr for a root node.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~kObject()

virtual kemena::kObject::~kObject ( )
virtual

Destroys the object.

Virtual to allow correct destruction through a kObject* pointer to a derived node. Does not delete attached children or the physics body.

Member Function Documentation

◆ addAudioListener()

void kemena::kObject::addAudioListener ( const kAudioListener & listener)

Attaches an audio listener descriptor to this object.

Parameters
listenerDescriptor to add.

◆ addAudioSource()

void kemena::kObject::addAudioSource ( const kAudioSource & source)

Appends an audio source descriptor to this object.

Parameters
sourceDescriptor to add.

◆ addParticle()

void kemena::kObject::addParticle ( const kParticle & particle)

Appends a particle system descriptor to this object.

Parameters
particleDescriptor to add.

◆ addScript()

void kemena::kObject::addScript ( const kScript & script)

Appends a script descriptor to this object.

Parameters
scriptDescriptor to add (uuid and fileName should be set by the caller).

◆ attachCharacter()

void kemena::kObject::attachCharacter ( kCharacterController * character)

Attaches a runtime character controller to this object.

Ownership stays with kPhysicsManager (destroy via destroyCharacter()).

◆ attachPhysics()

void kemena::kObject::attachPhysics ( kPhysicsObject * physicsObj)

Attaches a physics body to this object.

The kObject does NOT take ownership of physicsObj — it must be managed (and destroyed) via kPhysicsManager::destroyObject().

Parameters
physicsObjPhysics body created by kPhysicsManager::createObject().

◆ calculateForward()

kVec3 kemena::kObject::calculateForward ( )

Computes the local forward (-Z) direction in world space.

Returns
Normalised forward vector.

◆ calculateModelMatrix()

void kemena::kObject::calculateModelMatrix ( )

Recomputes the local and world-space model matrices.

Combines position, rotation, and scale into localTransform, then multiplies by the parent's world transform to produce worldTransform.

◆ calculateRight()

kVec3 kemena::kObject::calculateRight ( )

Computes the local right (+X) direction in world space.

Returns
Normalised right vector.

◆ calculateUp()

kVec3 kemena::kObject::calculateUp ( )

Computes the local up (+Y) direction in world space.

Returns
Normalised up vector.

◆ deserialize()

virtual void kemena::kObject::deserialize ( json data)
virtual

Restores the object state from a JSON value.

Parameters
dataJSON object produced by serialize().

Reimplemented in kemena::kCamera, and kemena::kMesh.

◆ detachCharacter()

void kemena::kObject::detachCharacter ( )

Detaches the character controller without destroying it.

◆ detachFromParent()

void kemena::kObject::detachFromParent ( )

Removes this object from its parent's children list.

The object is not deleted; its parent pointer is set to nullptr. Has no effect if the object has no parent.

◆ detachPhysics()

void kemena::kObject::detachPhysics ( )

Detaches the physics body without destroying it.

◆ draw()

virtual void kemena::kObject::draw ( )
virtual

Draws the object.

For base kObject (non-mesh, non-light) nodes this renders a billboard icon quad. Derived classes override this for their own geometry.

Reimplemented in kemena::kMesh.

◆ getActive()

bool kemena::kObject::getActive ( )

Returns whether this object is active (visible/processed).

Returns
true if the object and its children are rendered/updated.

◆ getAudioListeners()

std::vector< kAudioListener > & kemena::kObject::getAudioListeners ( )

Returns a mutable reference to the list of audio listener components (0 or 1).

◆ getAudioSources()

std::vector< kAudioSource > & kemena::kObject::getAudioSources ( )

Returns a mutable reference to the list of attached audio sources.

◆ getCharacterController()

kCharacterController * kemena::kObject::getCharacterController ( )

Returns the attached character controller, or nullptr.

◆ getCharacterDesc()

kCharacterControllerDesc & kemena::kObject::getCharacterDesc ( )

Returns a mutable reference to the character controller descriptor.

◆ getChildren()

std::vector< kObject * > kemena::kObject::getChildren ( )

Returns the list of direct children.

Returns
Copy of the children vector.

◆ getDebugMode()

bool kemena::kObject::getDebugMode ( )

Returns whether editor debug visualization is enabled.

Returns
true if debug shapes (frustum, light range, etc.) are drawn.

◆ getGlobalPosition()

kVec3 kemena::kObject::getGlobalPosition ( )

Returns the world-space position derived from the world transform.

Returns
Translation column of the world transform matrix.

◆ getGlobalRotation()

kQuat kemena::kObject::getGlobalRotation ( )

Returns the world-space rotation derived from the world transform.

Returns
Normalised world-space quaternion.

◆ getGlobalScale()

kVec3 kemena::kObject::getGlobalScale ( )

Returns the world-space scale derived from the world transform.

Returns
Per-axis world scale.

◆ getHasCharacterDesc()

bool kemena::kObject::getHasCharacterDesc ( ) const

Returns true if this object has a character controller configured.

◆ getHasNavMeshDesc()

bool kemena::kObject::getHasNavMeshDesc ( ) const

Returns true if this object carries a navigation surface.

◆ getHasPhysicsDesc()

bool kemena::kObject::getHasPhysicsDesc ( ) const

Returns true if this object has a physics body descriptor configured.

◆ getId()

unsigned int kemena::kObject::getId ( )

Returns the numeric identifier of this object.

Returns
Unique unsigned integer ID.

◆ getImportChild()

bool kemena::kObject::getImportChild ( ) const
inline

Whether this node is an import-derived sub-mesh (see setImportChild).

Returns
true if created by the model importer and excluded from serialization.

◆ getMaterial()

kMaterial * kemena::kObject::getMaterial ( )

Returns the assigned material.

Returns
Pointer to the material, or nullptr if none is set.

◆ getMaterialUuid()

kString kemena::kObject::getMaterialUuid ( ) const
inline

Returns the source asset UUID of the assigned material.

Returns
Material asset UUID, or empty string if none is assigned.

◆ getModelMatrixLocal()

kMat4 kemena::kObject::getModelMatrixLocal ( )

Returns the local model matrix (relative to the parent).

Returns
4x4 model matrix in parent/local space.

◆ getModelMatrixWorld()

kMat4 kemena::kObject::getModelMatrixWorld ( )

Returns the world-space model matrix.

Returns
4x4 model matrix in world space.

◆ getName()

kString kemena::kObject::getName ( )

Returns the display name of this object.

Returns
Human-readable name.

◆ getNavMeshDesc()

kNavMeshDesc & kemena::kObject::getNavMeshDesc ( )

Returns a mutable reference to the navigation surface descriptor.

◆ getParent()

kObject * kemena::kObject::getParent ( )

Returns the parent node.

Returns
Pointer to the parent, or nullptr if this is a root node.
Here is the call graph for this function:

◆ getParticles()

std::vector< kParticle > & kemena::kObject::getParticles ( )

Returns a mutable reference to the list of attached particle systems.

◆ getPhysicsDesc()

kPhysicsObjectDesc & kemena::kObject::getPhysicsDesc ( )

Returns a mutable reference to the physics body descriptor.

Only meaningful when getHasPhysicsDesc() returns true.

◆ getPhysicsObject()

kPhysicsObject * kemena::kObject::getPhysicsObject ( )

Returns the attached physics body, or nullptr if none is attached.

◆ getPosition()

kVec3 kemena::kObject::getPosition ( )

Returns the local position.

Returns
Position in parent space (or world space if root).

◆ getPrefabRef()

kString kemena::kObject::getPrefabRef ( ) const

Returns the prefab asset UUID this object is an instance of, or empty.

Non-empty only on the root node of a prefab instance. Set by the editor when instantiating a prefab into a scene.

◆ getRotation()

kQuat kemena::kObject::getRotation ( )

Returns the local rotation as a quaternion.

Returns
Unit quaternion representing the local orientation.

◆ getRotationEuler()

kVec3 kemena::kObject::getRotationEuler ( )

Returns the local rotation as Euler angles in degrees.

Returns
XYZ Euler angles in degrees.

◆ getScale()

kVec3 kemena::kObject::getScale ( )

Returns the local scale.

Returns
Per-axis scale factors.

◆ getScripts()

std::vector< kScript > & kemena::kObject::getScripts ( )

Returns a mutable reference to the list of attached scripts.

◆ getStatic()

bool kemena::kObject::getStatic ( )

Returns whether this object is marked as static (immobile geometry).

Returns
true if the object will be indexed in the static octree.

◆ getTemplateUuid()

kString kemena::kObject::getTemplateUuid ( ) const

Returns the UUID of the corresponding node in the prefab template.

Set on every node of a prefab instance subtree so the editor can match instance nodes back to their template counterparts.

◆ getType()

kNodeType kemena::kObject::getType ( )

Returns the scene-graph node type tag.

Returns
One of the kNodeType enum values.

◆ getUuid()

kString kemena::kObject::getUuid ( )

Returns the UUID kString of this object.

Returns
UUID v4 kString.

◆ removeAudioListener()

void kemena::kObject::removeAudioListener ( const kString & uuid)

Removes the audio listener with the given UUID from this object.

Parameters
uuidUUID of the listener to remove.

◆ removeAudioSource()

void kemena::kObject::removeAudioSource ( const kString & uuid)

Removes the audio source with the given UUID from this object.

Parameters
uuidUUID of the audio source to remove.

◆ removeParticle()

void kemena::kObject::removeParticle ( const kString & uuid)

Removes the particle system with the given UUID from this object.

Parameters
uuidUUID of the particle system to remove.

◆ removeScript()

void kemena::kObject::removeScript ( const kString & uuid)

Removes the script with the given UUID from this object.

Parameters
uuidUUID of the script to remove.

◆ rotate()

void kemena::kObject::rotate ( kVec3 rotationAxis,
float angularSpeed )

Rotates the object around an axis by a given angular speed.

Parameters
rotationAxisWorld-space rotation axis (normalised).
angularSpeedRotation magnitude in radians.

◆ serialize()

virtual json kemena::kObject::serialize ( )
virtual

Serialises the object to a JSON value.

Returns
JSON object containing all serialisable fields.

Reimplemented in kemena::kCamera, kemena::kLight, and kemena::kMesh.

◆ setActive()

void kemena::kObject::setActive ( bool newActive)

Activates or deactivates the object.

Parameters
newActivefalse to hide and skip the object during rendering.

◆ setDebugMode()

void kemena::kObject::setDebugMode ( bool newMode)

Enables or disables editor debug visualization for this object.

Parameters
newModetrue to draw debug shapes in the editor viewport.

◆ setHasCharacterDesc()

void kemena::kObject::setHasCharacterDesc ( bool val)

Sets whether this object has a character controller descriptor.

Parameters
valtrue = a character is created at game-start.

◆ setHasNavMeshDesc()

void kemena::kObject::setHasNavMeshDesc ( bool val)

Sets whether this object carries a navigation surface.

◆ setHasPhysicsDesc()

void kemena::kObject::setHasPhysicsDesc ( bool val)

Sets whether this object has a physics body descriptor.

Parameters
valtrue = descriptor is active and should create a body at game-start.

◆ setId()

void kemena::kObject::setId ( unsigned int newId)

Sets the numeric identifier.

Parameters
newIdNew ID value.

◆ setImportChild()

void kemena::kObject::setImportChild ( bool v)
inline

Marks this node as an import-derived sub-mesh.

Sub-meshes produced when loading a model file are reconstructed from that file on every load, so they must not be serialized as children of their parent (doing so would duplicate them). The editor still assigns them a UUID for selection/hierarchy purposes; this flag lets serialize() skip them while keeping authored children intact.

Parameters
vtrue if this node was created by the model importer.

◆ setMaterial()

void kemena::kObject::setMaterial ( kMaterial * newMaterial,
bool setChildren = true )

Assigns a material to this object and optionally its children.

Parameters
newMaterialMaterial to assign.
setChildrenIf true, the same material is assigned to all descendants.

◆ setMaterialUuid()

void kemena::kObject::setMaterialUuid ( const kString & uuid)
inline

Sets the source asset UUID of the assigned material.

The runtime kMaterial carries no link back to the .mat asset it was built from, so the editor records the material asset's UUID here. It is serialized with the object so the assignment survives save/load; an empty string means "no material asset assigned".

Parameters
uuidMaterial asset UUID, or empty string for none.

◆ setName()

void kemena::kObject::setName ( kString newName)

Sets the display name.

Parameters
newNameNew name kString.

◆ setParent()

void kemena::kObject::setParent ( kObject * newParent)

Reparents this object under newParent.

Parameters
newParentNew parent node.
Here is the call graph for this function:

◆ setParentKeepTransform()

void kemena::kObject::setParentKeepTransform ( kObject * newParent)

Reparents this object while keeping its world transform.

Computes new local position/rotation/scale such that the object's world-space pose is unchanged after switching parents — i.e. the object does not visually jump. Use this for editor reparent operations (drag in the hierarchy, etc.); use the plain setParent() when constructing scenes where the local transform is what you want preserved.

Parameters
newParentNew parent node, or nullptr to detach to root space.
Here is the call graph for this function:

◆ setPosition()

virtual void kemena::kObject::setPosition ( kVec3 newPosition)
virtual

Sets the local position.

Parameters
newPositionPosition in parent space.

Reimplemented in kemena::kCamera, and kemena::kMesh.

◆ setPrefabRef()

void kemena::kObject::setPrefabRef ( const kString & ref)

Sets the prefab asset UUID this object is an instance of.

◆ setRotation()

virtual void kemena::kObject::setRotation ( kQuat newRotation)
virtual

Sets the local rotation from a quaternion.

Parameters
newRotationUnit quaternion.

Reimplemented in kemena::kCamera, and kemena::kMesh.

◆ setScale()

virtual void kemena::kObject::setScale ( kVec3 newScale)
virtual

Sets the local scale.

Parameters
newScalePer-axis scale factors.

Reimplemented in kemena::kMesh.

◆ setStatic()

void kemena::kObject::setStatic ( bool newStatic)

Marks the object as static or dynamic.

Parameters
newStatictrue for immobile objects; false for moving/animated ones.

◆ setTemplateUuid()

void kemena::kObject::setTemplateUuid ( const kString & uuid)

Sets the corresponding template UUID for this prefab instance node.

◆ setType()

void kemena::kObject::setType ( kNodeType newType)

Sets the node type tag.

Parameters
newTypeNode type.

◆ setUuid()

void kemena::kObject::setUuid ( kString newUuid)

Sets the UUID kString.

Parameters
newUuidUUID v4 kString.

◆ syncFromCharacter()

void kemena::kObject::syncFromCharacter ( )

Copies the character controller's position into this object's local transform. Call once per frame after the physics update.

Here is the call graph for this function:

◆ syncFromPhysics()

void kemena::kObject::syncFromPhysics ( )

Copies the physics body's current position and rotation into this object's local transform.

Call this once per frame after kPhysicsManager::update() to keep the scene node in sync with the simulation.

Has no effect if no physics body is attached.


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