mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
move to es6
This commit is contained in:
parent
e06268fe6f
commit
40a9b3812b
@ -4,7 +4,14 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const Material = function (segment, layer) {
|
||||
class Material {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} segment
|
||||
* @param {*} layer
|
||||
*/
|
||||
constructor(segment, layer) {
|
||||
this.segment = segment;
|
||||
this.layer = layer;
|
||||
this.isReady = false;
|
||||
@ -21,17 +28,27 @@ const Material = function (segment, layer) {
|
||||
this._updateTexture = null;
|
||||
this._updatePickingMask = null;
|
||||
this.pickingReady = false;
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.assignLayer = function (layer) {
|
||||
/**
|
||||
* @param {*} layer
|
||||
*/
|
||||
assignLayer(layer) {
|
||||
this.layer = layer;
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.abortLoading = function () {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abortLoading() {
|
||||
this.layer.abortMaterialLoading(this);
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.applyImage = function (img) {
|
||||
/**
|
||||
*
|
||||
* @param {*} img
|
||||
*/
|
||||
applyImage(img) {
|
||||
if (this.segment.initialized) {
|
||||
this._updateTexture = null;
|
||||
//this.image = img;
|
||||
@ -43,9 +60,14 @@ Material.prototype.applyImage = function (img) {
|
||||
this.isLoading = false;
|
||||
this.texOffset = [0.0, 0.0, 1.0, 1.0];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.applyTexture = function (texture, pickingMask) {
|
||||
/**
|
||||
*
|
||||
* @param {*} texture
|
||||
* @param {*} pickingMask
|
||||
*/
|
||||
applyTexture(texture, pickingMask) {
|
||||
if (this.segment.initialized) {
|
||||
this.texture = texture;
|
||||
this._updateTexture = null;
|
||||
@ -58,20 +80,27 @@ Material.prototype.applyTexture = function (texture, pickingMask) {
|
||||
this.appliedNodeId = this.segment.node.nodeId;
|
||||
this.texOffset = [0.0, 0.0, 1.0, 1.0];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.textureNotExists = function () {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
textureNotExists() {
|
||||
if (this.segment.initialized) {
|
||||
this.pickingReady = true;
|
||||
this.isLoading = false;
|
||||
this.isReady = true;
|
||||
this.textureExists = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Material.prototype.clear = function () {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
clear() {
|
||||
this.loadingAttempts = 0;
|
||||
this.layer.clearMaterial(this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { Material };
|
||||
@ -4,16 +4,17 @@
|
||||
|
||||
'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) {
|
||||
class EntityCollectionNode {
|
||||
|
||||
constructor(layer, partId, parent, id, extent, planet, zoom) {
|
||||
this.layer = layer;
|
||||
this.parentNode = parent;
|
||||
this.childrenNodes = [];
|
||||
@ -30,13 +31,13 @@ const EntityCollectionNode = function (layer, partId, parent, id, extent, planet
|
||||
this.bsphere = new Sphere();
|
||||
|
||||
planet && this._setExtentBounds();
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.insertEntity = function (entity, rightNow) {
|
||||
insertEntity(entity, rightNow) {
|
||||
this.buildTree([entity], rightNow);
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype._addEntitiesToCollection = function (entities, rightNow) {
|
||||
_addEntitiesToCollection(entities, rightNow) {
|
||||
if (entities.length) {
|
||||
var l = this.layer,
|
||||
p = l._planet;
|
||||
@ -61,18 +62,18 @@ EntityCollectionNode.prototype._addEntitiesToCollection = function (entities, ri
|
||||
this.deferredEntities.push.apply(this.deferredEntities, entities);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype._setExtentBounds = function () {
|
||||
_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());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.__setLonLat__ = function (entity) {
|
||||
__setLonLat__(entity) {
|
||||
|
||||
if (entity._lonlat.isZero() && !entity._cartesian.isZero()) {
|
||||
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
|
||||
@ -84,9 +85,9 @@ EntityCollectionNode.prototype.__setLonLat__ = function (entity) {
|
||||
entity._lonlatMerc = null;
|
||||
}
|
||||
return entity._lonlatMerc;
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.buildTree = function (entities, rightNow) {
|
||||
buildTree(entities, rightNow) {
|
||||
|
||||
this.count += entities.length;
|
||||
|
||||
@ -127,13 +128,13 @@ EntityCollectionNode.prototype.buildTree = function (entities, rightNow) {
|
||||
} else {
|
||||
this._addEntitiesToCollection(entities, rightNow);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.isInside = function (entity) {
|
||||
isInside(entity) {
|
||||
return this.extent.isInside(entity._lonlatMerc);
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.createChildrenNodes = function () {
|
||||
createChildrenNodes() {
|
||||
var l = this.layer;
|
||||
var ext = this.extent;
|
||||
var size_x = ext.getWidth() * 0.5;
|
||||
@ -157,9 +158,9 @@ EntityCollectionNode.prototype.createChildrenNodes = function () {
|
||||
|
||||
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) {
|
||||
collectRenderCollectionsPASS1(visibleNodes, outArr) {
|
||||
var n = visibleNodes[this.nodeId];
|
||||
if (n) {
|
||||
var cn = this.childrenNodes;
|
||||
@ -176,9 +177,9 @@ EntityCollectionNode.prototype.collectRenderCollectionsPASS1 = function (visible
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.collectRenderCollectionsPASS2 = function (visibleNodes, outArr, renderingNodeId) {
|
||||
collectRenderCollectionsPASS2(visibleNodes, outArr, renderingNodeId) {
|
||||
var p = this.layer._planet;
|
||||
var cam = p.renderer.activeCamera;
|
||||
|
||||
@ -200,16 +201,16 @@ EntityCollectionNode.prototype.collectRenderCollectionsPASS2 = function (visible
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.applyCollection = function () {
|
||||
applyCollection() {
|
||||
this.entityCollection.addEntities(this.deferredEntities);
|
||||
this.deferredEntities.length = 0;
|
||||
this.deferredEntities = [];
|
||||
this._inTheQueue = false;
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.traverseTree = function (callback) {
|
||||
traverseTree(callback) {
|
||||
|
||||
var cn = this.childrenNodes;
|
||||
|
||||
@ -221,9 +222,9 @@ EntityCollectionNode.prototype.traverseTree = function (callback) {
|
||||
cn[quadTree.SW].traverseTree(callback);
|
||||
cn[quadTree.SE].traverseTree(callback);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.renderCollection = function (outArr, visibleNodes, renderingNodeId) {
|
||||
renderCollection(outArr, visibleNodes, renderingNodeId) {
|
||||
|
||||
var l = this.layer;
|
||||
|
||||
@ -276,29 +277,31 @@ EntityCollectionNode.prototype.renderCollection = function (outArr, visibleNodes
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNode.prototype.alignEntityToTheGround = function (entity, segment) {
|
||||
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 () {
|
||||
isVisible() {
|
||||
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);
|
||||
}
|
||||
|
||||
class EntityCollectionNodeWGS84 extends EntityCollectionNode {
|
||||
|
||||
constructor(layer, partId, parent, id, extent, planet, zoom) {
|
||||
super(layer, partId, parent, id, extent, planet, zoom);
|
||||
this.isNorth = false;
|
||||
};
|
||||
}
|
||||
|
||||
inherits(EntityCollectionNodeWGS84, EntityCollectionNode);
|
||||
|
||||
EntityCollectionNodeWGS84.prototype.createChildrenNodes = function () {
|
||||
createChildrenNodes() {
|
||||
var l = this.layer;
|
||||
var ext = this.extent;
|
||||
var size_x = ext.getWidth() * 0.5;
|
||||
@ -322,36 +325,42 @@ EntityCollectionNodeWGS84.prototype.createChildrenNodes = function () {
|
||||
|
||||
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 () {
|
||||
_setExtentBounds() {
|
||||
if (this.extent.northEast.lat > 0) {
|
||||
this.isNorth = true;
|
||||
}
|
||||
this.bsphere.setFromExtent(this.layer._planet.ellipsoid, this.extent);
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNodeWGS84.prototype.__setLonLat__ = function (entity) {
|
||||
__setLonLat__(entity) {
|
||||
if (entity._lonlat.isZero()) {
|
||||
entity._lonlat = this.layer._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
|
||||
}
|
||||
return entity._lonlat;
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNodeWGS84.prototype.isVisible = function () {
|
||||
isVisible() {
|
||||
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) {
|
||||
isInside(entity) {
|
||||
return this.extent.isInside(entity._lonlat);
|
||||
};
|
||||
};
|
||||
|
||||
EntityCollectionNodeWGS84.prototype.renderCollection = function (outArr, visibleNodes, renderingNode) {
|
||||
/**
|
||||
*
|
||||
* @param {*} outArr
|
||||
* @param {*} visibleNodes
|
||||
* @param {*} renderingNode
|
||||
*/
|
||||
renderCollection(outArr, visibleNodes, renderingNode) {
|
||||
|
||||
if (this.isNorth) {
|
||||
this.layer._renderingNodesNorth[this.nodeId] = true;
|
||||
@ -372,6 +381,7 @@ EntityCollectionNodeWGS84.prototype.renderCollection = function (outArr, visible
|
||||
this.entityCollection.pickingScale = this.layer.pickingScale;
|
||||
|
||||
outArr.push(this.entityCollection);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export { EntityCollectionNode, EntityCollectionNodeWGS84 };
|
||||
@ -2,13 +2,13 @@
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import { EPSG4326 } from "../proj/EPSG4326.js";
|
||||
import { EPSG3857 } from "../proj/EPSG3857.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { MAX_LAT, POLE } from "../mercator.js";
|
||||
import { MAX, MIN } from "../math.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { MAX_LAT } from "../mercator.js";
|
||||
import { EPSG3857 } from "../proj/EPSG3857.js";
|
||||
import { EPSG4326 } from "../proj/EPSG4326.js";
|
||||
import { MAX_NORMAL_ZOOM } from "../segment/Segment.js";
|
||||
import { getMatrixSubArray, getMatrixSubArrayBoundsExt } from "../utils/shared.js";
|
||||
|
||||
import {
|
||||
COMSIDE,
|
||||
E,
|
||||
@ -30,13 +30,28 @@ import {
|
||||
WALKTHROUGH
|
||||
} from "./quadTree.js";
|
||||
|
||||
import { MAX_NORMAL_ZOOM } from "../segment/Segment.js";
|
||||
|
||||
const VISIBLE_HEIGHT = 1400000.0;
|
||||
|
||||
let _tempHigh = new Vec3(),
|
||||
_tempLow = new Vec3();
|
||||
|
||||
const _vertOrder = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 1, y: 1 }
|
||||
];
|
||||
const _neGridSize = Math.sqrt(_vertOrder.length) - 1;
|
||||
|
||||
let BOUNDS = {
|
||||
xmin: 0.0,
|
||||
ymin: 0.0,
|
||||
zmin: 0.0,
|
||||
xmax: 0.0,
|
||||
ymax: 0.0,
|
||||
zmax: 0.0
|
||||
};
|
||||
|
||||
/**
|
||||
* Quad tree planet segment node.
|
||||
* @constructor
|
||||
@ -48,7 +63,9 @@ let _tempHigh = new Vec3(),
|
||||
* @param {number} tileZoom - Deep index of the quad tree.
|
||||
* @param {og.Extent} extent - Planet segment extent.
|
||||
*/
|
||||
const Node = function (SegmentPrototype, planet, partId, parent, id, tileZoom, extent) {
|
||||
class Node {
|
||||
|
||||
constructor(SegmentPrototype, planet, partId, parent, id, tileZoom, extent) {
|
||||
this.SegmentPrototype = SegmentPrototype;
|
||||
this.planet = planet;
|
||||
this.parentNode = parent;
|
||||
@ -68,17 +85,9 @@ const Node = function (SegmentPrototype, planet, partId, parent, id, tileZoom, e
|
||||
this.inFrustum = 0;
|
||||
this.createBounds();
|
||||
this.planet._createdNodesCount++;
|
||||
};
|
||||
};
|
||||
|
||||
const _vertOrder = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 1, y: 1 }
|
||||
];
|
||||
const _neGridSize = Math.sqrt(_vertOrder.length) - 1;
|
||||
|
||||
Node.prototype.createChildrenNodes = function () {
|
||||
createChildrenNodes() {
|
||||
this.ready = true;
|
||||
|
||||
var p = this.planet;
|
||||
@ -132,9 +141,9 @@ Node.prototype.createChildrenNodes = function () {
|
||||
z,
|
||||
new Extent(new LonLat(sw.lon + size_x, sw.lat), new LonLat(ne.lon, sw.lat + size_y))
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.createBounds = function () {
|
||||
createBounds() {
|
||||
let seg = this.segment;
|
||||
seg._setExtentLonLat();
|
||||
if (seg.tileZoom === 0) {
|
||||
@ -144,9 +153,9 @@ Node.prototype.createBounds = function () {
|
||||
} else {
|
||||
seg.createBoundsByParent();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.getState = function () {
|
||||
getState() {
|
||||
if (this.state === -1) {
|
||||
return this.state;
|
||||
}
|
||||
@ -158,15 +167,15 @@ Node.prototype.getState = function () {
|
||||
pn = pn.parentNode;
|
||||
}
|
||||
return this.state;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the same deep existent neighbour node.
|
||||
* @public
|
||||
* @param {Number} side - Neighbour side index e.g. og.quadTree.N, og.quadTree.W etc.
|
||||
* @returns {og.quadTree.Node} -
|
||||
*/
|
||||
Node.prototype.getEqualNeighbor = function (side) {
|
||||
getEqualNeighbor(side) {
|
||||
var pn = this;
|
||||
var part = NEIGHBOUR[side][pn.partId];
|
||||
if (part !== -1) {
|
||||
@ -188,13 +197,13 @@ Node.prototype.getEqualNeighbor = function (side) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.isBrother = function (node) {
|
||||
isBrother(node) {
|
||||
return !(this.parentNode || node.parentNode) || this.parentNode.id === node.parentNode.id;
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.renderTree = function (cam, maxZoom, terrainReadySegment, stopLoading) {
|
||||
renderTree(cam, maxZoom, terrainReadySegment, stopLoading) {
|
||||
if (
|
||||
this.planet._renderedNodes.length >= MAX_RENDERED_NODES ||
|
||||
this.planet._nodeCounterError_ > 2000
|
||||
@ -298,9 +307,9 @@ Node.prototype.renderTree = function (cam, maxZoom, terrainReadySegment, stopLoa
|
||||
} else {
|
||||
this.state = NOTRENDERING;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.traverseNodes = function (cam, maxZoom, terrainReadySegment, stopLoading) {
|
||||
traverseNodes(cam, maxZoom, terrainReadySegment, stopLoading) {
|
||||
if (!this.ready) {
|
||||
this.createChildrenNodes();
|
||||
}
|
||||
@ -311,15 +320,15 @@ Node.prototype.traverseNodes = function (cam, maxZoom, terrainReadySegment, stop
|
||||
n[1].renderTree(cam, maxZoom, terrainReadySegment, stopLoading);
|
||||
n[2].renderTree(cam, maxZoom, terrainReadySegment, stopLoading);
|
||||
n[3].renderTree(cam, maxZoom, terrainReadySegment, stopLoading);
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.prepareForRendering = function (
|
||||
prepareForRendering(
|
||||
cam,
|
||||
altVis,
|
||||
inFrustum,
|
||||
terrainReadySegment,
|
||||
stopLoading
|
||||
) {
|
||||
) {
|
||||
let seg = this.segment;
|
||||
|
||||
if (cam._lonLat.height < VISIBLE_HEIGHT) {
|
||||
@ -344,9 +353,9 @@ Node.prototype.prepareForRendering = function (
|
||||
this.state = NOTRENDERING;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.renderNode = function (inFrustum, onlyTerrain, terrainReadySegment, stopLoading) {
|
||||
renderNode(inFrustum, onlyTerrain, terrainReadySegment, stopLoading) {
|
||||
var seg = this.segment;
|
||||
|
||||
// Create and load terrain data
|
||||
@ -389,13 +398,13 @@ Node.prototype.renderNode = function (inFrustum, onlyTerrain, terrainReadySegmen
|
||||
|
||||
// Finally this node proceeds to rendering.
|
||||
this.addToRender(inFrustum);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Seraching for neighbours and pickup current node to render processing.
|
||||
* @public
|
||||
*/
|
||||
Node.prototype.addToRender = function (inFrustum) {
|
||||
addToRender(inFrustum) {
|
||||
this.state = RENDERING;
|
||||
|
||||
var nodes = this.planet._renderedNodes;
|
||||
@ -451,9 +460,9 @@ Node.prototype.addToRender = function (inFrustum) {
|
||||
k++;
|
||||
inFrustum >>= 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.getCommonSide = function (node) {
|
||||
getCommonSide(node) {
|
||||
var as = this.segment,
|
||||
bs = node.segment;
|
||||
|
||||
@ -559,10 +568,10 @@ Node.prototype.getCommonSide = function (node) {
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
};
|
||||
|
||||
// TODO: test test test
|
||||
Node.prototype.___getCommonSide___ = function (b) {
|
||||
// TODO: test test test
|
||||
___getCommonSide___(b) {
|
||||
var a = this,
|
||||
as = a.segment,
|
||||
bs = b.segment;
|
||||
@ -620,9 +629,9 @@ Node.prototype.___getCommonSide___ = function (b) {
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.whileNormalMapCreating = function () {
|
||||
whileNormalMapCreating() {
|
||||
var seg = this.segment;
|
||||
var maxZ = this.planet.terrain.maxZoom;
|
||||
|
||||
@ -648,18 +657,9 @@ Node.prototype.whileNormalMapCreating = function () {
|
||||
seg.parentNormalMapReady = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let BOUNDS = {
|
||||
xmin: 0.0,
|
||||
ymin: 0.0,
|
||||
zmin: 0.0,
|
||||
xmax: 0.0,
|
||||
ymax: 0.0,
|
||||
zmax: 0.0
|
||||
};
|
||||
|
||||
Node.prototype.whileTerrainLoading = function (terrainReadySegment, stopLoading) {
|
||||
whileTerrainLoading(terrainReadySegment, stopLoading) {
|
||||
const seg = this.segment;
|
||||
const terrain = this.planet.terrain;
|
||||
|
||||
@ -907,9 +907,9 @@ Node.prototype.whileTerrainLoading = function (terrainReadySegment, stopLoading)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.destroy = function () {
|
||||
destroy() {
|
||||
this.state = NOTRENDERING;
|
||||
this.segment.destroySegment();
|
||||
var n = this.neighbors;
|
||||
@ -922,9 +922,9 @@ Node.prototype.destroy = function () {
|
||||
this.sideSize = null;
|
||||
this.sideSizeLog2 = null;
|
||||
this.segment = null;
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.clearTree = function () {
|
||||
clearTree() {
|
||||
var state = this.getState();
|
||||
|
||||
if (state === NOTRENDERING) {
|
||||
@ -936,16 +936,16 @@ Node.prototype.clearTree = function () {
|
||||
this.nodes[i] && this.nodes[i].clearTree();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.clearBranches = function () {
|
||||
clearBranches() {
|
||||
for (let i = 0; i < this.nodes.length; i++) {
|
||||
this.nodes[i].clearBranches();
|
||||
this.nodes[i].segment.deleteMaterials();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.destroyBranches = function () {
|
||||
destroyBranches() {
|
||||
if (this.ready) {
|
||||
var nodesToRemove = [],
|
||||
i;
|
||||
@ -966,18 +966,18 @@ Node.prototype.destroyBranches = function () {
|
||||
nodesToRemove.length = 0;
|
||||
nodesToRemove = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.traverseTree = function (callback) {
|
||||
traverseTree(callback) {
|
||||
callback(this);
|
||||
if (this.ready) {
|
||||
for (var i = 0; i < this.nodes.length; i++) {
|
||||
this.nodes[i].traverseTree(callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Node.prototype.getOffsetOppositeNeighbourSide = function (neighbourNode, side) {
|
||||
getOffsetOppositeNeighbourSide(neighbourNode, side) {
|
||||
let pNode = this,
|
||||
neighbourZoom = neighbourNode.segment.tileZoom,
|
||||
offset = 0;
|
||||
@ -988,6 +988,7 @@ Node.prototype.getOffsetOppositeNeighbourSide = function (neighbourNode, side) {
|
||||
}
|
||||
|
||||
return offset;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export { Node };
|
||||
|
||||
@ -31,6 +31,30 @@ var _RenderingSlice = function (p) {
|
||||
};
|
||||
};
|
||||
|
||||
let _v0 = new Vec3(),
|
||||
_v1 = new Vec3(),
|
||||
_v2 = new Vec3(),
|
||||
_v3 = new Vec3();
|
||||
|
||||
let _ray = new Ray(),
|
||||
_rayEx = new Ray();
|
||||
|
||||
window.ELLNORM = false;
|
||||
|
||||
const _S = new Array(4);
|
||||
_S[N] = 0;
|
||||
_S[E] = 1;
|
||||
_S[S] = 1;
|
||||
_S[W] = 0;
|
||||
|
||||
const _V = new Array(4);
|
||||
_V[N] = false;
|
||||
_V[E] = true;
|
||||
_V[S] = false;
|
||||
_V[W] = true;
|
||||
|
||||
window.BBSC = 100;
|
||||
|
||||
/**
|
||||
* Planet segment Web Mercator tile class that stored and rendered with quad tree.
|
||||
* @class
|
||||
@ -39,7 +63,15 @@ var _RenderingSlice = function (p) {
|
||||
* @param {Number} tileZoom - Zoom index.
|
||||
* @param {og.Extent} extent - Segment extent.
|
||||
*/
|
||||
const Segment = function (node, planet, tileZoom, extent) {
|
||||
class Segment {
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
this.isPole = false;
|
||||
|
||||
this._tileGroup = 0;
|
||||
@ -216,21 +248,21 @@ const Segment = function (node, planet, tileZoom, extent) {
|
||||
this.readyToEngage = false;
|
||||
|
||||
this.plainProcessing = false;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns that segment good for rendering with camera by current lod ratio.
|
||||
* @public
|
||||
* @param {og.Camera} camera - Camera object.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
Segment.prototype.acceptForRendering = function (camera) {
|
||||
acceptForRendering(camera) {
|
||||
return (
|
||||
camera.projectedSize(this.bsphere.center, this._plainRadius) < 256 / this.planet._lodRatio
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns entity terrain point.
|
||||
* @public
|
||||
* @param {og.Entity} entity - Entity.
|
||||
@ -238,24 +270,15 @@ Segment.prototype.acceptForRendering = function (camera) {
|
||||
* @param {og.Vec3} [normal] - Terrain point normal.
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
Segment.prototype.getEntityTerrainPoint = function (entity, res, normal) {
|
||||
getEntityTerrainPoint(entity, res, normal) {
|
||||
return this.getTerrainPoint(entity._cartesian, entity._lonlatMerc, res, normal);
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.isEntityInside = function (e) {
|
||||
isEntityInside(e) {
|
||||
return this._extent.isInside(e._lonlatMerc);
|
||||
};
|
||||
};
|
||||
|
||||
let _v0 = new Vec3(),
|
||||
_v1 = new Vec3(),
|
||||
_v2 = new Vec3(),
|
||||
_v3 = new Vec3();
|
||||
|
||||
let _ray = new Ray(),
|
||||
_rayEx = new Ray();
|
||||
|
||||
window.ELLNORM = false;
|
||||
/**
|
||||
/**
|
||||
* Returns distance from object to terrain coordinates and terrain point that calculates out in the res parameter.
|
||||
* @public
|
||||
* @param {og.Vec3} xyz - Cartesian object position.
|
||||
@ -264,7 +287,7 @@ window.ELLNORM = false;
|
||||
* @param {og.Vec3} [normal] - Terrain point normal.
|
||||
* @returns {number} -
|
||||
*/
|
||||
Segment.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, normal) {
|
||||
getTerrainPoint(xyz, insideSegmentPosition, res, normal) {
|
||||
var verts = this.tempVertices;
|
||||
|
||||
_ray.set(xyz, xyz.negateTo());
|
||||
@ -340,19 +363,19 @@ Segment.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, n
|
||||
normal && normal.copy(xyz.normal());
|
||||
return xyz.distance(this.planet.ellipsoid.hitRay(_ray.origin, _ray.direction));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Project wgs86 to segment native projection.
|
||||
* @public
|
||||
* @param {LonLat} lonlat - Coordinates to project.
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
Segment.prototype.projectNative = function (lonlat) {
|
||||
projectNative(lonlat) {
|
||||
return lonlat.forwardMercator();
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.loadTerrain = function (forceLoading) {
|
||||
loadTerrain(forceLoading) {
|
||||
if (this.tileZoom < this.planet.terrain.minZoom) {
|
||||
this.terrainIsLoading = true;
|
||||
|
||||
@ -368,13 +391,13 @@ Segment.prototype.loadTerrain = function (forceLoading) {
|
||||
this.planet.terrain.loadTerrain(this, forceLoading);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Terrain obtained from server.
|
||||
* @param {Float32Array} elevations - Elevation data.
|
||||
*/
|
||||
Segment.prototype.elevationsExists = function (elevations) {
|
||||
elevationsExists(elevations) {
|
||||
if (this.plainReady && this.terrainIsLoading) {
|
||||
this.planet._terrainWorker.make(this, elevations);
|
||||
|
||||
@ -389,9 +412,9 @@ Segment.prototype.elevationsExists = function (elevations) {
|
||||
this.tempVerticesLow = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._checkEqualization = function (neighborSide, neigborNode) {
|
||||
_checkEqualization(neighborSide, neigborNode) {
|
||||
return (
|
||||
neigborNode && this.tileZoom >= neigborNode.segment.tileZoom
|
||||
|
||||
@ -405,9 +428,9 @@ Segment.prototype._checkEqualization = function (neighborSide, neigborNode) {
|
||||
// neigborNode.equalizedNeighborGridSize[OPSIDE[neighborSide]] !== this.gridSize
|
||||
//)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.equalize = function () {
|
||||
equalize() {
|
||||
if (this.tileZoom < 8 || this.gridSize < 2) {
|
||||
return;
|
||||
}
|
||||
@ -590,14 +613,14 @@ Segment.prototype.equalize = function () {
|
||||
vLow[index + 2] = nvLow[n_index + 2];
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.engage = function () {
|
||||
engage() {
|
||||
this.readyToEngage = false;
|
||||
this.createCoordsBuffers(this.tempVerticesHigh, this.tempVerticesLow, this.gridSize);
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._plainSegmentWorkerCallback = function (data) {
|
||||
_plainSegmentWorkerCallback(data) {
|
||||
this.plainProcessing = false;
|
||||
|
||||
if (this.initialized && !this.terrainReady) {
|
||||
@ -622,9 +645,9 @@ Segment.prototype._plainSegmentWorkerCallback = function (data) {
|
||||
|
||||
this.plainReady = true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._terrainWorkerCallback = function (data) {
|
||||
_terrainWorkerCallback(data) {
|
||||
if (this.plainReady) {
|
||||
this.readyToEngage = true;
|
||||
|
||||
@ -689,12 +712,12 @@ Segment.prototype._terrainWorkerCallback = function (data) {
|
||||
this.planet._normalMapCreator.queue(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Terrain is not obtained or not exists on the server.
|
||||
*/
|
||||
Segment.prototype.elevationsNotExists = function () {
|
||||
elevationsNotExists() {
|
||||
if (this.planet && this.tileZoom <= this.planet.terrain.maxZoom) {
|
||||
if (this.plainReady && this.terrainIsLoading) {
|
||||
this.terrainIsLoading = false;
|
||||
@ -723,21 +746,8 @@ Segment.prototype.elevationsNotExists = function () {
|
||||
this.terrainReady = true;
|
||||
this.terrainExists = false;
|
||||
}
|
||||
};
|
||||
|
||||
const _S = new Array(4);
|
||||
_S[N] = 0;
|
||||
_S[E] = 1;
|
||||
_S[S] = 1;
|
||||
_S[W] = 0;
|
||||
|
||||
const _V = new Array(4);
|
||||
_V[N] = false;
|
||||
_V[E] = true;
|
||||
_V[S] = false;
|
||||
_V[W] = true;
|
||||
|
||||
Segment.prototype._normalMapEdgeEqualize = function (side) {
|
||||
};
|
||||
_normalMapEdgeEqualize(side) {
|
||||
let nn = this.node.neighbors;
|
||||
let n = nn[side][0];
|
||||
let maxZ = this.planet.terrain.maxZoom;
|
||||
@ -820,23 +830,22 @@ Segment.prototype._normalMapEdgeEqualize = function (side) {
|
||||
b._appliedNeighborsZoom[OPSIDE[side]] = s.tileZoom;
|
||||
s.planet._normalMapCreator.queue(b);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.applyTerrain = function (elevations) {
|
||||
applyTerrain(elevations) {
|
||||
if (elevations) {
|
||||
this.elevationsExists(elevations);
|
||||
} else {
|
||||
this.elevationsNotExists();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete segment gl buffers.
|
||||
*/
|
||||
Segment.prototype.deleteBuffers = function () {
|
||||
deleteBuffers() {
|
||||
var gl = this.handler.gl;
|
||||
gl.deleteBuffer(this.vertexNormalBuffer);
|
||||
gl.deleteBuffer(this.vertexPositionBuffer);
|
||||
@ -848,12 +857,12 @@ Segment.prototype.deleteBuffers = function () {
|
||||
this.vertexPositionBufferHigh = null;
|
||||
this.vertexPositionBufferLow = null;
|
||||
this.vertexTextureCoordBuffer = null;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete materials.
|
||||
*/
|
||||
Segment.prototype.deleteMaterials = function () {
|
||||
deleteMaterials() {
|
||||
var m = this.materials;
|
||||
for (var i = 0; i < m.length; i++) {
|
||||
var mi = m[i];
|
||||
@ -862,12 +871,12 @@ Segment.prototype.deleteMaterials = function () {
|
||||
}
|
||||
}
|
||||
this.materials.length = 0;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete elevation data.
|
||||
*/
|
||||
Segment.prototype.deleteElevations = function () {
|
||||
deleteElevations() {
|
||||
this.terrainExists = false;
|
||||
this.terrainReady = false;
|
||||
this.terrainIsLoading = false;
|
||||
@ -903,31 +912,31 @@ Segment.prototype.deleteElevations = function () {
|
||||
this.normalMapTextureBias[1] = 0;
|
||||
this.normalMapTextureBias[2] = 1;
|
||||
this._inTheQueue = false;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear but not destroy segment data.
|
||||
*/
|
||||
Segment.prototype.clearSegment = function () {
|
||||
clearSegment() {
|
||||
this.plainReady = false;
|
||||
this.initialized = false;
|
||||
this.deleteBuffers();
|
||||
this.deleteMaterials();
|
||||
this.deleteElevations();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Removes cache records.
|
||||
*/
|
||||
Segment.prototype._freeCache = function () {
|
||||
_freeCache() {
|
||||
this.planet._quadTreeNodesCacheMerc[this.tileIndex] = null;
|
||||
delete this.planet._quadTreeNodesCacheMerc[this.tileIndex];
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear and destroy all segment data.
|
||||
*/
|
||||
Segment.prototype.destroySegment = function () {
|
||||
destroySegment() {
|
||||
this._freeCache();
|
||||
|
||||
this.clearSegment();
|
||||
@ -983,16 +992,16 @@ Segment.prototype.destroySegment = function () {
|
||||
this._appliedNeighborsZoom = null;
|
||||
|
||||
this._globalTextureCoordinates = null;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._setExtentLonLat = function () {
|
||||
_setExtentLonLat() {
|
||||
this._extentLonLat = this._extent.inverseMercator();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Creates bound volumes by segment geographical extent.
|
||||
*/
|
||||
Segment.prototype.createBoundsByExtent = function () {
|
||||
createBoundsByExtent() {
|
||||
var ellipsoid = this.planet.ellipsoid,
|
||||
extent = this._extentLonLat;
|
||||
|
||||
@ -1011,9 +1020,9 @@ Segment.prototype.createBoundsByExtent = function () {
|
||||
}
|
||||
|
||||
this.setBoundingVolume3v(coord_sw, coord_ne);
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.createBoundsByParent = function () {
|
||||
createBoundsByParent() {
|
||||
let pn = this.node;
|
||||
|
||||
while (pn.parentNode && !pn.segment.terrainReady) {
|
||||
@ -1133,18 +1142,17 @@ Segment.prototype.createBoundsByParent = function () {
|
||||
} else {
|
||||
this.createBoundsByExtent();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.setBoundingSphere = function (x, y, z, v) {
|
||||
setBoundingSphere(x, y, z, v) {
|
||||
this.bsphere.center.x = x;
|
||||
this.bsphere.center.y = y;
|
||||
this.bsphere.center.z = z;
|
||||
this.bsphere.radius = this.bsphere.center.distance(v);
|
||||
};
|
||||
};
|
||||
|
||||
window.BBSC = 100;
|
||||
|
||||
Segment.prototype.setBoundingVolume = function (xmin, ymin, zmin, xmax, ymax, zmax) {
|
||||
setBoundingVolume(xmin, ymin, zmin, xmax, ymax, zmax) {
|
||||
this.bbox.setFromBoundsArr([xmin, ymin, zmin, xmax, ymax, zmax]);
|
||||
|
||||
let x = xmin + (xmax - xmin) * 0.5,
|
||||
@ -1153,9 +1161,9 @@ Segment.prototype.setBoundingVolume = function (xmin, ymin, zmin, xmax, ymax, zm
|
||||
|
||||
this.bsphere.center.set(x, y, z);
|
||||
this.bsphere.radius = this.bsphere.center.distance(new Vec3(xmin, ymin, zmin));
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.setBoundingVolume3v = function (vmin, vmax) {
|
||||
setBoundingVolume3v(vmin, vmax) {
|
||||
this.bbox.setFromBoundsArr([vmin.x, vmin.y, vmin.z, vmax.x, vmax.y, vmax.z]);
|
||||
|
||||
let x = vmin.x + (vmax.x - vmin.x) * 0.5,
|
||||
@ -1164,9 +1172,9 @@ Segment.prototype.setBoundingVolume3v = function (vmin, vmax) {
|
||||
|
||||
this.bsphere.center.set(x, y, z);
|
||||
this.bsphere.radius = this.bsphere.center.distance(new Vec3(vmin.x, vmin.y, vmin.z));
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.setBoundingVolumeArr = function (bounds) {
|
||||
setBoundingVolumeArr(bounds) {
|
||||
this.bbox.setFromBoundsArr(bounds);
|
||||
|
||||
let x = bounds[0] + (bounds[3] - bounds[0]) * 0.5,
|
||||
@ -1175,9 +1183,9 @@ Segment.prototype.setBoundingVolumeArr = function (bounds) {
|
||||
|
||||
this.bsphere.center.set(x, y, z);
|
||||
this.bsphere.radius = this.bsphere.center.distance(new Vec3(bounds[0], bounds[1], bounds[2]));
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.createCoordsBuffers = function (verticesHigh, verticesLow, gridSize) {
|
||||
createCoordsBuffers(verticesHigh, verticesLow, gridSize) {
|
||||
var gsgs = (gridSize + 1) * (gridSize + 1);
|
||||
var h = this.handler;
|
||||
|
||||
@ -1199,9 +1207,9 @@ Segment.prototype.createCoordsBuffers = function (verticesHigh, verticesLow, gri
|
||||
this.vertexPositionBufferHigh = h.createArrayBuffer(verticesHigh, 3, gsgs);
|
||||
this.vertexPositionBufferLow = h.createArrayBuffer(verticesLow, 3, gsgs);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._addViewExtent = function () {
|
||||
_addViewExtent() {
|
||||
var ext = this._extentLonLat;
|
||||
|
||||
if (!this.planet._viewExtent) {
|
||||
@ -1229,9 +1237,9 @@ Segment.prototype._addViewExtent = function () {
|
||||
if (ext.northEast.lat > viewExt.northEast.lat) {
|
||||
viewExt.northEast.lat = ext.northEast.lat;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._assignTileIndexes = function () {
|
||||
_assignTileIndexes() {
|
||||
this._tileGroup = 0;
|
||||
var tileZoom = this.tileZoom;
|
||||
var extent = this._extent;
|
||||
@ -1251,9 +1259,9 @@ Segment.prototype._assignTileIndexes = function () {
|
||||
|
||||
this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
|
||||
this.planet._quadTreeNodesCacheMerc[this.tileIndex] = this.node;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.initialize = function () {
|
||||
initialize() {
|
||||
var p = this.planet;
|
||||
var n = this.node;
|
||||
|
||||
@ -1280,9 +1288,9 @@ Segment.prototype.initialize = function () {
|
||||
this._assignGlobalTextureCoordinates();
|
||||
|
||||
this.initialized = true;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._assignGlobalTextureCoordinates = function () {
|
||||
_assignGlobalTextureCoordinates() {
|
||||
var e = this._extent;
|
||||
this._globalTextureCoordinates[0] =
|
||||
(e.southWest.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
|
||||
@ -1292,9 +1300,9 @@ Segment.prototype._assignGlobalTextureCoordinates = function () {
|
||||
(e.northEast.lon + mercator.POLE) * mercator.ONE_BY_POLE_DOUBLE;
|
||||
this._globalTextureCoordinates[3] =
|
||||
(mercator.POLE - e.southWest.lat) * mercator.ONE_BY_POLE_DOUBLE;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.createPlainSegmentAsync = function () {
|
||||
createPlainSegmentAsync() {
|
||||
let p = this.planet,
|
||||
t = p.terrain;
|
||||
|
||||
@ -1302,15 +1310,15 @@ Segment.prototype.createPlainSegmentAsync = function () {
|
||||
this.plainProcessing = true;
|
||||
p._plainSegmentWorker.make(this);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.createPlainSegment = function () {
|
||||
createPlainSegment() {
|
||||
this.initialize();
|
||||
this._createPlainVertices();
|
||||
this.readyToEngage = true;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._createPlainVertices = function () {
|
||||
_createPlainVertices() {
|
||||
var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
|
||||
|
||||
var e = this._extent,
|
||||
@ -1402,19 +1410,19 @@ Segment.prototype._createPlainVertices = function () {
|
||||
this.terrainVerticesLow = vertsLow;
|
||||
|
||||
this.plainReady = true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets specific layer material.
|
||||
* @public
|
||||
* @param {og.Layer} layer - Layer object.
|
||||
* @returns {og.planetSegment.Material} - Segment material.
|
||||
*/
|
||||
Segment.prototype.getMaterialByLayer = function (layer) {
|
||||
getMaterialByLayer(layer) {
|
||||
return this.materials[layer._id];
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._getLayerExtentOffset = function (layer) {
|
||||
_getLayerExtentOffset(layer) {
|
||||
var v0s = layer._extentMerc;
|
||||
var v0t = this._extent;
|
||||
var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
|
||||
@ -1424,15 +1432,15 @@ Segment.prototype._getLayerExtentOffset = function (layer) {
|
||||
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];
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.screenRendering = function (
|
||||
screenRendering(
|
||||
sh,
|
||||
layerSlice,
|
||||
sliceIndex,
|
||||
defaultTexture,
|
||||
isOverlay
|
||||
) {
|
||||
) {
|
||||
var gl = this.handler.gl;
|
||||
var sha = sh.attributes,
|
||||
shu = sh.uniforms;
|
||||
@ -1580,15 +1588,15 @@ Segment.prototype.screenRendering = function (
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.drawElements(p.drawMode, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.heightPickingRendering = function (
|
||||
heightPickingRendering(
|
||||
sh,
|
||||
layerSlice,
|
||||
sliceIndex,
|
||||
defaultTexture,
|
||||
isOverlay
|
||||
) {
|
||||
) {
|
||||
var gl = this.handler.gl;
|
||||
var sha = sh.attributes,
|
||||
shu = sh.uniforms;
|
||||
@ -1655,15 +1663,15 @@ Segment.prototype.heightPickingRendering = function (
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.colorPickingRendering = function (
|
||||
colorPickingRendering(
|
||||
sh,
|
||||
layerSlice,
|
||||
sliceIndex,
|
||||
defaultTexture,
|
||||
isOverlay
|
||||
) {
|
||||
) {
|
||||
var gl = this.handler.gl;
|
||||
var sha = sh.attributes,
|
||||
shu = sh.uniforms;
|
||||
@ -1737,15 +1745,15 @@ Segment.prototype.colorPickingRendering = function (
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.depthRendering = function (
|
||||
depthRendering(
|
||||
sh,
|
||||
layerSlice,
|
||||
sliceIndex,
|
||||
defaultTexture,
|
||||
isOverlay
|
||||
) {
|
||||
) {
|
||||
var gl = this.handler.gl;
|
||||
var sha = sh.attributes,
|
||||
shu = sh.uniforms;
|
||||
@ -1812,9 +1820,9 @@ Segment.prototype.depthRendering = function (
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.drawElements(gl.TRIANGLE_STRIP, this._indexBuffer.numItems, gl.UNSIGNED_INT, 0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._getIndexBuffer = function () {
|
||||
_getIndexBuffer() {
|
||||
var s = this.node.sideSizeLog2;
|
||||
var cache = this.planet._indexesCache[Math.log2(this.gridSize)][s[0]][s[1]][s[2]][s[3]];
|
||||
if (!cache.buffer) {
|
||||
@ -1826,38 +1834,38 @@ Segment.prototype._getIndexBuffer = function () {
|
||||
indexes = null;
|
||||
}
|
||||
return cache.buffer;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype._collectVisibleNodes = function () {
|
||||
_collectVisibleNodes() {
|
||||
this.planet._visibleNodes[this.node.nodeId] = this.node;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.layerOverlap = function (layer) {
|
||||
layerOverlap(layer) {
|
||||
return this._extent.overlaps(layer._extentMerc);
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getDefaultTexture = function () {
|
||||
getDefaultTexture() {
|
||||
return this.planet.solidTextureOne;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getExtentLonLat = function () {
|
||||
getExtentLonLat() {
|
||||
return this._extentLonLat;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getExtentMerc = function () {
|
||||
getExtentMerc() {
|
||||
return this._extent;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getExtent = function () {
|
||||
getExtent() {
|
||||
return this._extent;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getNodeState = function () {
|
||||
getNodeState() {
|
||||
var vn = this.planet._visibleNodes[this.node.nodeId];
|
||||
return (vn && vn.state) || NOTRENDERING;
|
||||
};
|
||||
};
|
||||
|
||||
Segment.prototype.getNeighborSide = function (b) {
|
||||
getNeighborSide(b) {
|
||||
if (this.tileY === b.tileY) {
|
||||
if (this.tileX === b.tileXE) {
|
||||
return W;
|
||||
@ -1873,6 +1881,6 @@ Segment.prototype.getNeighborSide = function (b) {
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
export { Segment };
|
||||
|
||||
@ -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,36 +25,43 @@ 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) {
|
||||
class SegmentLonLat extends Segment {
|
||||
|
||||
/**
|
||||
* @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;
|
||||
Segment.call(this, node, planet, tileZoom, extent);
|
||||
this._projection = EPSG4326;
|
||||
this._extentMerc = new Extent(
|
||||
extent.southWest.forwardMercatorEPS01(),
|
||||
extent.northEast.forwardMercatorEPS01()
|
||||
);
|
||||
this.isPole = true;
|
||||
};
|
||||
};
|
||||
|
||||
inherits(SegmentLonLat, Segment);
|
||||
|
||||
SegmentLonLat.prototype._setExtentLonLat = function () {
|
||||
_setExtentLonLat() {
|
||||
this._extentLonLat = this._extent;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.projectNative = function (coords) {
|
||||
projectNative(coords) {
|
||||
return coords;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, normal) {
|
||||
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();
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.acceptForRendering = function (camera) {
|
||||
acceptForRendering(camera) {
|
||||
var maxPoleZoom;
|
||||
var lat = this._extent.northEast.lat;
|
||||
if (this._isNorth) {
|
||||
@ -68,9 +74,9 @@ SegmentLonLat.prototype.acceptForRendering = function (camera) {
|
||||
maxPoleZoom = 12 - Math.floor(Yz / 16);
|
||||
}
|
||||
return Segment.prototype.acceptForRendering.call(this, camera) || this.tileZoom >= maxPoleZoom;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._assignTileIndexes = function () {
|
||||
_assignTileIndexes() {
|
||||
var tileZoom = this.tileZoom;
|
||||
var extent = this._extent;
|
||||
|
||||
@ -101,9 +107,9 @@ SegmentLonLat.prototype._assignTileIndexes = function () {
|
||||
this.tileYS = this.tileY + 1;
|
||||
|
||||
this.tileIndex = Layer.getTileIndex(this.tileX, this.tileY, tileZoom);
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._createPlainVertices = function () {
|
||||
_createPlainVertices() {
|
||||
var gridSize = this.planet.terrain.gridSizeByZoom[this.tileZoom];
|
||||
|
||||
var e = this._extent,
|
||||
@ -201,29 +207,29 @@ SegmentLonLat.prototype._createPlainVertices = function () {
|
||||
this.normalMapNormalsRaw.set(nmNorms);
|
||||
|
||||
this.plainReady = true;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._assignGlobalTextureCoordinates = function () {
|
||||
_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;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._collectVisibleNodes = function () {
|
||||
_collectVisibleNodes() {
|
||||
if (this._isNorth) {
|
||||
this.planet._visibleNodesNorth[this.node.nodeId] = this.node;
|
||||
} else {
|
||||
this.planet._visibleNodesSouth[this.node.nodeId] = this.node;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.isEntityInside = function (e) {
|
||||
isEntityInside(e) {
|
||||
return this._extent.isInside(e._lonlat);
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._getLayerExtentOffset = function (layer) {
|
||||
_getLayerExtentOffset(layer) {
|
||||
var v0s = layer._extent;
|
||||
var v0t = this._extent;
|
||||
var sSize_x = v0s.northEast.lon - v0s.southWest.lon;
|
||||
@ -233,25 +239,25 @@ SegmentLonLat.prototype._getLayerExtentOffset = function (layer) {
|
||||
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];
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.layerOverlap = function (layer) {
|
||||
layerOverlap(layer) {
|
||||
return this._extent.overlaps(layer._extent);
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.getDefaultTexture = function () {
|
||||
getDefaultTexture() {
|
||||
return this._isNorth ? this.planet.solidTextureOne : this.planet.solidTextureTwo;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.getExtentLonLat = function () {
|
||||
getExtentLonLat() {
|
||||
return this._extent;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.getExtentMerc = function () {
|
||||
getExtentMerc() {
|
||||
return this._extentMerc;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype.getNodeState = function () {
|
||||
getNodeState() {
|
||||
var vn;
|
||||
if (this._isNorth) {
|
||||
vn = this.planet._visibleNodesNorth[this.node.nodeId];
|
||||
@ -259,10 +265,11 @@ SegmentLonLat.prototype.getNodeState = function () {
|
||||
vn = this.planet._visibleNodesSouth[this.node.nodeId];
|
||||
}
|
||||
return (vn && vn.state) || quadTree.NOTRENDERING;
|
||||
};
|
||||
};
|
||||
|
||||
SegmentLonLat.prototype._freeCache = function () {
|
||||
_freeCache() {
|
||||
//empty for a time
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
export { SegmentLonLat };
|
||||
|
||||
18
tests/quadTree/EntityCollectionNode.test.js
Normal file
18
tests/quadTree/EntityCollectionNode.test.js
Normal 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();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user