Kemena3D
Loading...
Searching...
No Matches
kobject.h
Go to the documentation of this file.
1
5
6#ifndef KOBJECT_H
7#define KOBJECT_H
8
9#include "kexport.h"
10#include "kdriver.h"
11
12#include <iostream>
13#include <string>
14#include <vector>
15
16#include <glm/glm.hpp>
17#include <glm/gtc/quaternion.hpp>
18
19#include <nlohmann/json.hpp>
20
21#include "kdatatype.h"
22#include "kmaterial.h"
23#include "kscriptmanager.h"
24#include "kphysicsobject.h"
26#include "knavmesh.h"
27#include "kparticle.h"
28#include "kaudiosource.h"
29
30using json = nlohmann::json;
31
32namespace kemena
33{
43 {
44 public:
49 kObject(kObject *parentNode = nullptr);
50
57 virtual ~kObject();
58
64
69 void setParent(kObject *newParent);
70
78
92
97 std::vector<kObject *> getChildren();
98
100 std::vector<kScript>& getScripts();
101
106 void addScript(const kScript& script);
107
112 void removeScript(const kString& uuid);
113
114 // --- Particles -------------------------------------------------------
115
117 std::vector<kParticle>& getParticles();
118
123 void addParticle(const kParticle& particle);
124
129 void removeParticle(const kString& uuid);
130
131 // --- Audio sources ---------------------------------------------------
132
134 std::vector<kAudioSource>& getAudioSources();
135
140 void addAudioSource(const kAudioSource& source);
141
146 void removeAudioSource(const kString& uuid);
147
148 // --- Audio listener --------------------------------------------------
149
151 std::vector<kAudioListener>& getAudioListeners();
152
157 void addAudioListener(const kAudioListener& listener);
158
163 void removeAudioListener(const kString& uuid);
164
165 // --- Physics descriptor (editor-side config) -------------------------
166
170 bool getHasPhysicsDesc() const;
171
176 void setHasPhysicsDesc(bool val);
177
184
185 // --- Character controller descriptor (editor-side config) ------------
186
189
194 void setHasCharacterDesc(bool val);
195
198
199 // --- Navigation surface descriptor (editor-side config) -------------
200
202 bool getHasNavMeshDesc() const;
203
205 void setHasNavMeshDesc(bool val);
206
209
215
220 void setType(kNodeType newType);
221
226 bool getActive();
227
232 void setActive(bool newActive);
233
238 bool getStatic();
239
244 void setStatic(bool newStatic);
245
251
256 void setDebugMode(bool newMode);
257
262 unsigned int getId();
263
268 void setId(unsigned int newId);
269
275
280 void setUuid(kString newUuid);
281
287
292 void setName(kString newName);
293
301
303 void setPrefabRef(const kString &ref);
304
312
314 void setTemplateUuid(const kString &uuid);
315
321
326 virtual void setPosition(kVec3 newPosition);
327
333
339
344 virtual void setRotation(kQuat newRotation);
345
351
356 virtual void setScale(kVec3 newScale);
357
363
369
375
381 void rotate(kVec3 rotationAxis, float angularSpeed);
382
388
394
400
406 void setMaterial(kMaterial *newMaterial, bool setChildren = true);
407
413
424 void setMaterialUuid(const kString &uuid) { materialUuid = uuid; }
425
430 kString getMaterialUuid() const { return materialUuid; }
431
443 void setImportChild(bool v) { importChild = v; }
444
449 bool getImportChild() const { return importChild; }
450
458
464
470
477 virtual void draw();
478
483 virtual json serialize();
484
489 virtual void deserialize(json data);
490
491 // --- Physics ---------------------------------------------------------
492
501 void attachPhysics(kPhysicsObject *physicsObj);
502
507
512
523
524 // --- Character controller -------------------------------------------
525
532
535
538
544
545 protected:
546 private:
547 kObject *parent = nullptr;
548 std::vector<kObject *> children;
549
550 bool isActive = true;
551 bool isStatic = false;
552 bool debugMode = false;
553
555 unsigned int id = 0;
556 kString uuid;
557 kString name;
558
559 kString prefabRef;
560 kString templateUuid;
561
562 kVec3 position = kVec3(0.0f, 0.0f, 0.0f);
563 kQuat rotation = kQuat(kVec3(0.0f, 0.0f, 0.0f));
564 kVec3 scale = kVec3(1.0f, 1.0f, 1.0f);
565
566 kMat4 localTransform = kMat4(1.0f);
567 kMat4 worldTransform = kMat4(1.0f);
568
569 kMaterial *material = nullptr;
570 kString materialUuid;
571 bool importChild = false;
572 kPhysicsObject *physicsObject = nullptr;
573
574 uint32_t iconVAO = 0;
575 uint32_t iconVertexBuffer = 0;
576 float iconVertices[12] =
577 {
578 -0.5f, -0.5f, 0.0f,
579 0.5f, -0.5f, 0.0f,
580 -0.5f, 0.5f, 0.0f,
581 0.5f, 0.5f, 0.0f,
582 };
583
584 std::vector<kScript> scripts;
585 std::vector<kParticle> particles;
586 std::vector<kAudioSource> audioSources;
587 std::vector<kAudioListener>audioListeners;
588
589 bool hasPhysicsDesc = false;
590 kPhysicsObjectDesc physicsDesc;
591
592 bool hasCharacterDesc = false;
593 kCharacterControllerDesc characterDesc;
594 kCharacterController *characterController = nullptr;
595
596 bool hasNavMeshDesc = false;
597 kNavMeshDesc navMeshDesc;
598 };
599}
600
601#endif // KOBJECT_H
Runtime wrapper around a Jolt character.
Definition kcharactercontroller.h:47
Groups a shader program with textures and surface parameters.
Definition kmaterial.h:27
bool getStatic()
Returns whether this object is marked as static (immobile geometry).
void setTemplateUuid(const kString &uuid)
Sets the corresponding template UUID for this prefab instance node.
void attachCharacter(kCharacterController *character)
Attaches a runtime character controller to this object.
kPhysicsObject * getPhysicsObject()
Returns the attached physics body, or nullptr if none is attached.
void setMaterial(kMaterial *newMaterial, bool setChildren=true)
Assigns a material to this object and optionally its children.
kString getName()
Returns the display name of this object.
virtual json serialize()
Serialises the object to a JSON value.
std::vector< kAudioListener > & getAudioListeners()
Returns a mutable reference to the list of audio listener components (0 or 1).
void setDebugMode(bool newMode)
Enables or disables editor debug visualization for this object.
void addAudioListener(const kAudioListener &listener)
Attaches an audio listener descriptor to this object.
void calculateModelMatrix()
Recomputes the local and world-space model matrices.
kVec3 getGlobalScale()
Returns the world-space scale derived from the world transform.
kString getUuid()
Returns the UUID kString of this object.
virtual void deserialize(json data)
Restores the object state from a JSON value.
kObject(kObject *parentNode=nullptr)
Constructs a kObject and optionally attaches it to a parent.
kNavMeshDesc & getNavMeshDesc()
Returns a mutable reference to the navigation surface descriptor.
std::vector< kObject * > getChildren()
Returns the list of direct children.
void setParent(kObject *newParent)
Reparents this object under newParent.
kVec3 getScale()
Returns the local scale.
std::vector< kAudioSource > & getAudioSources()
Returns a mutable reference to the list of attached audio sources.
kString getTemplateUuid() const
Returns the UUID of the corresponding node in the prefab template.
void removeParticle(const kString &uuid)
Removes the particle system with the given UUID from this object.
virtual ~kObject()
Destroys the object.
kMaterial * getMaterial()
Returns the assigned material.
kCharacterController * getCharacterController()
Returns the attached character controller, or nullptr.
kString getPrefabRef() const
Returns the prefab asset UUID this object is an instance of, or empty.
kCharacterControllerDesc & getCharacterDesc()
Returns a mutable reference to the character controller descriptor.
void setName(kString newName)
Sets the display name.
void removeScript(const kString &uuid)
Removes the script with the given UUID from this object.
kQuat getGlobalRotation()
Returns the world-space rotation derived from the world transform.
kString getMaterialUuid() const
Returns the source asset UUID of the assigned material.
Definition kobject.h:430
void addParticle(const kParticle &particle)
Appends a particle system descriptor to this object.
void syncFromCharacter()
Copies the character controller's position into this object's local transform. Call once per frame af...
void syncFromPhysics()
Copies the physics body's current position and rotation into this object's local transform.
void attachPhysics(kPhysicsObject *physicsObj)
Attaches a physics body to this object.
void detachFromParent()
Removes this object from its parent's children list.
kPhysicsObjectDesc & getPhysicsDesc()
Returns a mutable reference to the physics body descriptor.
kObject * getParent()
Returns the parent node.
void setMaterialUuid(const kString &uuid)
Sets the source asset UUID of the assigned material.
Definition kobject.h:424
void setParentKeepTransform(kObject *newParent)
Reparents this object while keeping its world transform.
kVec3 getPosition()
Returns the local position.
bool getImportChild() const
Whether this node is an import-derived sub-mesh (see setImportChild).
Definition kobject.h:449
void addAudioSource(const kAudioSource &source)
Appends an audio source descriptor to this object.
void detachPhysics()
Detaches the physics body without destroying it.
kVec3 calculateForward()
Computes the local forward (-Z) direction in world space.
kQuat getRotation()
Returns the local rotation as a quaternion.
virtual void setRotation(kQuat newRotation)
Sets the local rotation from a quaternion.
void rotate(kVec3 rotationAxis, float angularSpeed)
Rotates the object around an axis by a given angular speed.
kMat4 getModelMatrixWorld()
Returns the world-space model matrix.
void setImportChild(bool v)
Marks this node as an import-derived sub-mesh.
Definition kobject.h:443
bool getHasPhysicsDesc() const
Returns true if this object has a physics body descriptor configured.
virtual void setScale(kVec3 newScale)
Sets the local scale.
void setHasNavMeshDesc(bool val)
Sets whether this object carries a navigation surface.
void setActive(bool newActive)
Activates or deactivates the object.
virtual void draw()
Draws the object.
void addScript(const kScript &script)
Appends a script descriptor to this object.
std::vector< kParticle > & getParticles()
Returns a mutable reference to the list of attached particle systems.
std::vector< kScript > & getScripts()
Returns a mutable reference to the list of attached scripts.
bool getHasNavMeshDesc() const
Returns true if this object carries a navigation surface.
void removeAudioListener(const kString &uuid)
Removes the audio listener with the given UUID from this object.
bool getDebugMode()
Returns whether editor debug visualization is enabled.
virtual void setPosition(kVec3 newPosition)
Sets the local position.
kVec3 getGlobalPosition()
Returns the world-space position derived from the world transform.
bool getActive()
Returns whether this object is active (visible/processed).
void setHasCharacterDesc(bool val)
Sets whether this object has a character controller descriptor.
void setId(unsigned int newId)
Sets the numeric identifier.
void detachCharacter()
Detaches the character controller without destroying it.
void setType(kNodeType newType)
Sets the node type tag.
kVec3 calculateUp()
Computes the local up (+Y) direction in world space.
kNodeType getType()
Returns the scene-graph node type tag.
kVec3 calculateRight()
Computes the local right (+X) direction in world space.
void setHasPhysicsDesc(bool val)
Sets whether this object has a physics body descriptor.
kVec3 getRotationEuler()
Returns the local rotation as Euler angles in degrees.
unsigned int getId()
Returns the numeric identifier of this object.
void setStatic(bool newStatic)
Marks the object as static or dynamic.
bool getHasCharacterDesc() const
Returns true if this object has a character controller configured.
void removeAudioSource(const kString &uuid)
Removes the audio source with the given UUID from this object.
kMat4 getModelMatrixLocal()
Returns the local model matrix (relative to the parent).
void setUuid(kString newUuid)
Sets the UUID kString.
void setPrefabRef(const kString &ref)
Sets the prefab asset UUID this object is an instance of.
Represents a single rigid body or trigger volume inside the physics simulation.
Definition kphysicsobject.h:131
Audio emitter and listener component descriptors for scene objects.
Capsule character controller built on Jolt's JPH::Character.
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Abstract graphics driver interface used by the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Surface material combining a shader, textures, and PBR/Phong properties.
Navigation mesh baking and pathfinding.
nlohmann::json json
Definition kobject.h:30
Particle system component and manager.
A single physics body — shape, type (dynamic / static / kinematic / trigger), and runtime controls.
AngelScript engine wrapper: script-asset registry, text/bytecode compilation, and per-object script i...
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
std::string kString
Standard string alias.
Definition kdatatype.h:42
glm::quat kQuat
Unit quaternion.
Definition kdatatype.h:40
kNodeType
Scene-graph node type tag.
Definition kdatatype.h:86
@ NODE_TYPE_OBJECT
Generic empty object.
Definition kdatatype.h:87
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
glm::mat4 kMat4
4x4 float matrix.
Definition kdatatype.h:39
Marks a scene object as the audio listener (typically the main camera).
Definition kaudiosource.h:43
Describes an audio emitter attached to a scene object.
Definition kaudiosource.h:21
Editor-authored description of a character controller.
Definition kcharactercontroller.h:26
Serialisable settings for a navigation surface attached to an object in the editor.
Definition knavmesh.h:108
Data descriptor for a single particle system attached to a scene object.
Definition kparticle.h:23
All parameters needed to create a kPhysicsObject.
Definition kphysicsobject.h:92
Per-object script component descriptor.
Definition kscriptmanager.h:79