one material instance per node instead of the whole octree; add support for oct16 normals
This commit is contained in:
parent
709fc2ebca
commit
3658a7f4be
File diff suppressed because one or more lines are too long
11
build/js/potree.min.js
vendored
11
build/js/potree.min.js
vendored
File diff suppressed because one or more lines are too long
@ -34,9 +34,10 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
"uniform float screenHeight;",
|
||||
"uniform float fov;",
|
||||
"uniform float spacing;",
|
||||
"uniform float blendDepth;",
|
||||
"uniform float near;",
|
||||
"uniform float far;",
|
||||
"uniform float level;",
|
||||
"uniform float visibleNodesOffset;",
|
||||
"",
|
||||
"#if defined use_clip_box",
|
||||
" uniform mat4 clipBoxes[max_clip_boxes];",
|
||||
@ -50,7 +51,9 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
"uniform float size; // pixel size factor",
|
||||
"uniform float minSize; // minimum pixel size",
|
||||
"uniform float maxSize; // maximum pixel size",
|
||||
"uniform float octreeSize;",
|
||||
"uniform float nodeSize;",
|
||||
"uniform vec3 bbMin;",
|
||||
"uniform vec3 bbSize;",
|
||||
"uniform vec3 uColor;",
|
||||
"uniform float opacity;",
|
||||
@ -109,12 +112,12 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
" * find the tree depth at the point position",
|
||||
" */",
|
||||
"float getLocalTreeDepth(){",
|
||||
" vec3 offset = vec3(0.0, 0.0, 0.0);",
|
||||
" float iOffset = 0.0;",
|
||||
" float depth = 0.0;",
|
||||
" vec3 offset = bbMin;",
|
||||
" float iOffset = visibleNodesOffset;",
|
||||
" float depth = level;",
|
||||
" for(float i = 0.0; i <= 1000.0; i++){",
|
||||
" ",
|
||||
" float nodeSizeAtLevel = nodeSize / pow(2.0, i);",
|
||||
" float nodeSizeAtLevel = octreeSize / pow(2.0, i + level);",
|
||||
" vec3 index3d = (position - offset) / nodeSizeAtLevel;",
|
||||
" index3d = floor(index3d + 0.5);",
|
||||
" float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z;",
|
||||
@ -399,7 +402,6 @@ Potree.Shaders["pointcloud.fs"] = [
|
||||
"uniform float pcIndex;",
|
||||
"uniform float screenWidth;",
|
||||
"uniform float screenHeight;",
|
||||
"uniform float blendDepth;",
|
||||
"",
|
||||
"uniform sampler2D depthMap;",
|
||||
"",
|
||||
@ -431,7 +433,7 @@ Potree.Shaders["pointcloud.fs"] = [
|
||||
" #if defined weighted_splats",
|
||||
" vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);",
|
||||
" float depth = texture2D(depthMap, uv).r;",
|
||||
" if(vLinearDepth > depth + vRadius * 0.5){",
|
||||
" if(vLinearDepth > depth + vRadius){",
|
||||
" discard;",
|
||||
" }",
|
||||
" #endif",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -197,9 +197,37 @@ Potree.PointCloudOctree.prototype.updateProfileRequests = function(){
|
||||
Potree.PointCloudOctree.prototype.updatePointCloud = function(node, element, stack, visibleGeometryNames){
|
||||
this.numVisibleNodes++;
|
||||
this.numVisiblePoints += node.numPoints;
|
||||
node.material = this.material;
|
||||
this.visibleNodes.push(element);
|
||||
|
||||
node.material.fov = camera.fov * (Math.PI / 180);
|
||||
node.material.screenWidth = renderer.domElement.clientWidth;
|
||||
node.material.screenHeight = renderer.domElement.clientHeight;
|
||||
node.material.spacing = this.pcoGeometry.spacing;
|
||||
node.material.near = camera.near;
|
||||
node.material.far = camera.far;
|
||||
|
||||
node.material.octreeLevels = this.maxLevel;
|
||||
node.material.pointColorType = this.material.pointColorType;
|
||||
node.material.pointSizeType = this.material.pointSizeType;
|
||||
node.material.pointShape = this.material.pointShape;
|
||||
node.material.interpolate = this.material.interpolate;
|
||||
node.material.size = this.material.size;
|
||||
node.material.heightMin = this.material.heightMin;
|
||||
node.material.heightMax = this.material.heightMax;
|
||||
node.material.intensityMin = this.material.intensityMin;
|
||||
node.material.intensityMax = this.material.intensityMax;
|
||||
node.material.weighted = this.material.weighted;
|
||||
node.material.opacity = this.material.opacity;
|
||||
node.material.minSize = this.material.minSize;
|
||||
node.material.uniforms.level.value = node.level;
|
||||
|
||||
node.material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.size().x;
|
||||
node.material.uniforms.nodeSize.value = node.pcoGeometry.boundingBox.size().x;
|
||||
node.material.uniforms.bbMin.value = node.pcoGeometry.boundingBox.min.toArray();
|
||||
|
||||
node.material.uniforms.visibleNodesTexture = this.material.visibleNodesTexture;
|
||||
node.material.uniforms.visibleNodes.value = this.material.visibleNodesTexture;
|
||||
|
||||
if(node.level){
|
||||
this.maxLevel = Math.max(node.level, this.maxLevel);
|
||||
}
|
||||
@ -237,25 +265,6 @@ Potree.PointCloudOctree.prototype.updatePointCloud = function(node, element, sta
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.prototype.updateMaterial = function(vn, camera, renderer){
|
||||
this.material.fov = camera.fov * (Math.PI / 180);
|
||||
this.material.screenWidth = renderer.domElement.clientWidth;
|
||||
this.material.screenHeight = renderer.domElement.clientHeight;
|
||||
this.material.spacing = this.pcoGeometry.spacing;
|
||||
this.material.near = camera.near;
|
||||
this.material.far = camera.far;
|
||||
|
||||
if(this.material.pointSizeType){
|
||||
if(this.material.pointSizeType === Potree.PointSizeType.ADAPTIVE
|
||||
|| this.material.pointColorType === Potree.PointColorType.OCTREE_DEPTH){
|
||||
|
||||
this.updateVisibilityTexture(this.material, vn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
Potree.PointCloudOctree.prototype.updateLoadQueue = function(vn){
|
||||
if(this.loadQueue.length > 0){
|
||||
if(this.loadQueue.length >= 2){
|
||||
@ -345,7 +354,15 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){
|
||||
vn.push(this.visibleNodes[i].node);
|
||||
}
|
||||
|
||||
this.updateMaterial(vn, camera, renderer);
|
||||
// update visibility texture
|
||||
if(this.material.pointSizeType){
|
||||
if(this.material.pointSizeType === Potree.PointSizeType.ADAPTIVE
|
||||
|| this.material.pointColorType === Potree.PointColorType.OCTREE_DEPTH){
|
||||
|
||||
this.updateVisibilityTexture(this.material, vn);
|
||||
}
|
||||
}
|
||||
|
||||
Potree.PointCloudOctree.lru.freeMemory();
|
||||
};
|
||||
|
||||
@ -494,6 +511,7 @@ Potree.PointCloudOctree.prototype.updateVisibilityTexture = function(material, v
|
||||
|
||||
for(var i = 0; i < visibleNodes.length; i++){
|
||||
var node = visibleNodes[i];
|
||||
node.material.uniforms.visibleNodesOffset.value = i;
|
||||
|
||||
var children = [];
|
||||
for(var j = 0; j < node.children.length; j++){
|
||||
@ -576,7 +594,8 @@ Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
|
||||
var geometryNode = proxy.geometryNode;
|
||||
if(geometryNode.loaded === true){
|
||||
var geometry = geometryNode.geometry;
|
||||
var node = new THREE.PointCloud(geometry, this.material);
|
||||
var material = new Potree.PointCloudMaterial();
|
||||
var node = new THREE.PointCloud(geometry, material);
|
||||
node.name = proxy.name;
|
||||
node.level = proxy.level;
|
||||
node.numPoints = proxy.numPoints;
|
||||
|
||||
@ -78,6 +78,8 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
geometry.addAttribute("classification", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === PointAttributeNames.NORMAL_SPHEREMAPPED){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === PointAttributeNames.NORMAL_OCT16){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ PointAttributeNames.FILLER = 5;
|
||||
PointAttributeNames.INTENSITY = 6;
|
||||
PointAttributeNames.CLASSIFICATION = 7;
|
||||
PointAttributeNames.NORMAL_SPHEREMAPPED = 8;
|
||||
PointAttributeNames.NORMAL_OCT16 = 9;
|
||||
|
||||
/**
|
||||
* Some types of possible point attribute data formats
|
||||
@ -90,6 +91,10 @@ PointAttribute.CLASSIFICATION = new PointAttribute(
|
||||
PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute(
|
||||
PointAttributeNames.NORMAL_SPHEREMAPPED,
|
||||
PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
|
||||
PointAttribute.NORMAL_OCT16 = new PointAttribute(
|
||||
PointAttributeNames.NORMAL_OCT16,
|
||||
PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
|
||||
/**
|
||||
* Ordered list of PointAttributes used to identify how points are aligned in a buffer.
|
||||
@ -140,7 +145,10 @@ PointAttributes.prototype.hasColors = function(){
|
||||
PointAttributes.prototype.hasNormals = function(){
|
||||
for(var name in this.attributes){
|
||||
var pointAttribute = this.attributes[name];
|
||||
if(pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED || pointAttribute === PointAttribute.NORMAL_FLOATS){
|
||||
if(
|
||||
pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED ||
|
||||
pointAttribute === PointAttribute.NORMAL_FLOATS ||
|
||||
pointAttribute === PointAttribute.NORMAL_OCT16){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +82,8 @@ Potree.TreeType = {
|
||||
};
|
||||
|
||||
Potree.PointCloudMaterial = function(parameters){
|
||||
THREE.Material.call( this );
|
||||
|
||||
parameters = parameters || {};
|
||||
|
||||
var color = new THREE.Color( 0x000000 );
|
||||
@ -103,7 +105,6 @@ Potree.PointCloudMaterial = function(parameters){
|
||||
this.numClipBoxes = 0;
|
||||
this._clipMode = Potree.ClipMode.DISABLED;
|
||||
this._weighted = false;
|
||||
this._blendDepth = 0.1;
|
||||
this._depthMap;
|
||||
this._gradient = Potree.Gradients.RAINBOW;
|
||||
this._classification = Potree.Classification.DEFAULT;
|
||||
@ -129,18 +130,21 @@ Potree.PointCloudMaterial = function(parameters){
|
||||
minSize: { type: "f", value: 2 },
|
||||
maxSize: { type: "f", value: 2 },
|
||||
nodeSize: { type: "f", value: nodeSize },
|
||||
octreeSize: { type: "f", value: 0 },
|
||||
bbMin: { type: "fv", value: [0,0,0] },
|
||||
bbSize: { type: "fv", value: [0,0,0] },
|
||||
heightMin: { type: "f", value: 0.0 },
|
||||
heightMax: { type: "f", value: 1.0 },
|
||||
intensityMin: { type: "f", value: 0.0 },
|
||||
intensityMax: { type: "f", value: 1.0 },
|
||||
clipBoxCount: { type: "f", value: 0 },
|
||||
level: { type: "f", value: 0 },
|
||||
visibleNodesOffset: { type: "f", value: 0 },
|
||||
visibleNodes: { type: "t", value: this.visibleNodesTexture },
|
||||
pcIndex: { type: "f", value: 0 },
|
||||
gradient: { type: "t", value: this.gradientTexture },
|
||||
classificationLUT: { type: "t", value: this.classificationTexture },
|
||||
clipBoxes: { type: "Matrix4fv", value: [] },
|
||||
blendDepth: { type: "f", value: this._blendDepth },
|
||||
depthMap: { type: "t", value: null },
|
||||
diffuse: { type: "fv", value: [1,1,1]},
|
||||
ambient: { type: "fv", value: [0.1, 0.1, 0.1]},
|
||||
@ -377,18 +381,6 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "spacing", {
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Potree.PointCloudMaterial.prototype, "blendDepth", {
|
||||
get: function(){
|
||||
return this.uniforms.blendDepth.value;
|
||||
},
|
||||
set: function(value){
|
||||
if(this.uniforms.blendDepth.value !== value){
|
||||
this.uniforms.blendDepth.value = value;
|
||||
//this.updateShaderSource();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Potree.PointCloudMaterial.prototype, "useClipBox", {
|
||||
get: function(){
|
||||
return this._useClipBox;
|
||||
@ -476,9 +468,11 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "opacity", {
|
||||
return this.uniforms.opacity.value;
|
||||
},
|
||||
set: function(value){
|
||||
if(this.uniforms.opacity.value !== value){
|
||||
this.uniforms.opacity.value = value;
|
||||
this.updateShaderSource();
|
||||
if(this.uniforms.opacity){
|
||||
if(this.uniforms.opacity.value !== value){
|
||||
this.uniforms.opacity.value = value;
|
||||
this.updateShaderSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -62,7 +62,6 @@ uniform float far;
|
||||
uniform float pcIndex;
|
||||
uniform float screenWidth;
|
||||
uniform float screenHeight;
|
||||
uniform float blendDepth;
|
||||
|
||||
uniform sampler2D depthMap;
|
||||
|
||||
@ -94,7 +93,7 @@ void main() {
|
||||
#if defined weighted_splats
|
||||
vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);
|
||||
float depth = texture2D(depthMap, uv).r;
|
||||
if(vLinearDepth > depth + vRadius * 0.5){
|
||||
if(vLinearDepth > depth + vRadius){
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -33,9 +33,10 @@ uniform float screenWidth;
|
||||
uniform float screenHeight;
|
||||
uniform float fov;
|
||||
uniform float spacing;
|
||||
uniform float blendDepth;
|
||||
uniform float near;
|
||||
uniform float far;
|
||||
uniform float level;
|
||||
uniform float visibleNodesOffset;
|
||||
|
||||
#if defined use_clip_box
|
||||
uniform mat4 clipBoxes[max_clip_boxes];
|
||||
@ -49,7 +50,9 @@ uniform float intensityMax;
|
||||
uniform float size; // pixel size factor
|
||||
uniform float minSize; // minimum pixel size
|
||||
uniform float maxSize; // maximum pixel size
|
||||
uniform float octreeSize;
|
||||
uniform float nodeSize;
|
||||
uniform vec3 bbMin;
|
||||
uniform vec3 bbSize;
|
||||
uniform vec3 uColor;
|
||||
uniform float opacity;
|
||||
@ -108,12 +111,12 @@ bool isBitSet(float number, float index){
|
||||
* find the tree depth at the point position
|
||||
*/
|
||||
float getLocalTreeDepth(){
|
||||
vec3 offset = vec3(0.0, 0.0, 0.0);
|
||||
float iOffset = 0.0;
|
||||
float depth = 0.0;
|
||||
vec3 offset = bbMin;
|
||||
float iOffset = visibleNodesOffset;
|
||||
float depth = level;
|
||||
for(float i = 0.0; i <= 1000.0; i++){
|
||||
|
||||
float nodeSizeAtLevel = nodeSize / pow(2.0, i);
|
||||
float nodeSizeAtLevel = octreeSize / pow(2.0, i + level);
|
||||
vec3 index3d = (position - offset) / nodeSizeAtLevel;
|
||||
index3d = floor(index3d + 0.5);
|
||||
float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z;
|
||||
|
||||
@ -137,7 +137,37 @@ onmessage = function(event){
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === PointAttribute.NORMAL_OCT16.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 u = (bx / 255) * 2 - 1;
|
||||
var v = (by / 255) * 2 - 1;
|
||||
|
||||
var z = 1 - Math.abs(u) - Math.abs(v);
|
||||
|
||||
if(z >= 0){
|
||||
var x = u;
|
||||
var y = v;
|
||||
}else{
|
||||
var x = - (v/Math.sign(v) - 1) / Math.sign(u);
|
||||
var y = - (u/Math.sign(u) - 1) / Math.sign(v);
|
||||
}
|
||||
|
||||
var length = Math.sqrt(x*x + y*y + z*z);
|
||||
x = x / length;
|
||||
y = y / length;
|
||||
z = z / length;
|
||||
|
||||
normals[3*j + 0] = x;
|
||||
normals[3*j + 1] = y;
|
||||
normals[3*j + 2] = z;
|
||||
}
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
}
|
||||
|
||||
offset += pointAttribute.byteSize;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user