Skip to main content

WorldQueryHitTestResult

Class

The result of the hitTest method call.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — SPECS only
  • Camera Kit MobileNot supported — SPECS only

Platform details

  • Snapchat — Not supported — SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — SPECS only.

  • Camera Kit Mobile — Not supported — SPECS only.

The result of the hitTest method call. This includes the world position of the hit, the world normal of the hit. Returns null if no intersection with environment was detected.

Index

Example

// Set object's position and rotation if WorldQuery ray hits something.

onHitTestResult(result) {
if (result === null) {
// no hit detected
} else {
// get hit information
const hitPosition = results.position;
const hitNormal = results.normal;
//identifying the direction the object should look at based on the normal of the hit location.

var lookDirection;
if (1 - Math.abs(hitNormal.normalize().dot(vec3.up())) < 0.01) {
lookDirection = vec3.forward();
} else {
lookDirection = hitNormal.cross(vec3.up());
}
const toRotation = quat.lookAt(lookDirection, hitNormal);

//set position and rotation

this.targetObject.getTransform().setWorldPosition(hitPosition);
this.targetObject.getTransform().setWorldRotation(toRotation);
}
}

Extends

Properties

classification

readonly classification: SurfaceClassification

SPECS only

The classification of the surface at the position where the ray intersects with the environment.

Since

Lens Scripting Version 377


normal

readonly normal: vec3

SPECS only

A normal of the surface at the position where the ray intersects with the environment.


position

readonly position: vec3

SPECS only

A position where ray intersects with the environment.

Methods

getTypeName()

static getTypeName(): TypeName<WorldQueryHitTestResult>

SPECS only

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<WorldQueryHitTestResult>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame