Skip to content

Commit

Permalink
point cloud: repeat rendering as long as there are loading nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
minorua committed May 22, 2020
1 parent c837327 commit 9806f03
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions js/Qgis2threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3135,21 +3135,50 @@ Q3D.PolygonLayer.prototype.setSideVisible = function (visible) {
};


// Potree
(function () {
if (typeof Potree === "undefined") return;

class Q3DGRP extends Potree.Group
{
constructor(layer)
{
super();
this.layer = layer;
this.timerId = null;
}

onAfterRender(renderer, scene, camera, geometry, material, group)
{
super.onAfterRender(renderer, scene, camera, geometry, material, group);

// repeat rendering as long as there are loading nodes
if (Potree.Global.numNodesLoading && this.timerId === null) {
var _this = this;
_this.timerId = window.setTimeout(function () {
_this.timerId = null;
_this.layer.requestRender();
}, 100);
}
}
}
Q3D.PCGroup = Q3DGRP;
})();


/*
Q3D.PointCloudLayer --> Q3D.MapLayer
*/
Q3D.PointCloudLayer = function () {
Q3D.MapLayer.call(this);
this.type = Q3D.LayerType.PointCloud;
this.timerId = null;
};

Q3D.PointCloudLayer.prototype = Object.create(Q3D.MapLayer.prototype);
Q3D.PointCloudLayer.prototype.constructor = Q3D.PointCloudLayer;

Q3D.PointCloudLayer.prototype.loadJSONObject = function (jsonObject, scene) {

var _this = this;
var p = jsonObject.properties;
var need_reload = (this.properties.colorType !== p.colorType);

Expand All @@ -3173,10 +3202,12 @@ Q3D.PointCloudLayer.prototype.loadJSONObject = function (jsonObject, scene) {
g.updateMatrixWorld();
}

this.pcg = new Potree.Group();
this.pcg = new Q3D.PCGroup(this);
this.pcg.setPointBudget(10000000);
this.addObject(this.pcg);

var _this = this;

Potree.loadPointCloud(p.url, p.name, function(e) {
_this.pcg.add(e.pointcloud);
_this.updatePosition(scene);
Expand All @@ -3194,7 +3225,6 @@ Q3D.PointCloudLayer.prototype.loadJSONObject = function (jsonObject, scene) {
_this.materials.add(mtl);

_this.requestRender();
_this.requestRepeatRender(500, 60);
});
};

Expand All @@ -3209,26 +3239,6 @@ Q3D.PointCloudLayer.prototype.updatePosition = function (scene) {
g.updateMatrixWorld();
};

Q3D.PointCloudLayer.prototype.requestRepeatRender = function (interval, repeat) {
var times = 0, _this = this;

var func = function () {
if (++times <= repeat) _this.requestRender();
else {
clearInterval(_this.timerId);
_this.timerId = null;
}
};

if (this.timerId === null || interval != this.timerInterval) {
if (this.timerId !== null) {
clearInterval(this.timerId);
}
this.timerId = setInterval(func, interval);
this.timerInterval = interval;
}
}

Object.defineProperty(Q3D.PointCloudLayer.prototype, "visible", {
get: function () {
return this.objectGroup.visible;
Expand All @@ -3248,20 +3258,16 @@ Object.defineProperty(Q3D.PointCloudLayer.prototype, "visible", {
}

this.requestRender();
this.requestRepeatRender(500, 60);
}
});

Q3D.PointCloudLayer.prototype.loadedPointCount = function () {
var c = 0, visible = 0, invisible = 0;
var c = 0;
this.objectGroup.traverse(function (obj) {
if (obj instanceof THREE.Points) {
c += obj.geometry.getAttribute("position").count;
if (obj.visible) visible++;
else invisible++;
}
});
console.log("total: " + c + " (visible: " + visible + ", invisible: " + invisible + ")"); // TODO: remove
return c;
};

Expand Down

0 comments on commit 9806f03

Please sign in to comment.