MCPcopy Index your code
hub / github.com/anvaka/yaot

github.com/anvaka/yaot @v1.1.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.3 ↗ · + Follow
416 symbols 783 edges 9 files 2 documented · 0% updated 10y ago★ 52
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

yaot Build Status

Octree in javascript. Extremely fast module to query points in 3D space. Can be used to find points under mouse cursor in 3D scene.

usage

This module is best suited for static scenes, where points are not changed over time. To get started initialize the tree:

// First we need to create the tree:
var createTree = require('yaot');

var tree = createTree();
var points = [
  0, 0, 0, // First point at 0, 0, 0
  10, 0, 0 // second point at 10, 0, 0
]
tree.init(points);

// Now we are ready to query it:
// Which points lie inside sphere with center at 0, 0, 0 and radius 2?
var matches = tree.intersectSphere(0, 0, 0, 2);
// matches[0] === 0 -> the point at first index of `points` array is there!

// Let's extend our sphere:
var matches = tree.intersectSphere(0, 0, 0, 20);
// matches[0] === 0 -> Point at index 0 is here too
// matches[1] === 3 -> Point at index 3 from `points` array also inisde

You can also query points which lies inside octants intersected by a ray. This is very useful when you want to know which points lie under mouse cursor.

var rayOrigin = {
  x: 1, y: 0, z: 0
};
var rayDirection = {
  x: -1, y: 0, z: 0
};
var matches = tree.intersectRay(rayOrigin, rayDirection)

// If you want to limit where ray starts checking against intersection
// you can pass option `near` argumnet:
var near = 10; // by default it is 0, but could be made bigger!
var matches10PixelsAway = tree.intersectRay(rayOrigin, rayDirection, near);

// You can also limit upper bound by setting `far` argument:
var far = 100; // By default it is positive infinity, which matches all.
var matchesPointsBetween10And100Pixels =
    tree.intersectRay(rayOrigin, rayDirection, near, far);

To see how to use it with three.js please read about demo below.

demo

A three.js demo is available here (src). You can compare its performance to native three.js raycaster.intersectObjects() method (src). Open dev console on both pages to see the timers. Octree solution is 42 times faster than native raycaster.intersectObjects().

Video comparison is available here: https://www.youtube.com/watch?v=9Z-Yzb-WSKg

Keep in mind that raycaster is generalized solution which works with any three.js objects, while octree is very much specialized.

This module is also used in the code galaxies. Source code is here.

install

With npm do:

npm install yaot

license

MIT

Core symbols most depended-on inside this repo

addLine
called by 25
demo/bundle_tree.js
addLine
called by 25
demo/bundle_ray.js
setPoint
called by 21
demo/bundle_tree.js
setPoint
called by 21
demo/bundle_ray.js
paramThreeToGL
called by 16
demo/bundle_tree.js
paramThreeToGL
called by 16
demo/bundle_ray.js
getRandomPoint
called by 12
perf/index.js
sqr
called by 9
index.js

Shape

Function 416

Languages

TypeScript100%

Modules by API surface

demo/bundle_tree.js191 symbols
demo/bundle_ray.js191 symbols
index.js16 symbols
demo/raycaster.js6 symbols
demo/octree.js6 symbols
perf/index.js3 symbols
lib/treeNode.js2 symbols
lib/bounds3.js1 symbols

For agents

$ claude mcp add yaot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact