add support for normals
This commit is contained in:
parent
e8022ccd67
commit
251d9d5489
File diff suppressed because one or more lines are too long
12
build/js/potree.min.js
vendored
12
build/js/potree.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -76,6 +76,8 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
geometry.addAttribute("intensity", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === PointAttributeNames.CLASSIFICATION){
|
||||
geometry.addAttribute("classification", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === PointAttributeNames.NORMAL){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ PointAttributeNames.NORMAL_FLOATS = 4; // float x, y, z;
|
||||
PointAttributeNames.FILLER = 5;
|
||||
PointAttributeNames.INTENSITY = 6;
|
||||
PointAttributeNames.CLASSIFICATION = 7;
|
||||
PointAttributeNames.NORMAL = 8;
|
||||
|
||||
/**
|
||||
* Some types of possible point attribute data formats
|
||||
@ -85,6 +86,10 @@ PointAttribute.INTENSITY = new PointAttribute(
|
||||
PointAttribute.CLASSIFICATION = new PointAttribute(
|
||||
PointAttributeNames.CLASSIFICATION,
|
||||
PointAttributeTypes.DATA_TYPE_UINT8, 1);
|
||||
|
||||
PointAttribute.NORMAL = new PointAttribute(
|
||||
PointAttributeNames.NORMAL,
|
||||
PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
|
||||
/**
|
||||
* Ordered list of PointAttributes used to identify how points are aligned in a buffer.
|
||||
|
||||
@ -64,7 +64,8 @@ Potree.PointColorType = {
|
||||
POINT_INDEX: 7,
|
||||
CLASSIFICATION: 8,
|
||||
RETURN_NUMBER: 9,
|
||||
SOURCE: 10
|
||||
SOURCE: 10,
|
||||
NORMAL: 11
|
||||
};
|
||||
|
||||
Potree.ClipMode = {
|
||||
@ -163,6 +164,8 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){
|
||||
attributes.returnNumber = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === Potree.PointColorType.SOURCE){
|
||||
attributes.pointSourceID = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === Potree.PointColorType.NORMAL){
|
||||
attributes.normal = { type: "f", value: [] };
|
||||
}
|
||||
|
||||
var precision = "";
|
||||
@ -265,6 +268,8 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){
|
||||
defines += "#define color_type_return_number\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.SOURCE){
|
||||
defines += "#define color_type_source\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.NORMAL){
|
||||
defines += "#define color_type_normal\n";
|
||||
}
|
||||
|
||||
if(this.clipMode === Potree.ClipMode.DISABLED){
|
||||
@ -695,6 +700,7 @@ Potree.PointCloudMaterial.vs_points = [
|
||||
"attribute float returnNumber; ",
|
||||
"attribute float pointSourceID; ",
|
||||
"attribute vec4 indices; ",
|
||||
"attribute vec3 normal; ",
|
||||
" ",
|
||||
"uniform mat4 modelMatrix; ",
|
||||
"uniform mat4 modelViewMatrix; ",
|
||||
@ -856,6 +862,8 @@ Potree.PointCloudMaterial.vs_points = [
|
||||
" #elif defined color_type_source ",
|
||||
" float w = mod(pointSourceID, 10.0) / 10.0; ",
|
||||
" vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; ",
|
||||
" #elif defined color_type_normal ",
|
||||
" vColor = (modelMatrix * vec4(normal, 0.0)).xyz; ",
|
||||
" #endif ",
|
||||
" ",
|
||||
" ",
|
||||
|
||||
@ -105,6 +105,39 @@ onmessage = function(event){
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === PointAttribute.NORMAL.name){
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4*3);
|
||||
var normals = new Float32Array(buff);
|
||||
|
||||
for(var j = 0; j < numPoints; j++){
|
||||
var bx = cv.getUint8(offset + j * pointAttributes.byteSize + 0);
|
||||
var by = cv.getUint8(offset + j * pointAttributes.byteSize + 1);
|
||||
|
||||
var ex = bx / 255;
|
||||
var ey = by / 255;
|
||||
|
||||
var nx = ex * 2 - 1;
|
||||
var ny = ey * 2 - 1;
|
||||
var nz = 1;
|
||||
var nw = -1;
|
||||
|
||||
var l = (nx * (-nx)) + (ny * (-ny)) + (nz * (-nw));
|
||||
nz = l;
|
||||
nx = nx * Math.sqrt(l);
|
||||
ny = ny * Math.sqrt(l);
|
||||
|
||||
nx = nx * 2;
|
||||
ny = ny * 2;
|
||||
nz = nz * 2 - 1;
|
||||
|
||||
normals[3*j + 0] = nx;
|
||||
normals[3*j + 1] = ny;
|
||||
normals[3*j + 2] = nz;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}
|
||||
|
||||
offset += pointAttribute.byteSize;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user