API Docs for:
Show:

LS.Physics Class

Defined in: ../src/physics.js:94
Module: LS

Physics is in charge of all physics testing methods Right now is mostly used for testing collisions with rays agains the colliders in the scene

Constructor

LS.Physics

()

Methods

raycast

(
  • origin
  • direction
  • options
)
Array

Cast a ray that traverses the scene checking for collisions with Colliders

Parameters:

  • origin Vec3

    in world space

  • direction Vec3

    in world space

  • options Object

    ( max_dist maxium distance, layers which layers to check, scene, first_collision )

Returns:

Array:

Array of Collision objects containing all the nodes that collided with the ray or null in the form [SceneNode, Collider, collision point, distance]

raycastRenderInstances

(
  • origin
  • direction
  • options
)
Array

Cast a ray that traverses the scene checking for collisions with RenderInstances instead of colliders Similar to Physics.raycast but using the RenderInstances (if options.triangle_collision it builds Octrees for the RIs whose OOBB collides with the ray)

Parameters:

  • origin Vec3

    in world space

  • direction Vec3

    in world space

  • options Object

    { instances: array of instances, if not the scene will be used, triangle_collision: true if you want to test against triangles, max_distance: maxium ray distance, layers, scene, max_distance, first_collision : returns the first collision (which could be not the closest one) }

Returns:

Array:

array containing all the RenderInstances that collided with the ray in the form [SceneNode, RenderInstance, collision point, distance]

raycastRenderInstances

(
  • origin
  • direction
  • node
  • options
)
Array

Cast a ray that traverses the scene checking for collisions with RenderInstances instead of colliders Similar to Physics.raycast but using the RenderInstances (if options.triangle_collision it builds Octrees for the RIs whose OOBB collides with the ray)

Parameters:

  • origin Vec3

    in world space

  • direction Vec3

    in world space

  • node LS.SceneNode
  • options Object

    ( triangle_collision: true if you want to test against triangles, max_distance: maxium ray distance, layers, scene, max_distance, first_collision : returns the first collision (which could be not the closest one) )

Returns:

Array:

array containing all the RenderInstances that collided with the ray in the form [SceneNode, RenderInstance, collision point, distance]

testSphere

(
  • origin
  • radius
  • options
)
PhysicsInstance

Test if a sphere collides with any of the colliders in the scene

Parameters:

  • origin Vec3

    in world space

  • radius Radius
  • options Object

    layers, colliders, scene

Returns:

PhysicsInstance:

the first PhysicsObject that collided with, otherwise null