move to es6

This commit is contained in:
Thibaut Lassalle 2021-10-16 06:24:59 -07:00
parent e06268fe6f
commit 40a9b3812b
6 changed files with 3294 additions and 3221 deletions

View File

@ -4,74 +4,103 @@
'use strict';
const Material = function (segment, layer) {
this.segment = segment;
this.layer = layer;
this.isReady = false;
this.isLoading = false;
this.texture = null;
this.pickingMask = null;
//this.image = null;
this.textureExists = false;
this.appliedNodeId = 0;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
this.loadingAttempts = 0;
class Material {
// vector data
this._updateTexture = null;
this._updatePickingMask = null;
this.pickingReady = false;
};
Material.prototype.assignLayer = function (layer) {
this.layer = layer;
};
Material.prototype.abortLoading = function () {
this.layer.abortMaterialLoading(this);
};
Material.prototype.applyImage = function (img) {
if (this.segment.initialized) {
this._updateTexture = null;
//this.image = img;
this.texture = this.segment.handler.createTexture(img);
this.appliedNodeId = this.segment.node.nodeId;
this.isReady = true;
this.pickingReady = true;
this.textureExists = true;
/**
*
* @param {*} segment
* @param {*} layer
*/
constructor(segment, layer) {
this.segment = segment;
this.layer = layer;
this.isReady = false;
this.isLoading = false;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
}
};
Material.prototype.applyTexture = function (texture, pickingMask) {
if (this.segment.initialized) {
this.texture = texture;
this._updateTexture = null;
this.pickingMask = pickingMask || null;
this._updatePickingMask = null;
this.isReady = true;
this.pickingReady = true;
this.textureExists = true;
this.isLoading = false;
this.appliedNodeId = this.segment.node.nodeId;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
}
};
Material.prototype.textureNotExists = function () {
if (this.segment.initialized) {
this.pickingReady = true;
this.isLoading = false;
this.isReady = true;
this.texture = null;
this.pickingMask = null;
//this.image = null;
this.textureExists = false;
this.appliedNodeId = 0;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
this.loadingAttempts = 0;
// vector data
this._updateTexture = null;
this._updatePickingMask = null;
this.pickingReady = false;
}
};
Material.prototype.clear = function () {
this.loadingAttempts = 0;
this.layer.clearMaterial(this);
};
/**
* @param {*} layer
*/
assignLayer(layer) {
this.layer = layer;
}
export { Material };
/**
*
*/
abortLoading() {
this.layer.abortMaterialLoading(this);
}
/**
*
* @param {*} img
*/
applyImage(img) {
if (this.segment.initialized) {
this._updateTexture = null;
//this.image = img;
this.texture = this.segment.handler.createTexture(img);
this.appliedNodeId = this.segment.node.nodeId;
this.isReady = true;
this.pickingReady = true;
this.textureExists = true;
this.isLoading = false;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
}
}
/**
*
* @param {*} texture
* @param {*} pickingMask
*/
applyTexture(texture, pickingMask) {
if (this.segment.initialized) {
this.texture = texture;
this._updateTexture = null;
this.pickingMask = pickingMask || null;
this._updatePickingMask = null;
this.isReady = true;
this.pickingReady = true;
this.textureExists = true;
this.isLoading = false;
this.appliedNodeId = this.segment.node.nodeId;
this.texOffset = [0.0, 0.0, 1.0, 1.0];
}
}
/**
*
*/
textureNotExists() {
if (this.segment.initialized) {
this.pickingReady = true;
this.isLoading = false;
this.isReady = true;
this.textureExists = false;
}
}
/**
*
*/
clear() {
this.loadingAttempts = 0;
this.layer.clearMaterial(this);
}
}
export { Material };

View File

@ -4,374 +4,384 @@
'use strict';
import * as mercator from '../mercator.js';
import * as quadTree from './quadTree.js';
import { Sphere } from '../bv/Sphere.js';
import { EntityCollection } from '../entity/EntityCollection.js';
import { Extent } from '../Extent.js';
import { LonLat } from '../LonLat.js';
import { inherits } from '../inherits.js';
import { Sphere } from '../bv/Sphere.js';
import { Vec3 } from '../math/Vec3.js';
import * as mercator from '../mercator.js';
import * as quadTree from './quadTree.js';
const EntityCollectionNode = function (layer, partId, parent, id, extent, planet, zoom) {
this.layer = layer;
this.parentNode = parent;
this.childrenNodes = [];
this.partId = partId;
this.nodeId = partId + id;
this.state = null;
this.extent = extent;
this.count = 0;
this.deferredEntities = [];
this.entityCollection = null;
this.zoom = zoom;
this._inTheQueue = false;
class EntityCollectionNode {
this.bsphere = new Sphere();
constructor(layer, partId, parent, id, extent, planet, zoom) {
this.layer = layer;
this.parentNode = parent;
this.childrenNodes = [];
this.partId = partId;
this.nodeId = partId + id;
this.state = null;
this.extent = extent;
this.count = 0;
this.deferredEntities = [];
this.entityCollection = null;
this.zoom = zoom;
this._inTheQueue = false;
planet && this._setExtentBounds();
};
this.bsphere = new Sphere();
EntityCollectionNode.prototype.insertEntity = function (entity, rightNow) {
this.buildTree([entity], rightNow);
};
planet && this._setExtentBounds();
};
EntityCollectionNode.prototype._addEntitiesToCollection = function (entities, rightNow) {
if (entities.length) {
var l = this.layer,
p = l._planet;
insertEntity(entity, rightNow) {
this.buildTree([entity], rightNow);
};
_addEntitiesToCollection(entities, rightNow) {
if (entities.length) {
var l = this.layer,
p = l._planet;
var ec = this.entityCollection;
if (!ec) {
ec = new EntityCollection({
pickingEnabled: l._pickingEnabled,
labelMaxLetters: l._labelMaxLetters
});
ec._layer = this.layer;
ec.addTo(p, true);
ec._quadNode = this;
l._bindEventsDefault(ec);
this.entityCollection = ec;
}
if (rightNow || !l.async) {
this.entityCollection.addEntities(entities);
} else {
this.deferredEntities.push.apply(this.deferredEntities, entities);
}
}
};
_setExtentBounds() {
if (!this.nodeId) {
this.bsphere.radius = this.layer._planet.ellipsoid._a;
this.bsphere.center = new Vec3();
} else {
this.bsphere.setFromExtent(this.layer._planet.ellipsoid, this.extent.inverseMercator());
}
};
__setLonLat__(entity) {
if (entity._lonlat.isZero() && !entity._cartesian.isZero()) {
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
}
if (Math.abs(entity._lonlat.lat) < mercator.MAX_LAT) {
entity._lonlatMerc = entity._lonlat.forwardMercator();
} else {
entity._lonlatMerc = null;
}
return entity._lonlatMerc;
};
buildTree(entities, rightNow) {
this.count += entities.length;
if (entities.length > this.layer._nodeCapacity || this.zoom > this.layer.minZoom) {
var cn = this.childrenNodes;
if (!cn.length) {
this.createChildrenNodes();
}
var en_nw = [],
en_ne = [],
en_sw = [],
en_se = [];
var i = entities.length;
while (i--) {
var ei = entities[i];
if (cn[quadTree.NW].isInside(ei)) {
ei._nodePtr = cn[quadTree.NW];
en_nw.push(ei);
} else if (cn[quadTree.NE].isInside(ei)) {
ei._nodePtr = cn[quadTree.NE];
en_ne.push(ei);
} else if (cn[quadTree.SW].isInside(ei)) {
ei._nodePtr = cn[quadTree.SW];
en_sw.push(ei);
} else if (cn[quadTree.SE].isInside(ei)) {
ei._nodePtr = cn[quadTree.SE];
en_se.push(ei);
}
}
en_nw.length && cn[quadTree.NW].buildTree(en_nw, rightNow);
en_ne.length && cn[quadTree.NE].buildTree(en_ne, rightNow);
en_sw.length && cn[quadTree.SW].buildTree(en_sw, rightNow);
en_se.length && cn[quadTree.SE].buildTree(en_se, rightNow);
} else {
this._addEntitiesToCollection(entities, rightNow);
}
};
isInside(entity) {
return this.extent.isInside(entity._lonlatMerc);
};
createChildrenNodes() {
var l = this.layer;
var ext = this.extent;
var size_x = ext.getWidth() * 0.5;
var size_y = ext.getHeight() * 0.5;
var ne = ext.northEast,
sw = ext.southWest;
var id = this.nodeId * 4 + 1;
var c = new LonLat(sw.lon + size_x, sw.lat + size_y);
var nd = this.childrenNodes;
var p = this.layer._planet;
var z = this.zoom + 1;
nd[quadTree.NW] = new EntityCollectionNode(l, quadTree.NW, this, id,
new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat)), p, z);
nd[quadTree.NE] = new EntityCollectionNode(l, quadTree.NE, this, id,
new Extent(c, new LonLat(ne.lon, ne.lat)), p, z);
nd[quadTree.SW] = new EntityCollectionNode(l, quadTree.SW, this, id,
new Extent(new LonLat(sw.lon, sw.lat), c), p, z);
nd[quadTree.SE] = new EntityCollectionNode(l, quadTree.SE, this, id,
new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y)), p, z);
};
collectRenderCollectionsPASS1(visibleNodes, outArr) {
var n = visibleNodes[this.nodeId];
if (n) {
var cn = this.childrenNodes;
if (this.entityCollection) {
this.renderCollection(outArr, visibleNodes);
} else if (cn.length) {
if (n.state === quadTree.RENDERING) {
this.layer._secondPASS.push(this);
} else {
cn[quadTree.NW].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.NE].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.SW].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.SE].collectRenderCollectionsPASS1(visibleNodes, outArr);
}
}
}
};
collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId) {
var p = this.layer._planet;
var cam = p.renderer.activeCamera;
var altVis = (cam.eye.distance(this.bsphere.center) - this.bsphere.radius <
quadTree.VISIBLE_DISTANCE * Math.sqrt(cam._lonLat.height)) || cam._lonLat.height > 10000;
if (this.count > 0 && altVis &&
p.renderer.activeCamera.frustum.containsSphere(this.bsphere) > 0) {
var cn = this.childrenNodes;
if (this.entityCollection) {
this.renderCollection(outArr, visibleNodes, renderingNodeId);
} else if (cn.length) {
cn[quadTree.NW].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.NE].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.SW].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.SE].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
}
}
};
applyCollection() {
this.entityCollection.addEntities(this.deferredEntities);
this.deferredEntities.length = 0;
this.deferredEntities = [];
this._inTheQueue = false;
};
traverseTree(callback) {
var cn = this.childrenNodes;
if (this.entityCollection) {
callback(this);
} else if (cn.length) {
cn[quadTree.NW].traverseTree(callback);
cn[quadTree.NE].traverseTree(callback);
cn[quadTree.SW].traverseTree(callback);
cn[quadTree.SE].traverseTree(callback);
}
};
renderCollection(outArr, visibleNodes, renderingNodeId) {
var l = this.layer;
l._renderingNodes[this.nodeId] = true;
if (this.deferredEntities.length && !this._inTheQueue) {
if (l.async) {
l._queueDeferredNode(this);
} else {
this.applyCollection();
}
}
var ec = this.entityCollection;
if (!ec) {
ec = new EntityCollection({
pickingEnabled: l._pickingEnabled,
labelMaxLetters: l._labelMaxLetters
});
ec._layer = this.layer;
ec.addTo(p, true);
ec._quadNode = this;
l._bindEventsDefault(ec);
this.entityCollection = ec;
}
ec._fadingOpacity = l._fadingOpacity;
ec.scaleByDistance = l.scaleByDistance;
ec.pickingScale = l.pickingScale;
if (rightNow || !l.async) {
this.entityCollection.addEntities(entities);
} else {
this.deferredEntities.push.apply(this.deferredEntities, entities);
}
}
};
ec.polygonOffsetFactor = l.polygonOffsetFactor;
ec.polygonOffsetUnits = l.polygonOffsetUnits;
EntityCollectionNode.prototype._setExtentBounds = function () {
if (!this.nodeId) {
this.bsphere.radius = this.layer._planet.ellipsoid._a;
this.bsphere.center = new Vec3();
} else {
this.bsphere.setFromExtent(this.layer._planet.ellipsoid, this.extent.inverseMercator());
}
};
outArr.push(ec);
EntityCollectionNode.prototype.__setLonLat__ = function (entity) {
if (l.clampToGround || l.relativeToGround) {
var e = ec._entities;
var i = e.length;
if (entity._lonlat.isZero() && !entity._cartesian.isZero()) {
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
}
if (Math.abs(entity._lonlat.lat) < mercator.MAX_LAT) {
entity._lonlatMerc = entity._lonlat.forwardMercator();
} else {
entity._lonlatMerc = null;
}
return entity._lonlatMerc;
};
EntityCollectionNode.prototype.buildTree = function (entities, rightNow) {
this.count += entities.length;
if (entities.length > this.layer._nodeCapacity || this.zoom > this.layer.minZoom) {
var cn = this.childrenNodes;
if (!cn.length) {
this.createChildrenNodes();
}
var en_nw = [],
en_ne = [],
en_sw = [],
en_se = [];
var i = entities.length;
while (i--) {
var ei = entities[i];
if (cn[quadTree.NW].isInside(ei)) {
ei._nodePtr = cn[quadTree.NW];
en_nw.push(ei);
} else if (cn[quadTree.NE].isInside(ei)) {
ei._nodePtr = cn[quadTree.NE];
en_ne.push(ei);
} else if (cn[quadTree.SW].isInside(ei)) {
ei._nodePtr = cn[quadTree.SW];
en_sw.push(ei);
} else if (cn[quadTree.SE].isInside(ei)) {
ei._nodePtr = cn[quadTree.SE];
en_se.push(ei);
}
}
en_nw.length && cn[quadTree.NW].buildTree(en_nw, rightNow);
en_ne.length && cn[quadTree.NE].buildTree(en_ne, rightNow);
en_sw.length && cn[quadTree.SW].buildTree(en_sw, rightNow);
en_se.length && cn[quadTree.SE].buildTree(en_se, rightNow);
} else {
this._addEntitiesToCollection(entities, rightNow);
}
};
EntityCollectionNode.prototype.isInside = function (entity) {
return this.extent.isInside(entity._lonlatMerc);
};
EntityCollectionNode.prototype.createChildrenNodes = function () {
var l = this.layer;
var ext = this.extent;
var size_x = ext.getWidth() * 0.5;
var size_y = ext.getHeight() * 0.5;
var ne = ext.northEast,
sw = ext.southWest;
var id = this.nodeId * 4 + 1;
var c = new LonLat(sw.lon + size_x, sw.lat + size_y);
var nd = this.childrenNodes;
var p = this.layer._planet;
var z = this.zoom + 1;
nd[quadTree.NW] = new EntityCollectionNode(l, quadTree.NW, this, id,
new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat)), p, z);
nd[quadTree.NE] = new EntityCollectionNode(l, quadTree.NE, this, id,
new Extent(c, new LonLat(ne.lon, ne.lat)), p, z);
nd[quadTree.SW] = new EntityCollectionNode(l, quadTree.SW, this, id,
new Extent(new LonLat(sw.lon, sw.lat), c), p, z);
nd[quadTree.SE] = new EntityCollectionNode(l, quadTree.SE, this, id,
new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y)), p, z);
};
EntityCollectionNode.prototype.collectRenderCollectionsPASS1 = function (visibleNodes, outArr) {
var n = visibleNodes[this.nodeId];
if (n) {
var cn = this.childrenNodes;
if (this.entityCollection) {
this.renderCollection(outArr, visibleNodes);
} else if (cn.length) {
if (n.state === quadTree.RENDERING) {
this.layer._secondPASS.push(this);
if (visibleNodes[this.nodeId] && visibleNodes[this.nodeId].state === quadTree.RENDERING) {
while (i--) {
let ei = e[i];
this.alignEntityToTheGround(ei, visibleNodes[this.nodeId].segment);
}
} else if (renderingNodeId) {
while (i--) {
let ei = e[i];
this.alignEntityToTheGround(ei, visibleNodes[renderingNodeId].segment);
}
} else {
cn[quadTree.NW].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.NE].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.SW].collectRenderCollectionsPASS1(visibleNodes, outArr);
cn[quadTree.SE].collectRenderCollectionsPASS1(visibleNodes, outArr);
}
}
}
};
EntityCollectionNode.prototype.collectRenderCollectionsPASS2 = function (visibleNodes, outArr, renderingNodeId) {
var p = this.layer._planet;
var cam = p.renderer.activeCamera;
var altVis = (cam.eye.distance(this.bsphere.center) - this.bsphere.radius <
quadTree.VISIBLE_DISTANCE * Math.sqrt(cam._lonLat.height)) || cam._lonLat.height > 10000;
if (this.count > 0 && altVis &&
p.renderer.activeCamera.frustum.containsSphere(this.bsphere) > 0) {
var cn = this.childrenNodes;
if (this.entityCollection) {
this.renderCollection(outArr, visibleNodes, renderingNodeId);
} else if (cn.length) {
cn[quadTree.NW].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.NE].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.SW].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
cn[quadTree.SE].collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId);
}
}
};
EntityCollectionNode.prototype.applyCollection = function () {
this.entityCollection.addEntities(this.deferredEntities);
this.deferredEntities.length = 0;
this.deferredEntities = [];
this._inTheQueue = false;
};
EntityCollectionNode.prototype.traverseTree = function (callback) {
var cn = this.childrenNodes;
if (this.entityCollection) {
callback(this);
} else if (cn.length) {
cn[quadTree.NW].traverseTree(callback);
cn[quadTree.NE].traverseTree(callback);
cn[quadTree.SW].traverseTree(callback);
cn[quadTree.SE].traverseTree(callback);
}
};
EntityCollectionNode.prototype.renderCollection = function (outArr, visibleNodes, renderingNodeId) {
var l = this.layer;
l._renderingNodes[this.nodeId] = true;
if (this.deferredEntities.length && !this._inTheQueue) {
if (l.async) {
l._queueDeferredNode(this);
} else {
this.applyCollection();
}
}
var ec = this.entityCollection;
ec._fadingOpacity = l._fadingOpacity;
ec.scaleByDistance = l.scaleByDistance;
ec.pickingScale = l.pickingScale;
ec.polygonOffsetFactor = l.polygonOffsetFactor;
ec.polygonOffsetUnits = l.polygonOffsetUnits;
outArr.push(ec);
if (l.clampToGround || l.relativeToGround) {
var e = ec._entities;
var i = e.length;
if (visibleNodes[this.nodeId] && visibleNodes[this.nodeId].state === quadTree.RENDERING) {
while (i--) {
let ei = e[i];
this.alignEntityToTheGround(ei, visibleNodes[this.nodeId].segment);
}
} else if (renderingNodeId) {
while (i--) {
let ei = e[i];
this.alignEntityToTheGround(ei, visibleNodes[renderingNodeId].segment);
}
} else {
var n = l._planet._renderedNodes;
while (i--) {
let ei = e[i];
let j = n.length;
while (j--) {
if (n[j].segment.isEntityInside(ei)) {
this.alignEntityToTheGround(ei, n[j].segment);
break;
var n = l._planet._renderedNodes;
while (i--) {
let ei = e[i];
let j = n.length;
while (j--) {
if (n[j].segment.isEntityInside(ei)) {
this.alignEntityToTheGround(ei, n[j].segment);
break;
}
}
}
}
}
}
};
};
EntityCollectionNode.prototype.alignEntityToTheGround = function (entity, segment) {
var res = new Vec3();
segment.getEntityTerrainPoint(entity, res);
entity._setCartesian3vSilent(res.addA(res.normal().scale((Number(this.layer.relativeToGround) && entity._altitude) || 0.0)));
};
alignEntityToTheGround(entity, segment) {
var res = new Vec3();
segment.getEntityTerrainPoint(entity, res);
entity._setCartesian3vSilent(res.addA(res.normal().scale((Number(this.layer.relativeToGround) && entity._altitude) || 0.0)));
};
EntityCollectionNode.prototype.isVisible = function () {
if (this.layer._renderingNodes[this.nodeId]) {
return true;
}
return false;
};
const EntityCollectionNodeWGS84 = function (layer, partId, parent, id, extent, planet, zoom) {
EntityCollectionNode.call(this, layer, partId, parent, id, extent, planet, zoom);
this.isNorth = false;
};
inherits(EntityCollectionNodeWGS84, EntityCollectionNode);
EntityCollectionNodeWGS84.prototype.createChildrenNodes = function () {
var l = this.layer;
var ext = this.extent;
var size_x = ext.getWidth() * 0.5;
var size_y = ext.getHeight() * 0.5;
var ne = ext.northEast,
sw = ext.southWest;
var id = this.nodeId * 4 + 1;
var c = new LonLat(sw.lon + size_x, sw.lat + size_y);
var nd = this.childrenNodes;
var p = this.layer._planet;
var z = this.zoom + 1;
nd[quadTree.NW] = new EntityCollectionNodeWGS84(l, quadTree.NW, this, id,
new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat)), p, z);
nd[quadTree.NE] = new EntityCollectionNodeWGS84(l, quadTree.NE, this, id,
new Extent(c, new LonLat(ne.lon, ne.lat)), p, z);
nd[quadTree.SW] = new EntityCollectionNodeWGS84(l, quadTree.SW, this, id,
new Extent(new LonLat(sw.lon, sw.lat), c), p, z);
nd[quadTree.SE] = new EntityCollectionNodeWGS84(l, quadTree.SE, this, id,
new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y)), p, z);
};
EntityCollectionNodeWGS84.prototype._setExtentBounds = function () {
if (this.extent.northEast.lat > 0) {
this.isNorth = true;
}
this.bsphere.setFromExtent(this.layer._planet.ellipsoid, this.extent);
};
EntityCollectionNodeWGS84.prototype.__setLonLat__ = function (entity) {
if (entity._lonlat.isZero()) {
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
}
return entity._lonlat;
};
EntityCollectionNodeWGS84.prototype.isVisible = function () {
if (this.isNorth && this.layer._renderingNodesNorth[this.nodeId]) {
return true;
} else if (this.layer._renderingNodesSouth[this.nodeId]) {
return true;
}
return false;
};
EntityCollectionNodeWGS84.prototype.isInside = function (entity) {
return this.extent.isInside(entity._lonlat);
};
EntityCollectionNodeWGS84.prototype.renderCollection = function (outArr, visibleNodes, renderingNode) {
if (this.isNorth) {
this.layer._renderingNodesNorth[this.nodeId] = true;
} else {
this.layer._renderingNodesSouth[this.nodeId] = true;
}
if (this.deferredEntities.length && !this._inTheQueue) {
if (this.layer.async) {
this.layer._queueDeferredNode(this);
} else {
this.applyCollection();
isVisible() {
if (this.layer._renderingNodes[this.nodeId]) {
return true;
}
return false;
};
}
class EntityCollectionNodeWGS84 extends EntityCollectionNode {
constructor(layer, partId, parent, id, extent, planet, zoom) {
super(layer, partId, parent, id, extent, planet, zoom);
this.isNorth = false;
}
this.entityCollection._fadingOpacity = this.layer._fadingOpacity;
this.entityCollection.scaleByDistance = this.layer.scaleByDistance;
this.entityCollection.pickingScale = this.layer.pickingScale;
createChildrenNodes() {
var l = this.layer;
var ext = this.extent;
var size_x = ext.getWidth() * 0.5;
var size_y = ext.getHeight() * 0.5;
var ne = ext.northEast,
sw = ext.southWest;
var id = this.nodeId * 4 + 1;
var c = new LonLat(sw.lon + size_x, sw.lat + size_y);
var nd = this.childrenNodes;
var p = this.layer._planet;
var z = this.zoom + 1;
outArr.push(this.entityCollection);
};
nd[quadTree.NW] = new EntityCollectionNodeWGS84(l, quadTree.NW, this, id,
new Extent(new LonLat(sw.lon, sw.lat + size_y), new LonLat(sw.lon + size_x, ne.lat)), p, z);
export { EntityCollectionNode, EntityCollectionNodeWGS84 };
nd[quadTree.NE] = new EntityCollectionNodeWGS84(l, quadTree.NE, this, id,
new Extent(c, new LonLat(ne.lon, ne.lat)), p, z);
nd[quadTree.SW] = new EntityCollectionNodeWGS84(l, quadTree.SW, this, id,
new Extent(new LonLat(sw.lon, sw.lat), c), p, z);
nd[quadTree.SE] = new EntityCollectionNodeWGS84(l, quadTree.SE, this, id,
new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y)), p, z);
};
_setExtentBounds() {
if (this.extent.northEast.lat > 0) {
this.isNorth = true;
}
this.bsphere.setFromExtent(this.layer._planet.ellipsoid, this.extent);
};
__setLonLat__(entity) {
if (entity._lonlat.isZero()) {
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
}
return entity._lonlat;
};
isVisible() {
if (this.isNorth && this.layer._renderingNodesNorth[this.nodeId]) {
return true;
} else if (this.layer._renderingNodesSouth[this.nodeId]) {
return true;
}
return false;
};
isInside(entity) {
return this.extent.isInside(entity._lonlat);
};
/**
*
* @param {*} outArr
* @param {*} visibleNodes
* @param {*} renderingNode
*/
renderCollection(outArr, visibleNodes, renderingNode) {
if (this.isNorth) {
this.layer._renderingNodesNorth[this.nodeId] = true;
} else {
this.layer._renderingNodesSouth[this.nodeId] = true;
}
if (this.deferredEntities.length && !this._inTheQueue) {
if (this.layer.async) {
this.layer._queueDeferredNode(this);
} else {
this.applyCollection();
}
}
this.entityCollection._fadingOpacity = this.layer._fadingOpacity;
this.entityCollection.scaleByDistance = this.layer.scaleByDistance;
this.entityCollection.pickingScale = this.layer.pickingScale;
outArr.push(this.entityCollection);
};
}
export { EntityCollectionNode, EntityCollectionNodeWGS84 };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,13 @@
"use strict";
import * as mercator from "../mercator.js";
import * as quadTree from "../quadTree/quadTree.js";
import { EPSG4326 } from "../proj/EPSG4326.js";
import { Extent } from "../Extent.js";
import { inherits } from "../inherits.js";
import { Layer } from "../layer/Layer.js";
import { LonLat } from "../LonLat.js";
import { Segment } from "./Segment.js";
import { Vec3 } from "../math/Vec3.js";
import * as mercator from "../mercator.js";
import { EPSG4326 } from "../proj/EPSG4326.js";
import * as quadTree from "../quadTree/quadTree.js";
import { Segment } from "./Segment.js";
const _heightLat = 90.0 - mercator.MAX_LAT;
const _maxPoleZoom = 7;
@ -26,243 +25,251 @@ let _tempHigh = new Vec3(),
* @param {Number} tileZoom - Segment tile zoom index.
* @param {og.Extent} extent - Segment WGS84 extent.
*/
const SegmentLonLat = function (node, planet, tileZoom, extent) {
this._isNorth = false;
Segment.call(this, node, planet, tileZoom, extent);
this._projection = EPSG4326;
this._extentMerc = new Extent(
extent.southWest.forwardMercatorEPS01(),
extent.northEast.forwardMercatorEPS01()
);
this.isPole = true;
};
class SegmentLonLat extends Segment {
inherits(SegmentLonLat, Segment);
SegmentLonLat.prototype._setExtentLonLat = function () {
this._extentLonLat = this._extent;
};
SegmentLonLat.prototype.projectNative = function (coords) {
return coords;
};
SegmentLonLat.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, normal) {
res.copy(this.planet.ellipsoid.hitRay(xyz, xyz.negateTo().normalize()));
if (normal) {
normal.copy(res.normal());
}
return xyz.length() - res.length();
};
SegmentLonLat.prototype.acceptForRendering = function (camera) {
var maxPoleZoom;
var lat = this._extent.northEast.lat;
if (this._isNorth) {
//north pole limits
let Yz = Math.floor((90.0 - lat) / _pieceSize);
maxPoleZoom = Math.floor(Yz / 16) + 7;
} else {
//south pole limits
let Yz = Math.floor((mercator.MIN_LAT - lat) / _pieceSize);
maxPoleZoom = 12 - Math.floor(Yz / 16);
}
return Segment.prototype.acceptForRendering.call(this, camera) || this.tileZoom >= maxPoleZoom;
};
SegmentLonLat.prototype._assignTileIndexes = function () {
var tileZoom = this.tileZoom;
var extent = this._extent;
this.tileX = Math.round(
Math.abs(-180.0 - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
);
var lat = extent.northEast.lat;
if (lat > 0) {
//north pole
this._isNorth = true;
this._tileGroup = 1;
this.tileY = Math.round((90.0 - lat) / (extent.northEast.lat - extent.southWest.lat));
} else {
//south pole
this._tileGroup = 2;
this.tileY = Math.round(
(mercator.MIN_LAT - lat) / (extent.northEast.lat - extent.southWest.lat)
/**
* @param {quadTree.Node} node - Segment node.
* @param {scene.Planet} planet - Current planet scene.
* @param {number} tileZoom - Zoom index.
* @param {Extent} extent - Segment extent.
*/
constructor(node, planet, tileZoom, extent) {
super(node, planet, tileZoom, extent);
this._isNorth = false;
this._projection = EPSG4326;
this._extentMerc = new Extent(
extent.southWest.forwardMercatorEPS01(),
extent.northEast.forwardMercatorEPS01()
);
}
this.isPole = true;
};
var p2 = 1 << tileZoom;
this.tileXE = (this.tileX + 1) % p2;
this.tileXW = (p2 + this.tileX - 1) % p2;
this.tileYN = this.tileY - 1;
this.tileYS = this.tileY + 1;
_setExtentLonLat() {
this._extentLonLat = this._extent;
};
this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
};
projectNative(coords) {
return coords;
};
SegmentLonLat.prototype._createPlainVertices = function () {
var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
var e = this._extent,
fgs = this.planet.terrain.plainGridSize;
var lonSize = e.getWidth();
var latSize = e.getHeight();
var llStep = lonSize / Math.max(fgs, gridSize);
var ltStep = latSize / gridSize;
var esw_lon = e.southWest.lon,
ene_lat = e.northEast.lat;
var dg = Math.max(fgs / gridSize, 1),
gs = Math.max(fgs, gridSize) + 1;
var r2 = this.planet.ellipsoid._invRadii2;
var ind = 0,
nmInd = 0;
const gsgs = gs * gs;
var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
this.plainNormals = new Float32Array(gridSize3);
this.plainVertices = new Float64Array(gridSize3);
this.plainVerticesHigh = new Float32Array(gridSize3);
this.plainVerticesLow = new Float32Array(gridSize3);
this.normalMapNormals = new Float32Array(gsgs * 3);
this.normalMapVertices = new Float64Array(gsgs * 3);
this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
this.normalMapVerticesLow = new Float32Array(gsgs * 3);
var verts = this.plainVertices,
vertsHigh = this.plainVerticesHigh,
vertsLow = this.plainVerticesLow,
norms = this.plainNormals,
nmVerts = this.normalMapVertices,
nmVertsHigh = this.normalMapVerticesHigh,
nmVertsLow = this.normalMapVerticesLow,
nmNorms = this.normalMapNormals;
for (var k = 0; k < gsgs; k++) {
var j = k % gs,
i = ~~(k / gs);
var v = this.planet.ellipsoid.lonLatToCartesian(
new LonLat(esw_lon + j * llStep, ene_lat - i * ltStep)
);
var nx = v.x * r2.x,
ny = v.y * r2.y,
nz = v.z * r2.z;
var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
var nxl = nx * l,
nyl = ny * l,
nzl = nz * l;
Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
nmVerts[nmInd] = v.x;
nmVertsHigh[nmInd] = _tempHigh.x;
nmVertsLow[nmInd] = _tempLow.x;
nmNorms[nmInd++] = nxl;
nmVerts[nmInd] = v.y;
nmVertsHigh[nmInd] = _tempHigh.y;
nmVertsLow[nmInd] = _tempLow.y;
nmNorms[nmInd++] = nyl;
nmVerts[nmInd] = v.z;
nmVertsHigh[nmInd] = _tempHigh.z;
nmVertsLow[nmInd] = _tempLow.z;
nmNorms[nmInd++] = nzl;
if (i % dg === 0 && j % dg === 0) {
verts[ind] = v.x;
vertsHigh[ind] = _tempHigh.x;
vertsLow[ind] = _tempLow.x;
norms[ind++] = nxl;
verts[ind] = v.y;
vertsHigh[ind] = _tempHigh.y;
vertsLow[ind] = _tempLow.y;
norms[ind++] = nyl;
verts[ind] = v.z;
vertsHigh[ind] = _tempHigh.z;
vertsLow[ind] = _tempLow.z;
norms[ind++] = nzl;
getTerrainPoint(xyz, insideSegmentPosition, res, normal) {
res.copy(this.planet.ellipsoid.hitRay(xyz, xyz.negateTo().normalize()));
if (normal) {
normal.copy(res.normal());
}
}
return xyz.length() - res.length();
};
this.terrainVertices = verts;
this.terrainVerticesHigh = vertsHigh;
this.terrainVerticesLow = vertsLow;
acceptForRendering(camera) {
var maxPoleZoom;
var lat = this._extent.northEast.lat;
if (this._isNorth) {
//north pole limits
let Yz = Math.floor((90.0 - lat) / _pieceSize);
maxPoleZoom = Math.floor(Yz / 16) + 7;
} else {
//south pole limits
let Yz = Math.floor((mercator.MIN_LAT - lat) / _pieceSize);
maxPoleZoom = 12 - Math.floor(Yz / 16);
}
return Segment.prototype.acceptForRendering.call(this, camera) || this.tileZoom >= maxPoleZoom;
};
//store raw normals
this.normalMapNormalsRaw = new Float32Array(nmNorms.length);
this.normalMapNormalsRaw.set(nmNorms);
_assignTileIndexes() {
var tileZoom = this.tileZoom;
var extent = this._extent;
this.plainReady = true;
};
this.tileX = Math.round(
Math.abs(-180.0 - extent.southWest.lon) / (extent.northEast.lon - extent.southWest.lon)
);
SegmentLonLat.prototype._assignGlobalTextureCoordinates = function () {
var e = this._extent;
this._globalTextureCoordinates[0] = (e.southWest.lon + 180.0) / 360.0;
this._globalTextureCoordinates[1] = (90 - e.northEast.lat) / 180.0;
this._globalTextureCoordinates[2] = (e.northEast.lon + 180.0) / 360.0;
this._globalTextureCoordinates[3] = (90 - e.southWest.lat) / 180.0;
};
var lat = extent.northEast.lat;
SegmentLonLat.prototype._collectVisibleNodes = function () {
if (this._isNorth) {
this.planet._visibleNodesNorth[this.node.nodeId] = this.node;
} else {
this.planet._visibleNodesSouth[this.node.nodeId] = this.node;
}
};
if (lat > 0) {
//north pole
this._isNorth = true;
this._tileGroup = 1;
this.tileY = Math.round((90.0 - lat) / (extent.northEast.lat - extent.southWest.lat));
} else {
//south pole
this._tileGroup = 2;
this.tileY = Math.round(
(mercator.MIN_LAT - lat) / (extent.northEast.lat - extent.southWest.lat)
);
}
SegmentLonLat.prototype.isEntityInside = function (e) {
return this._extent.isInside(e._lonlat);
};
var p2 = 1 << tileZoom;
this.tileXE = (this.tileX + 1) % p2;
this.tileXW = (p2 + this.tileX - 1) % p2;
SegmentLonLat.prototype._getLayerExtentOffset = function (layer) {
var v0s = layer._extent;
var v0t = this._extent;
var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
return [dV0s_x, dV0s_y, dSize_x, dSize_y];
};
this.tileYN = this.tileY - 1;
this.tileYS = this.tileY + 1;
SegmentLonLat.prototype.layerOverlap = function (layer) {
return this._extent.overlaps(layer._extent);
};
this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
};
SegmentLonLat.prototype.getDefaultTexture = function () {
return this._isNorth ? this.planet.solidTextureOne : this.planet.solidTextureTwo;
};
_createPlainVertices() {
var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
SegmentLonLat.prototype.getExtentLonLat = function () {
return this._extent;
};
var e = this._extent,
fgs = this.planet.terrain.plainGridSize;
var lonSize = e.getWidth();
var latSize = e.getHeight();
var llStep = lonSize / Math.max(fgs, gridSize);
var ltStep = latSize / gridSize;
var esw_lon = e.southWest.lon,
ene_lat = e.northEast.lat;
var dg = Math.max(fgs / gridSize, 1),
gs = Math.max(fgs, gridSize) + 1;
var r2 = this.planet.ellipsoid._invRadii2;
var ind = 0,
nmInd = 0;
const gsgs = gs * gs;
SegmentLonLat.prototype.getExtentMerc = function () {
return this._extentMerc;
};
var gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
SegmentLonLat.prototype.getNodeState = function () {
var vn;
if (this._isNorth) {
vn = this.planet._visibleNodesNorth[this.node.nodeId];
} else {
vn = this.planet._visibleNodesSouth[this.node.nodeId];
}
return (vn && vn.state) || quadTree.NOTRENDERING;
};
this.plainNormals = new Float32Array(gridSize3);
this.plainVertices = new Float64Array(gridSize3);
this.plainVerticesHigh = new Float32Array(gridSize3);
this.plainVerticesLow = new Float32Array(gridSize3);
SegmentLonLat.prototype._freeCache = function () {
//empty for a time
};
this.normalMapNormals = new Float32Array(gsgs * 3);
this.normalMapVertices = new Float64Array(gsgs * 3);
this.normalMapVerticesHigh = new Float32Array(gsgs * 3);
this.normalMapVerticesLow = new Float32Array(gsgs * 3);
var verts = this.plainVertices,
vertsHigh = this.plainVerticesHigh,
vertsLow = this.plainVerticesLow,
norms = this.plainNormals,
nmVerts = this.normalMapVertices,
nmVertsHigh = this.normalMapVerticesHigh,
nmVertsLow = this.normalMapVerticesLow,
nmNorms = this.normalMapNormals;
for (var k = 0; k < gsgs; k++) {
var j = k % gs,
i = ~~(k / gs);
var v = this.planet.ellipsoid.lonLatToCartesian(
new LonLat(esw_lon + j * llStep, ene_lat - i * ltStep)
);
var nx = v.x * r2.x,
ny = v.y * r2.y,
nz = v.z * r2.z;
var l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
var nxl = nx * l,
nyl = ny * l,
nzl = nz * l;
Vec3.doubleToTwoFloats(v, _tempHigh, _tempLow);
nmVerts[nmInd] = v.x;
nmVertsHigh[nmInd] = _tempHigh.x;
nmVertsLow[nmInd] = _tempLow.x;
nmNorms[nmInd++] = nxl;
nmVerts[nmInd] = v.y;
nmVertsHigh[nmInd] = _tempHigh.y;
nmVertsLow[nmInd] = _tempLow.y;
nmNorms[nmInd++] = nyl;
nmVerts[nmInd] = v.z;
nmVertsHigh[nmInd] = _tempHigh.z;
nmVertsLow[nmInd] = _tempLow.z;
nmNorms[nmInd++] = nzl;
if (i % dg === 0 && j % dg === 0) {
verts[ind] = v.x;
vertsHigh[ind] = _tempHigh.x;
vertsLow[ind] = _tempLow.x;
norms[ind++] = nxl;
verts[ind] = v.y;
vertsHigh[ind] = _tempHigh.y;
vertsLow[ind] = _tempLow.y;
norms[ind++] = nyl;
verts[ind] = v.z;
vertsHigh[ind] = _tempHigh.z;
vertsLow[ind] = _tempLow.z;
norms[ind++] = nzl;
}
}
this.terrainVertices = verts;
this.terrainVerticesHigh = vertsHigh;
this.terrainVerticesLow = vertsLow;
//store raw normals
this.normalMapNormalsRaw = new Float32Array(nmNorms.length);
this.normalMapNormalsRaw.set(nmNorms);
this.plainReady = true;
};
_assignGlobalTextureCoordinates() {
var e = this._extent;
this._globalTextureCoordinates[0] = (e.southWest.lon + 180.0) / 360.0;
this._globalTextureCoordinates[1] = (90 - e.northEast.lat) / 180.0;
this._globalTextureCoordinates[2] = (e.northEast.lon + 180.0) / 360.0;
this._globalTextureCoordinates[3] = (90 - e.southWest.lat) / 180.0;
};
_collectVisibleNodes() {
if (this._isNorth) {
this.planet._visibleNodesNorth[this.node.nodeId] = this.node;
} else {
this.planet._visibleNodesSouth[this.node.nodeId] = this.node;
}
};
isEntityInside(e) {
return this._extent.isInside(e._lonlat);
};
_getLayerExtentOffset(layer) {
var v0s = layer._extent;
var v0t = this._extent;
var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
var sSize_y = v0s.northEast.lat - v0s.southWest.lat;
var dV0s_x = (v0t.southWest.lon - v0s.southWest.lon) / sSize_x;
var dV0s_y = (v0s.northEast.lat - v0t.northEast.lat) / sSize_y;
var dSize_x = (v0t.northEast.lon - v0t.southWest.lon) / sSize_x;
var dSize_y = (v0t.northEast.lat - v0t.southWest.lat) / sSize_y;
return [dV0s_x, dV0s_y, dSize_x, dSize_y];
};
layerOverlap(layer) {
return this._extent.overlaps(layer._extent);
};
getDefaultTexture() {
return this._isNorth ? this.planet.solidTextureOne : this.planet.solidTextureTwo;
};
getExtentLonLat() {
return this._extent;
};
getExtentMerc() {
return this._extentMerc;
};
getNodeState() {
var vn;
if (this._isNorth) {
vn = this.planet._visibleNodesNorth[this.node.nodeId];
} else {
vn = this.planet._visibleNodesSouth[this.node.nodeId];
}
return (vn && vn.state) || quadTree.NOTRENDERING;
};
_freeCache() {
//empty for a time
};
}
export { SegmentLonLat };

View File

@ -0,0 +1,18 @@
import { EntityCollectionNode, EntityCollectionNodeWGS84 } from '../../src/og/quadTree/EntityCollectionNode';
describe('EntityCollectionNode class', () => {
test('EntityCollectionNode', () => {
const item = new EntityCollectionNode();
expect(item).toBeTruthy();
expect(item.buildTree).toBeTruthy();
expect(item.renderCollection).toBeTruthy();
});
test('EntityCollectionNodeWGS84', () => {
const item = new EntityCollectionNodeWGS84(3);
expect(item).toBeTruthy();
expect(item.layer).toBe(3);
expect(item.buildTree).toBeTruthy();
expect(item.renderCollection).toBeTruthy();
});
});