### Using Local Coordinate APIs for Precision in Noa (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/positions.md Provides examples of using `_local` prefixed APIs like `noa.ents._localGetPosition` and `noa._localPick`. These functions operate in the local frame of reference, offering higher precision for operations like raycasting or directly manipulating physics/render positions, especially far from the world origin. ```javascript // do a raycast from an entity's position, the normal way var dir = noa.camera.getDirection() var pos = noa.ents.getPosition(id) var res = noa.pick(pos, dir) // same thing but higher precision var pos = noa.ents._localGetPosition(id) var res = noa._localPick(pos, dir) // full list of _local APIs noa._localPick noa.ents._localGetPosition noa.ents._localSetPosition noa.camera._localGetPosition noa.camera._localGetTargetPosition ``` -------------------------------- ### Importing Babylon Mesh Builder (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/history.md Shows how to import specific Babylon.js mesh builder modules, like 'boxBuilder', which may be required if your client code uses Babylon mesh creation functions directly. ```JavaScript import '@babylonjs/core/Meshes/Builders/boxBuilder' ``` -------------------------------- ### Managing Entity Position Component in Noa (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/positions.md Demonstrates how to create an entity, add the `position` component with initial values (position, width, height), and use basic `noa.ents` methods like `hasPosition`, `getPosition`, and `setPosition` to check and modify the entity's global position. ```javascript var id = noa.entities.createEntity() noa.ents.addComponent(id, noa.ents.names.position, { position: [1, 2, 3], width: 1, height: 2 }) noa.ents.hasPosition(id) // true noa.ents.getPosition(id) // [1, 2, 3] noa.ents.setPosition(id, [4.5, 5, 6]) ``` -------------------------------- ### Converting Between Local and Global Coordinates in Noa (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/positions.md Illustrates the use of `noa.localToGlobal` and `noa.globalToLocal` functions for precise coordinate conversions. It shows how to handle integer global positions with fractional precise offsets, and also the simplified usage where the global array includes fractions (though less precise for large worlds). ```javascript // noa has two functions to precisely convert between global and local coords. // In both cases the "global" argument is treated as integer values, // and the "precisePos" is fractional offsets to the global position noa.localToGlobal(local, global, precisePos) noa.globalToLocal(global, precisePos, local) // e.g. var local = [] noa.globalToLocal([1, 2, 3], [0.1, 0.1, 0.1], local) console.log(local) // [1.1, 2.1, 3.1], converted to local coords var pos = [] var frac = [] noa.localToGlobal(local, pos, frac) console.log(pos) // [1, 2, 3] console.log(frac) // [0.1, 0.1, 0.1] // In both cases the "precise" argument can be omitted, // so the "global" array will be treated as full (int+fraction) values. // This may cause precision issues in very large game worlds. var pos = [1.1, 2.1, 3.1] noa.globalToLocal(pos, null, local) noa.localToGlobal(local, pos) console.log(pos) // approx. [1.1, 2.1, 3.1] ``` -------------------------------- ### Importing Noa Engine (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/history.md Illustrates the updated method for importing the main Engine class from the 'noa-engine' package using a named export. ```JavaScript import {Engine} from 'noa-engine' ``` -------------------------------- ### Accessing Full Position Component State in Noa (JavaScript) Source: https://github.com/fenomas/noa/blob/master/docs/positions.md Shows how to retrieve the entire state object for the `position` component using `noa.ents.getPositionData(id)`. This allows direct access to all properties stored in the component state, such as `position`, `width`, and `height`. ```javascript var posState = noa.ents.getPositionData(id) posState.position // [4.5, 5, 6] posState.width // 1 posState.height // 2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.