Added GreyhoundBinaryLoader
This commit is contained in:
parent
559048a6ef
commit
dc639cd033
@ -25,6 +25,7 @@ var paths = {
|
||||
"src/loader/POCLoader.js",
|
||||
"src/loader/PointAttributes.js",
|
||||
"src/loader/BinaryLoader.js",
|
||||
"src/loader/GreyhoundBinaryLoader.js",
|
||||
"src/loader/GreyhoundLoader.js",
|
||||
"src/loader/LasLazLoader.js",
|
||||
"src/materials/PointCloudMaterial.js",
|
||||
|
||||
@ -19,7 +19,7 @@ Potree.BinaryLoader.prototype.load = function(node){
|
||||
|
||||
var url = node.getURL();
|
||||
|
||||
if(this.version.equalOrHigher("1.4") && !node.pggGeometry){
|
||||
if(this.version.equalOrHigher("1.4")){
|
||||
url += ".bin";
|
||||
}
|
||||
|
||||
|
||||
114
src/loader/GreyhoundBinaryLoader.js
Normal file
114
src/loader/GreyhoundBinaryLoader.js
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
Potree.GreyhoundBinaryLoader = function(version, boundingBox, scale){
|
||||
if(typeof(version) === "string"){
|
||||
this.version = new Potree.Version(version);
|
||||
}else{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
this.boundingBox = boundingBox;
|
||||
this.scale = scale;
|
||||
};
|
||||
|
||||
Potree.GreyhoundBinaryLoader.prototype.load = function(node){
|
||||
if(node.loaded){
|
||||
return;
|
||||
}
|
||||
|
||||
var scope = this;
|
||||
|
||||
var url = node.getURL();
|
||||
|
||||
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;
|
||||
scope.parse(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.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
|
||||
|
||||
var numPoints = buffer.byteLength / node.pggGeometry.pointAttributes.byteSize;
|
||||
var pointAttributes = node.pggGeometry.pointAttributes;
|
||||
|
||||
node.numPoints = numPoints;
|
||||
|
||||
|
||||
var ww = Potree.workers.binaryDecoder.getWorker();
|
||||
ww.onmessage = function(e){
|
||||
var data = e.data;
|
||||
var buffers = data.attributeBuffers;
|
||||
var tightBoundingBox = new THREE.Box3(
|
||||
new THREE.Vector3().fromArray(data.tightBoundingBox.min),
|
||||
new THREE.Vector3().fromArray(data.tightBoundingBox.max)
|
||||
);
|
||||
|
||||
Potree.workers.binaryDecoder.returnWorker(ww);
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
|
||||
for(var property in buffers){
|
||||
if(buffers.hasOwnProperty(property)){
|
||||
var buffer = buffers[property].buffer;
|
||||
var attribute = buffers[property].attribute;
|
||||
var numElements = attribute.numElements;
|
||||
|
||||
if(parseInt(property) === Potree.PointAttributeNames.POSITION_CARTESIAN){
|
||||
geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.COLOR_PACKED){
|
||||
geometry.addAttribute("color", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.INTENSITY){
|
||||
geometry.addAttribute("intensity", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.CLASSIFICATION){
|
||||
geometry.addAttribute("classification", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL_SPHEREMAPPED){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL_OCT16){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
geometry.addAttribute("indices", new THREE.BufferAttribute(new Float32Array(data.indices), 1));
|
||||
|
||||
if(!geometry.attributes.normal){
|
||||
var buffer = new Float32Array(numPoints*3);
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
//geometry.boundingBox = tightBoundingBox;
|
||||
node.geometry = geometry;
|
||||
//node.boundingBox = tightBoundingBox;
|
||||
node.tightBoundingBox = tightBoundingBox;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pggGeometry.numNodesLoading--;
|
||||
};
|
||||
|
||||
var message = {
|
||||
buffer: buffer,
|
||||
pointAttributes: pointAttributes,
|
||||
version: this.version.version,
|
||||
min: [ node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z ],
|
||||
offset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z],
|
||||
scale: this.scale
|
||||
};
|
||||
ww.postMessage(message, [message.buffer]);
|
||||
|
||||
};
|
||||
@ -96,7 +96,7 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
pgg.offset = offset;
|
||||
pgg.scale = SCALE; //greyhoundInfo.scale;
|
||||
|
||||
pgg.loader = new Potree.BinaryLoader(version, boundingBox, pgg.scale);
|
||||
pgg.loader = new Potree.GreyhoundBinaryLoader(version, boundingBox, pgg.scale);
|
||||
|
||||
|
||||
var nodes = {};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user