val ball = Entity.create()
ball.setComponent(
Physics(
shape = "sphere",
state = PhysicsState.DYNAMIC,
density = 1.0f,
restitution = 0.8f
)
)
class Physics
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),
linearDamping: Float = 0.05f,
angularDamping: Float = 0.05f,
allowSleeping: Boolean = true,
state: PhysicsState = PhysicsState.DYNAMIC,
collisionShapeType: CollisionShapeType = CollisionShapeType.PRIMITIVE,
collisionMeshNode: String = "",
maxConvexHulls: Int = 8,
) : ComponentBasePhysics
(
linearVelocity
, angularVelocity
, dimensions
, shape
, densityInternal
, applyForce
, restitution
, frictionInternal
, linearDamping
, angularDamping
, allowSleeping
, 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),
linearDamping: Float = 0.05f,
angularDamping: Float = 0.05f,
allowSleeping: Boolean = true,
state: PhysicsState = PhysicsState.DYNAMIC,
collisionShapeType: CollisionShapeType = CollisionShapeType.PRIMITIVE,
collisionMeshNode: String = "",
maxConvexHulls: Int = 8,
)Parameters dimensions: Vector3
: Size of a primitive shape in meters: half the width, height and depth of a "box", the radius of a "sphere" in x, and the radius in x and full height in y of a cylinder. Primitive shapes are at least 1 mm across.
shape: String
: URL or path to the collision shape file (GLTF/GLB format) or primitive name ("box", "sphere", "cylinderX", "cylinderY" or "cylinderZ"). In a glTF collision mesh, neighbouring triangles should share vertices: export it with positions only, or merge its vertices. Otherwise bodies catch on the edges between triangles.
densityInternal: FloatapplyForce: Vector3
: Impulse to apply once, at the next physics step, in newton-seconds (x, y, z). It changes the velocity by applyForce / mass, then resets to zero. For a force that acts over time, call ScenePhysicsObject.applyForce every frame.
restitution: Float
: Bounciness coefficient (0.0 = no bounce, 1.0 = perfect bounce). A contact uses the larger restitution of the two bodies.
frictionInternal: Vector3linearDamping: Float
: How fast the object's movement slows by itself, as a rate per second: speed decays by about e^(-d * t)
angularDamping: Float
: How fast the object's spin slows by itself, as a rate per second. Nothing else slows a rolling object, so raise this to make balls stop sooner.
allowSleeping: Boolean
: Whether the body may fall asleep once it has been nearly still for a while. A sleeping body costs no CPU until something touches or moves it.
state: PhysicsState
: Physics simulation state (STATIC, DYNAMIC, or KINEMATIC)
Changing state, density, restitution, friction, damping or allowSleeping updates the existing body. Changing shape recreates it. linearVelocity and angularVelocity only set the body's starting velocity.
Setting the entity's Transform moves a DYNAMIC body there and wakes it; the body keeps its velocity, and physics carries on moving it from there. Setting a STATIC body's Transform teleports it without affecting other bodies, so a body resting on it stays where it is. To move a body yourself, make it KINEMATIC: a kinematic body pushes, carries and wakes the bodies it touches.
collisionShapeType: CollisionShapeTypecollisionMeshNode: StringmaxConvexHulls: IntReturns Physics |
allowSleeping
: Boolean
[Get][Set] |
Whether the body may fall asleep once it has been nearly still for a while. A sleeping body costs no CPU until something touches or moves it. Turn this off for bodies that must keep moving, however slowly.
Signature
var allowSleeping: Boolean |
angularDamping
: Float
[Get][Set] |
How fast the object's spin slows by itself, as a rate per second. Nothing else slows a rolling object, so raise this to make balls stop sooner.
Signature
var angularDamping: Float |
angularVelocity
: Vector3
[Get][Set] |
Initial angular velocity of the object in rad/s (x, y, z)
Signature
var angularVelocity: Vector3 |
applyForce
: Vector3
[Get][Set] |
Impulse to apply once at the next physics step, in newton-seconds (x, y, z). It changes the velocity by applyForce / mass, then resets to zero.
Signature
var applyForce: Vector3 |
cachable
: Boolean
[Get][Set] |
Signature
open override var cachable: Boolean |
collisionMeshNode
: String
[Get][Set] |
Not supported yet: the whole glTF in the shape attribute is the collision shape.
Signature
var collisionMeshNode: String |
collisionShapeType
: CollisionShapeType
[Get][Set] |
How a glTF shape becomes a collision shape. CONVEX_HULL wraps its vertices in a convex hull, which suits DYNAMIC objects; every other value builds a triangle mesh, for STATIC and KINEMATIC objects only. Leaving it at PRIMITIVE for a glTF shape logs a warning.
Signature
var collisionShapeType: CollisionShapeType |
density
: Float
[Get][Set] |
Signature
var density: Float |
densityInternal
: Float
[Get][Set] |
Internal storage for the body's mass in kg (use density property instead)
Signature
var densityInternal: Float |
dimensions
: Vector3
[Get][Set] |
Size of a primitive shape in meters: half the width, height and depth of a box, the radius of a sphere in x, and the radius in x and full height in y of a cylinder
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; only sliding has an effect). Use friction property instead.
Signature
var frictionInternal: Vector3 |
linearDamping
: Float
[Get][Set] |
How fast the object's movement slows by itself, as a rate per second: speed decays by about e^(-d * t)
Signature
var linearDamping: Float |
linearVelocity
: Vector3
[Get][Set] |
Initial linear velocity of the object in m/s (x, y, z)
Signature
var linearVelocity: Vector3 |
maxConvexHulls
: Int
[Get][Set] |
Not supported yet, since CONVEX_DECOMPOSITION builds a triangle mesh.
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). A contact uses the larger restitution of the two bodies.
Signature
var restitution: Float |
shape
: String
[Get][Set] |
URL or path to the collision shape file (GLTF/GLB format) or primitive name ('box', 'sphere', 'cylinderX', 'cylinderY' or 'cylinderZ'). In a glTF collision mesh, neighbouring triangles should share vertices, or bodies catch on the edges between them.
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<out Enum<*>>?
The enum class, or null if the key doesn't exist or is not an enum
|
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
|
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 |
allowSleepingData
: BooleanAttributeData
[Get] |
Signature
val allowSleepingData: BooleanAttributeData |
allowSleepingId
: Int
[Get] |
Signature
val allowSleepingId: Int |
angularDampingData
: FloatAttributeData
[Get] |
Signature
val angularDampingData: FloatAttributeData |
angularDampingId
: Int
[Get] |
Signature
val angularDampingId: Int |
angularVelocityData
: Vector3AttributeData
[Get] |
Signature
val angularVelocityData: Vector3AttributeData |
angularVelocityId
: Int
[Get] |
Signature
val angularVelocityId: Int |
applyForceData
: Vector3AttributeData
[Get] |
Signature
val applyForceData: Vector3AttributeData |
applyForceId
: Int
[Get] |
Signature
val applyForceId: Int |
attributeKeys_
: IntArray
[Get] |
Signature
val attributeKeys_: IntArray |
attributeNames_
: Array<String>
[Get] |
Signature
val attributeNames_: Array<String> |
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
: Int
[Get] |
Signature
val collisionMeshNodeId: Int |
collisionShapeTypeData
: EnumAttributeData
[Get] |
Signature
val collisionShapeTypeData: EnumAttributeData |
collisionShapeTypeId
: Int
[Get] |
Signature
val collisionShapeTypeId: Int |
createDefaultInstance
: () -> Physics
[Get] |
Signature
open override val createDefaultInstance: () -> Physics |
densityInternalData
: FloatAttributeData
[Get] |
Signature
val densityInternalData: FloatAttributeData |
densityInternalId
: Int
[Get] |
Signature
val densityInternalId: Int |
dimensionsData
: Vector3AttributeData
[Get] |
Signature
val dimensionsData: Vector3AttributeData |
dimensionsId
: Int
[Get] |
Signature
val dimensionsId: Int |
enumClassesMap_
: Map<Int, Class<out Enum<*>>>
[Get] |
Signature
val enumClassesMap_: Map<Int, Class<out Enum<*>>> |
frictionInternalData
: Vector3AttributeData
[Get] |
Signature
val frictionInternalData: Vector3AttributeData |
frictionInternalId
: Int
[Get] |
Signature
val frictionInternalId: Int |
id
: Int
[Get] |
Signature
open override val id: Int |
keyStringToKeyIntMap_
: Map<String, Int>
[Get] |
Signature
val keyStringToKeyIntMap_: Map<String, Int> |
linearDampingData
: FloatAttributeData
[Get] |
Signature
val linearDampingData: FloatAttributeData |
linearDampingId
: Int
[Get] |
Signature
val linearDampingId: Int |
linearVelocityData
: Vector3AttributeData
[Get] |
Signature
val linearVelocityData: Vector3AttributeData |
linearVelocityId
: Int
[Get] |
Signature
val linearVelocityId: Int |
maxConvexHullsData
: IntAttributeData
[Get] |
Signature
val maxConvexHullsData: IntAttributeData |
maxConvexHullsId
: Int
[Get] |
Signature
val maxConvexHullsId: Int |
restitutionData
: FloatAttributeData
[Get] |
Signature
val restitutionData: FloatAttributeData |
restitutionId
: Int
[Get] |
Signature
val restitutionId: Int |
shapeData
: StringAttributeData
[Get] |
Signature
val shapeData: StringAttributeData |
shapeId
: Int
[Get] |
Signature
val shapeId: Int |
stateData
: EnumAttributeData
[Get] |
Signature
val stateData: EnumAttributeData |
stateId
: Int
[Get] |
Signature
val stateId: Int |
attributeCount
()
|
Signature
open override fun attributeCount(): Int Returns Int |
attributeKeys
()
|
Signature
open override fun attributeKeys(): IntArray Returns IntArray |
attributeMetaData
()
| Returns Map |
attributeNames
()
|
Signature
open override fun attributeNames(): Array<String> Returns Array<String> |
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<Int, Class<out Enum<*>>> |
keyStringToKeyIntMap
(
keyString
)
|
Signature
open override fun keyStringToKeyIntMap(keyString: String): Int? Parameters keyString: StringReturns Int? |
keyToIndex
(
key
)
|
Signature
open override fun keyToIndex(key: Int): Int Parameters key: IntReturns Int |