From High Fidelity Documentation
Jump to: navigation, search

Entities API

JavaScript API

voxelCoordsToLocalCoords() converts the specified voxel coordinates in the reference frame of the specified PolyVox entity to local coordinates in the entity's frame of reference.

Note: Local coordinates have the same scale as world coordinates.


voxelCoordsToLocalCoords(entityID, voxelCoords) // Returns vec3


entityID: EntityItemID: The PolyVox entity that is the frame of reference for the specified voxel coordinates and the returned local coordinates

voxelCoords: vec3: The voxel coordinates to be converted to local coordinates


vec3: Coordinates in local-space


This example creates a PolyVox entity just in front of the avatar. It then uses voxelCoordsToLocalCoords() to get the voxel coordinates of the local position of 1,1,1 for the newly created entity.

// Create entity properties
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));  
var properties = {
  type: "PolyVox",
  position: pos

// Add the new PolyVox entity
var Ent = Entities.addEntity(properties);

// Get the voxel coordinates of the local position 1, 1, 1
var localCoords = Entities.voxelCoordsToLocalCoords(Ent, {x:1, y:1, z:1});


Check the High Fidelity source for more information and examples: