3D Spatial hash
How do I make an 3d spatial hash?
What is a 3d spatial hash? How do you make a 3d spatial hash? This script and codes were developed by Sarah Cartwright on 05 December 2022, Monday.
3D Spatial hash - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>3D Spatial hash</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> This Pen does nothing on its own - it is used in other pens. <script src="js/index.js"></script>
</body>
</html>
3D Spatial hash - Script Codes CSS Codes
body { padding: 10px; margin: 0px; background: #2e2e2e; color: #909090; font: 12px arial, sans-serif;
}
3D Spatial hash - Script Codes JS Codes
function spatialHash(cellSize){ this.cellSize = cellSize; this.bucket = []; // Yay for very sparse arrays.
}
spatialHash.prototype.hash3D = function(x, y, z){ var ix = Math.floor((x+1000)/this.cellSize), iy = Math.floor((y+1000)/this.cellSize), iz = Math.floor((z+1000)/this.cellSize); return ((ix * 73856093) ^ (iy * 19349663) ^ (iz * 83492791) ); //% 5000; //5000 is size of hash table.
}
spatialHash.prototype.add = function(x, y, z, obj){ var hash = this.hash3D(x, y, z); if(this.bucket[hash]===undefined) this.bucket[hash] = [obj]; else this.bucket[hash].push(obj);
}
spatialHash.prototype.clear = function(){ this.bucket = [];
}
spatialHash.prototype.getLocal = function(x, y, z){ var nearObjects = []; var o = this.cellSize; for(var xx=-o*2; xx<o*2+o; xx+=o) for(var yy=-o*2; yy<o*2+o; yy+=o) for(var zz=-o*2; zz<o*2+o; zz+=o){ var newObjects = this.bucket[this.hash3D(x+xx, y+yy, z+zz)]; if(newObjects !== undefined) nearObjects = nearObjects.concat(newObjects); } return nearObjects;
}
/*
console.clear();
var SH = new spatialHash(5);
for(var i=0; i<30; i+=2){ SH.add(i,2,3,"TEST"+i);
}
console.log(SH.getLocal(10,2,2));
SH.clear();
console.log(SH.getLocal(17,2,2));
*/
Developer | Sarah Cartwright |
Username | SarahC |
Uploaded | December 05, 2022 |
Rating | 3 |
Size | 2,084 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Blue balls and fireflies. | 4,057 Kb |
Firework types | 3,349 Kb |
OLED Emulator - Sprites | 7,784 Kb |
3D Tools | 2,502 Kb |
Web-worker workload levelling | 2,797 Kb |
Tinted image renderer | 2,176 Kb |
3D Deathchase | 2,665 Kb |
Firework - Smoke types | 7,632 Kb |
OLED Emulator - Horizontal bytes | 5,745 Kb |
3D Fireworks | 5,096 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Login with flip 3d animation | Mariusbalaj | 3,014 Kb |
Hover Animation from UNIQLO | Insprd | 3,772 Kb |
LAMP PURE CSS with Animation | Dam62500 | 2,911 Kb |
CSS Social Media Icon | TychoBlender | 3,871 Kb |
CSS Donut Charts | Seanstopnik | 2,908 Kb |
A Pen by Malith Hettiarachchi | MalZiiirA | 5,531 Kb |
Loading Bar | Jaradlight | 2,333 Kb |
Resume | Rottingroom | 5,483 Kb |
Sign Up Form | Sicontis | 5,272 Kb |
SVG hamburger menu button | Elifitch | 2,602 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!