potree/src/PointCloudOctreeGeometry.js

87 lines
2.1 KiB
JavaScript

var nodesLoadTimes = {};
Potree.PointCloudOctreeGeometry = function(){
Potree.PointCloudOctree.lru = Potree.PointCloudOctree.lru || new LRU();
this.url = null;
this.octreeDir = null;
this.spacing = 0;
this.boundingBox = null;
this.root = null;
this.numNodesLoading = 0;
this.nodes = null;
this.pointAttributes = null;
}
Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){
this.name = name;
this.index = parseInt(name.charAt(name.length-1));
this.pcoGeometry = pcoGeometry;
this.boundingBox = boundingBox;
this.boundingSphere = boundingBox.getBoundingSphere();
this.children = {};
this.numPoints = 0;
this.level = null;
}
Potree.PointCloudOctreeGeometryNode.prototype.addChild = function(child){
this.children[child.index] = child;
child.parent = this;
}
Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
if(this.loading === true || this.pcoGeometry.numNodesLoading > 1){
return;
}else{
this.loading = true;
}
if(Potree.PointCloudOctree.lru.numPoints + this.numPoints >= Potree.pointLoadLimit){
Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints);
}
this.pcoGeometry.numNodesLoading++;
this.pcoGeometry.loader.load(this);
}
Potree.BinaryNodeLoader = function(){
}
Potree.BinaryNodeLoader.load = function(node, extension, callback){
var url = node.pcoGeometry.octreeDir + "/" + node.name;
if(extension !== undefined && extension.length > 0){
url += "." + extension;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
var buffer = xhr.response;
callback(node, buffer);
} else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
}
}
};
try{
xhr.send(null);
}catch(e){
console.log("fehler beim laden der punktwolke: " + e);
}
}
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
delete this.geometry;
this.loaded = false;
}