val ball = Entity.create()
ball.setComponent(
Physics(
shape = "sphere",
state = PhysicsState.DYNAMIC,
density = 1.0f,
restitution = 0.8f
)
)
class Physics(linearVelocity: Vector3 = Vector3(0.0f, 0.0f, 0.0f), angularVelocity: Vector3 = Vector3(0.0f, 0.0f, 0.0f), dimensions: Vector3 = Vector3(0.5f, 0.5f, 0.5f), shape: String = "box", densityInternal: Float = 1.0f, applyForce: Vector3 = Vector3(0.0f, 0.0f, 0.0f), restitution: Float = 0.2f, frictionInternal: Vector3 = Vector3(0.5f, 0.0f, 0.0f), state: PhysicsState = PhysicsState.DYNAMIC, collisionShapeType: CollisionShapeType = CollisionShapeType.PRIMITIVE, collisionMeshNode: String = "", maxConvexHulls: Int = 8) : ComponentBase
Physics
(
linearVelocity
, angularVelocity
, dimensions
, shape
, densityInternal
, applyForce
, restitution
, frictionInternal
, state
, collisionShapeType
, collisionMeshNode
, maxConvexHulls
)
|
Signature
constructor(linearVelocity: Vector3 = Vector3(0.0f, 0.0f, 0.0f), angularVelocity: Vector3 = Vector3(0.0f, 0.0f, 0.0f), dimensions: Vector3 = Vector3(0.5f, 0.5f, 0.5f), shape: String = "box", densityInternal: Float = 1.0f, applyForce: Vector3 = Vector3(0.0f, 0.0f, 0.0f), restitution: Float = 0.2f, frictionInternal: Vector3 = Vector3(0.5f, 0.0f, 0.0f), state: PhysicsState = PhysicsState.DYNAMIC, collisionShapeType: CollisionShapeType = CollisionShapeType.PRIMITIVE, collisionMeshNode: String = "", maxConvexHulls: Int = 8) Parameters shape: String
: URL or path to the collision shape file (GLTF/GLB format) or primitive name ("box", "sphere")
densityInternal: Floatrestitution: Float
: Bounciness coefficient (0.0 = no bounce, 1.0 = perfect bounce)
frictionInternal: Vector3collisionShapeType: CollisionShapeTypecollisionMeshNode: StringmaxConvexHulls: IntReturns Physics |
angularVelocity
: Vector3
[Get][Set] |
Initial angular velocity of the object in rad/s (x, y, z)
Signature
var angularVelocity: Vector3 |
applyForce
: Vector3
[Get][Set] |
Force vector to apply to the object in Newtons (x, y, z)
Signature
var applyForce: Vector3 |
cachable
: BuildConfig.COMPONENTCACHE_LEVEL >= 1
[Get][Set] |
Signature
open override var cachable: BuildConfig.COMPONENTCACHE_LEVEL >= 1 |
collisionMeshNode
: String
[Get][Set] |
Optional name of mesh node in glTF to use for collision. Empty string uses the shape attribute. Useful for pre-baked low-poly collision meshes.
Signature
var collisionMeshNode: String |
collisionShapeType
: CollisionShapeType
[Get][Set] |
How the collision shape is generated. PRIMITIVE uses shape attribute, TRIANGLE_MESH uses exact glTF mesh (static only), CONVEX_HULL generates from vertices (fast for dynamics), CONVEX_DECOMPOSITION for complex concave shapes.
Signature
var collisionShapeType: CollisionShapeType |
density
: Float
[Get][Set] |
Signature
var density: Float |
densityInternal
: Float
[Get][Set] |
Internal storage for mass density (use density property instead)
Signature
var densityInternal: Float |
dimensions
: Vector3
[Get][Set] |
Size of the collision shape for primitive shapes (width, height, depth)
Signature
var dimensions: Vector3 |
entID
: Long
[Get][Set] |
Signature
var entID: Long |
friction
: FrictionObject
[Get][Set] |
Signature
var friction: FrictionObject |
frictionInternal
: Vector3
[Get][Set] |
Internal storage for friction values (sliding, rolling, spinning). Use friction property instead.
Signature
var frictionInternal: Vector3 |
isDirty
: Boolean
[Get][Set] |
Signature
var isDirty: Boolean |
linearVelocity
: Vector3
[Get][Set] |
Initial linear velocity of the object in m/s (x, y, z)
Signature
var linearVelocity: Vector3 |
maxConvexHulls
: Int
[Get][Set] |
Maximum number of convex hulls for CONVEX_DECOMPOSITION. Higher values = more accurate but slower.
Signature
var maxConvexHulls: Int |
recycled
: Boolean
[Get][Set] |
Signature
var recycled: Boolean |
restitution
: Float
[Get][Set] |
Bounciness coefficient (0.0 = no bounce, 1.0 = perfect bounce)
Signature
var restitution: Float |
shape
: String
[Get][Set] |
URL or path to the collision shape file (GLTF/GLB format) or primitive name ('box', 'sphere')
Signature
var shape: String |
state
: PhysicsState
[Get][Set] |
Physics simulation state (STATIC, DYNAMIC, or KINEMATIC)
Signature
var state: PhysicsState |
timeStamp
: Long
[Get][Set] |
Signature
var timeStamp: Long |
applyMaterial
(
material
)
|
Signature
fun applyMaterial(material: PhysicsMaterial): Physics Parameters material: PhysicsMaterialReturns Physics |
companion
()
|
Gets the companion object for this component.
The companion object provides metadata about the component.
Signature
open override fun companion(): ComponentCompanion Throws RuntimeException
If the companion is not implemented
|
getComponentDataAttributeType
(
key
)
|
Gets the attribute type for the specified key.
Signature
fun getComponentDataAttributeType(key: Int): AttributePrimitive? Parameters key: Int
The integer key to look up
|
getComponentDataAttributeType
(
keyString
)
|
Gets the attribute type for the specified string key.
Signature
fun getComponentDataAttributeType(keyString: String): AttributePrimitive? Parameters keyString: String
The string key to look up
Throws IllegalArgumentException
If the key doesn't exist
|
getComponentDataKey
(
key
)
|
Gets the integer key associated with the specified string key.
Signature
fun getComponentDataKey(key: String): Int? Parameters key: String
The string key to look up
Returns Int?
The integer key, or null if the string key doesn't exist
|
getComponentDataValue
(
key
)
|
Gets the value for the specified key.
Signature
fun getComponentDataValue(key: Int): Any? Parameters key: Int
The integer key to look up
Returns Any?
The value associated with the key, or null if the key doesn't exist
|
getComponentDataValue
(
keyString
)
|
Gets the value for the specified string key.
Signature
fun getComponentDataValue(keyString: String): Any? Parameters keyString: String
The string key to look up
Returns Any?
The value associated with the key, or null if the key doesn't exist
Throws IllegalArgumentException
If the key doesn't exist
|
getEnumClass
(
key
)
|
Gets the enum class associated with the specified string key.
Signature
fun getEnumClass(key: String): Class<out Enum<*>>? Parameters key: String
The string key to look up
Returns Class?
The enum class, or null if the key doesn't exist or is not an enum
|
hasAttributeChanges
()
|
Returns true if any attribute has been modified since the last read/write sync.
This is a read-only check. To clear the flag, call Entity.setComponent which syncs changes to native and resets the dirty state.
Signature
fun hasAttributeChanges(): Boolean Returns Boolean |
hasComponentData
(
key
)
|
Checks if this component has data for the specified key.
Signature
fun hasComponentData(key: Int): Boolean Parameters key: Int
The integer key to check
Returns Boolean
True if the component has data for the key, false otherwise
|
hasComponentData
(
keyString
)
|
Checks if this component has data for the specified string key.
Signature
fun hasComponentData(keyString: String): Boolean Parameters keyString: String
The string key to check
Returns Boolean
True if the component has data for the key, false otherwise
|
read
(
e
, cachable
)
|
Reads component data from the specified entity.
Signature
fun read(e: Entity, cachable: Boolean) Parameters cachable: Boolean
Whether the component's data should be cached
|
recycle
()
|
Recycles this component by returning it to its pool.
If the component has a pool assigned, it will be returned to that pool for reuse.
Signature
fun recycle() |
reset
()
|
Resets the component to its default state.
This method is called when a component is recycled to clear any state. Subclasses should override this method to reset their specific state.
Signature
open fun reset() |
setComponentDataValue
(
key
, value
)
|
Sets the value for the specified key.
Signature
fun setComponentDataValue(key: Int, value: Any): Boolean Parameters key: Int
The integer key to set
value: Any
The value to set
Returns Boolean
True if the value was set successfully, false otherwise
|
setComponentDataValue
(
keyString
, value
)
|
Sets the value for the specified string key.
Signature
fun setComponentDataValue(keyString: String, value: Any): Boolean Parameters keyString: String
The string key to set
value: Any
The value to set
Returns Boolean
True if the key exists and the value was set, false otherwise
|
setPool
(
pool
, entID
)
|
Sets the component pool and entity ID for this component.
This is used for component recycling to track which pool the component belongs to and which entity it was associated with.
Signature
fun setPool(pool: ComponentPool<*>, entID: Long) Parameters pool: ComponentPool
The component pool this component belongs to
entID: Long
The ID of the entity this component is associated with
|
toString
()
|
Signature
open override fun toString(): String Returns String |
typeID
()
|
Returns the unique type ID of this component.
Each component type must have a unique ID for identification in the entity-component system.
Signature
open override fun typeID(): Int Returns Int
The unique type ID for this component
|
write
(
e
)
|
Writes this component's data to the specified entity.
Signature
fun write(e: Entity) Parameters |
angularVelocityData
: Vector3AttributeData
[Get] |
Signature
val angularVelocityData: Vector3AttributeData |
angularVelocityId
:
[Get] |
Signature
val angularVelocityId: |
applyForceData
: Vector3AttributeData
[Get] |
Signature
val applyForceData: Vector3AttributeData |
applyForceId
:
[Get] |
Signature
val applyForceId: |
attributeKeys_
: IntArray
[Get] |
Signature
val attributeKeys_: IntArray |
attributeTypeCounts_
: IntArray
[Get] |
Signature
val attributeTypeCounts_: IntArray |
attributeTypes_
: IntArray
[Get] |
Signature
val attributeTypes_: IntArray |
attrMetaData_
: Map
[Get] |
Signature
val attrMetaData_: Map |
collisionMeshNodeData
: StringAttributeData
[Get] |
Signature
val collisionMeshNodeData: StringAttributeData |
collisionMeshNodeId
:
[Get] |
Signature
val collisionMeshNodeId: |
collisionShapeTypeData
: EnumAttributeData
[Get] |
Signature
val collisionShapeTypeData: EnumAttributeData |
collisionShapeTypeId
:
[Get] |
Signature
val collisionShapeTypeId: |
createDefaultInstance
: Function0
[Get] |
Signature
open override val createDefaultInstance: () -> Physics |
densityInternalData
: FloatAttributeData
[Get] |
Signature
val densityInternalData: FloatAttributeData |
densityInternalId
:
[Get] |
Signature
val densityInternalId: |
dimensionsData
: Vector3AttributeData
[Get] |
Signature
val dimensionsData: Vector3AttributeData |
dimensionsId
:
[Get] |
Signature
val dimensionsId: |
enumClassesMap_
: Map
[Get] |
Signature
val enumClassesMap_: Map<Int, Class<out Enum<*>>> |
frictionInternalData
: Vector3AttributeData
[Get] |
Signature
val frictionInternalData: Vector3AttributeData |
frictionInternalId
:
[Get] |
Signature
val frictionInternalId: |
id
:
[Get] |
Signature
open override val id: |
keyStringToKeyIntMap_
: Map
[Get] |
Signature
val keyStringToKeyIntMap_: Map<String, Int> |
linearVelocityData
: Vector3AttributeData
[Get] |
Signature
val linearVelocityData: Vector3AttributeData |
linearVelocityId
:
[Get] |
Signature
val linearVelocityId: |
maxConvexHullsData
: IntAttributeData
[Get] |
Signature
val maxConvexHullsData: IntAttributeData |
maxConvexHullsId
:
[Get] |
Signature
val maxConvexHullsId: |
restitutionData
: FloatAttributeData
[Get] |
Signature
val restitutionData: FloatAttributeData |
restitutionId
:
[Get] |
Signature
val restitutionId: |
shapeData
: StringAttributeData
[Get] |
Signature
val shapeData: StringAttributeData |
shapeId
:
[Get] |
Signature
val shapeId: |
stateData
: EnumAttributeData
[Get] |
Signature
val stateData: EnumAttributeData |
stateId
:
[Get] |
Signature
val stateId: |
attributeKeys
()
|
Signature
open override fun attributeKeys(): IntArray Returns IntArray |
attributeMetaData
()
| Returns Map |
attributeTypeCountAvailable
()
|
Signature
open override fun attributeTypeCountAvailable(): Boolean Returns Boolean |
attributeTypeCounts
()
|
Signature
open override fun attributeTypeCounts(): IntArray Returns IntArray |
attributeTypes
()
|
Signature
open override fun attributeTypes(): IntArray Returns IntArray |
dependents
()
|
Signature
open fun dependents(): IntArray Returns IntArray |
enumClassesMap
()
|
Signature
open override fun enumClassesMap(): Map<Int, Class<out Enum<*>>> Returns Map |
keyStringToKeyIntMap
(
keyString
)
|
Signature
open override fun keyStringToKeyIntMap(keyString: String): Int? Parameters keyString: StringReturns Int? |