<?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
force:
Vector3 |
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
()
:
Pose |
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
angularVelocity:
Vector3 |
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
velocity:
Vector3 |
setPose
(
pose
)
|
Sets the position and rotation of this physics object.
Signature
fun setPose(pose: Pose) Parameters
pose:
Pose |
setRestitution
(
restitution
)
|
Sets the restitution (bounciness) of this physics object.
Signature
fun setRestitution(restitution: Float) Parameters
restitution:
Float
|
createBox
(
scene
,
entity
,
width
,
height
,
depth
,
mass
)
:
ScenePhysicsObject |
Creates a box-shaped physics object.
Signature
fun createBox(scene: Scene, entity: Entity?, width: Float, height: Float, depth: Float, mass: Float): ScenePhysicsObject Parameters
scene:
Scene
entity:
Entity?
width:
Float
height:
Float
depth:
Float
mass:
Float
|
createGLTF
(
scene
,
entity
,
filename
,
mass
)
:
ScenePhysicsObject |
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
)
:
ScenePhysicsObject |
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
|