open class ScenePhysicsObject
<?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)
}
}
| Name | Summary |
|---|---|
Companion | object Companion |
| Name | Summary |
|---|---|
entity | val entity: Entity? |
handle | var handle: Long Native handle to the physics object. |
| Name | Summary |
|---|---|
applyForce | |
applyForceAtRelativePosition | |
applyTorque | fun applyTorque(torqueX: Float, torqueY: Float, torqueZ: Float) Applies a torque (rotational force) to this physics object. |
destroy | fun destroy() |
getPose | |
setAngularVelocity | |
setFriction | fun setFriction(friction: Float, rolling: Float = friction, spinning: Float) Sets the friction properties of this physics object. |
setLinearVelocity | |
setPose | |
setRestitution | fun setRestitution(restitution: Float) Sets the restitution (bounciness) of this physics object. |
object Companion
| Name | Summary |
|---|---|
createBox | |
createGLTF | |
createSphere | |
setCallbackEntities | fun setCallbackEntities(scene: Long, entities: LongArray) Sets the entities that will receive physics callbacks. |