<?xml version="1.0" ?>
<ComponentSchema packageName="com.meta.aether.apps.experiments.physics">
<Component name="CustomPhysics">
<Vector3Attribute
name="initialLinearVelocity"
defaultValue="0.0f, 0.0f, 0.0f"
/>
</Component>
</ComponentSchema>
class CustomPhysicsSystem() : SystemBase() {
private val physicsObjects_ = HashMap<Entity, ScenePhysicsObject>()
override fun execute() {
val q = Query.where { changed(CustomPhysics.id) and has(Transform.id) }
for (ent in q.eval()) {
if (physicsObjects_.containsKey(ent)) {
continue
}
val physics = ScenePhysicsObject.createBox(getScene(), ent, 0.25f, 0.25f, 0.25f, 0.5f)
physicsObjects_.put(ent, physics)
physics.setPose(ent.getComponent<Transform>().transform)
physics.setLinearVelocity(ent.getComponent<CustomPhysics>().initialLinearVelocity)
Log.i("Physics", "Created physics object for entity $ent $physics")
}
}
override fun delete(entity: Entity) {
if (physicsObjects_.containsKey(entity)) {
physicsObjects_[entity]?.destroy()
physicsObjects_.remove(entity)
}
}
open class ScenePhysicsObject
entity
: Entity?
[Get] |
Signature
val entity: Entity? |
handle
: Long
[Get] |
Native handle to the physics object.
Signature
var handle: Long |
applyForce
(
force
)
|
Applies a force to this physics object
Signature
fun applyForce(force: Vector3) Parameters |
applyForceAtRelativePosition
(
force
, relativePos
)
|
Applies a force to this physics object at a specified position relative to its center.
This can create both linear and angular acceleration depending on the force and position.
Signature
fun applyForceAtRelativePosition(force: Vector3, relativePos: Vector3) |
applyTorque
(
torqueX
, torqueY
, torqueZ
)
|
Applies a torque (rotational force) to this physics object.
Signature
fun applyTorque(torqueX: Float, torqueY: Float, torqueZ: Float) Parameters torqueX: Float
The X component of the torque vector
torqueY: Float
The Y component of the torque vector
torqueZ: Float
The Z component of the torque vector
|
destroy
()
|
Signature
fun destroy() |
getPose
()
|
Gets the current position and rotation of this physics object.
Signature
fun getPose(): Pose |
setAngularVelocity
(
angularVelocity
)
|
Sets the angular velocity of this physics object.
Signature
fun setAngularVelocity(angularVelocity: Vector3) Parameters |
setBodyType
(
bodyType
, mass
)
|
Sets the body type (STATIC, DYNAMIC, or KINEMATIC) of this physics object.
Signature
fun setBodyType(bodyType: PhysicsState, mass: Float) Parameters mass: Float
The mass for dynamic bodies (ignored for static/kinematic)
|
setDamping
(
linearDamping
, angularDamping
)
|
Sets the linear and angular damping for this physics object.
Damping reduces velocity over time, simulating air resistance or friction. Higher values cause faster velocity decay.
Signature
fun setDamping(linearDamping: Float = 0.05f, angularDamping: Float = 0.85f) Parameters linearDamping: Float
Linear velocity damping (0.0 = no damping, 1.0 = full damping). Default: 0.05
angularDamping: Float
Angular velocity damping (0.0 = no damping, 1.0 = full damping). Default: 0.85
|
setDeactivationTime
(
time
)
|
Sets the deactivation time for this physics object.
When a physics body comes to rest (below sleeping thresholds), it will deactivate after this amount of time to save CPU resources.
Signature
fun setDeactivationTime(time: Float = 0.8f) Parameters time: Float
Time in seconds before deactivation. Default: 0.8
|
setFriction
(
friction
, rolling
, spinning
)
|
Sets the friction properties of this physics object.
Signature
fun setFriction(friction: Float, rolling: Float = friction, spinning: Float) Parameters friction: Float
The surface friction coefficient
rolling: Float
The rolling friction coefficient (defaults to the same as surface friction)
spinning: Float
The spinning friction coefficient
|
setLinearVelocity
(
velocity
)
|
Sets the linear velocity of this physics object.
Signature
fun setLinearVelocity(velocity: Vector3) Parameters |
setPose
(
pose
)
|
Sets the position and rotation of this physics object.
Signature
fun setPose(pose: Pose) Parameters |
setRestitution
(
restitution
)
|
Sets the restitution (bounciness) of this physics object.
Signature
fun setRestitution(restitution: Float) Parameters restitution: Float
The restitution value (0.0 = no bounce)
|
setSleepingThresholds
(
linear
, angular
)
|
Sets the sleeping thresholds for this physics object.
When linear and angular velocities fall below these thresholds, the body begins the deactivation countdown. Lower values keep bodies active longer.
Signature
fun setSleepingThresholds(linear: Float = 1.6f, angular: Float = 2.5f) Parameters linear: Float
Linear velocity threshold in m/s. Default: 1.6
angular: Float
Angular velocity threshold in rad/s. Default: 2.5
|
createBox
(
scene
, entity
, width
, height
, depth
, mass
)
|
Creates a box-shaped physics object.
Signature
fun createBox(scene: Scene, entity: Entity?, width: Float, height: Float, depth: Float, mass: Float): ScenePhysicsObject Parameters width: Float
Width of the box in meters
height: Float
Height of the box in meters
depth: Float
Depth of the box in meters
mass: Float
Mass of the box in kilograms (0 for static objects)
|
createFromCollider
(
scene
, entity
, collider
, mass
)
|
Creates a physics object using an existing collider.
This allows multiple physics objects to share the same collision shape, reducing memory usage when many objects have the same geometry.
Signature
fun createFromCollider(scene: Scene, entity: Entity?, collider: ScenePhysicsCollider, mass: Float): ScenePhysicsObject Parameters mass: Float
Mass of the object in kilograms (0 for static objects)
|
createGLTF
(
scene
, entity
, filename
, mass
)
|
Creates a physics object from a GLTF model file.
The collision shape will be generated from the model's geometry.
Signature
fun createGLTF(scene: Scene, entity: Entity?, filename: String, mass: Float): ScenePhysicsObject Parameters |
createSphere
(
scene
, entity
, radius
, mass
)
|
Creates a sphere-shaped physics object.
Signature
fun createSphere(scene: Scene, entity: Entity?, radius: Float, mass: Float): ScenePhysicsObject Parameters |
setCallbackEntities
(
scene
, entities
)
|
Sets the entities that will receive physics callbacks.
Signature
fun setCallbackEntities(scene: Long, entities: LongArray) Parameters scene: Long
The scene handle
entities: LongArray
Array of entity IDs that will receive physics callbacks
|