<?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
torqueY:
Float
torqueZ:
Float
|
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
|
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
angularDamping:
Float
|
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
|
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
rolling:
Float
spinning:
Float
|
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
|
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
angular:
Float
|
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
height:
Float
depth:
Float
mass:
Float
|
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
|
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
entities:
LongArray
|