API reference
API reference
Select your platform
No SDKs available
No versions available

ScenePhysicsObject

ScenePhysicsObject

open class ScenePhysicsObject
Represents a physics-enabled object in a 3D scene. Can be used to create custom physics implementations using the ECS.
Needs the com.meta.spatial.physics.PhysicsFeature to be enabled to work. Consider using the com.meta.spatial.physics.Physics component before implementing a custom physics system.
Example of a Custom Physics System, which creates a Physics box with initial linear velocity specified by the CustomPhysics component.
Component:
<?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>
System:
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)
  }
}

Types

NameSummary
Companion
object Companion

Properties

NameSummary
entity
val entity: Entity?
handle
var handle: Long

Native handle to the physics object.

Functions

NameSummary
applyForce
fun applyForce(force: Vector3)

Applies a force to this physics object
applyForceAtRelativePosition
fun applyForceAtRelativePosition(force: Vector3, relativePos: Vector3)

Applies a force to this physics object at a specified position relative to its center.
applyTorque
fun applyTorque(torqueX: Float, torqueY: Float, torqueZ: Float)

Applies a torque (rotational force) to this physics object.
destroy
fun destroy()
getPose
fun getPose(): Pose

Gets the current position and rotation of this physics object.
setAngularVelocity
fun setAngularVelocity(angularVelocity: Vector3)

Sets the angular velocity of this physics object.
setFriction
fun setFriction(friction: Float, rolling: Float = friction, spinning: Float)

Sets the friction properties of this physics object.
setLinearVelocity
fun setLinearVelocity(velocity: Vector3)

Sets the linear velocity of this physics object.
setPose
fun setPose(pose: Pose)

Sets the position and rotation of this physics object.
setRestitution
fun setRestitution(restitution: Float)

Sets the restitution (bounciness) of this physics object.

Companion

object Companion

Functions

NameSummary
createBox
fun createBox(scene: Scene, entity: Entity?, width: Float, height: Float, depth: Float, mass: Float): ScenePhysicsObject

Creates a box-shaped physics object.
createGLTF
fun createGLTF(scene: Scene, entity: Entity?, filename: String, mass: Float): ScenePhysicsObject

Creates a physics object from a GLTF model file.
createSphere
fun createSphere(scene: Scene, entity: Entity?, radius: Float, mass: Float): ScenePhysicsObject

Creates a sphere-shaped physics object.
setCallbackEntities
fun setCallbackEntities(scene: Long, entities: LongArray)

Sets the entities that will receive physics callbacks.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon