3.5 KiB
How Does Loading Nodes Work?
Relevant classes are:
- PointCloudOctree
Manages the octree. Contains methods that finds currently visible nodes for rendering or loading. - PointCloudOctreeNode
The hierarchy consists of instances of this class. Contains methods to load or unload point cloud data. - PointCloudOctreeSceneNode
A subclass of SceneNode that can be attached to the scenegraph. Contains the PointCloudOctree instance. - POCLoader
Loads the point cloud hierarchy from a file.
Loading Data
At first, POCLoader.load(file) reads the point cloud hierarchy from cloud.js and builds a graph of PointcloudOctreeNode instances. This graph will be attached to a PointCloudOctree instance. During rendering, PointCloudOctree.prepareRender() traverses through nodes that are visible from the current point of view. If it encounters a node whose point cloud data has not been loaded, it will stop traversing further down the hierarchy and schedule it for loading by adding it to loadQueue.
// schedule loading of missing point cloud data
if (shouldBeRendered && current.pointCloud == null) {
if(!current.isLoading){
this.loadQueue.push(current);
}
continue;
}
The last step of _prepareRender() is a call to PointcloudOctree.processLoadQueue(). Nodes in loadQueue are sorted by their size and we want to load larger nodes first so processLoadQueue() will tell the first few nodes in loadQueue to start loading point cloud data by calling PointcloudOctreeNode.loadCloudAjax(node). The remaining nodes in the queue will be ignored. They'll be loaded at a later time once all their ancestors have been loaded. Additionaly, there are checks to make sure that the size of all loaded nodes does not exceed the point cloud memory limit and that no more than loadingNodesLimit nodes are loaded at a time.
// process the first x nodes in the queue.
if(this.loadQueue.length > 0 ){
for(var i = 0; i < Math.min(x, this.loadQueue.length); i++){
if(lru.byteSize + this.loadQueue[i].sizeInBytes() < PointcloudOctreeNode.memoryThreshold){
if(this.nodesBeeingLoaded.length < this.loadingNodesLimit){
PointcloudOctreeNode.loadCloudAjax(this.loadQueue[i]);
}
}
}
}
PointcloudOctreeNode.loadCloudAjax(node) creates an asynchronous XMLHttpRequest to read the point cloud data from the corresponding file in ./data. Once the request is finished, PointcloudOctreeNode.loadCloudData(node, buffer, url) is called to send the data directly to the GPU.
Cleanup Data
Pointcloud data can be very large and often it might be necessary to unload some data to create space for new data. PointcloudOctreeNode.memoryThreshold defines a limit for how much point cloud data potree will load. If loading a new node exceeds this limit, potree will first remove some old nodes that weren't rendered in a while. PointcloudOctreeNode.lruNodes (least-recently-used nodes) contains a list of all loaded nodes, ordered by the last time they've been rendered. Recently rendered nodes are at the end of the list. PointcloudOctree.cleanupCache(bytesNeeded, exceptionsRenderQueue) checks if the byte size of all currently loaded nodes, plus the additional size of bytesNeeded exceeds the limit. If it does, it will remove the first few nodes of lruNodes, except nodes contained in exceptionsRenderQueue. This is done to avoid removing nodes that were scheduled to be rendered.