new pxlColliders()
- Description:
Collision intersection handling class; ray intersection with geometry faces.
This is implemented indipendent of Three.js raycasting, and is optimized for pxlNav's needs.When adding a 3d scene file to your room, any objects in you
SceneRoot/Colliders
group will automatically register aspxlEnums.COLLIDER_TYPE.FLOOR
colliders.
Automatically adding them tothis.pxlColliders
accessible from your room.The reason this is indipendent of Three.js raycasting is performance.
When pxlNav loads a room, it will parse the colliders in your scene, pre-calculating math data for faster & grid-optimized ray intersection.
This allows for much much larger polygon counts in your colliders, as well as more complex scenes.This is also why there is a
castGravityRay
function, it's making assumptions about what triangles to check based on the camera's X,Z position.
- Source:
Methods
(static) buildHelper(roomObj, colliderType) → {object}
- Description:
Build a helper object for the specified room and collider type
Displays random Green -to- Blue colors per triangle in the collision object.
This is good for visualizing what your ground collider looks like,
Like, if you are getting caught on the geometry while walking around.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
roomObj |
object | pxlRoom object; you can pass |
colliderType |
enum | Type of collider to build (e.g., FLOOR, WALL); see |
Returns:
- Helper Mesh object containing geometry and material for the collider visualization
- Type
- object
(static) castGravityRay(roomName, origin, colliderTypeopt, multiHitsopt) → {Array}
- Description:
Cast a ray from an Origin (Vector3) in gravity's direction and check for collision against the specified collider type in the given pxlRoom. Returns an array of collision hits, sorted by distance from the origin.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
string | Name of the pxlRoom to check collision against |
||
origin |
Vector3 | Origin point of the ray |
||
colliderType |
string |
<optional> |
pxlEnums.COLLIDER_TYPE.FLOOR
|
Type of collider to check against; see |
multiHits |
boolean |
<optional> |
true
|
If |
Returns:
Array of collision hit objects, sorted by distance from the origin. Each object in the array contains -
"object" : Collided Three.js object
"pos" : Vector3 position of the collision
"dist" : Distance from the origin
- Type
- Array
(static) castInteractRay(roomName, objectInteractList, camera, screenUVopt, multiHitsopt) → {Array}
- Description:
Cast a ray from the provided camera through the specified screen UV coordinates and check for collision against the provided list of interactable objects in the given pxlRoom. Returns an array of collision hits, sorted by distance from the camera.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
string | Name of the pxlRoom to check collision against |
||
objectInteractList |
Array | Array of Three.js objects to check collision against |
||
camera |
Camera | Three.js camera object to cast the ray from |
||
screenUV |
Vector2 |
<optional> |
Vector2(0.0, 0.0)
|
Screen UV coordinates in Normalized Device Coordinates (NDC), from -1 to 1;
|
multiHits |
boolean |
<optional> |
true
|
If |
Returns:
Array of collision hit objects, sorted by distance from the camera. Each object in the array contains -
"object" : Collided Three.js object
"pos" : Vector3 position of the collision
- Type
- Array
(static) castRay(roomName, origin, direction, colliderTypeopt, geoSideopt, multiHitsopt) → {Array}
- Description:
Cast a ray from an Origin (Vector3) in a given Direction (Vector3) and check for collision against the specified collider type in the given pxlRoom. Returns an array of collision hits, sorted by distance from the origin.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
string | Name of the pxlRoom to check collision against |
||
origin |
Vector3 | Origin point of the ray |
||
direction |
Vector3 | Direction vector of the ray; should be normalized |
||
colliderType |
string |
<optional> |
pxlEnums.COLLIDER_TYPE.FLOOR
|
Type of collider to check against; see |
geoSide |
string |
<optional> |
pxlEnums.GEOMETRY_SIDE.DOUBLE
|
Which side of the geometry to check against; see |
multiHits |
boolean |
<optional> |
true
|
If |
Returns:
Array of collision hit objects, sorted by distance from the origin. Each object in the array contains -
"object" : Collided Three.js object
"pos" : Vector3 position of the collision
"dist" : Distance from the origin
- Type
- Array
(static) prepColliders(colliderTypeopt, gridSizeopt)
- Description:
Add & Prepare object collider to the collision system. Only object's with user-detail attributes
colliderType
are included.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
|
object | pxlRoom to enable the collider for; pass |
||
colliderType |
string |
<optional> |
pxlEnums.COLLIDER_TYPE.FLOOR
|
Type of collider to prep; see |
gridSize |
number | null |
<optional> |
null
|
Size of the hash grid for collider face grouping; if |
(static) prepInteractables(colliderTypeopt)
- Description:
Prepare interactable colliders for the room and add to the collision system. Only object's with user-detail attributes
colliderType
are included.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
|
object | pxlRoom to enable the collider for; pass |
||
colliderType |
string |
<optional> |
pxlEnums.COLLIDER_TYPE.HOVERABLE
|
Type of interactable collider to prep; see |
(static) setHelperActiveFace(roomName, colliderType, faceIdx)
- Description:
Passive function which toggles the "highlighted" face of the specific collision type objects
- Source:
Parameters:
Name | Type | Description |
---|---|---|
roomName |
string | The name of the room with the specific collider type |
colliderType |
enum | Type of collider to build (e.g., FLOOR, WALL); see |
faceIdx |
number | The index of the face to highlight; set to -1 to disable highlighting |
(static) stepHelper(roomObj, colliderType) → {object}
- Description:
Currently not implemented!
Update the collider helper's visible triangles to only display the grid the camera is currently in.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
roomObj |
object | pxlRoom object; you can pass |
colliderType |
enum | Type of collider to build (e.g., FLOOR, WALL); see |
Returns:
- Perform a single frame's calculation to update the collider helper's visible triangles based on the room object's current position
- Type
- object