mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
使用rollup改写。
This commit is contained in:
parent
e983bb9bff
commit
affeb76785
@ -4,7 +4,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>ZeroGIS</title>
|
||||
<title>Web Globe</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
|
||||
@ -1,61 +1,2 @@
|
||||
require.config({
|
||||
baseUrl: "js",
|
||||
paths: {
|
||||
world: "world"
|
||||
},
|
||||
waitSeconds: 0
|
||||
});
|
||||
|
||||
window.onload = function () {
|
||||
require(["world/Globe", "world/BingTiledLayer", "world/NokiaTiledLayer", "world/OsmTiledLayer", "world/SosoTiledLayer", "world/TiandituTiledLayer", "world/GoogleTiledLayer"],
|
||||
function (Globe, BingTiledLayer, NokiaTiledLayer, OsmTiledLayer, SosoTiledLayer, TiandituTiledLayer, GoogleTiledLayer) {
|
||||
|
||||
var canvas, globe;
|
||||
|
||||
function startWebGL() {
|
||||
globe = new Globe(canvas);
|
||||
var mapSelector = document.getElementById("container");
|
||||
mapSelector.onchange = changeTiledLayer;
|
||||
changeTiledLayer();
|
||||
}
|
||||
|
||||
function changeTiledLayer() {
|
||||
var mapSelector = document.getElementById("mapSelector");
|
||||
mapSelector.blur();
|
||||
var newTiledLayer = null;
|
||||
var args = null;
|
||||
var value = mapSelector.value;
|
||||
switch (value) {
|
||||
case "google":
|
||||
newTiledLayer = new GoogleTiledLayer();
|
||||
break;
|
||||
case "bing":
|
||||
newTiledLayer = new BingTiledLayer();
|
||||
break;
|
||||
case "osm":
|
||||
newTiledLayer = new OsmTiledLayer();
|
||||
break;
|
||||
case "soso":
|
||||
newTiledLayer = new SosoTiledLayer();
|
||||
break;
|
||||
case "tianditu":
|
||||
newTiledLayer = new TiandituTiledLayer();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (newTiledLayer) {
|
||||
globe.setTiledLayer(newTiledLayer);
|
||||
}
|
||||
}
|
||||
|
||||
function initAll() {
|
||||
canvas = document.getElementById("container");
|
||||
startWebGL();
|
||||
}
|
||||
|
||||
canvas = document.getElementById("container");
|
||||
startWebGL();
|
||||
});
|
||||
};
|
||||
export { default as Globe } from './world/Globe';
|
||||
export { default as GoogleTiledLayer } from './world/GoogleTiledLayer';
|
||||
File diff suppressed because one or more lines are too long
@ -1,20 +1,24 @@
|
||||
define(["world/Kernel", "world/TiledLayer"], function(Kernel, TiledLayer) {
|
||||
//使用代理
|
||||
var ArcGISTiledLayer = function(args) {
|
||||
import Kernel from './Kernel';
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
//使用代理
|
||||
var ArcGISTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
this.service = "";
|
||||
if (args) {
|
||||
if (args.url) {
|
||||
this.service = args.url;
|
||||
}
|
||||
if (args.url) {
|
||||
this.service = args.url;
|
||||
}
|
||||
}
|
||||
};
|
||||
ArcGISTiledLayer.prototype = new TiledLayer();
|
||||
ArcGISTiledLayer.prototype.constructor = ArcGISTiledLayer;
|
||||
ArcGISTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
ArcGISTiledLayer.prototype = new TiledLayer();
|
||||
ArcGISTiledLayer.prototype.constructor = ArcGISTiledLayer;
|
||||
|
||||
ArcGISTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var url = Kernel.proxy + "?" + this.service + "/tile/" + level + "/" + row + "/" + column;
|
||||
return url;
|
||||
};
|
||||
return ArcGISTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default ArcGISTiledLayer;
|
||||
@ -1,16 +1,20 @@
|
||||
define(["world/Kernel", "world/TiledLayer"], function(Kernel, TiledLayer) {
|
||||
//使用代理
|
||||
var AutonaviTiledLayer = function(args) {
|
||||
import Kernel from './Kernel';
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
//使用代理
|
||||
var AutonaviTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
AutonaviTiledLayer.prototype = new TiledLayer();
|
||||
AutonaviTiledLayer.prototype.constructor = AutonaviTiledLayer;
|
||||
AutonaviTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
AutonaviTiledLayer.prototype = new TiledLayer();
|
||||
AutonaviTiledLayer.prototype.constructor = AutonaviTiledLayer;
|
||||
|
||||
AutonaviTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var sum = level + row + column;
|
||||
var serverIdx = 1 + sum % 4; //1、2、3、4
|
||||
var url = Kernel.proxy + "?//webrd0" + serverIdx + ".is.autonavi.com/appmaptile?x=" + column + "&y=" + row + "&z=" + level + "&lang=zh_cn&size=1&scale=1&style=8";
|
||||
return url;
|
||||
};
|
||||
return AutonaviTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default AutonaviTiledLayer;
|
||||
@ -1,11 +1,15 @@
|
||||
define(["world/Math", "world/TiledLayer"], function(MathUtils, TiledLayer) {
|
||||
//Bing地图
|
||||
var BingTiledLayer = function(args) {
|
||||
import Math from './Math';
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
//Bing地图
|
||||
var BingTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
BingTiledLayer.prototype = new TiledLayer();
|
||||
BingTiledLayer.prototype.constructor = BingTiledLayer;
|
||||
BingTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
BingTiledLayer.prototype = new TiledLayer();
|
||||
BingTiledLayer.prototype.constructor = BingTiledLayer;
|
||||
|
||||
BingTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var url = "";
|
||||
var tileX = column;
|
||||
@ -15,34 +19,33 @@ define(["world/Math", "world/TiledLayer"], function(MathUtils, TiledLayer) {
|
||||
var delta = strTileX2.length - strTileY2.length;
|
||||
var i;
|
||||
if (delta > 0) {
|
||||
for (i = 0; i < delta; i++) {
|
||||
strTileY2 = '0' + strTileY2;
|
||||
}
|
||||
for (i = 0; i < delta; i++) {
|
||||
strTileY2 = '0' + strTileY2;
|
||||
}
|
||||
} else if (delta < 0) {
|
||||
delta = -delta;
|
||||
for (i = 0; i < delta; i++) {
|
||||
strTileX2 = '0' + strTileX2;
|
||||
}
|
||||
delta = -delta;
|
||||
for (i = 0; i < delta; i++) {
|
||||
strTileX2 = '0' + strTileX2;
|
||||
}
|
||||
}
|
||||
var strMerge2 = "";
|
||||
for (i = 0; i < strTileY2.length; i++) {
|
||||
var charY = strTileY2[i];
|
||||
var charX = strTileX2[i];
|
||||
strMerge2 += charY + charX;
|
||||
var charY = strTileY2[i];
|
||||
var charX = strTileX2[i];
|
||||
strMerge2 += charY + charX;
|
||||
}
|
||||
var strMerge4 = MathUtils.numerationSystemChange(2, 4, strMerge2);
|
||||
if (strMerge4.length < level) {
|
||||
delta = level - strMerge4.length;
|
||||
for (i = 0; i < delta; i++) {
|
||||
strMerge4 = '0' + strMerge4;
|
||||
}
|
||||
delta = level - strMerge4.length;
|
||||
for (i = 0; i < delta; i++) {
|
||||
strMerge4 = '0' + strMerge4;
|
||||
}
|
||||
}
|
||||
var sum = level + row + column;
|
||||
var serverIdx = sum % 8; //0,1,2,3,4,5,6,7
|
||||
//var styles = ['a','r','h']
|
||||
url = "//ecn.t" + serverIdx + ".tiles.virtualearth.net/tiles/h" + strMerge4 + ".jpeg?g=1239&mkt=en-us";
|
||||
return url;
|
||||
};
|
||||
};
|
||||
|
||||
return BingTiledLayer;
|
||||
});
|
||||
export default BingTiledLayer;
|
||||
@ -1,16 +1,22 @@
|
||||
define(["world/TiledLayer", "world/NokiaTiledLayer", "world/GoogleTiledLayer", "world/OsmTiledLayer"], function(TiledLayer) {
|
||||
var BlendTiledLayer = function(args) {
|
||||
import TiledLayer from './TiledLayer';
|
||||
import NokiaTiledLayer from './NokiaTiledLayer';
|
||||
import GoogleTiledLayer from './GoogleTiledLayer';
|
||||
import OsmTiledLayer from './OsmTiledLayer';
|
||||
|
||||
var BlendTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
BlendTiledLayer.prototype = new TiledLayer();
|
||||
BlendTiledLayer.prototype.constructor = BlendTiledLayer;
|
||||
BlendTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
BlendTiledLayer.prototype = new TiledLayer();
|
||||
BlendTiledLayer.prototype.constructor = BlendTiledLayer;
|
||||
|
||||
BlendTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var array = [NokiaTiledLayer, GoogleTiledLayer, OsmTiledLayer];
|
||||
var sum = level + row + column;
|
||||
var idx = sum % 3;
|
||||
var url = array[idx].prototype.getImageUrl.apply(this, arguments);
|
||||
return url;
|
||||
};
|
||||
return BlendTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default BlendTiledLayer;
|
||||
@ -1,41 +1,44 @@
|
||||
define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, MathUtils) {
|
||||
var Elevation = {
|
||||
import Kernel from './Kernel';
|
||||
import Utils from './Utils';
|
||||
import MathUtils from './Math';
|
||||
|
||||
var Elevation = {
|
||||
//sampleserver4.arcgisonline.com
|
||||
//23.21.85.73
|
||||
elevationUrl: "//sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationData",
|
||||
elevations: {}, //缓存的高程数据
|
||||
factor: 1 //高程缩放因子
|
||||
};
|
||||
//根据level获取包含level高程信息的ancestorElevationLevel
|
||||
Elevation.getAncestorElevationLevel = function(level) {
|
||||
};
|
||||
//根据level获取包含level高程信息的ancestorElevationLevel
|
||||
Elevation.getAncestorElevationLevel = function (level) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
var a = Math.floor((level - 1 - Kernel.ELEVATION_LEVEL) / 3);
|
||||
var ancestor = Kernel.ELEVATION_LEVEL + 3 * a;
|
||||
return ancestor;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据传入的extent以及行列数请求高程数据,返回(segment+1) * (segment+1)个数据,且乘积不能超过10000
|
||||
* 也就是说如果传递的是一个正方形的extent,那么segment最大取99,此处设置的segment是80
|
||||
*/
|
||||
Elevation.requestElevationsByTileGrid = function(level, row, column) {
|
||||
/**
|
||||
* 根据传入的extent以及行列数请求高程数据,返回(segment+1) * (segment+1)个数据,且乘积不能超过10000
|
||||
* 也就是说如果传递的是一个正方形的extent,那么segment最大取99,此处设置的segment是80
|
||||
*/
|
||||
Elevation.requestElevationsByTileGrid = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
var segment = 80;
|
||||
var name = level + "_" + row + "_" + column;
|
||||
//只要elevations中有属性name,那么就表示该高程已经请求过或正在请求,这样就不要重新请求了
|
||||
//只有在完全没请求过的情况下去请求高程数据
|
||||
if (this.elevations.hasOwnProperty(name)) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
this.elevations[name] = null;
|
||||
var Eproj = MathUtils.getTileWebMercatorEnvelopeByGrid(level, row, column);
|
||||
@ -48,13 +51,13 @@ define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, Ma
|
||||
var a = gridWidth / 2;
|
||||
var b = gridHeight / 2;
|
||||
var extent = {
|
||||
xmin: minX - a,
|
||||
ymin: minY - b,
|
||||
xmax: maxX + a,
|
||||
ymax: maxY + b,
|
||||
spatialReference: {
|
||||
wkid: 102100
|
||||
}
|
||||
xmin: minX - a,
|
||||
ymin: minY - b,
|
||||
xmax: maxX + a,
|
||||
ymax: maxY + b,
|
||||
spatialReference: {
|
||||
wkid: 102100
|
||||
}
|
||||
};
|
||||
var strExtent = encodeURIComponent(JSON.stringify(extent));
|
||||
var rows = segment + 1;
|
||||
@ -64,62 +67,62 @@ define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, Ma
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
function callback() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
try {
|
||||
var result = JSON.parse(xhr.responseText);
|
||||
if (this.factor == 1) {
|
||||
this.elevations[name] = result.data;
|
||||
} else {
|
||||
this.elevations[name] = Utils.map(function(item) {
|
||||
return item * this.factor;
|
||||
}.bind(this));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("requestElevationsByTileGrid_callback error", e);
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
try {
|
||||
var result = JSON.parse(xhr.responseText);
|
||||
if (this.factor == 1) {
|
||||
this.elevations[name] = result.data;
|
||||
} else {
|
||||
this.elevations[name] = Utils.map(function (item) {
|
||||
return item * this.factor;
|
||||
}.bind(this));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("requestElevationsByTileGrid_callback error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.onreadystatechange = callback.bind(this);
|
||||
xhr.open("GET", "proxy.jsp?" + this.elevationUrl + "?" + args, true);
|
||||
xhr.send();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
//无论怎样都尽量返回高程值,如果存在精确的高程,就获取精确高程;如果精确高程不存在,就返回上一个高程级别的估算高程
|
||||
//有可能
|
||||
Elevation.getElevation = function(level, row, column) {
|
||||
//无论怎样都尽量返回高程值,如果存在精确的高程,就获取精确高程;如果精确高程不存在,就返回上一个高程级别的估算高程
|
||||
//有可能
|
||||
Elevation.getElevation = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
var result = null;
|
||||
var exactResult = this.getExactElevation(level, row, column);
|
||||
if (exactResult) {
|
||||
//获取到准确高程
|
||||
result = exactResult;
|
||||
//获取到准确高程
|
||||
result = exactResult;
|
||||
} else {
|
||||
//获取插值高程
|
||||
result = this.getLinearElevation(level, row, column);
|
||||
//获取插值高程
|
||||
result = this.getLinearElevation(level, row, column);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
//把>=8级的任意一个切片的tileGrid传进去,返回其高程值,该高程值是经过过滤了的,就是从大切片数据中抽吸出了其自身的高程信息
|
||||
//获取准确高程
|
||||
Elevation.getExactElevation = function(level, row, column) {
|
||||
//把>=8级的任意一个切片的tileGrid传进去,返回其高程值,该高程值是经过过滤了的,就是从大切片数据中抽吸出了其自身的高程信息
|
||||
//获取准确高程
|
||||
Elevation.getExactElevation = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
var result = null;
|
||||
var elevationLevel = this.getAncestorElevationLevel(level);
|
||||
@ -127,59 +130,59 @@ define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, Ma
|
||||
var elevationTileName = elevationTileGrid.level + "_" + elevationTileGrid.row + "_" + elevationTileGrid.column;
|
||||
var ancestorElevations = this.elevations[elevationTileName];
|
||||
if (ancestorElevations instanceof Array && ancestorElevations.length > 0) {
|
||||
if (level > Kernel.ELEVATION_LEVEL) {
|
||||
//ltTileGridLevel表示level级别下位于Tile7左上角的TileGrid
|
||||
var ltTileGridLevel = {
|
||||
level: elevationTileGrid.level,
|
||||
row: elevationTileGrid.row,
|
||||
column: elevationTileGrid.column
|
||||
}; //与level在同级别下但是在Tile7左上角的那个TileGrid
|
||||
while (ltTileGridLevel.level != level) {
|
||||
ltTileGridLevel = MathUtils.getTileGridByParent(ltTileGridLevel.level, ltTileGridLevel.row, ltTileGridLevel.column, MathUtils.LEFT_TOP);
|
||||
}
|
||||
if (ltTileGridLevel.level == level) {
|
||||
//bigRow表示在level等级下当前grid距离左上角的grid的行数
|
||||
var bigRow = row - ltTileGridLevel.row;
|
||||
//bigColumn表示在level等级下当前grid距离左上角的grid的列数
|
||||
var bigColumn = column - ltTileGridLevel.column;
|
||||
var a = 81; //T7包含(80+1)*(80+1)个高程数据
|
||||
var deltaLevel = (elevationLevel + 3) - level; //当前level与T10相差的等级
|
||||
var deltaCount = Math.pow(2, deltaLevel); //一个当前tile能包含deltaCount*deltaCount个第10级的tile
|
||||
//startSmallIndex表示该tile的左上角点在81*81的点阵中的索引号
|
||||
//bigRow*deltaCount表示当前切片距离T7最上面的切片的行包含了多少T10行,再乘以10表示跨过的高程点阵行数
|
||||
//bigColumn*deltaCount表示当前切片距离T7最左边的切片的列包含了多少T10列,再乘以10表示跨国的高程点阵列数
|
||||
var startSmallIndex = (bigRow * deltaCount * 10) * a + bigColumn * deltaCount * 10;
|
||||
result = {
|
||||
sourceLevel: elevationLevel,
|
||||
elevations: []
|
||||
};
|
||||
for (var i = 0; i <= 10; i++) {
|
||||
var idx = startSmallIndex;
|
||||
for (var j = 0; j <= 10; j++) {
|
||||
var ele = ancestorElevations[idx];
|
||||
result.elevations.push(ele);
|
||||
idx += deltaCount;
|
||||
if (level > Kernel.ELEVATION_LEVEL) {
|
||||
//ltTileGridLevel表示level级别下位于Tile7左上角的TileGrid
|
||||
var ltTileGridLevel = {
|
||||
level: elevationTileGrid.level,
|
||||
row: elevationTileGrid.row,
|
||||
column: elevationTileGrid.column
|
||||
}; //与level在同级别下但是在Tile7左上角的那个TileGrid
|
||||
while (ltTileGridLevel.level != level) {
|
||||
ltTileGridLevel = MathUtils.getTileGridByParent(ltTileGridLevel.level, ltTileGridLevel.row, ltTileGridLevel.column, MathUtils.LEFT_TOP);
|
||||
}
|
||||
if (ltTileGridLevel.level == level) {
|
||||
//bigRow表示在level等级下当前grid距离左上角的grid的行数
|
||||
var bigRow = row - ltTileGridLevel.row;
|
||||
//bigColumn表示在level等级下当前grid距离左上角的grid的列数
|
||||
var bigColumn = column - ltTileGridLevel.column;
|
||||
var a = 81; //T7包含(80+1)*(80+1)个高程数据
|
||||
var deltaLevel = (elevationLevel + 3) - level; //当前level与T10相差的等级
|
||||
var deltaCount = Math.pow(2, deltaLevel); //一个当前tile能包含deltaCount*deltaCount个第10级的tile
|
||||
//startSmallIndex表示该tile的左上角点在81*81的点阵中的索引号
|
||||
//bigRow*deltaCount表示当前切片距离T7最上面的切片的行包含了多少T10行,再乘以10表示跨过的高程点阵行数
|
||||
//bigColumn*deltaCount表示当前切片距离T7最左边的切片的列包含了多少T10列,再乘以10表示跨国的高程点阵列数
|
||||
var startSmallIndex = (bigRow * deltaCount * 10) * a + bigColumn * deltaCount * 10;
|
||||
result = {
|
||||
sourceLevel: elevationLevel,
|
||||
elevations: []
|
||||
};
|
||||
for (var i = 0; i <= 10; i++) {
|
||||
var idx = startSmallIndex;
|
||||
for (var j = 0; j <= 10; j++) {
|
||||
var ele = ancestorElevations[idx];
|
||||
result.elevations.push(ele);
|
||||
idx += deltaCount;
|
||||
}
|
||||
//遍历完一行之后往下移,startSmallIndex表示一行的左边的起点
|
||||
startSmallIndex += deltaCount * a;
|
||||
}
|
||||
}
|
||||
//遍历完一行之后往下移,startSmallIndex表示一行的左边的起点
|
||||
startSmallIndex += deltaCount * a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
//获取线性插值的高程,比如要找E12的估算高程,那么就先找到E10的精确高程,E10的精确高程是从E7中提取的
|
||||
//即E7(81*81)->E10(11*11)->插值计算E11、E12、E13
|
||||
Elevation.getLinearElevation = function(level, row, column) {
|
||||
//获取线性插值的高程,比如要找E12的估算高程,那么就先找到E10的精确高程,E10的精确高程是从E7中提取的
|
||||
//即E7(81*81)->E10(11*11)->插值计算E11、E12、E13
|
||||
Elevation.getLinearElevation = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
var result = null;
|
||||
var elevationLevel = this.getAncestorElevationLevel(level);
|
||||
@ -187,35 +190,35 @@ define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, Ma
|
||||
var exactAncestorElevations = this.getExactElevation(elevationTileGrid.level, elevationTileGrid.row, elevationTileGrid.column);
|
||||
var deltaLevel = level - elevationLevel;
|
||||
if (exactAncestorElevations) {
|
||||
result = {
|
||||
sourceLevel: elevationLevel - 3,
|
||||
elevations: null
|
||||
};
|
||||
if (deltaLevel == 1) {
|
||||
result.elevations = this.getLinearElevationFromParent(exactAncestorElevations, level, row, column);
|
||||
} else if (deltaLevel == 2) {
|
||||
result.elevations = this.getLinearElevationFromParent2(exactAncestorElevations, level, row, column);
|
||||
} else if (deltaLevel == 3) {
|
||||
result.elevations = this.getLinearElevationFromParent3(exactAncestorElevations, level, row, column);
|
||||
}
|
||||
result = {
|
||||
sourceLevel: elevationLevel - 3,
|
||||
elevations: null
|
||||
};
|
||||
if (deltaLevel == 1) {
|
||||
result.elevations = this.getLinearElevationFromParent(exactAncestorElevations, level, row, column);
|
||||
} else if (deltaLevel == 2) {
|
||||
result.elevations = this.getLinearElevationFromParent2(exactAncestorElevations, level, row, column);
|
||||
} else if (deltaLevel == 3) {
|
||||
result.elevations = this.getLinearElevationFromParent3(exactAncestorElevations, level, row, column);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
//从直接父节点的高程数据中获取不是很准确的高程数据,比如T11从E10的高程中(10+1)*(10+1)中获取不是很准确的高程
|
||||
//通过线性插值的方式获取高程,不精确
|
||||
Elevation.getLinearElevationFromParent = function(parentElevations, level, row, column) {
|
||||
//从直接父节点的高程数据中获取不是很准确的高程数据,比如T11从E10的高程中(10+1)*(10+1)中获取不是很准确的高程
|
||||
//通过线性插值的方式获取高程,不精确
|
||||
Elevation.getLinearElevationFromParent = function (parentElevations, level, row, column) {
|
||||
if (!(Utils.isArray(parentElevations) && parentElevations.length > 0)) {
|
||||
throw "invalid parentElevations";
|
||||
throw "invalid parentElevations";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
//position为切片在直接父切片中的位置
|
||||
var position = MathUtils.getTilePositionOfParent(level, row, column);
|
||||
@ -223,81 +226,81 @@ define(["world/Kernel", "world/Utils", "world/Math"], function(Kernel, Utils, Ma
|
||||
var elevatios6_6 = [];
|
||||
var startIndex = 0;
|
||||
if (position == MathUtils.LEFT_TOP) {
|
||||
startIndex = 0;
|
||||
startIndex = 0;
|
||||
} else if (position == MathUtils.RIGHT_TOP) {
|
||||
startIndex = 5;
|
||||
startIndex = 5;
|
||||
} else if (position == MathUtils.LEFT_BOTTOM) {
|
||||
startIndex = 11 * 5;
|
||||
startIndex = 11 * 5;
|
||||
} else if (position == MathUtils.RIGHT_BOTTOM) {
|
||||
startIndex = 60;
|
||||
startIndex = 60;
|
||||
}
|
||||
var i,j,idx;
|
||||
var i, j, idx;
|
||||
for (i = 0; i <= 5; i++) {
|
||||
idx = startIndex;
|
||||
for (j = 0; j <= 5; j++) {
|
||||
var ele = parentElevations[idx];
|
||||
elevatios6_6.push(ele);
|
||||
idx++;
|
||||
}
|
||||
//下移一行
|
||||
startIndex += 11;
|
||||
idx = startIndex;
|
||||
for (j = 0; j <= 5; j++) {
|
||||
var ele = parentElevations[idx];
|
||||
elevatios6_6.push(ele);
|
||||
idx++;
|
||||
}
|
||||
//下移一行
|
||||
startIndex += 11;
|
||||
}
|
||||
//此时elevatios6_6表示的(5+1)*(5+1)的高程数据信息
|
||||
|
||||
var eleExact,eleExactTop,eleLinear;
|
||||
var eleExact, eleExactTop, eleLinear;
|
||||
//下面通过对每一行上的6个点数字两两取平均变成11个点数据
|
||||
var elevations6_11 = [];
|
||||
for (i = 0; i <= 5; i++) {
|
||||
for (j = 0; j <= 5; j++) {
|
||||
idx = 6 * i + j;
|
||||
eleExact = elevatios6_6[idx];
|
||||
if (j > 0) {
|
||||
eleExactLeft = elevatios6_6[idx - 1];
|
||||
eleLinear = (eleExactLeft + eleExact) / 2;
|
||||
elevations6_11.push(eleLinear);
|
||||
for (j = 0; j <= 5; j++) {
|
||||
idx = 6 * i + j;
|
||||
eleExact = elevatios6_6[idx];
|
||||
if (j > 0) {
|
||||
eleExactLeft = elevatios6_6[idx - 1];
|
||||
eleLinear = (eleExactLeft + eleExact) / 2;
|
||||
elevations6_11.push(eleLinear);
|
||||
}
|
||||
elevations6_11.push(eleExact);
|
||||
}
|
||||
elevations6_11.push(eleExact);
|
||||
}
|
||||
}
|
||||
//此时elevations6_11表示的是(5+1)*(10+1)的高程数据信息,对每行进行了线性插值
|
||||
|
||||
//下面要对每列进行线性插值,使得每列上的6个点数字两两取平均变成11个点数据
|
||||
var elevations11_11 = [];
|
||||
for (i = 0; i <= 5; i++) {
|
||||
for (j = 0; j <= 10; j++) {
|
||||
idx = 11 * i + j;
|
||||
eleExact = elevations6_11[idx];
|
||||
if (i > 0) {
|
||||
eleExactTop = elevations6_11[idx - 11];
|
||||
eleLinear = (eleExactTop + eleExact) / 2;
|
||||
elevations11_11[(2 * i - 1) * 11 + j] = eleLinear;
|
||||
for (j = 0; j <= 10; j++) {
|
||||
idx = 11 * i + j;
|
||||
eleExact = elevations6_11[idx];
|
||||
if (i > 0) {
|
||||
eleExactTop = elevations6_11[idx - 11];
|
||||
eleLinear = (eleExactTop + eleExact) / 2;
|
||||
elevations11_11[(2 * i - 1) * 11 + j] = eleLinear;
|
||||
}
|
||||
elevations11_11[2 * i * 11 + j] = eleExact;
|
||||
}
|
||||
elevations11_11[2 * i * 11 + j] = eleExact;
|
||||
}
|
||||
}
|
||||
//此时elevations11_11表示的是(10+1)*(10+1)的高程数据信息
|
||||
|
||||
return elevations11_11;
|
||||
};
|
||||
};
|
||||
|
||||
//从相隔两级的高程中获取线性插值数据,比如从T10上面获取T12的高程数据
|
||||
//parent2Elevations是(10+1)*(10+1)的高程数据
|
||||
//level、row、column是子孙切片的信息
|
||||
Elevation.getLinearElevationFromParent2 = function(parent2Elevations, level, row, column) {
|
||||
//从相隔两级的高程中获取线性插值数据,比如从T10上面获取T12的高程数据
|
||||
//parent2Elevations是(10+1)*(10+1)的高程数据
|
||||
//level、row、column是子孙切片的信息
|
||||
Elevation.getLinearElevationFromParent2 = function (parent2Elevations, level, row, column) {
|
||||
var parentTileGrid = MathUtils.getTileGridAncestor(level - 1, level, row, column);
|
||||
var parentElevations = this.getLinearElevationFromParent(parent2Elevations, parentTileGrid.level, parentTileGrid.row, parentTileGrid.column);
|
||||
var elevations = this.getLinearElevationFromParent(parentElevations, level, row, column);
|
||||
return elevations;
|
||||
};
|
||||
};
|
||||
|
||||
//从相隔三级的高程中获取线性插值数据,比如从T10上面获取T13的高程数据
|
||||
//parent3Elevations是(10+1)*(10+1)的高程数据
|
||||
//level、row、column是重孙切片的信息
|
||||
Elevation.getLinearElevationFromParent3 = function(parent3Elevations, level, row, column) {
|
||||
//从相隔三级的高程中获取线性插值数据,比如从T10上面获取T13的高程数据
|
||||
//parent3Elevations是(10+1)*(10+1)的高程数据
|
||||
//level、row、column是重孙切片的信息
|
||||
Elevation.getLinearElevationFromParent3 = function (parent3Elevations, level, row, column) {
|
||||
var parentTileGrid = MathUtils.getTileGridAncestor(level - 1, level, row, column);
|
||||
var parentElevations = this.getLinearElevationFromParent2(parent3Elevations, parentTileGrid.level, parentTileGrid.row, parentTileGrid.column);
|
||||
var elevations = this.getLinearElevationFromParent(parentElevations, level, row, column);
|
||||
return elevations;
|
||||
};
|
||||
return Elevation;
|
||||
});
|
||||
};
|
||||
|
||||
export default Elevation;
|
||||
@ -1,12 +1,14 @@
|
||||
define({
|
||||
UNKNOWN:"UNKNOWN",
|
||||
FULL_IN:"FULL_IN",
|
||||
FULL_OUT:"FULL_OUT",
|
||||
IN_OUT:"IN_OUT",
|
||||
NOKIA_TILED_MAP:"NOKIA_TILED_MAP",
|
||||
Google_TILED_MAP:"Google_TILED_MAP",
|
||||
OSM_TILED_MAP:"OSM_TILED_MAP",
|
||||
BLENDED_TILED_MAP:"BLENDED_TILED_MAP",
|
||||
GLOBE_TILE:"GLOBE_TILE",
|
||||
TERRAIN_TILE:"TERRAIN_TILE"
|
||||
});
|
||||
var Enum = {
|
||||
UNKNOWN: "UNKNOWN",
|
||||
FULL_IN: "FULL_IN",
|
||||
FULL_OUT: "FULL_OUT",
|
||||
IN_OUT: "IN_OUT",
|
||||
NOKIA_TILED_MAP: "NOKIA_TILED_MAP",
|
||||
Google_TILED_MAP: "Google_TILED_MAP",
|
||||
OSM_TILED_MAP: "OSM_TILED_MAP",
|
||||
BLENDED_TILED_MAP: "BLENDED_TILED_MAP",
|
||||
GLOBE_TILE: "GLOBE_TILE",
|
||||
TERRAIN_TILE: "TERRAIN_TILE"
|
||||
};
|
||||
|
||||
export default Enum;
|
||||
@ -1,5 +1,8 @@
|
||||
define(["world/Kernel", "world/Math", "world/Vector"], function(Kernel, MathUtils, Vector) {
|
||||
var EventModule = {
|
||||
import Kernel from './Kernel';
|
||||
import MathUtils from './Math';
|
||||
import Vector from './Vector';
|
||||
|
||||
var EventModule = {
|
||||
canvas: null,
|
||||
bMouseDown: false,
|
||||
dragGeo: null,
|
||||
@ -7,202 +10,202 @@ define(["world/Kernel", "world/Math", "world/Vector"], function(Kernel, MathUtil
|
||||
previousY: -1,
|
||||
onMouseMoveListener: null,
|
||||
|
||||
bindEvents: function(canvas) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
throw "invalid canvas: not HTMLCanvasElement";
|
||||
}
|
||||
this.canvas = canvas;
|
||||
this.onMouseMoveListener = this.onMouseMove.bind(this);
|
||||
window.addEventListener("resize", this.initLayout.bind(this));
|
||||
this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
|
||||
this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
|
||||
this.canvas.addEventListener("dblclick", this.onDbClick.bind(this));
|
||||
this.canvas.addEventListener("mousewheel", this.onMouseWheel.bind(this));
|
||||
this.canvas.addEventListener("DOMMouseScroll", this.onMouseWheel.bind(this));
|
||||
document.body.addEventListener("keydown", this.onKeyDown.bind(this));
|
||||
bindEvents: function (canvas) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
throw "invalid canvas: not HTMLCanvasElement";
|
||||
}
|
||||
this.canvas = canvas;
|
||||
this.onMouseMoveListener = this.onMouseMove.bind(this);
|
||||
window.addEventListener("resize", this.initLayout.bind(this));
|
||||
this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
|
||||
this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
|
||||
this.canvas.addEventListener("dblclick", this.onDbClick.bind(this));
|
||||
this.canvas.addEventListener("mousewheel", this.onMouseWheel.bind(this));
|
||||
this.canvas.addEventListener("DOMMouseScroll", this.onMouseWheel.bind(this));
|
||||
document.body.addEventListener("keydown", this.onKeyDown.bind(this));
|
||||
},
|
||||
|
||||
initLayout: function() {
|
||||
if (this.canvas instanceof HTMLCanvasElement) {
|
||||
this.canvas.width = document.body.clientWidth;
|
||||
this.canvas.height = document.body.clientHeight;
|
||||
if (Kernel.globe) {
|
||||
Kernel.globe.camera.setAspect(this.canvas.width / this.canvas.height);
|
||||
Kernel.globe.refresh();
|
||||
initLayout: function () {
|
||||
if (this.canvas instanceof HTMLCanvasElement) {
|
||||
this.canvas.width = document.body.clientWidth;
|
||||
this.canvas.height = document.body.clientHeight;
|
||||
if (Kernel.globe) {
|
||||
Kernel.globe.camera.setAspect(this.canvas.width / this.canvas.height);
|
||||
Kernel.globe.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//将地球表面的某一点移动到Canvas上
|
||||
moveLonLatToCanvas: function(lon, lat, canvasX, canvasY) {
|
||||
var pickResult = Kernel.globe.camera.getPickCartesianCoordInEarthByCanvas(canvasX, canvasY);
|
||||
if (pickResult.length > 0) {
|
||||
var newLonLat = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
var newLon = newLonLat[0];
|
||||
var newLat = newLonLat[1];
|
||||
this.moveGeo(lon, lat, newLon, newLat);
|
||||
}
|
||||
},
|
||||
|
||||
moveGeo: function(oldLon, oldLat, newLon, newLat) {
|
||||
var camera = Kernel.globe.camera;
|
||||
var deltaLonRadian = -MathUtils.degreeToRadian(newLon - oldLon); //旋转的经度
|
||||
var deltaLatRadian = MathUtils.degreeToRadian(newLat - oldLat); //旋转的纬度
|
||||
camera.worldRotateY(deltaLonRadian);
|
||||
var lightDir = camera.getLightDirection();
|
||||
var plumbVector = this.getPlumbVector(lightDir);
|
||||
camera.worldRotateByVector(deltaLatRadian, plumbVector);
|
||||
},
|
||||
|
||||
onMouseDown: function(event) {
|
||||
if (Kernel.globe) {
|
||||
this.bMouseDown = true;
|
||||
this.previousX = event.layerX || event.offsetX;
|
||||
this.previousY = event.layerY || event.offsetY;
|
||||
var pickResult = Kernel.globe.camera.getPickCartesianCoordInEarthByCanvas(this.previousX, this.previousY);
|
||||
moveLonLatToCanvas: function (lon, lat, canvasX, canvasY) {
|
||||
var pickResult = Kernel.globe.camera.getPickCartesianCoordInEarthByCanvas(canvasX, canvasY);
|
||||
if (pickResult.length > 0) {
|
||||
this.dragGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
console.log("单击点三维坐标:(" + pickResult[0].x + "," + pickResult[0].y + "," + pickResult[0].z + ");经纬度坐标:[" + this.dragGeo[0] + "," + this.dragGeo[1] + "]");
|
||||
var newLonLat = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
var newLon = newLonLat[0];
|
||||
var newLat = newLonLat[1];
|
||||
this.moveGeo(lon, lat, newLon, newLat);
|
||||
}
|
||||
this.canvas.addEventListener("mousemove", this.onMouseMoveListener, false);
|
||||
}
|
||||
},
|
||||
|
||||
onMouseMove: function(event) {
|
||||
var globe = Kernel.globe;
|
||||
if (globe && this.bMouseDown) {
|
||||
var currentX = event.layerX || event.offsetX;
|
||||
var currentY = event.layerY || event.offsetY;
|
||||
var pickResult = globe.camera.getPickCartesianCoordInEarthByCanvas(currentX, currentY);
|
||||
if (pickResult.length > 0) {
|
||||
//鼠标在地球范围内
|
||||
if (this.dragGeo) {
|
||||
//鼠标拖动过程中要显示底图
|
||||
//globe.showAllSubTiledLayerAndTiles();
|
||||
var newGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
this.moveGeo(this.dragGeo[0], this.dragGeo[1], newGeo[0], newGeo[1]);
|
||||
} else {
|
||||
//进入地球内部
|
||||
this.dragGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
}
|
||||
this.previousX = currentX;
|
||||
this.previousY = currentY;
|
||||
this.canvas.style.cursor = "pointer";
|
||||
} else {
|
||||
//鼠标超出地球范围
|
||||
this.previousX = -1;
|
||||
this.previousY = -1;
|
||||
this.dragGeo = null;
|
||||
this.canvas.style.cursor = "default";
|
||||
moveGeo: function (oldLon, oldLat, newLon, newLat) {
|
||||
var camera = Kernel.globe.camera;
|
||||
var deltaLonRadian = -MathUtils.degreeToRadian(newLon - oldLon); //旋转的经度
|
||||
var deltaLatRadian = MathUtils.degreeToRadian(newLat - oldLat); //旋转的纬度
|
||||
camera.worldRotateY(deltaLonRadian);
|
||||
var lightDir = camera.getLightDirection();
|
||||
var plumbVector = this.getPlumbVector(lightDir);
|
||||
camera.worldRotateByVector(deltaLatRadian, plumbVector);
|
||||
},
|
||||
|
||||
onMouseDown: function (event) {
|
||||
if (Kernel.globe) {
|
||||
this.bMouseDown = true;
|
||||
this.previousX = event.layerX || event.offsetX;
|
||||
this.previousY = event.layerY || event.offsetY;
|
||||
var pickResult = Kernel.globe.camera.getPickCartesianCoordInEarthByCanvas(this.previousX, this.previousY);
|
||||
if (pickResult.length > 0) {
|
||||
this.dragGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
console.log("单击点三维坐标:(" + pickResult[0].x + "," + pickResult[0].y + "," + pickResult[0].z + ");经纬度坐标:[" + this.dragGeo[0] + "," + this.dragGeo[1] + "]");
|
||||
}
|
||||
this.canvas.addEventListener("mousemove", this.onMouseMoveListener, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onMouseUp: function() {
|
||||
this.bMouseDown = false;
|
||||
this.previousX = -1;
|
||||
this.previousY = -1;
|
||||
this.dragGeo = null;
|
||||
if (this.canvas instanceof HTMLCanvasElement) {
|
||||
this.canvas.removeEventListener("mousemove", this.onMouseMoveListener, false);
|
||||
this.canvas.style.cursor = "default";
|
||||
}
|
||||
},
|
||||
|
||||
onDbClick: function(event) {
|
||||
var globe = Kernel.globe;
|
||||
if (globe) {
|
||||
var absoluteX = event.layerX || event.offsetX;
|
||||
var absoluteY = event.layerY || event.offsetY;
|
||||
var pickResult = globe.camera.getPickCartesianCoordInEarthByCanvas(absoluteX, absoluteY);
|
||||
globe.setLevel(globe.CURRENT_LEVEL + 1);
|
||||
if (pickResult.length >= 1) {
|
||||
var pickVertice = pickResult[0];
|
||||
var lonlat = MathUtils.cartesianCoordToGeographic(pickVertice);
|
||||
var lon = lonlat[0];
|
||||
var lat = lonlat[1];
|
||||
globe.setLevel(globe.CURRENT_LEVEL + 1);
|
||||
this.moveLonLatToCanvas(lon, lat, absoluteX, absoluteY);
|
||||
onMouseMove: function (event) {
|
||||
var globe = Kernel.globe;
|
||||
if (globe && this.bMouseDown) {
|
||||
var currentX = event.layerX || event.offsetX;
|
||||
var currentY = event.layerY || event.offsetY;
|
||||
var pickResult = globe.camera.getPickCartesianCoordInEarthByCanvas(currentX, currentY);
|
||||
if (pickResult.length > 0) {
|
||||
//鼠标在地球范围内
|
||||
if (this.dragGeo) {
|
||||
//鼠标拖动过程中要显示底图
|
||||
//globe.showAllSubTiledLayerAndTiles();
|
||||
var newGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
this.moveGeo(this.dragGeo[0], this.dragGeo[1], newGeo[0], newGeo[1]);
|
||||
} else {
|
||||
//进入地球内部
|
||||
this.dragGeo = MathUtils.cartesianCoordToGeographic(pickResult[0]);
|
||||
}
|
||||
this.previousX = currentX;
|
||||
this.previousY = currentY;
|
||||
this.canvas.style.cursor = "pointer";
|
||||
} else {
|
||||
//鼠标超出地球范围
|
||||
this.previousX = -1;
|
||||
this.previousY = -1;
|
||||
this.dragGeo = null;
|
||||
this.canvas.style.cursor = "default";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onMouseWheel: function(event) {
|
||||
var globe = Kernel.globe;
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaLevel = 0;
|
||||
var delta;
|
||||
if (event.wheelDelta) {
|
||||
//非Firefox
|
||||
delta = event.wheelDelta;
|
||||
deltaLevel = parseInt(delta / 120);
|
||||
} else if (event.detail) {
|
||||
//Firefox
|
||||
delta = event.detail;
|
||||
deltaLevel = -parseInt(delta / 3);
|
||||
}
|
||||
var newLevel = globe.CURRENT_LEVEL + deltaLevel;
|
||||
globe.setLevel(newLevel);
|
||||
onMouseUp: function () {
|
||||
this.bMouseDown = false;
|
||||
this.previousX = -1;
|
||||
this.previousY = -1;
|
||||
this.dragGeo = null;
|
||||
if (this.canvas instanceof HTMLCanvasElement) {
|
||||
this.canvas.removeEventListener("mousemove", this.onMouseMoveListener, false);
|
||||
this.canvas.style.cursor = "default";
|
||||
}
|
||||
},
|
||||
|
||||
onKeyDown: function(event) {
|
||||
var globe = Kernel.globe;
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
onDbClick: function (event) {
|
||||
var globe = Kernel.globe;
|
||||
if (globe) {
|
||||
var absoluteX = event.layerX || event.offsetX;
|
||||
var absoluteY = event.layerY || event.offsetY;
|
||||
var pickResult = globe.camera.getPickCartesianCoordInEarthByCanvas(absoluteX, absoluteY);
|
||||
globe.setLevel(globe.CURRENT_LEVEL + 1);
|
||||
if (pickResult.length >= 1) {
|
||||
var pickVertice = pickResult[0];
|
||||
var lonlat = MathUtils.cartesianCoordToGeographic(pickVertice);
|
||||
var lon = lonlat[0];
|
||||
var lat = lonlat[1];
|
||||
globe.setLevel(globe.CURRENT_LEVEL + 1);
|
||||
this.moveLonLatToCanvas(lon, lat, absoluteX, absoluteY);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
var MIN_PITCH = 36;
|
||||
var DELTA_PITCH = 2;
|
||||
var camera = globe.camera;
|
||||
var keyNum = event.keyCode !== undefined ? event.keyCode : event.which;
|
||||
//上、下、左、右:38、40、37、39
|
||||
if (keyNum == 38 || keyNum == 40) {
|
||||
if (keyNum == 38) {
|
||||
if (camera.pitch <= MIN_PITCH) {
|
||||
onMouseWheel: function (event) {
|
||||
var globe = Kernel.globe;
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
} else if (keyNum == 40) {
|
||||
if (camera.pitch >= 90) {
|
||||
return;
|
||||
}
|
||||
DELTA_PITCH *= -1;
|
||||
}
|
||||
|
||||
var pickResult = camera.getDirectionIntersectPointWithEarth();
|
||||
if (pickResult.length > 0) {
|
||||
var pIntersect = pickResult[0];
|
||||
var pCamera = camera.getPosition();
|
||||
var legnth2Intersect = MathUtils.getLengthFromVerticeToVertice(pCamera, pIntersect);
|
||||
var mat = camera.matrix.copy();
|
||||
mat.setColumnTrans(pIntersect.x, pIntersect.y, pIntersect.z);
|
||||
var DELTA_RADIAN = MathUtils.degreeToRadian(DELTA_PITCH);
|
||||
mat.localRotateX(DELTA_RADIAN);
|
||||
var dirZ = mat.getColumnZ().getVector();
|
||||
dirZ.setLength(legnth2Intersect);
|
||||
var pNew = pIntersect.plus(dirZ);
|
||||
camera.look(pNew, pIntersect);
|
||||
camera.pitch -= DELTA_PITCH;
|
||||
globe.refresh();
|
||||
} else {
|
||||
alert("视线与地球无交点");
|
||||
var deltaLevel = 0;
|
||||
var delta;
|
||||
if (event.wheelDelta) {
|
||||
//非Firefox
|
||||
delta = event.wheelDelta;
|
||||
deltaLevel = parseInt(delta / 120);
|
||||
} else if (event.detail) {
|
||||
//Firefox
|
||||
delta = event.detail;
|
||||
deltaLevel = -parseInt(delta / 3);
|
||||
}
|
||||
}
|
||||
var newLevel = globe.CURRENT_LEVEL + deltaLevel;
|
||||
globe.setLevel(newLevel);
|
||||
},
|
||||
|
||||
getPlumbVector: function(direction) {
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction: not World.Vector";
|
||||
}
|
||||
var dir = direction.getCopy();
|
||||
dir.y = 0;
|
||||
dir.normalize();
|
||||
var plumbVector = new Vector(-dir.z, 0, dir.x);
|
||||
plumbVector.normalize();
|
||||
return plumbVector;
|
||||
onKeyDown: function (event) {
|
||||
var globe = Kernel.globe;
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
|
||||
var MIN_PITCH = 36;
|
||||
var DELTA_PITCH = 2;
|
||||
var camera = globe.camera;
|
||||
var keyNum = event.keyCode !== undefined ? event.keyCode : event.which;
|
||||
//上、下、左、右:38、40、37、39
|
||||
if (keyNum == 38 || keyNum == 40) {
|
||||
if (keyNum == 38) {
|
||||
if (camera.pitch <= MIN_PITCH) {
|
||||
return;
|
||||
}
|
||||
} else if (keyNum == 40) {
|
||||
if (camera.pitch >= 90) {
|
||||
return;
|
||||
}
|
||||
DELTA_PITCH *= -1;
|
||||
}
|
||||
|
||||
var pickResult = camera.getDirectionIntersectPointWithEarth();
|
||||
if (pickResult.length > 0) {
|
||||
var pIntersect = pickResult[0];
|
||||
var pCamera = camera.getPosition();
|
||||
var legnth2Intersect = MathUtils.getLengthFromVerticeToVertice(pCamera, pIntersect);
|
||||
var mat = camera.matrix.copy();
|
||||
mat.setColumnTrans(pIntersect.x, pIntersect.y, pIntersect.z);
|
||||
var DELTA_RADIAN = MathUtils.degreeToRadian(DELTA_PITCH);
|
||||
mat.localRotateX(DELTA_RADIAN);
|
||||
var dirZ = mat.getColumnZ().getVector();
|
||||
dirZ.setLength(legnth2Intersect);
|
||||
var pNew = pIntersect.plus(dirZ);
|
||||
camera.look(pNew, pIntersect);
|
||||
camera.pitch -= DELTA_PITCH;
|
||||
globe.refresh();
|
||||
} else {
|
||||
alert("视线与地球无交点");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getPlumbVector: function (direction) {
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction: not World.Vector";
|
||||
}
|
||||
var dir = direction.getCopy();
|
||||
dir.y = 0;
|
||||
dir.normalize();
|
||||
var plumbVector = new Vector(-dir.z, 0, dir.x);
|
||||
plumbVector.normalize();
|
||||
return plumbVector;
|
||||
}
|
||||
};
|
||||
return EventModule;
|
||||
});
|
||||
};
|
||||
|
||||
export default EventModule;
|
||||
@ -1,112 +1,120 @@
|
||||
define(["world/Kernel", "world/Utils", "world/ShaderContent", "world/WebGLRenderer", "world/PerspectiveCamera", "world/Scene",
|
||||
"world/TiledLayer", "world/SubTiledLayer", "world/Tile", "world/Image", "world/Event"],
|
||||
function(Kernel, Utils, ShaderContent, WebGLRenderer, PerspectiveCamera, Scene, TiledLayer, SubTiledLayer, Tile, Image1, Event) {
|
||||
import Kernel from './Kernel';
|
||||
import Utils from './Utils';
|
||||
import ShaderContent from './ShaderContent';
|
||||
import WebGLRenderer from './WebGLRenderer';
|
||||
import PerspectiveCamera from './PerspectiveCamera';
|
||||
import Scene from './Scene';
|
||||
import TiledLayer from './TiledLayer';
|
||||
import SubTiledLayer from './SubTiledLayer';
|
||||
import Tile from './Tile';
|
||||
import Image1 from './Image';
|
||||
import Event from './Event';
|
||||
|
||||
var Globe = function(canvas, args) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
var Globe = function (canvas, args) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
throw "invalid canvas: not HTMLCanvasElement";
|
||||
}
|
||||
args = args || {};
|
||||
Kernel.globe = this;
|
||||
this.MAX_LEVEL = 15; //最大的渲染级别15
|
||||
this.CURRENT_LEVEL = -1; //当前渲染等级
|
||||
this.REFRESH_INTERVAL = 300; //Globe自动刷新时间间隔,以毫秒为单位
|
||||
this.idTimeOut = null; //refresh自定刷新的timeOut的handle
|
||||
this.renderer = null;
|
||||
this.scene = null;
|
||||
this.camera = null;
|
||||
this.tiledLayer = null;
|
||||
var vs_content = ShaderContent.SIMPLE_SHADER.VS_CONTENT;
|
||||
var fs_content = ShaderContent.SIMPLE_SHADER.FS_CONTENT;
|
||||
this.renderer = Kernel.renderer = new WebGLRenderer(canvas, vs_content, fs_content);
|
||||
this.scene = new Scene();
|
||||
var radio = canvas.width / canvas.height;
|
||||
this.camera = new PerspectiveCamera(30, radio, 1.0, 20000000.0);
|
||||
this.renderer.bindScene(this.scene);
|
||||
this.renderer.bindCamera(this.camera);
|
||||
this.setLevel(0);
|
||||
this.renderer.setIfAutoRefresh(true);
|
||||
Event.initLayout();
|
||||
};
|
||||
Globe.prototype = {
|
||||
constructor: Globe,
|
||||
}
|
||||
args = args || {};
|
||||
Kernel.globe = this;
|
||||
this.MAX_LEVEL = 15; //最大的渲染级别15
|
||||
this.CURRENT_LEVEL = -1; //当前渲染等级
|
||||
this.REFRESH_INTERVAL = 300; //Globe自动刷新时间间隔,以毫秒为单位
|
||||
this.idTimeOut = null; //refresh自定刷新的timeOut的handle
|
||||
this.renderer = null;
|
||||
this.scene = null;
|
||||
this.camera = null;
|
||||
this.tiledLayer = null;
|
||||
var vs_content = ShaderContent.VS_CONTENT;
|
||||
var fs_content = ShaderContent.FS_CONTENT;
|
||||
this.renderer = Kernel.renderer = new WebGLRenderer(canvas, vs_content, fs_content);
|
||||
this.scene = new Scene();
|
||||
var radio = canvas.width / canvas.height;
|
||||
this.camera = new PerspectiveCamera(30, radio, 1.0, 20000000.0);
|
||||
this.renderer.bindScene(this.scene);
|
||||
this.renderer.bindCamera(this.camera);
|
||||
this.setLevel(0);
|
||||
this.renderer.setIfAutoRefresh(true);
|
||||
Event.initLayout();
|
||||
};
|
||||
Globe.prototype = {
|
||||
constructor: Globe,
|
||||
|
||||
setTiledLayer: function(tiledLayer) {
|
||||
setTiledLayer: function (tiledLayer) {
|
||||
if (!(tiledLayer instanceof TiledLayer)) {
|
||||
throw "invalid tiledLayer: not World.TiledLayer";
|
||||
throw "invalid tiledLayer: not World.TiledLayer";
|
||||
}
|
||||
|
||||
clearTimeout(this.idTimeOut);
|
||||
//在更换切片图层的类型时清空缓存的图片
|
||||
Image1.clear();
|
||||
if (this.tiledLayer) {
|
||||
var b = this.scene.remove(this.tiledLayer);
|
||||
if (!b) {
|
||||
console.error("this.scene.remove(this.tiledLayer)失败");
|
||||
}
|
||||
this.scene.tiledLayer = null;
|
||||
var b = this.scene.remove(this.tiledLayer);
|
||||
if (!b) {
|
||||
console.error("this.scene.remove(this.tiledLayer)失败");
|
||||
}
|
||||
this.scene.tiledLayer = null;
|
||||
}
|
||||
this.tiledLayer = tiledLayer;
|
||||
this.scene.add(this.tiledLayer);
|
||||
//添加第0级的子图层
|
||||
var subLayer0 = new SubTiledLayer({
|
||||
level: 0
|
||||
level: 0
|
||||
});
|
||||
this.tiledLayer.add(subLayer0);
|
||||
|
||||
//要对level为1的图层进行特殊处理,在创建level为1时就创建其中的全部的四个tile
|
||||
var subLayer1 = new SubTiledLayer({
|
||||
level: 1
|
||||
level: 1
|
||||
});
|
||||
this.tiledLayer.add(subLayer1);
|
||||
Kernel.canvas.style.cursor = "wait";
|
||||
for (var m = 0; m <= 1; m++) {
|
||||
for (var n = 0; n <= 1; n++) {
|
||||
var args = {
|
||||
level: 1,
|
||||
row: m,
|
||||
column: n,
|
||||
url: ""
|
||||
};
|
||||
args.url = this.tiledLayer.getImageUrl(args.level, args.row, args.column);
|
||||
var tile = new Tile(args);
|
||||
subLayer1.add(tile);
|
||||
}
|
||||
for (var n = 0; n <= 1; n++) {
|
||||
var args = {
|
||||
level: 1,
|
||||
row: m,
|
||||
column: n,
|
||||
url: ""
|
||||
};
|
||||
args.url = this.tiledLayer.getImageUrl(args.level, args.row, args.column);
|
||||
var tile = new Tile(args);
|
||||
subLayer1.add(tile);
|
||||
}
|
||||
}
|
||||
Kernel.canvas.style.cursor = "default";
|
||||
this.tick();
|
||||
},
|
||||
},
|
||||
|
||||
setLevel: function(level) {
|
||||
setLevel: function (level) {
|
||||
if (!Utils.isInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (level < 0) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
level = level > this.MAX_LEVEL ? this.MAX_LEVEL : level; //超过最大的渲染级别就不渲染
|
||||
if (level != this.CURRENT_LEVEL) {
|
||||
if (this.camera instanceof PerspectiveCamera) {
|
||||
//要先执行camera.setLevel,然后再刷新
|
||||
this.camera.setLevel(level);
|
||||
this.refresh();
|
||||
}
|
||||
if (this.camera instanceof PerspectiveCamera) {
|
||||
//要先执行camera.setLevel,然后再刷新
|
||||
this.camera.setLevel(level);
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 返回当前的各种矩阵信息:视点矩阵、投影矩阵、两者乘积,以及前三者的逆矩阵
|
||||
* @returns {{View: null, _View: null, Proj: null, _Proj: null, ProjView: null, _View_Proj: null}}
|
||||
* @private
|
||||
*/
|
||||
_getMatrixInfo: function() {
|
||||
/**
|
||||
* 返回当前的各种矩阵信息:视点矩阵、投影矩阵、两者乘积,以及前三者的逆矩阵
|
||||
* @returns {{View: null, _View: null, Proj: null, _Proj: null, ProjView: null, _View_Proj: null}}
|
||||
* @private
|
||||
*/
|
||||
_getMatrixInfo: function () {
|
||||
var options = {
|
||||
View: null, //视点矩阵
|
||||
_View: null, //视点矩阵的逆矩阵
|
||||
Proj: null, //投影矩阵
|
||||
_Proj: null, //投影矩阵的逆矩阵
|
||||
ProjView: null, //投影矩阵与视点矩阵的乘积
|
||||
_View_Proj: null //视点逆矩阵与投影逆矩阵的乘积
|
||||
View: null, //视点矩阵
|
||||
_View: null, //视点矩阵的逆矩阵
|
||||
Proj: null, //投影矩阵
|
||||
_Proj: null, //投影矩阵的逆矩阵
|
||||
ProjView: null, //投影矩阵与视点矩阵的乘积
|
||||
_View_Proj: null //视点逆矩阵与投影逆矩阵的乘积
|
||||
};
|
||||
options.View = this.getViewMatrix();
|
||||
options._View = options.View.getInverseMatrix();
|
||||
@ -115,26 +123,26 @@ define(["world/Kernel", "world/Utils", "world/ShaderContent", "world/WebGLRender
|
||||
options.ProjView = options.Proj.multiplyMatrix(options.View);
|
||||
options._View_Proj = options.ProjView.getInverseMatrix();
|
||||
return options;
|
||||
},
|
||||
},
|
||||
|
||||
tick: function() {
|
||||
tick: function () {
|
||||
var globe = Kernel.globe;
|
||||
if (globe) {
|
||||
globe.refresh();
|
||||
this.idTimeOut = setTimeout(globe.tick, globe.REFRESH_INTERVAL);
|
||||
globe.refresh();
|
||||
this.idTimeOut = setTimeout(globe.tick, globe.REFRESH_INTERVAL);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
refresh: function () {
|
||||
if (!this.tiledLayer || !this.scene || !this.camera) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
var level = this.CURRENT_LEVEL + 3;
|
||||
this.tiledLayer.updateSubLayerCount(level);
|
||||
var projView = this.camera.getProjViewMatrix();
|
||||
var options = {
|
||||
projView: projView,
|
||||
threshold: 1
|
||||
projView: projView,
|
||||
threshold: 1
|
||||
};
|
||||
options.threshold = Math.min(90 / this.camera.pitch, 1.5);
|
||||
//最大级别的level所对应的可见TileGrids
|
||||
@ -143,26 +151,26 @@ define(["world/Kernel", "world/Utils", "world/ShaderContent", "world/WebGLRender
|
||||
var parentTileGrids = lastLevelTileGrids;
|
||||
var i;
|
||||
for (i = level; i >= 2; i--) {
|
||||
levelsTileGrids.push(parentTileGrids); //此行代码表示第i层级的可见切片
|
||||
parentTileGrids = Utils.map(parentTileGrids, function(item) {
|
||||
return item.getParent();
|
||||
});
|
||||
parentTileGrids = Utils.filterRepeatArray(parentTileGrids);
|
||||
levelsTileGrids.push(parentTileGrids); //此行代码表示第i层级的可见切片
|
||||
parentTileGrids = Utils.map(parentTileGrids, function (item) {
|
||||
return item.getParent();
|
||||
});
|
||||
parentTileGrids = Utils.filterRepeatArray(parentTileGrids);
|
||||
}
|
||||
levelsTileGrids.reverse(); //2-level
|
||||
for (i = 2; i <= level; i++) {
|
||||
var subLevel = i;
|
||||
var subLayer = this.tiledLayer.children[subLevel];
|
||||
subLayer.updateTiles(levelsTileGrids[0], true);
|
||||
levelsTileGrids.splice(0, 1);
|
||||
var subLevel = i;
|
||||
var subLayer = this.tiledLayer.children[subLevel];
|
||||
subLayer.updateTiles(levelsTileGrids[0], true);
|
||||
levelsTileGrids.splice(0, 1);
|
||||
}
|
||||
if (Kernel.TERRAIN_ENABLED) {
|
||||
this.requestElevationsAndCheckTerrain();
|
||||
this.requestElevationsAndCheckTerrain();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
//请求更新高程数据,并检测Terrain
|
||||
requestElevationsAndCheckTerrain: function() {
|
||||
//请求更新高程数据,并检测Terrain
|
||||
requestElevationsAndCheckTerrain: function () {
|
||||
var level = this.tiledLayer.children.length - 1;
|
||||
//当level>7时请求更新高程数据
|
||||
//请求的数据与第7级的切片大小相同
|
||||
@ -170,16 +178,16 @@ define(["world/Kernel", "world/Utils", "world/ShaderContent", "world/WebGLRender
|
||||
|
||||
//达到TERRAIN_LEVEL级别时考虑三维请求
|
||||
if (level >= Kernel.TERRAIN_LEVEL) {
|
||||
for (var i = Kernel.ELEVATION_LEVEL + 1; i <= level; i++) {
|
||||
var subLayer = this.tiledLayer.children[i];
|
||||
subLayer.requestElevations();
|
||||
//检查SubTiledLayer下的子图层是否符合转换成TerrainTile的条件,如果适合就自动以三维地形图显示
|
||||
if (i >= Kernel.TERRAIN_LEVEL) {
|
||||
subLayer.checkTerrain();
|
||||
for (var i = Kernel.ELEVATION_LEVEL + 1; i <= level; i++) {
|
||||
var subLayer = this.tiledLayer.children[i];
|
||||
subLayer.requestElevations();
|
||||
//检查SubTiledLayer下的子图层是否符合转换成TerrainTile的条件,如果适合就自动以三维地形图显示
|
||||
if (i >= Kernel.TERRAIN_LEVEL) {
|
||||
subLayer.checkTerrain();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return Globe;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default Globe;
|
||||
@ -1,16 +1,19 @@
|
||||
define(["world/TiledLayer"], function (TiledLayer) {
|
||||
//Google
|
||||
var GoogleTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
GoogleTiledLayer.prototype = new TiledLayer();
|
||||
GoogleTiledLayer.prototype.constructor = GoogleTiledLayer;
|
||||
GoogleTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var sum = level + row + column;
|
||||
var idx = 1 + sum % 3;
|
||||
var url = "//mt" + idx + ".google.cn/vt/lyrs=y&hl=zh-CN&gl=CN&src=app&x=" + column + "&y=" + row + "&z=" + level + "&s=Galil";
|
||||
return url;
|
||||
};
|
||||
return GoogleTiledLayer;
|
||||
});
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
//Google
|
||||
var GoogleTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
|
||||
GoogleTiledLayer.prototype = new TiledLayer();
|
||||
GoogleTiledLayer.prototype.constructor = GoogleTiledLayer;
|
||||
|
||||
GoogleTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var sum = level + row + column;
|
||||
var idx = 1 + sum % 3;
|
||||
var url = "//mt" + idx + ".google.cn/vt/lyrs=y&hl=zh-CN&gl=CN&src=app&x=" + column + "&y=" + row + "&z=" + level + "&s=Galil";
|
||||
return url;
|
||||
};
|
||||
|
||||
export default GoogleTiledLayer;
|
||||
@ -1,41 +1,47 @@
|
||||
define(["world/Utils"], function(Utils) {
|
||||
//缓存图片信息1、2、3、4级的图片信息
|
||||
var Image1 = {
|
||||
import Utils from './Utils';
|
||||
|
||||
//缓存图片信息1、2、3、4级的图片信息
|
||||
var Image1 = {
|
||||
MAX_LEVEL: 4, //缓存图片的最大level
|
||||
images: {}
|
||||
};
|
||||
Image1.add = function(url, img) {
|
||||
};
|
||||
|
||||
Image1.add = function (url, img) {
|
||||
if (!Utils.isString(url)) {
|
||||
throw "invalid url: not string";
|
||||
throw "invalid url: not string";
|
||||
}
|
||||
if (!(img instanceof HTMLImageElement)) {
|
||||
throw "invalid img: not HTMLImageElement";
|
||||
throw "invalid img: not HTMLImageElement";
|
||||
}
|
||||
this.images[url] = img;
|
||||
};
|
||||
Image1.get = function(url) {
|
||||
};
|
||||
|
||||
Image1.get = function (url) {
|
||||
if (!Utils.isString(url)) {
|
||||
throw "invalid url: not string";
|
||||
throw "invalid url: not string";
|
||||
}
|
||||
return this.images[url];
|
||||
};
|
||||
Image1.remove = function(url) {
|
||||
};
|
||||
|
||||
Image1.remove = function (url) {
|
||||
if (!(Utils.isString(url))) {
|
||||
throw "invalid url: not string";
|
||||
throw "invalid url: not string";
|
||||
}
|
||||
delete this.images[url];
|
||||
};
|
||||
Image1.clear = function() {
|
||||
};
|
||||
|
||||
Image1.clear = function () {
|
||||
this.images = {};
|
||||
};
|
||||
Image1.getCount = function() {
|
||||
};
|
||||
|
||||
Image1.getCount = function () {
|
||||
var count = 0;
|
||||
for (var url in this.images) {
|
||||
if (this.images.hasOwnProperty(url)) {
|
||||
count++;
|
||||
}
|
||||
if (this.images.hasOwnProperty(url)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
};
|
||||
return Image1;
|
||||
});
|
||||
};
|
||||
|
||||
export default Image1;
|
||||
@ -1,15 +1,17 @@
|
||||
define({
|
||||
gl: null,
|
||||
canvas: null,
|
||||
idCounter: 0, //Object3D对象的唯一标识
|
||||
renderer: null,
|
||||
globe: null,
|
||||
BASE_LEVEL: 6, //渲染的基准层级
|
||||
EARTH_RADIUS: 6378137,
|
||||
MAX_PROJECTED_COORD: 20037508.3427892,
|
||||
ELEVATION_LEVEL: 7, //开始获取高程数据
|
||||
TERRAIN_LEVEL: 10, //开始显示三维地形
|
||||
TERRAIN_ENABLED: false, //是否启用三维地形
|
||||
TERRAIN_PITCH: 80, //开始显示三维地形的pich
|
||||
proxy: ""
|
||||
});
|
||||
var Kernel = {
|
||||
gl: null,
|
||||
canvas: null,
|
||||
idCounter: 0, //Object3D对象的唯一标识
|
||||
renderer: null,
|
||||
globe: null,
|
||||
BASE_LEVEL: 6, //渲染的基准层级
|
||||
EARTH_RADIUS: 6378137,
|
||||
MAX_PROJECTED_COORD: 20037508.3427892,
|
||||
ELEVATION_LEVEL: 7, //开始获取高程数据
|
||||
TERRAIN_LEVEL: 10, //开始显示三维地形
|
||||
TERRAIN_ENABLED: false, //是否启用三维地形
|
||||
TERRAIN_PITCH: 80, //开始显示三维地形的pich
|
||||
proxy: ""
|
||||
};
|
||||
|
||||
export default Kernel;
|
||||
@ -1,34 +1,40 @@
|
||||
define(["world/Vertice", "world/Vector"], function(Vertice, Vector) {
|
||||
var Line = function(position, direction) {
|
||||
import Vertice from './Vertice';
|
||||
import Vector from './Vector';
|
||||
|
||||
var Line = function (position, direction) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
throw "invalid position";
|
||||
}
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
};
|
||||
Line.prototype.constructor = Line;
|
||||
Line.prototype.setVertice = function(position) {
|
||||
};
|
||||
|
||||
Line.prototype.constructor = Line;
|
||||
|
||||
Line.prototype.setVertice = function (position) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
throw "invalid position";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
return this;
|
||||
};
|
||||
Line.prototype.setVector = function(direction) {
|
||||
};
|
||||
|
||||
Line.prototype.setVector = function (direction) {
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
return this;
|
||||
};
|
||||
Line.prototype.getCopy = function() {
|
||||
};
|
||||
|
||||
Line.prototype.getCopy = function () {
|
||||
var lineCopy = new Line(this.vertice, this.vector);
|
||||
return lineCopy;
|
||||
};
|
||||
return Line;
|
||||
});
|
||||
};
|
||||
|
||||
export default Line;
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,295 +1,297 @@
|
||||
define(["require", "world/Utils", "world/Vertice", "world/Vector"], function(require, Utils, Vertice, Vector) {
|
||||
import Utils from './Utils';
|
||||
import Vertice from './Vertice';
|
||||
import Vector from './Vector';
|
||||
|
||||
var Matrix = function(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
||||
var Matrix = function (m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
||||
this.elements = new Float32Array(16);
|
||||
|
||||
this.setElements(
|
||||
(m11 === undefined ? 1 : m11), (m12 === undefined ? 0 : m12), (m13 === undefined ? 0 : m13), (m14 === undefined ? 0 : m14),
|
||||
(m21 === undefined ? 0 : m21), (m22 === undefined ? 1 : m22), (m23 === undefined ? 0 : m23), (m24 === undefined ? 0 : m24),
|
||||
(m31 === undefined ? 0 : m31), (m32 === undefined ? 0 : m32), (m33 === undefined ? 1 : m33), (m34 === undefined ? 0 : m34),
|
||||
(m41 === undefined ? 0 : m41), (m42 === undefined ? 0 : m42), (m43 === undefined ? 0 : m43), (m44 === undefined ? 1 : m44)
|
||||
(m11 === undefined ? 1 : m11), (m12 === undefined ? 0 : m12), (m13 === undefined ? 0 : m13), (m14 === undefined ? 0 : m14),
|
||||
(m21 === undefined ? 0 : m21), (m22 === undefined ? 1 : m22), (m23 === undefined ? 0 : m23), (m24 === undefined ? 0 : m24),
|
||||
(m31 === undefined ? 0 : m31), (m32 === undefined ? 0 : m32), (m33 === undefined ? 1 : m33), (m34 === undefined ? 0 : m34),
|
||||
(m41 === undefined ? 0 : m41), (m42 === undefined ? 0 : m42), (m43 === undefined ? 0 : m43), (m44 === undefined ? 1 : m44)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
Matrix.prototype = {
|
||||
Matrix.prototype = {
|
||||
constructor: Matrix,
|
||||
|
||||
setElements: function(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
||||
var count = arguments.length;
|
||||
if (count < 16) {
|
||||
throw "invalid arguments:arguments length error";
|
||||
}
|
||||
for (var i = 0; i < count; i++) {
|
||||
if (!Utils.isNumber(arguments[i])) {
|
||||
throw "invalid arguments[" + i + "]";
|
||||
setElements: function (m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
||||
var count = arguments.length;
|
||||
if (count < 16) {
|
||||
throw "invalid arguments:arguments length error";
|
||||
}
|
||||
}
|
||||
var values = this.elements;
|
||||
values[0] = m11;
|
||||
values[4] = m12;
|
||||
values[8] = m13;
|
||||
values[12] = m14;
|
||||
values[1] = m21;
|
||||
values[5] = m22;
|
||||
values[9] = m23;
|
||||
values[13] = m24;
|
||||
values[2] = m31;
|
||||
values[6] = m32;
|
||||
values[10] = m33;
|
||||
values[14] = m34;
|
||||
values[3] = m41;
|
||||
values[7] = m42;
|
||||
values[11] = m43;
|
||||
values[15] = m44;
|
||||
return this;
|
||||
for (var i = 0; i < count; i++) {
|
||||
if (!Utils.isNumber(arguments[i])) {
|
||||
throw "invalid arguments[" + i + "]";
|
||||
}
|
||||
}
|
||||
var values = this.elements;
|
||||
values[0] = m11;
|
||||
values[4] = m12;
|
||||
values[8] = m13;
|
||||
values[12] = m14;
|
||||
values[1] = m21;
|
||||
values[5] = m22;
|
||||
values[9] = m23;
|
||||
values[13] = m24;
|
||||
values[2] = m31;
|
||||
values[6] = m32;
|
||||
values[10] = m33;
|
||||
values[14] = m34;
|
||||
values[3] = m41;
|
||||
values[7] = m42;
|
||||
values[11] = m43;
|
||||
values[15] = m44;
|
||||
return this;
|
||||
},
|
||||
|
||||
setColumnX: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[0] = x;
|
||||
this.elements[1] = y;
|
||||
this.elements[2] = z;
|
||||
setColumnX: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[0] = x;
|
||||
this.elements[1] = y;
|
||||
this.elements[2] = z;
|
||||
},
|
||||
|
||||
getColumnX: function() {
|
||||
return new Vertice(this.elements[0], this.elements[1], this.elements[2]);
|
||||
getColumnX: function () {
|
||||
return new Vertice(this.elements[0], this.elements[1], this.elements[2]);
|
||||
},
|
||||
|
||||
setColumnY: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[4] = x;
|
||||
this.elements[5] = y;
|
||||
this.elements[6] = z;
|
||||
setColumnY: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[4] = x;
|
||||
this.elements[5] = y;
|
||||
this.elements[6] = z;
|
||||
},
|
||||
|
||||
getColumnY: function() {
|
||||
return new Vertice(this.elements[4], this.elements[5], this.elements[6]);
|
||||
getColumnY: function () {
|
||||
return new Vertice(this.elements[4], this.elements[5], this.elements[6]);
|
||||
},
|
||||
|
||||
setColumnZ: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[8] = x;
|
||||
this.elements[9] = y;
|
||||
this.elements[10] = z;
|
||||
setColumnZ: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[8] = x;
|
||||
this.elements[9] = y;
|
||||
this.elements[10] = z;
|
||||
},
|
||||
|
||||
getColumnZ: function() {
|
||||
return new Vertice(this.elements[8], this.elements[9], this.elements[10]);
|
||||
getColumnZ: function () {
|
||||
return new Vertice(this.elements[8], this.elements[9], this.elements[10]);
|
||||
},
|
||||
|
||||
setColumnTrans: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[12] = x;
|
||||
this.elements[13] = y;
|
||||
this.elements[14] = z;
|
||||
setColumnTrans: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[12] = x;
|
||||
this.elements[13] = y;
|
||||
this.elements[14] = z;
|
||||
},
|
||||
|
||||
getColumnTrans: function() {
|
||||
return new Vertice(this.elements[12], this.elements[13], this.elements[14]);
|
||||
getColumnTrans: function () {
|
||||
return new Vertice(this.elements[12], this.elements[13], this.elements[14]);
|
||||
},
|
||||
|
||||
setLastRowDefault: function() {
|
||||
this.elements[3] = 0;
|
||||
this.elements[7] = 0;
|
||||
this.elements[11] = 0;
|
||||
this.elements[15] = 1;
|
||||
setLastRowDefault: function () {
|
||||
this.elements[3] = 0;
|
||||
this.elements[7] = 0;
|
||||
this.elements[11] = 0;
|
||||
this.elements[15] = 1;
|
||||
},
|
||||
|
||||
//对当前矩阵进行转置,并对当前矩阵产生影响
|
||||
transpose: function() {
|
||||
var result = this.getTransposeMatrix();
|
||||
this.setMatrixByOther(result);
|
||||
transpose: function () {
|
||||
var result = this.getTransposeMatrix();
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
//返回当前矩阵的转置矩阵,不对当前矩阵产生影响
|
||||
getTransposeMatrix: function() {
|
||||
var result = new Matrix();
|
||||
result.elements[0] = this.elements[0];
|
||||
result.elements[4] = this.elements[1];
|
||||
result.elements[8] = this.elements[2];
|
||||
result.elements[12] = this.elements[3];
|
||||
getTransposeMatrix: function () {
|
||||
var result = new Matrix();
|
||||
result.elements[0] = this.elements[0];
|
||||
result.elements[4] = this.elements[1];
|
||||
result.elements[8] = this.elements[2];
|
||||
result.elements[12] = this.elements[3];
|
||||
|
||||
result.elements[1] = this.elements[4];
|
||||
result.elements[5] = this.elements[5];
|
||||
result.elements[9] = this.elements[6];
|
||||
result.elements[13] = this.elements[7];
|
||||
result.elements[1] = this.elements[4];
|
||||
result.elements[5] = this.elements[5];
|
||||
result.elements[9] = this.elements[6];
|
||||
result.elements[13] = this.elements[7];
|
||||
|
||||
result.elements[2] = this.elements[8];
|
||||
result.elements[6] = this.elements[9];
|
||||
result.elements[10] = this.elements[10];
|
||||
result.elements[14] = this.elements[11];
|
||||
result.elements[2] = this.elements[8];
|
||||
result.elements[6] = this.elements[9];
|
||||
result.elements[10] = this.elements[10];
|
||||
result.elements[14] = this.elements[11];
|
||||
|
||||
result.elements[3] = this.elements[12];
|
||||
result.elements[7] = this.elements[13];
|
||||
result.elements[11] = this.elements[14];
|
||||
result.elements[15] = this.elements[15];
|
||||
return result;
|
||||
result.elements[3] = this.elements[12];
|
||||
result.elements[7] = this.elements[13];
|
||||
result.elements[11] = this.elements[14];
|
||||
result.elements[15] = this.elements[15];
|
||||
return result;
|
||||
},
|
||||
|
||||
//对当前矩阵进行取逆操作,并对当前矩阵产生影响
|
||||
inverse: function() {
|
||||
var result = this.getInverseMatrix();
|
||||
this.setMatrixByOther(result);
|
||||
inverse: function () {
|
||||
var result = this.getInverseMatrix();
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
//返回当前矩阵的逆矩阵,不对当前矩阵产生影响
|
||||
getInverseMatrix: function() {
|
||||
var a = this.elements;
|
||||
var result = new Matrix();
|
||||
var b = result.elements;
|
||||
var c = a[0],
|
||||
d = a[1],
|
||||
e = a[2],
|
||||
g = a[3],
|
||||
f = a[4],
|
||||
h = a[5],
|
||||
i = a[6],
|
||||
j = a[7],
|
||||
k = a[8],
|
||||
l = a[9],
|
||||
n = a[10],
|
||||
o = a[11],
|
||||
m = a[12],
|
||||
p = a[13],
|
||||
r = a[14],
|
||||
s = a[15];
|
||||
var A = c * h - d * f;
|
||||
var B = c * i - e * f;
|
||||
var t = c * j - g * f;
|
||||
var u = d * i - e * h;
|
||||
var v = d * j - g * h;
|
||||
var w = e * j - g * i;
|
||||
var x = k * p - l * m;
|
||||
var y = k * r - n * m;
|
||||
var z = k * s - o * m;
|
||||
var C = l * r - n * p;
|
||||
var D = l * s - o * p;
|
||||
var E = n * s - o * r;
|
||||
var q = A * E - B * D + t * C + u * z - v * y + w * x;
|
||||
if (!q) return null;
|
||||
q = 1 / q;
|
||||
b[0] = (h * E - i * D + j * C) * q;
|
||||
b[1] = (-d * E + e * D - g * C) * q;
|
||||
b[2] = (p * w - r * v + s * u) * q;
|
||||
b[3] = (-l * w + n * v - o * u) * q;
|
||||
b[4] = (-f * E + i * z - j * y) * q;
|
||||
b[5] = (c * E - e * z + g * y) * q;
|
||||
b[6] = (-m * w + r * t - s * B) * q;
|
||||
b[7] = (k * w - n * t + o * B) * q;
|
||||
b[8] = (f * D - h * z + j * x) * q;
|
||||
b[9] = (-c * D + d * z - g * x) * q;
|
||||
b[10] = (m * v - p * t + s * A) * q;
|
||||
b[11] = (-k * v + l * t - o * A) * q;
|
||||
b[12] = (-f * C + h * y - i * x) * q;
|
||||
b[13] = (c * C - d * y + e * x) * q;
|
||||
b[14] = (-m * u + p * B - r * A) * q;
|
||||
b[15] = (k * u - l * B + n * A) * q;
|
||||
return result;
|
||||
getInverseMatrix: function () {
|
||||
var a = this.elements;
|
||||
var result = new Matrix();
|
||||
var b = result.elements;
|
||||
var c = a[0],
|
||||
d = a[1],
|
||||
e = a[2],
|
||||
g = a[3],
|
||||
f = a[4],
|
||||
h = a[5],
|
||||
i = a[6],
|
||||
j = a[7],
|
||||
k = a[8],
|
||||
l = a[9],
|
||||
n = a[10],
|
||||
o = a[11],
|
||||
m = a[12],
|
||||
p = a[13],
|
||||
r = a[14],
|
||||
s = a[15];
|
||||
var A = c * h - d * f;
|
||||
var B = c * i - e * f;
|
||||
var t = c * j - g * f;
|
||||
var u = d * i - e * h;
|
||||
var v = d * j - g * h;
|
||||
var w = e * j - g * i;
|
||||
var x = k * p - l * m;
|
||||
var y = k * r - n * m;
|
||||
var z = k * s - o * m;
|
||||
var C = l * r - n * p;
|
||||
var D = l * s - o * p;
|
||||
var E = n * s - o * r;
|
||||
var q = A * E - B * D + t * C + u * z - v * y + w * x;
|
||||
if (!q) return null;
|
||||
q = 1 / q;
|
||||
b[0] = (h * E - i * D + j * C) * q;
|
||||
b[1] = (-d * E + e * D - g * C) * q;
|
||||
b[2] = (p * w - r * v + s * u) * q;
|
||||
b[3] = (-l * w + n * v - o * u) * q;
|
||||
b[4] = (-f * E + i * z - j * y) * q;
|
||||
b[5] = (c * E - e * z + g * y) * q;
|
||||
b[6] = (-m * w + r * t - s * B) * q;
|
||||
b[7] = (k * w - n * t + o * B) * q;
|
||||
b[8] = (f * D - h * z + j * x) * q;
|
||||
b[9] = (-c * D + d * z - g * x) * q;
|
||||
b[10] = (m * v - p * t + s * A) * q;
|
||||
b[11] = (-k * v + l * t - o * A) * q;
|
||||
b[12] = (-f * C + h * y - i * x) * q;
|
||||
b[13] = (c * C - d * y + e * x) * q;
|
||||
b[14] = (-m * u + p * B - r * A) * q;
|
||||
b[15] = (k * u - l * B + n * A) * q;
|
||||
return result;
|
||||
},
|
||||
|
||||
setMatrixByOther: function(otherMatrix) {
|
||||
if (!(otherMatrix instanceof Matrix)) {
|
||||
throw "invalid otherMatrix";
|
||||
}
|
||||
for (var i = 0; i < otherMatrix.elements.length; i++) {
|
||||
this.elements[i] = otherMatrix.elements[i];
|
||||
}
|
||||
setMatrixByOther: function (otherMatrix) {
|
||||
if (!(otherMatrix instanceof Matrix)) {
|
||||
throw "invalid otherMatrix";
|
||||
}
|
||||
for (var i = 0; i < otherMatrix.elements.length; i++) {
|
||||
this.elements[i] = otherMatrix.elements[i];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 将矩阵设置为单位阵
|
||||
*/
|
||||
setUnitMatrix: function() {
|
||||
this.setElements(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
setUnitMatrix: function () {
|
||||
this.setElements(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断矩阵是否为单位阵
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUnitMatrix: function() {
|
||||
var values = this.elements;
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (i % 4 === 0) {
|
||||
if (values[i] != 1) {
|
||||
//斜对角线上的值需要为1
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (values[i] !== 0) {
|
||||
//非斜对角线上的值需要为0
|
||||
return false;
|
||||
}
|
||||
isUnitMatrix: function () {
|
||||
var values = this.elements;
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (i % 4 === 0) {
|
||||
if (values[i] != 1) {
|
||||
//斜对角线上的值需要为1
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (values[i] !== 0) {
|
||||
//非斜对角线上的值需要为0
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
},
|
||||
|
||||
copy: function() {
|
||||
return new Matrix(this.elements[0], this.elements[4], this.elements[8], this.elements[12],
|
||||
this.elements[1], this.elements[5], this.elements[9], this.elements[13],
|
||||
this.elements[2], this.elements[6], this.elements[10], this.elements[14],
|
||||
this.elements[3], this.elements[7], this.elements[11], this.elements[15]);
|
||||
copy: function () {
|
||||
return new Matrix(this.elements[0], this.elements[4], this.elements[8], this.elements[12],
|
||||
this.elements[1], this.elements[5], this.elements[9], this.elements[13],
|
||||
this.elements[2], this.elements[6], this.elements[10], this.elements[14],
|
||||
this.elements[3], this.elements[7], this.elements[11], this.elements[15]);
|
||||
},
|
||||
|
||||
multiplyMatrix: function(otherMatrix) {
|
||||
if (!(otherMatrix instanceof Matrix)) {
|
||||
throw "invalid otherMatrix";
|
||||
}
|
||||
var values1 = this.elements;
|
||||
var values2 = otherMatrix.elements;
|
||||
var m11 = values1[0] * values2[0] + values1[4] * values2[1] + values1[8] * values2[2] + values1[12] * values2[3];
|
||||
var m12 = values1[0] * values2[4] + values1[4] * values2[5] + values1[8] * values2[6] + values1[12] * values2[7];
|
||||
var m13 = values1[0] * values2[8] + values1[4] * values2[9] + values1[8] * values2[10] + values1[12] * values2[11];
|
||||
var m14 = values1[0] * values2[12] + values1[4] * values2[13] + values1[8] * values2[14] + values1[12] * values2[15];
|
||||
var m21 = values1[1] * values2[0] + values1[5] * values2[1] + values1[9] * values2[2] + values1[13] * values2[3];
|
||||
var m22 = values1[1] * values2[4] + values1[5] * values2[5] + values1[9] * values2[6] + values1[13] * values2[7];
|
||||
var m23 = values1[1] * values2[8] + values1[5] * values2[9] + values1[9] * values2[10] + values1[13] * values2[11];
|
||||
var m24 = values1[1] * values2[12] + values1[5] * values2[13] + values1[9] * values2[14] + values1[13] * values2[15];
|
||||
var m31 = values1[2] * values2[0] + values1[6] * values2[1] + values1[10] * values2[2] + values1[14] * values2[3];
|
||||
var m32 = values1[2] * values2[4] + values1[6] * values2[5] + values1[10] * values2[6] + values1[14] * values2[7];
|
||||
var m33 = values1[2] * values2[8] + values1[6] * values2[9] + values1[10] * values2[10] + values1[14] * values2[11];
|
||||
var m34 = values1[2] * values2[12] + values1[6] * values2[13] + values1[10] * values2[14] + values1[14] * values2[15];
|
||||
var m41 = values1[3] * values2[0] + values1[7] * values2[1] + values1[11] * values2[2] + values1[15] * values2[3];
|
||||
var m42 = values1[3] * values2[4] + values1[7] * values2[5] + values1[11] * values2[6] + values1[15] * values2[7];
|
||||
var m43 = values1[3] * values2[8] + values1[7] * values2[9] + values1[11] * values2[10] + values1[15] * values2[11];
|
||||
var m44 = values1[3] * values2[12] + values1[7] * values2[13] + values1[11] * values2[14] + values1[15] * values2[15];
|
||||
return new Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
|
||||
multiplyMatrix: function (otherMatrix) {
|
||||
if (!(otherMatrix instanceof Matrix)) {
|
||||
throw "invalid otherMatrix";
|
||||
}
|
||||
var values1 = this.elements;
|
||||
var values2 = otherMatrix.elements;
|
||||
var m11 = values1[0] * values2[0] + values1[4] * values2[1] + values1[8] * values2[2] + values1[12] * values2[3];
|
||||
var m12 = values1[0] * values2[4] + values1[4] * values2[5] + values1[8] * values2[6] + values1[12] * values2[7];
|
||||
var m13 = values1[0] * values2[8] + values1[4] * values2[9] + values1[8] * values2[10] + values1[12] * values2[11];
|
||||
var m14 = values1[0] * values2[12] + values1[4] * values2[13] + values1[8] * values2[14] + values1[12] * values2[15];
|
||||
var m21 = values1[1] * values2[0] + values1[5] * values2[1] + values1[9] * values2[2] + values1[13] * values2[3];
|
||||
var m22 = values1[1] * values2[4] + values1[5] * values2[5] + values1[9] * values2[6] + values1[13] * values2[7];
|
||||
var m23 = values1[1] * values2[8] + values1[5] * values2[9] + values1[9] * values2[10] + values1[13] * values2[11];
|
||||
var m24 = values1[1] * values2[12] + values1[5] * values2[13] + values1[9] * values2[14] + values1[13] * values2[15];
|
||||
var m31 = values1[2] * values2[0] + values1[6] * values2[1] + values1[10] * values2[2] + values1[14] * values2[3];
|
||||
var m32 = values1[2] * values2[4] + values1[6] * values2[5] + values1[10] * values2[6] + values1[14] * values2[7];
|
||||
var m33 = values1[2] * values2[8] + values1[6] * values2[9] + values1[10] * values2[10] + values1[14] * values2[11];
|
||||
var m34 = values1[2] * values2[12] + values1[6] * values2[13] + values1[10] * values2[14] + values1[14] * values2[15];
|
||||
var m41 = values1[3] * values2[0] + values1[7] * values2[1] + values1[11] * values2[2] + values1[15] * values2[3];
|
||||
var m42 = values1[3] * values2[4] + values1[7] * values2[5] + values1[11] * values2[6] + values1[15] * values2[7];
|
||||
var m43 = values1[3] * values2[8] + values1[7] * values2[9] + values1[11] * values2[10] + values1[15] * values2[11];
|
||||
var m44 = values1[3] * values2[12] + values1[7] * values2[13] + values1[11] * values2[14] + values1[15] * values2[15];
|
||||
return new Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -297,249 +299,248 @@ define(["require", "world/Utils", "world/Vertice", "world/Vector"], function(req
|
||||
* @param c 四元数组
|
||||
* @return {Matrix} 列向量,四元数组
|
||||
*/
|
||||
multiplyColumn: function(c) {
|
||||
var valid = Utils.isArray(c) && c.length == 4;
|
||||
if (!valid) {
|
||||
throw "invalid c";
|
||||
}
|
||||
var values1 = this.elements;
|
||||
var values2 = c;
|
||||
var m11 = values1[0] * values2[0] + values1[4] * values2[1] + values1[8] * values2[2] + values1[12] * values2[3];
|
||||
var m21 = values1[1] * values2[0] + values1[5] * values2[1] + values1[9] * values2[2] + values1[13] * values2[3];
|
||||
var m31 = values1[2] * values2[0] + values1[6] * values2[1] + values1[10] * values2[2] + values1[14] * values2[3];
|
||||
var m41 = values1[3] * values2[0] + values1[7] * values2[1] + values1[11] * values2[2] + values1[15] * values2[3];
|
||||
return [m11, m21, m31, m41];
|
||||
},
|
||||
|
||||
divide: function(a) {
|
||||
if (!Utils.isNumber(a)) {
|
||||
throw "invalid a:a is not number";
|
||||
}
|
||||
if (a === 0) {
|
||||
throw "invalid a:a is 0";
|
||||
}
|
||||
if (a !== 0) {
|
||||
for (var i = 0, length = this.elements.length; i < length; i++) {
|
||||
this.elements[i] /= a;
|
||||
multiplyColumn: function (c) {
|
||||
var valid = Utils.isArray(c) && c.length == 4;
|
||||
if (!valid) {
|
||||
throw "invalid c";
|
||||
}
|
||||
}
|
||||
var values1 = this.elements;
|
||||
var values2 = c;
|
||||
var m11 = values1[0] * values2[0] + values1[4] * values2[1] + values1[8] * values2[2] + values1[12] * values2[3];
|
||||
var m21 = values1[1] * values2[0] + values1[5] * values2[1] + values1[9] * values2[2] + values1[13] * values2[3];
|
||||
var m31 = values1[2] * values2[0] + values1[6] * values2[1] + values1[10] * values2[2] + values1[14] * values2[3];
|
||||
var m41 = values1[3] * values2[0] + values1[7] * values2[1] + values1[11] * values2[2] + values1[15] * values2[3];
|
||||
return [m11, m21, m31, m41];
|
||||
},
|
||||
|
||||
worldTranslate: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[12] += x;
|
||||
this.elements[13] += y;
|
||||
this.elements[14] += z;
|
||||
divide: function (a) {
|
||||
if (!Utils.isNumber(a)) {
|
||||
throw "invalid a:a is not number";
|
||||
}
|
||||
if (a === 0) {
|
||||
throw "invalid a:a is 0";
|
||||
}
|
||||
if (a !== 0) {
|
||||
for (var i = 0, length = this.elements.length; i < length; i++) {
|
||||
this.elements[i] /= a;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
localTranslate: function(x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
var localColumn = [x, y, z, 1];
|
||||
var worldColumn = this.multiplyColumn(localColumn);
|
||||
var origin = this.getPosition();
|
||||
this.worldTranslate(worldColumn[0] - origin.x, worldColumn[1] - origin.y, worldColumn[2] - origin.z);
|
||||
worldTranslate: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
this.elements[12] += x;
|
||||
this.elements[13] += y;
|
||||
this.elements[14] += z;
|
||||
},
|
||||
|
||||
worldScale: function(scaleX, scaleY, scaleZ) {
|
||||
scaleX = (scaleX !== undefined) ? scaleX : 1;
|
||||
scaleY = (scaleY !== undefined) ? scaleY : 1;
|
||||
scaleZ = (scaleZ !== undefined) ? scaleZ : 1;
|
||||
if (!Utils.isNumber(scaleX)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(scaleY)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(scaleZ)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
var m = new Matrix(scaleX, 0, 0, 0,
|
||||
0, scaleY, 0, 0,
|
||||
0, 0, scaleZ, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
localTranslate: function (x, y, z) {
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
var localColumn = [x, y, z, 1];
|
||||
var worldColumn = this.multiplyColumn(localColumn);
|
||||
var origin = this.getPosition();
|
||||
this.worldTranslate(worldColumn[0] - origin.x, worldColumn[1] - origin.y, worldColumn[2] - origin.z);
|
||||
},
|
||||
|
||||
localScale: function(scaleX, scaleY, scaleZ) {
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
this.worldScale(scaleX, scaleY, scaleZ);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
worldScale: function (scaleX, scaleY, scaleZ) {
|
||||
scaleX = (scaleX !== undefined) ? scaleX : 1;
|
||||
scaleY = (scaleY !== undefined) ? scaleY : 1;
|
||||
scaleZ = (scaleZ !== undefined) ? scaleZ : 1;
|
||||
if (!Utils.isNumber(scaleX)) {
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(scaleY)) {
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(scaleZ)) {
|
||||
throw "invalid z";
|
||||
}
|
||||
var m = new Matrix(scaleX, 0, 0, 0,
|
||||
0, scaleY, 0, 0,
|
||||
0, 0, scaleZ, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
worldRotateX: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(1, 0, 0, 0,
|
||||
0, c, -s, 0,
|
||||
0, s, c, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
localScale: function (scaleX, scaleY, scaleZ) {
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
this.worldScale(scaleX, scaleY, scaleZ);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
},
|
||||
|
||||
worldRotateY: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(c, 0, s, 0,
|
||||
0, 1, 0, 0, -s, 0, c, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
worldRotateX: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(1, 0, 0, 0,
|
||||
0, c, -s, 0,
|
||||
0, s, c, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
worldRotateZ: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(c, -s, 0, 0,
|
||||
s, c, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
worldRotateY: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(c, 0, s, 0,
|
||||
0, 1, 0, 0, -s, 0, c, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
worldRotateByVector: function(radian, vector) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
if (!(vector instanceof Vector)) {
|
||||
throw "invalid vector:not Vector";
|
||||
}
|
||||
var x = vector.x;
|
||||
var y = vector.y;
|
||||
var z = vector.z;
|
||||
|
||||
var length, s, c;
|
||||
var xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
|
||||
|
||||
s = Math.sin(radian);
|
||||
c = Math.cos(radian);
|
||||
|
||||
length = Math.sqrt(x * x + y * y + z * z);
|
||||
|
||||
// Rotation matrix is normalized
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
|
||||
xx = x * x;
|
||||
yy = y * y;
|
||||
zz = z * z;
|
||||
xy = x * y;
|
||||
yz = y * z;
|
||||
zx = z * x;
|
||||
xs = x * s;
|
||||
ys = y * s;
|
||||
zs = z * s;
|
||||
one_c = 1.0 - c;
|
||||
|
||||
var m11 = (one_c * xx) + c; //M(0,0)
|
||||
var m12 = (one_c * xy) - zs; //M(0,1)
|
||||
var m13 = (one_c * zx) + ys; //M(0,2)
|
||||
var m14 = 0.0; //M(0,3) 表示平移X
|
||||
|
||||
var m21 = (one_c * xy) + zs; //M(1,0)
|
||||
var m22 = (one_c * yy) + c; //M(1,1)
|
||||
var m23 = (one_c * yz) - xs; //M(1,2)
|
||||
var m24 = 0.0; //M(1,3) 表示平移Y
|
||||
|
||||
var m31 = (one_c * zx) - ys; //M(2,0)
|
||||
var m32 = (one_c * yz) + xs; //M(2,1)
|
||||
var m33 = (one_c * zz) + c; //M(2,2)
|
||||
var m34 = 0.0; //M(2,3) 表示平移Z
|
||||
|
||||
var m41 = 0.0; //M(3,0)
|
||||
var m42 = 0.0; //M(3,1)
|
||||
var m43 = 0.0; //M(3,2)
|
||||
var m44 = 1.0; //M(3,3)
|
||||
|
||||
var mat = new Matrix(m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
m41, m42, m43, m44);
|
||||
var result = mat.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
worldRotateZ: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var c = Math.cos(radian);
|
||||
var s = Math.sin(radian);
|
||||
var m = new Matrix(c, -s, 0, 0,
|
||||
s, c, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
var result = m.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
localRotateX: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnX = this.getColumnX().getVector();
|
||||
this.worldRotateByVector(radian, columnX);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
worldRotateByVector: function (radian, vector) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
if (!(vector instanceof Vector)) {
|
||||
throw "invalid vector:not Vector";
|
||||
}
|
||||
var x = vector.x;
|
||||
var y = vector.y;
|
||||
var z = vector.z;
|
||||
|
||||
var length, s, c;
|
||||
var xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
|
||||
|
||||
s = Math.sin(radian);
|
||||
c = Math.cos(radian);
|
||||
|
||||
length = Math.sqrt(x * x + y * y + z * z);
|
||||
|
||||
// Rotation matrix is normalized
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
|
||||
xx = x * x;
|
||||
yy = y * y;
|
||||
zz = z * z;
|
||||
xy = x * y;
|
||||
yz = y * z;
|
||||
zx = z * x;
|
||||
xs = x * s;
|
||||
ys = y * s;
|
||||
zs = z * s;
|
||||
one_c = 1.0 - c;
|
||||
|
||||
var m11 = (one_c * xx) + c; //M(0,0)
|
||||
var m12 = (one_c * xy) - zs; //M(0,1)
|
||||
var m13 = (one_c * zx) + ys; //M(0,2)
|
||||
var m14 = 0.0; //M(0,3) 表示平移X
|
||||
|
||||
var m21 = (one_c * xy) + zs; //M(1,0)
|
||||
var m22 = (one_c * yy) + c; //M(1,1)
|
||||
var m23 = (one_c * yz) - xs; //M(1,2)
|
||||
var m24 = 0.0; //M(1,3) 表示平移Y
|
||||
|
||||
var m31 = (one_c * zx) - ys; //M(2,0)
|
||||
var m32 = (one_c * yz) + xs; //M(2,1)
|
||||
var m33 = (one_c * zz) + c; //M(2,2)
|
||||
var m34 = 0.0; //M(2,3) 表示平移Z
|
||||
|
||||
var m41 = 0.0; //M(3,0)
|
||||
var m42 = 0.0; //M(3,1)
|
||||
var m43 = 0.0; //M(3,2)
|
||||
var m44 = 1.0; //M(3,3)
|
||||
|
||||
var mat = new Matrix(m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
m41, m42, m43, m44);
|
||||
var result = mat.multiplyMatrix(this);
|
||||
this.setMatrixByOther(result);
|
||||
},
|
||||
|
||||
localRotateY: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnY = this.getColumnY().getVector();
|
||||
this.worldRotateByVector(radian, columnY);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
localRotateX: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnX = this.getColumnX().getVector();
|
||||
this.worldRotateByVector(radian, columnX);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
},
|
||||
|
||||
localRotateZ: function(radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnZ = this.getColumnZ().getVector();
|
||||
this.worldRotateByVector(radian, columnZ);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
localRotateY: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnY = this.getColumnY().getVector();
|
||||
this.worldRotateByVector(radian, columnY);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
},
|
||||
|
||||
localRotateZ: function (radian) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian:not number";
|
||||
}
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
var columnZ = this.getColumnZ().getVector();
|
||||
this.worldRotateByVector(radian, columnZ);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
},
|
||||
|
||||
//localVector指的是相对于模型坐标系中的向量
|
||||
localRotateByVector: function(radian, localVector) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian: not number";
|
||||
}
|
||||
if (!(localVector instanceof Vector)) {
|
||||
throw "invalid localVector: not Vector";
|
||||
}
|
||||
var localColumn = localVector.getArray();
|
||||
localColumn.push(1); //四元数组
|
||||
var worldColumn = this.multiplyColumn(localColumn); //模型坐标转换为世界坐标
|
||||
var worldVector = new Vector(worldColumn[0], worldColumn[1], worldColumn[2]);
|
||||
localRotateByVector: function (radian, localVector) {
|
||||
if (!Utils.isNumber(radian)) {
|
||||
throw "invalid radian: not number";
|
||||
}
|
||||
if (!(localVector instanceof Vector)) {
|
||||
throw "invalid localVector: not Vector";
|
||||
}
|
||||
var localColumn = localVector.getArray();
|
||||
localColumn.push(1); //四元数组
|
||||
var worldColumn = this.multiplyColumn(localColumn); //模型坐标转换为世界坐标
|
||||
var worldVector = new Vector(worldColumn[0], worldColumn[1], worldColumn[2]);
|
||||
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
this.worldRotateByVector(radian, worldVector);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
var transVertice = this.getColumnTrans();
|
||||
this.setColumnTrans(0, 0, 0);
|
||||
this.worldRotateByVector(radian, worldVector);
|
||||
this.setColumnTrans(transVertice.x, transVertice.y, transVertice.z);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return Matrix;
|
||||
});
|
||||
export default Matrix;
|
||||
@ -1,16 +1,19 @@
|
||||
define(["world/TiledLayer"], function(TiledLayer) {
|
||||
var NokiaTiledLayer = function(args) {
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
var NokiaTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
NokiaTiledLayer.prototype = new TiledLayer();
|
||||
NokiaTiledLayer.prototype.constructor = NokiaTiledLayer;
|
||||
NokiaTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
NokiaTiledLayer.prototype = new TiledLayer();
|
||||
NokiaTiledLayer.prototype.constructor = NokiaTiledLayer;
|
||||
|
||||
NokiaTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var sum = level + row + column;
|
||||
var idx = 1 + sum % 4; //1,2,3,4
|
||||
//https://1.base.maps.api.here.com/maptile/2.1/maptile/2ae1d8fbb0/normal.day/4/9/7/512/png8?app_id=xWVIueSv6JL0aJ5xqTxb&app_code=djPZyynKsbTjIUDOBcHZ2g&lg=eng&ppi=72&pview=DEF
|
||||
var url = "//"+idx+".base.maps.api.here.com/maptile/2.1/maptile/2ae1d8fbb0/normal.day/"+level+"/"+column+"/"+row+"/512/png8?app_id=xWVIueSv6JL0aJ5xqTxb&app_code=djPZyynKsbTjIUDOBcHZ2g&lg=eng&ppi=72&pview=DEF";
|
||||
var url = "//" + idx + ".base.maps.api.here.com/maptile/2.1/maptile/2ae1d8fbb0/normal.day/" + level + "/" + column + "/" + row + "/512/png8?app_id=xWVIueSv6JL0aJ5xqTxb&app_code=djPZyynKsbTjIUDOBcHZ2g&lg=eng&ppi=72&pview=DEF";
|
||||
return url;
|
||||
};
|
||||
return NokiaTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default NokiaTiledLayer;
|
||||
@ -1,81 +1,83 @@
|
||||
define(["world/Kernel", "world/Matrix", "world/TextureMaterial"],
|
||||
function(Kernel, Matrix, TextureMaterial) {
|
||||
/**
|
||||
import Kernel from './Kernel';
|
||||
import Matrix from './Matrix';
|
||||
import TextureMaterial from './TextureMaterial';
|
||||
|
||||
/**
|
||||
* 三维对象的基类
|
||||
* @param args
|
||||
* @constructor
|
||||
*/
|
||||
var Object3D = function(args) {
|
||||
this.id = ++Kernel.idCounter;
|
||||
this.matrix = new Matrix();
|
||||
this.parent = null;
|
||||
this.vertices = [];
|
||||
this.vertexBuffer = null;
|
||||
this.indices = [];
|
||||
this.indexBuffer = null;
|
||||
this.textureCoords = [];
|
||||
this.textureCoordBuffer = null;
|
||||
this.material = null;
|
||||
this.visible = true;
|
||||
if (args && args.material) {
|
||||
var Object3D = function (args) {
|
||||
this.id = ++Kernel.idCounter;
|
||||
this.matrix = new Matrix();
|
||||
this.parent = null;
|
||||
this.vertices = [];
|
||||
this.vertexBuffer = null;
|
||||
this.indices = [];
|
||||
this.indexBuffer = null;
|
||||
this.textureCoords = [];
|
||||
this.textureCoordBuffer = null;
|
||||
this.material = null;
|
||||
this.visible = true;
|
||||
if (args && args.material) {
|
||||
this.material = args.material;
|
||||
}
|
||||
this.createVerticeData(args);
|
||||
};
|
||||
Object3D.prototype = {
|
||||
constructor: Object3D,
|
||||
}
|
||||
this.createVerticeData(args);
|
||||
};
|
||||
Object3D.prototype = {
|
||||
constructor: Object3D,
|
||||
|
||||
/**
|
||||
* 根据传入的参数生成vertices和indices,然后通过调用setBuffers初始化buffer
|
||||
* @param params 传入的参数
|
||||
*/
|
||||
createVerticeData: function(params) {
|
||||
/**
|
||||
* 根据传入的参数生成vertices和indices,然后通过调用setBuffers初始化buffer
|
||||
* @param params 传入的参数
|
||||
*/
|
||||
createVerticeData: function (params) {
|
||||
/*var infos = {
|
||||
vertices:vertices,
|
||||
indices:indices
|
||||
};
|
||||
this.setBuffers(infos);*/
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置buffer,由createVerticeData函数调用
|
||||
* @param infos 包含vertices和indices信息,由createVerticeData传入参数
|
||||
*/
|
||||
setBuffers: function(infos) {
|
||||
/**
|
||||
* 设置buffer,由createVerticeData函数调用
|
||||
* @param infos 包含vertices和indices信息,由createVerticeData传入参数
|
||||
*/
|
||||
setBuffers: function (infos) {
|
||||
if (infos) {
|
||||
this.vertices = infos.vertices || [];
|
||||
this.indices = infos.indices || [];
|
||||
this.textureCoords = infos.textureCoords || [];
|
||||
if (this.vertices.length > 0 && this.indices.length > 0) {
|
||||
if (!(gl.isBuffer(this.vertexBuffer))) {
|
||||
this.vertexBuffer = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.vertices), gl.STATIC_DRAW);
|
||||
this.vertices = infos.vertices || [];
|
||||
this.indices = infos.indices || [];
|
||||
this.textureCoords = infos.textureCoords || [];
|
||||
if (this.vertices.length > 0 && this.indices.length > 0) {
|
||||
if (!(gl.isBuffer(this.vertexBuffer))) {
|
||||
this.vertexBuffer = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.vertices), gl.STATIC_DRAW);
|
||||
|
||||
if (!(gl.isBuffer(this.indexBuffer))) {
|
||||
this.indexBuffer = gl.createBuffer();
|
||||
if (!(gl.isBuffer(this.indexBuffer))) {
|
||||
this.indexBuffer = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), gl.STATIC_DRAW);
|
||||
}
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), gl.STATIC_DRAW);
|
||||
}
|
||||
|
||||
//使用纹理
|
||||
if (this.material instanceof TextureMaterial) {
|
||||
if (this.textureCoords.length > 0) { //提供了纹理坐标
|
||||
if (!(gl.isBuffer(this.textureCoordBuffer))) {
|
||||
this.textureCoordBuffer = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.textureCoords), gl.STATIC_DRAW);
|
||||
//使用纹理
|
||||
if (this.material instanceof TextureMaterial) {
|
||||
if (this.textureCoords.length > 0) { //提供了纹理坐标
|
||||
if (!(gl.isBuffer(this.textureCoordBuffer))) {
|
||||
this.textureCoordBuffer = gl.createBuffer();
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.textureCoords), gl.STATIC_DRAW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
||||
},
|
||||
},
|
||||
|
||||
setShaderMatrix: function(camera) {
|
||||
setShaderMatrix: function (camera) {
|
||||
// if (!(camera instanceof PerspectiveCamera)) {
|
||||
// throw "invalid camera : not World.PerspectiveCamera";
|
||||
// }
|
||||
@ -83,147 +85,147 @@ define(["world/Kernel", "world/Matrix", "world/TextureMaterial"],
|
||||
var mvMatrix = camera.viewMatrix.multiplyMatrix(this.matrix);
|
||||
gl.uniformMatrix4fv(gl.shaderProgram.uMVMatrix, false, mvMatrix.elements);
|
||||
gl.uniformMatrix4fv(gl.shaderProgram.uPMatrix, false, camera.projMatrix.elements);
|
||||
},
|
||||
},
|
||||
|
||||
draw: function(camera) {
|
||||
draw: function (camera) {
|
||||
// if (!(camera instanceof PerspectiveCamera)) {
|
||||
// throw "invalid camera : not World.PerspectiveCamera";
|
||||
// }
|
||||
if (this.visible) {
|
||||
if (this.material instanceof TextureMaterial && this.material.loaded) {
|
||||
gl.enableVertexAttribArray(gl.shaderProgram.aTextureCoord);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(gl.shaderProgram.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
if (this.material instanceof TextureMaterial && this.material.loaded) {
|
||||
gl.enableVertexAttribArray(gl.shaderProgram.aTextureCoord);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureCoordBuffer);
|
||||
gl.vertexAttribPointer(gl.shaderProgram.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.material.texture);
|
||||
gl.uniform1i(gl.shaderProgram.uSampler, 0);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.material.texture);
|
||||
gl.uniform1i(gl.shaderProgram.uSampler, 0);
|
||||
|
||||
this.setShaderMatrix(camera);
|
||||
this.setShaderMatrix(camera);
|
||||
|
||||
//往shader中对vertex赋值
|
||||
gl.enableVertexAttribArray(gl.shaderProgram.aVertexPosition);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.vertexAttribPointer(gl.shaderProgram.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
//往shader中对vertex赋值
|
||||
gl.enableVertexAttribArray(gl.shaderProgram.aVertexPosition);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.vertexAttribPointer(gl.shaderProgram.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//设置索引,但不用往shader中赋值
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
//绘图
|
||||
gl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
//设置索引,但不用往shader中赋值
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
//绘图
|
||||
gl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
//释放显存中的buffer资源
|
||||
releaseBuffers: function() {
|
||||
//释放显存中的buffer资源
|
||||
releaseBuffers: function () {
|
||||
//释放显卡中的资源
|
||||
if (gl.isBuffer(this.vertexBuffer)) {
|
||||
gl.deleteBuffer(this.vertexBuffer);
|
||||
gl.deleteBuffer(this.vertexBuffer);
|
||||
}
|
||||
if (gl.isBuffer(this.indexBuffer)) {
|
||||
gl.deleteBuffer(this.indexBuffer);
|
||||
gl.deleteBuffer(this.indexBuffer);
|
||||
}
|
||||
if (gl.isBuffer(this.textureCoordBuffer)) {
|
||||
gl.deleteBuffer(this.textureCoordBuffer);
|
||||
gl.deleteBuffer(this.textureCoordBuffer);
|
||||
}
|
||||
this.vertexBuffer = null;
|
||||
this.indexBuffer = null;
|
||||
this.textureCoordBuffer = null;
|
||||
},
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
destroy: function () {
|
||||
this.parent = null;
|
||||
this.releaseBuffers();
|
||||
if (this.material instanceof TextureMaterial) {
|
||||
this.material.releaseTexture();
|
||||
this.material = null;
|
||||
this.material.releaseTexture();
|
||||
this.material = null;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
//需要子类重写
|
||||
getPosition: function() {
|
||||
//需要子类重写
|
||||
getPosition: function () {
|
||||
var position = this.matrix.getColumnTrans();
|
||||
return position;
|
||||
},
|
||||
},
|
||||
|
||||
//需要子类重写
|
||||
setPosition: function(x, y, z) {
|
||||
//需要子类重写
|
||||
setPosition: function (x, y, z) {
|
||||
this.matrix.setColumnTrans(x, y, z);
|
||||
},
|
||||
},
|
||||
|
||||
worldTranslate: function(x, y, z) {
|
||||
worldTranslate: function (x, y, z) {
|
||||
this.matrix.worldTranslate(x, y, z);
|
||||
},
|
||||
},
|
||||
|
||||
localTranslate: function(x, y, z) {
|
||||
localTranslate: function (x, y, z) {
|
||||
this.matrix.localTranslate(x, y, z);
|
||||
},
|
||||
},
|
||||
|
||||
worldScale: function(scaleX, scaleY, scaleZ) {
|
||||
worldScale: function (scaleX, scaleY, scaleZ) {
|
||||
this.matrix.worldScale(scaleX, scaleY, scaleZ);
|
||||
},
|
||||
},
|
||||
|
||||
localScale: function(scaleX, scaleY, scaleZ) {
|
||||
localScale: function (scaleX, scaleY, scaleZ) {
|
||||
this.matrix.localScale(scaleX, scaleY, scaleZ);
|
||||
},
|
||||
},
|
||||
|
||||
worldRotateX: function(radian) {
|
||||
worldRotateX: function (radian) {
|
||||
this.matrix.worldRotateX(radian);
|
||||
},
|
||||
},
|
||||
|
||||
worldRotateY: function(radian) {
|
||||
worldRotateY: function (radian) {
|
||||
this.matrix.worldRotateY(radian);
|
||||
},
|
||||
},
|
||||
|
||||
worldRotateZ: function(radian) {
|
||||
worldRotateZ: function (radian) {
|
||||
this.matrix.worldRotateZ(radian);
|
||||
},
|
||||
},
|
||||
|
||||
worldRotateByVector: function(radian, vector) {
|
||||
worldRotateByVector: function (radian, vector) {
|
||||
this.matrix.worldRotateByVector(radian, vector);
|
||||
},
|
||||
},
|
||||
|
||||
localRotateX: function(radian) {
|
||||
localRotateX: function (radian) {
|
||||
this.matrix.localRotateX(radian);
|
||||
},
|
||||
},
|
||||
|
||||
localRotateY: function(radian) {
|
||||
localRotateY: function (radian) {
|
||||
this.matrix.localRotateY(radian);
|
||||
},
|
||||
},
|
||||
|
||||
localRotateZ: function(radian) {
|
||||
localRotateZ: function (radian) {
|
||||
this.matrix.localRotateZ(radian);
|
||||
},
|
||||
},
|
||||
|
||||
//localVector指的是相对于模型坐标系中的向量
|
||||
localRotateByVector: function(radian, localVector) {
|
||||
//localVector指的是相对于模型坐标系中的向量
|
||||
localRotateByVector: function (radian, localVector) {
|
||||
this.matrix.localRotateByVector(radian, localVector);
|
||||
},
|
||||
},
|
||||
|
||||
getXAxisDirection: function() {
|
||||
getXAxisDirection: function () {
|
||||
var columnX = this.matrix.getColumnX(); //Vertice
|
||||
var directionX = columnX.getVector(); //Vector
|
||||
directionX.normalize();
|
||||
return directionX;
|
||||
},
|
||||
},
|
||||
|
||||
getYAxisDirection: function() {
|
||||
getYAxisDirection: function () {
|
||||
var columnY = this.matrix.getColumnY();
|
||||
var directionY = columnY.getVector();
|
||||
directionY.normalize();
|
||||
return directionY;
|
||||
},
|
||||
},
|
||||
|
||||
getZAxisDirection: function() {
|
||||
getZAxisDirection: function () {
|
||||
var columnZ = this.matrix.getColumnZ();
|
||||
var directionZ = columnZ.getVector();
|
||||
directionZ.normalize();
|
||||
return directionZ;
|
||||
}
|
||||
};
|
||||
return Object3D;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default Object3D;
|
||||
@ -1,135 +1,138 @@
|
||||
define(["world/Kernel", "world/Matrix", "world/Object3D", "world/PerspectiveCamera"],
|
||||
function(Kernel, Matrix, Object3D, PerspectiveCamera) {
|
||||
//三维对象集合
|
||||
var Object3DComponents = function() {
|
||||
import Kernel from './Kernel';
|
||||
import Matrix from './Matrix';
|
||||
import Object3D from './Object3D';
|
||||
import PerspectiveCamera from './PerspectiveCamera';
|
||||
|
||||
//三维对象集合
|
||||
var Object3DComponents = function () {
|
||||
this.id = ++Kernel.idCounter;
|
||||
this.matrix = new Matrix();
|
||||
this.visible = true;
|
||||
this.parent = null;
|
||||
this.children = [];
|
||||
};
|
||||
Object3DComponents.prototype = {
|
||||
};
|
||||
Object3DComponents.prototype = {
|
||||
constructor: Object3DComponents,
|
||||
|
||||
add: function(obj) {
|
||||
if (!(obj instanceof Object3D || obj instanceof Object3DComponents)) {
|
||||
throw "invalid obj: not World.Object3D or Object3DComponents";
|
||||
}
|
||||
add: function (obj) {
|
||||
if (!(obj instanceof Object3D || obj instanceof Object3DComponents)) {
|
||||
throw "invalid obj: not World.Object3D or Object3DComponents";
|
||||
}
|
||||
|
||||
if (this.findObjById(obj.id) !== null) {
|
||||
console.debug("obj已经存在于Object3DComponents中,无法将其再次加入!");
|
||||
return;
|
||||
} else {
|
||||
this.children.push(obj);
|
||||
obj.parent = this;
|
||||
}
|
||||
if (this.findObjById(obj.id) !== null) {
|
||||
console.debug("obj已经存在于Object3DComponents中,无法将其再次加入!");
|
||||
return;
|
||||
} else {
|
||||
this.children.push(obj);
|
||||
obj.parent = this;
|
||||
}
|
||||
},
|
||||
|
||||
remove: function(obj) {
|
||||
if (obj) {
|
||||
var result = this.findObjById(obj.id);
|
||||
if (result === null) {
|
||||
console.debug("obj不存在于Object3DComponents中,所以无法将其从中删除!");
|
||||
return false;
|
||||
remove: function (obj) {
|
||||
if (obj) {
|
||||
var result = this.findObjById(obj.id);
|
||||
if (result === null) {
|
||||
console.debug("obj不存在于Object3DComponents中,所以无法将其从中删除!");
|
||||
return false;
|
||||
}
|
||||
obj.destroy();
|
||||
this.children.splice(result.index, 1);
|
||||
obj = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
obj.destroy();
|
||||
this.children.splice(result.index, 1);
|
||||
obj = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
//销毁所有的子节点
|
||||
clear: function() {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
obj.destroy();
|
||||
}
|
||||
this.children = [];
|
||||
clear: function () {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
obj.destroy();
|
||||
}
|
||||
this.children = [];
|
||||
},
|
||||
|
||||
//销毁自身及其子节点
|
||||
destroy: function() {
|
||||
this.parent = null;
|
||||
this.clear();
|
||||
destroy: function () {
|
||||
this.parent = null;
|
||||
this.clear();
|
||||
},
|
||||
|
||||
findObjById: function(objId) {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
if (obj.id == objId) {
|
||||
obj.index = i;
|
||||
return obj;
|
||||
findObjById: function (objId) {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
if (obj.id == objId) {
|
||||
obj.index = i;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
},
|
||||
|
||||
draw: function(camera) {
|
||||
if (!(camera instanceof PerspectiveCamera)) {
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
if (obj) {
|
||||
if (obj.visible) {
|
||||
obj.draw(camera);
|
||||
}
|
||||
draw: function (camera) {
|
||||
if (!(camera instanceof PerspectiveCamera)) {
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var obj = this.children[i];
|
||||
if (obj) {
|
||||
if (obj.visible) {
|
||||
obj.draw(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
worldTranslate: function(x, y, z) {
|
||||
this.matrix.worldTranslate(x, y, z);
|
||||
worldTranslate: function (x, y, z) {
|
||||
this.matrix.worldTranslate(x, y, z);
|
||||
},
|
||||
|
||||
localTranslate: function(x, y, z) {
|
||||
this.matrix.localTranslate(x, y, z);
|
||||
localTranslate: function (x, y, z) {
|
||||
this.matrix.localTranslate(x, y, z);
|
||||
},
|
||||
|
||||
worldScale: function(scaleX, scaleY, scaleZ) {
|
||||
this.matrix.worldScale(scaleX, scaleY, scaleZ);
|
||||
worldScale: function (scaleX, scaleY, scaleZ) {
|
||||
this.matrix.worldScale(scaleX, scaleY, scaleZ);
|
||||
},
|
||||
|
||||
localScale: function(scaleX, scaleY, scaleZ) {
|
||||
this.matrix.localScale(scaleX, scaleY, scaleZ);
|
||||
localScale: function (scaleX, scaleY, scaleZ) {
|
||||
this.matrix.localScale(scaleX, scaleY, scaleZ);
|
||||
},
|
||||
|
||||
worldRotateX: function(radian) {
|
||||
this.matrix.worldRotateX(radian);
|
||||
worldRotateX: function (radian) {
|
||||
this.matrix.worldRotateX(radian);
|
||||
},
|
||||
|
||||
worldRotateY: function(radian) {
|
||||
this.matrix.worldRotateY(radian);
|
||||
worldRotateY: function (radian) {
|
||||
this.matrix.worldRotateY(radian);
|
||||
},
|
||||
|
||||
worldRotateZ: function(radian) {
|
||||
this.matrix.worldRotateZ(radian);
|
||||
worldRotateZ: function (radian) {
|
||||
this.matrix.worldRotateZ(radian);
|
||||
},
|
||||
|
||||
worldRotateByVector: function(radian, vector) {
|
||||
this.matrix.worldRotateByVector(radian, vector);
|
||||
worldRotateByVector: function (radian, vector) {
|
||||
this.matrix.worldRotateByVector(radian, vector);
|
||||
},
|
||||
|
||||
localRotateX: function(radian) {
|
||||
this.matrix.localRotateX(radian);
|
||||
localRotateX: function (radian) {
|
||||
this.matrix.localRotateX(radian);
|
||||
},
|
||||
|
||||
localRotateY: function(radian) {
|
||||
this.matrix.localRotateY(radian);
|
||||
localRotateY: function (radian) {
|
||||
this.matrix.localRotateY(radian);
|
||||
},
|
||||
|
||||
localRotateZ: function(radian) {
|
||||
this.matrix.localRotateZ(radian);
|
||||
localRotateZ: function (radian) {
|
||||
this.matrix.localRotateZ(radian);
|
||||
},
|
||||
|
||||
//localVector指的是相对于模型坐标系中的向量
|
||||
localRotateByVector: function(radian, localVector) {
|
||||
this.matrix.localRotateByVector(radian, localVector);
|
||||
localRotateByVector: function (radian, localVector) {
|
||||
this.matrix.localRotateByVector(radian, localVector);
|
||||
}
|
||||
};
|
||||
return Object3DComponents;
|
||||
});
|
||||
};
|
||||
|
||||
export default Object3DComponents;
|
||||
@ -1,17 +1,20 @@
|
||||
define(["world/TiledLayer"], function(TiledLayer) {
|
||||
//OpenStreetMap
|
||||
var OsmTiledLayer = function(args) {
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
//OpenStreetMap
|
||||
var OsmTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
OsmTiledLayer.prototype = new TiledLayer();
|
||||
OsmTiledLayer.prototype.constructor = OsmTiledLayer;
|
||||
OsmTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
OsmTiledLayer.prototype = new TiledLayer();
|
||||
OsmTiledLayer.prototype.constructor = OsmTiledLayer;
|
||||
|
||||
OsmTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var sum = level + row + column;
|
||||
var idx = sum % 3;
|
||||
var server = ["a","b","c"][idx];
|
||||
var url = "//"+server+".tile.openstreetmap.org/"+level+"/"+column+"/"+row+".png";
|
||||
var server = ["a", "b", "c"][idx];
|
||||
var url = "//" + server + ".tile.openstreetmap.org/" + level + "/" + column + "/" + row + ".png";
|
||||
return url;
|
||||
};
|
||||
return OsmTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default OsmTiledLayer;
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
||||
define(["world/Utils"], function(Utils) {
|
||||
/**
|
||||
import Utils from './Utils';
|
||||
|
||||
/**
|
||||
* 三维空间中的平面,其法向量为(A,B,C)
|
||||
* @param A
|
||||
* @param B
|
||||
@ -8,28 +9,29 @@ define(["world/Utils"], function(Utils) {
|
||||
* @return {Object}
|
||||
* @constructor
|
||||
*/
|
||||
var Plan = function(A, B, C, D) {
|
||||
if (!Utils.isNumber(A)) {
|
||||
throw "invalid A";
|
||||
}
|
||||
if (!Utils.isNumber(B)) {
|
||||
throw "invalid B";
|
||||
}
|
||||
if (!Utils.isNumber(C)) {
|
||||
throw "invalid C";
|
||||
}
|
||||
if (!Utils.isNumber(D)) {
|
||||
throw "invalid D";
|
||||
}
|
||||
this.A = A;
|
||||
this.B = B;
|
||||
this.C = C;
|
||||
this.D = D;
|
||||
};
|
||||
Plan.prototype.constructor = Plan;
|
||||
Plan.prototype.getCopy = function() {
|
||||
var planCopy = new Plan(this.A, this.B, this.C, this.D);
|
||||
return planCopy;
|
||||
};
|
||||
return Plan;
|
||||
});
|
||||
var Plan = function (A, B, C, D) {
|
||||
if (!Utils.isNumber(A)) {
|
||||
throw "invalid A";
|
||||
}
|
||||
if (!Utils.isNumber(B)) {
|
||||
throw "invalid B";
|
||||
}
|
||||
if (!Utils.isNumber(C)) {
|
||||
throw "invalid C";
|
||||
}
|
||||
if (!Utils.isNumber(D)) {
|
||||
throw "invalid D";
|
||||
}
|
||||
this.A = A;
|
||||
this.B = B;
|
||||
this.C = C;
|
||||
this.D = D;
|
||||
};
|
||||
|
||||
Plan.prototype.constructor = Plan;
|
||||
Plan.prototype.getCopy = function () {
|
||||
var planCopy = new Plan(this.A, this.B, this.C, this.D);
|
||||
return planCopy;
|
||||
};
|
||||
|
||||
export default Plan;
|
||||
@ -1,43 +1,49 @@
|
||||
define(["world/Vertice", "world/Vector"], function(Vertice, Vector) {
|
||||
/**
|
||||
* 射线
|
||||
* @param position 射线起点 World.Vertice类型
|
||||
* @param direction 射线方向 World.Vector类型
|
||||
* @constructor
|
||||
*/
|
||||
var Ray = function(position, direction) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
}
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
};
|
||||
Ray.prototype.constructor = Ray;
|
||||
Ray.prototype.setVertice = function(position) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
return this;
|
||||
};
|
||||
Ray.prototype.setVector = function(direction) {
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
return this;
|
||||
};
|
||||
Ray.prototype.getCopy = function() {
|
||||
var rayCopy = new Ray(this.vertice, this.vector);
|
||||
return rayCopy;
|
||||
};
|
||||
Ray.prototype.rotateVertice = function(vertice) {
|
||||
};
|
||||
import Vertice from './Vertice';
|
||||
import Vector from './Vector';
|
||||
|
||||
return Ray;
|
||||
});
|
||||
/**
|
||||
* 射线
|
||||
* @param position 射线起点 World.Vertice类型
|
||||
* @param direction 射线方向 World.Vector类型
|
||||
* @constructor
|
||||
*/
|
||||
var Ray = function (position, direction) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
}
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
};
|
||||
|
||||
Ray.prototype.constructor = Ray;
|
||||
|
||||
Ray.prototype.setVertice = function (position) {
|
||||
if (!(position instanceof Vertice)) {
|
||||
throw "invalid position";
|
||||
}
|
||||
this.vertice = position.getCopy();
|
||||
return this;
|
||||
};
|
||||
|
||||
Ray.prototype.setVector = function (direction) {
|
||||
if (!(direction instanceof Vector)) {
|
||||
throw "invalid direction";
|
||||
}
|
||||
this.vector = direction.getCopy();
|
||||
this.vector.normalize();
|
||||
return this;
|
||||
};
|
||||
|
||||
Ray.prototype.getCopy = function () {
|
||||
var rayCopy = new Ray(this.vertice, this.vector);
|
||||
return rayCopy;
|
||||
};
|
||||
|
||||
Ray.prototype.rotateVertice = function (vertice) {
|
||||
};
|
||||
|
||||
export default Ray;
|
||||
@ -1,8 +1,10 @@
|
||||
define(["world/Object3DComponents"], function(Object3DComponents) {
|
||||
var Scene = function(args) {
|
||||
import Object3DComponents from './Object3DComponents';
|
||||
|
||||
var Scene = function (args) {
|
||||
Object3DComponents.apply(this, arguments);
|
||||
};
|
||||
Scene.prototype = new Object3DComponents();
|
||||
Scene.prototype.constructor = Scene;
|
||||
return Scene;
|
||||
});
|
||||
};
|
||||
|
||||
Scene.prototype = new Object3DComponents();
|
||||
Scene.prototype.constructor = Scene;
|
||||
|
||||
export default Scene;
|
||||
@ -1,6 +1,6 @@
|
||||
define({
|
||||
SIMPLE_SHADER: {
|
||||
var SIMPLE_SHADER = {
|
||||
VS_CONTENT: "attribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nvarying vec2 vTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvoid main()\n{\ngl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition,1.0);\nvTextureCoord = aTextureCoord;\n}",
|
||||
FS_CONTENT: "#ifdef GL_ES\nprecision highp float;\n#endif\nuniform bool uUseTexture;\nuniform float uShininess;\nuniform vec3 uLightDirection;\nuniform vec4 uLightAmbient;\nuniform vec4 uLightDiffuse;\nuniform vec4 uLightSpecular;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nvoid main()\n{\ngl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));\n}"
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default SIMPLE_SHADER;
|
||||
@ -1,10 +1,13 @@
|
||||
define(["world/TiledLayer"], function(TiledLayer) {
|
||||
var SosoTiledLayer = function(args) {
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
var SosoTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
SosoTiledLayer.prototype = new TiledLayer();
|
||||
SosoTiledLayer.prototype.constructor = SosoTiledLayer;
|
||||
SosoTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
SosoTiledLayer.prototype = new TiledLayer();
|
||||
SosoTiledLayer.prototype.constructor = SosoTiledLayer;
|
||||
|
||||
SosoTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var url = "";
|
||||
var tileCount = Math.pow(2, level);
|
||||
@ -18,6 +21,6 @@ define(["world/TiledLayer"], function(TiledLayer) {
|
||||
//var maptileUrl = "http://p"+serverIdx+".map.soso.com/maptilesv2/"+level+"/"+A+"/"+B+"/"+a+"_"+b+".png";
|
||||
url = sateUrl;
|
||||
return url;
|
||||
};
|
||||
return SosoTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
return SosoTiledLayer;
|
||||
@ -1,197 +1,210 @@
|
||||
define(["world/Kernel", "world/Utils", "world/Math", "world/Object3DComponents", "world/Tile", "world/Elevation"],
|
||||
function(Kernel, Utils, MathUtils, Object3DComponents, Tile, Elevation) {
|
||||
var SubTiledLayer = function(args) {
|
||||
Object3DComponents.apply(this, arguments);
|
||||
this.level = -1;
|
||||
//该级要请求的高程数据的层级,7[8,9,10];10[11,12,13];13[14,15,16];16[17,18,19]
|
||||
this.elevationLevel = -1;
|
||||
this.tiledLayer = null;
|
||||
if (args) {
|
||||
import Kernel from './Kernel';
|
||||
import Utils from './Utils';
|
||||
import Math from './Math';
|
||||
import Object3DComponents from './Object3DComponents';
|
||||
import Tile from './Tile';
|
||||
import Elevation from './Elevation';
|
||||
|
||||
var SubTiledLayer = function (args) {
|
||||
Object3DComponents.apply(this, arguments);
|
||||
this.level = -1;
|
||||
//该级要请求的高程数据的层级,7[8,9,10];10[11,12,13];13[14,15,16];16[17,18,19]
|
||||
this.elevationLevel = -1;
|
||||
this.tiledLayer = null;
|
||||
if (args) {
|
||||
if (args.level !== undefined) {
|
||||
this.level = args.level;
|
||||
this.elevationLevel = Elevation.getAncestorElevationLevel(this.level);
|
||||
this.level = args.level;
|
||||
this.elevationLevel = Elevation.getAncestorElevationLevel(this.level);
|
||||
}
|
||||
}
|
||||
};
|
||||
SubTiledLayer.prototype = new Object3DComponents();
|
||||
SubTiledLayer.prototype.constructor = SubTiledLayer;
|
||||
//重写draw方法
|
||||
SubTiledLayer.prototype.draw = function(camera) {
|
||||
if (this.level >= Kernel.TERRAIN_LEVEL && Kernel.globe && Kernel.globe.pitch <= Kernel.TERRAIN_PITCH) {
|
||||
}
|
||||
};
|
||||
|
||||
SubTiledLayer.prototype = new Object3DComponents();
|
||||
SubTiledLayer.prototype.constructor = SubTiledLayer;
|
||||
|
||||
//重写draw方法
|
||||
SubTiledLayer.prototype.draw = function (camera) {
|
||||
if (this.level >= Kernel.TERRAIN_LEVEL && Kernel.globe && Kernel.globe.pitch <= Kernel.TERRAIN_PITCH) {
|
||||
gl.clear(gl.DEPTH_BUFFER_BIT);
|
||||
gl.clearDepth(1);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
} else {
|
||||
} else {
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
}
|
||||
Object3DComponents.prototype.draw.apply(this, arguments);
|
||||
};
|
||||
//重写Object3DComponents的add方法
|
||||
SubTiledLayer.prototype.add = function(tile) {
|
||||
if (!(tile instanceof Tile)) {
|
||||
}
|
||||
Object3DComponents.prototype.draw.apply(this, arguments);
|
||||
};
|
||||
|
||||
//重写Object3DComponents的add方法
|
||||
SubTiledLayer.prototype.add = function (tile) {
|
||||
if (!(tile instanceof Tile)) {
|
||||
throw "invalid tile: not Tile";
|
||||
}
|
||||
if (tile.level == this.level) {
|
||||
}
|
||||
if (tile.level == this.level) {
|
||||
Object3DComponents.prototype.add.apply(this, arguments);
|
||||
tile.subTiledLayer = this;
|
||||
}
|
||||
};
|
||||
//调用其父的getImageUrl
|
||||
SubTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
}
|
||||
};
|
||||
|
||||
//调用其父的getImageUrl
|
||||
SubTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
}
|
||||
var url = "";
|
||||
if (this.tiledLayer) {
|
||||
}
|
||||
var url = "";
|
||||
if (this.tiledLayer) {
|
||||
url = this.tiledLayer.getImageUrl(level, row, column);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
//重写Object3DComponents的destroy方法
|
||||
SubTiledLayer.prototype.destroy = function() {
|
||||
Object3DComponents.prototype.destroy.apply(this, arguments);
|
||||
this.tiledLayer = null;
|
||||
};
|
||||
//根据level、row、column查找tile,可以供调试用
|
||||
SubTiledLayer.prototype.findTile = function(level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
//重写Object3DComponents的destroy方法
|
||||
SubTiledLayer.prototype.destroy = function () {
|
||||
Object3DComponents.prototype.destroy.apply(this, arguments);
|
||||
this.tiledLayer = null;
|
||||
};
|
||||
|
||||
//根据level、row、column查找tile,可以供调试用
|
||||
SubTiledLayer.prototype.findTile = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
}
|
||||
var length = this.children.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
}
|
||||
var length = this.children.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
var tile = this.children[i];
|
||||
if (tile.level == level && tile.row == row && tile.column == column) {
|
||||
return tile;
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
//根据传入的tiles信息进行更新其children
|
||||
SubTiledLayer.prototype.updateTiles = function(visibleTileGrids, bAddNew) { //camera,options
|
||||
//var visibleTileGrids = camera.getVisibleTilesByLevel(this.level,options);
|
||||
//检查visibleTileGrids中是否存在指定的切片信息
|
||||
function checkTileExist(tileArray, lev, row, col) {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
//根据传入的tiles信息进行更新其children
|
||||
SubTiledLayer.prototype.updateTiles = function (visibleTileGrids, bAddNew) { //camera,options
|
||||
//var visibleTileGrids = camera.getVisibleTilesByLevel(this.level,options);
|
||||
//检查visibleTileGrids中是否存在指定的切片信息
|
||||
function checkTileExist(tileArray, lev, row, col) {
|
||||
var result = {
|
||||
isExist: false,
|
||||
index: -1
|
||||
isExist: false,
|
||||
index: -1
|
||||
};
|
||||
for (var m = 0; m < tileArray.length; m++) {
|
||||
var tileInfo = tileArray[m];
|
||||
if (tileInfo.level == lev && tileInfo.row == row && tileInfo.column == col) {
|
||||
result.isExist = true;
|
||||
result.index = m;
|
||||
return result;
|
||||
}
|
||||
var tileInfo = tileArray[m];
|
||||
if (tileInfo.level == lev && tileInfo.row == row && tileInfo.column == col) {
|
||||
result.isExist = true;
|
||||
result.index = m;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//记录应该删除的切片
|
||||
var tilesNeedDelete = [];
|
||||
var i, tile;
|
||||
for (i = 0; i < this.children.length; i++) {
|
||||
//记录应该删除的切片
|
||||
var tilesNeedDelete = [];
|
||||
var i, tile;
|
||||
for (i = 0; i < this.children.length; i++) {
|
||||
tile = this.children[i];
|
||||
var checkResult = checkTileExist(visibleTileGrids, tile.level, tile.row, tile.column);
|
||||
var isExist = checkResult.isExist;
|
||||
if (isExist) {
|
||||
visibleTileGrids.splice(checkResult.index, 1); //已处理
|
||||
visibleTileGrids.splice(checkResult.index, 1); //已处理
|
||||
} else {
|
||||
//暂时不删除,先添加要删除的标记,循环删除容易出错
|
||||
tilesNeedDelete.push(tile);
|
||||
//暂时不删除,先添加要删除的标记,循环删除容易出错
|
||||
tilesNeedDelete.push(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//集中进行删除
|
||||
while (tilesNeedDelete.length > 0) {
|
||||
//集中进行删除
|
||||
while (tilesNeedDelete.length > 0) {
|
||||
var b = this.remove(tilesNeedDelete[0]);
|
||||
tilesNeedDelete.splice(0, 1);
|
||||
if (!b) {
|
||||
console.debug("LINE:2191,subTiledLayer.remove(tilesNeedDelete[0])失败");
|
||||
console.debug("LINE:2191,subTiledLayer.remove(tilesNeedDelete[0])失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bAddNew) {
|
||||
if (bAddNew) {
|
||||
//添加新增的切片
|
||||
for (i = 0; i < visibleTileGrids.length; i++) {
|
||||
var tileGridInfo = visibleTileGrids[i];
|
||||
var args = {
|
||||
level: tileGridInfo.level,
|
||||
row: tileGridInfo.row,
|
||||
column: tileGridInfo.column,
|
||||
url: ""
|
||||
};
|
||||
args.url = this.tiledLayer.getImageUrl(args.level, args.row, args.column);
|
||||
tile = new Tile(args);
|
||||
this.add(tile);
|
||||
var tileGridInfo = visibleTileGrids[i];
|
||||
var args = {
|
||||
level: tileGridInfo.level,
|
||||
row: tileGridInfo.row,
|
||||
column: tileGridInfo.column,
|
||||
url: ""
|
||||
};
|
||||
args.url = this.tiledLayer.getImageUrl(args.level, args.row, args.column);
|
||||
tile = new Tile(args);
|
||||
this.add(tile);
|
||||
}
|
||||
}
|
||||
};
|
||||
//如果bForce为true,则表示强制显示为三维,不考虑level
|
||||
SubTiledLayer.prototype.checkTerrain = function(bForce) {
|
||||
var globe = Kernel.globe;
|
||||
var show3d = bForce === true ? true : this.level >= Kernel.TERRAIN_LEVEL;
|
||||
if (show3d && globe && globe.camera && globe.camera.pitch < Kernel.TERRAIN_PITCH) {
|
||||
}
|
||||
};
|
||||
|
||||
//如果bForce为true,则表示强制显示为三维,不考虑level
|
||||
SubTiledLayer.prototype.checkTerrain = function (bForce) {
|
||||
var globe = Kernel.globe;
|
||||
var show3d = bForce === true ? true : this.level >= Kernel.TERRAIN_LEVEL;
|
||||
if (show3d && globe && globe.camera && globe.camera.pitch < Kernel.TERRAIN_PITCH) {
|
||||
var tiles = this.children;
|
||||
for (var i = 0; i < tiles.length; i++) {
|
||||
var tile = tiles[i];
|
||||
tile.checkTerrain(bForce);
|
||||
var tile = tiles[i];
|
||||
tile.checkTerrain(bForce);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//根据当前子图层下的tiles获取其对应的祖先高程切片的TileGrid //getAncestorElevationTileGrids
|
||||
//7 8 9 10; 10 11 12 13; 13 14 15 16; 16 17 18 19;
|
||||
SubTiledLayer.prototype.requestElevations = function() {
|
||||
var result = [];
|
||||
if (this.level > Kernel.ELEVATION_LEVEL) {
|
||||
//根据当前子图层下的tiles获取其对应的祖先高程切片的TileGrid //getAncestorElevationTileGrids
|
||||
//7 8 9 10; 10 11 12 13; 13 14 15 16; 16 17 18 19;
|
||||
SubTiledLayer.prototype.requestElevations = function () {
|
||||
var result = [];
|
||||
if (this.level > Kernel.ELEVATION_LEVEL) {
|
||||
var tiles = this.children;
|
||||
var i, name;
|
||||
for (i = 0; i < tiles.length; i++) {
|
||||
var tile = tiles[i];
|
||||
var tileGrid = MathUtils.getTileGridAncestor(this.elevationLevel, tile.level, tile.row, tile.column);
|
||||
name = tileGrid.level + "_" + tileGrid.row + "_" + tileGrid.column;
|
||||
if (result.indexOf(name) < 0) {
|
||||
result.push(name);
|
||||
}
|
||||
var tile = tiles[i];
|
||||
var tileGrid = MathUtils.getTileGridAncestor(this.elevationLevel, tile.level, tile.row, tile.column);
|
||||
name = tileGrid.level + "_" + tileGrid.row + "_" + tileGrid.column;
|
||||
if (result.indexOf(name) < 0) {
|
||||
result.push(name);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < result.length; i++) {
|
||||
name = result[i];
|
||||
var a = name.split('_');
|
||||
var eleLevel = parseInt(a[0]);
|
||||
var eleRow = parseInt(a[1]);
|
||||
var eleColumn = parseInt(a[2]);
|
||||
//只要elevations中有属性name,那么就表示该高程已经请求过或正在请求,这样就不要重新请求了
|
||||
//只有在完全没请求过的情况下去请求高程数据
|
||||
if (!Elevation.elevations.hasOwnProperty(name)) {
|
||||
Elevation.requestElevationsByTileGrid(eleLevel, eleRow, eleColumn);
|
||||
}
|
||||
name = result[i];
|
||||
var a = name.split('_');
|
||||
var eleLevel = parseInt(a[0]);
|
||||
var eleRow = parseInt(a[1]);
|
||||
var eleColumn = parseInt(a[2]);
|
||||
//只要elevations中有属性name,那么就表示该高程已经请求过或正在请求,这样就不要重新请求了
|
||||
//只有在完全没请求过的情况下去请求高程数据
|
||||
if (!Elevation.elevations.hasOwnProperty(name)) {
|
||||
Elevation.requestElevationsByTileGrid(eleLevel, eleRow, eleColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
SubTiledLayer.prototype.checkIfLoaded = function() {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
}
|
||||
};
|
||||
|
||||
SubTiledLayer.prototype.checkIfLoaded = function () {
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
var tile = this.children[i];
|
||||
if (tile) {
|
||||
var isTileLoaded = tile.material.loaded;
|
||||
if (!isTileLoaded) {
|
||||
return false;
|
||||
}
|
||||
var isTileLoaded = tile.material.loaded;
|
||||
if (!isTileLoaded) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return SubTiledLayer;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export default SubTiledLayer;
|
||||
@ -1,38 +1,41 @@
|
||||
define(["world/Utils"], function(Utils) {
|
||||
var TextureMaterial = function(args) {
|
||||
if (args) {
|
||||
this.texture = gl.createTexture();
|
||||
this.image = null;
|
||||
this.loaded = false;
|
||||
this.delete = false;
|
||||
if (args.image instanceof Image && args.image.width > 0 && args.image.height > 0) {
|
||||
this.setImage(args.image);
|
||||
} else if (typeof args.url == "string") {
|
||||
this.setImageUrl(args.url);
|
||||
}
|
||||
}
|
||||
};
|
||||
import Utils from './Utils';
|
||||
|
||||
TextureMaterial.prototype.setImage = function(image) {
|
||||
if (image instanceof Image && image.width > 0 && image.height > 0) {
|
||||
this.image = image;
|
||||
this.onLoad();
|
||||
var TextureMaterial = function (args) {
|
||||
if (args) {
|
||||
this.texture = gl.createTexture();
|
||||
this.image = null;
|
||||
this.loaded = false;
|
||||
this.delete = false;
|
||||
if (args.image instanceof Image && args.image.width > 0 && args.image.height > 0) {
|
||||
this.setImage(args.image);
|
||||
} else if (typeof args.url == "string") {
|
||||
this.setImageUrl(args.url);
|
||||
}
|
||||
}
|
||||
};
|
||||
TextureMaterial.prototype.setImageUrl = function(url) {
|
||||
};
|
||||
|
||||
TextureMaterial.prototype.setImage = function (image) {
|
||||
if (image instanceof Image && image.width > 0 && image.height > 0) {
|
||||
this.image = image;
|
||||
this.onLoad();
|
||||
}
|
||||
};
|
||||
|
||||
TextureMaterial.prototype.setImageUrl = function (url) {
|
||||
if (!Utils.isString(url)) {
|
||||
throw "invalid url: not string";
|
||||
throw "invalid url: not string";
|
||||
}
|
||||
this.image = new Image();
|
||||
this.image.crossOrigin = 'anonymous'; //很重要,因为图片是跨域获得的,所以一定要加上此句代码
|
||||
this.image.onload = this.onLoad.bind(this);
|
||||
this.image.src = url;
|
||||
};
|
||||
//图片加载完成时触发
|
||||
TextureMaterial.prototype.onLoad = function() {
|
||||
};
|
||||
|
||||
//图片加载完成时触发
|
||||
TextureMaterial.prototype.onLoad = function () {
|
||||
//要考虑纹理已经被移除掉了图片才进入onLoad这种情况
|
||||
if (this.delete) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
||||
@ -49,13 +52,14 @@ define(["world/Utils"], function(Utils) {
|
||||
gl.generateMipmap(gl.TEXTURE_2D);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
this.loaded = true;
|
||||
};
|
||||
//释放显卡中的texture资源
|
||||
TextureMaterial.prototype.releaseTexture = function() {
|
||||
};
|
||||
|
||||
//释放显卡中的texture资源
|
||||
TextureMaterial.prototype.releaseTexture = function () {
|
||||
if (gl.isTexture(this.texture)) {
|
||||
gl.deleteTexture(this.texture);
|
||||
this.delete = true;
|
||||
gl.deleteTexture(this.texture);
|
||||
this.delete = true;
|
||||
}
|
||||
};
|
||||
return TextureMaterial;
|
||||
});
|
||||
};
|
||||
|
||||
export default TextureMaterial;
|
||||
@ -1,16 +1,19 @@
|
||||
define(["world/TiledLayer"], function(TiledLayer) {
|
||||
var TiandituTiledLayer = function(args) {
|
||||
import TiledLayer from './TiledLayer';
|
||||
|
||||
var TiandituTiledLayer = function (args) {
|
||||
TiledLayer.apply(this, arguments);
|
||||
};
|
||||
TiandituTiledLayer.prototype = new TiledLayer();
|
||||
TiandituTiledLayer.prototype.constructor = TiandituTiledLayer;
|
||||
TiandituTiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
TiandituTiledLayer.prototype = new TiledLayer();
|
||||
TiandituTiledLayer.prototype.constructor = TiandituTiledLayer;
|
||||
|
||||
TiandituTiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
TiledLayer.prototype.getImageUrl.apply(this, arguments);
|
||||
var url = "";
|
||||
var sum = level + row + column;
|
||||
var serverIdx = sum % 8;
|
||||
url = "//t" + serverIdx + ".tianditu.com/DataServer?T=vec_w&x=" + column + "&y=" + row + "&l=" + level;
|
||||
return url;
|
||||
};
|
||||
return TiandituTiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default TiandituTiledLayer;
|
||||
@ -1,8 +1,13 @@
|
||||
define(["world/Kernel", "world/Object3D", "world/Enum", "world/Elevation", "world/Math", "world/TileMaterial"],
|
||||
function(Kernel, Object3D, Enum, Elevation, MathUtils, TileMaterial) {
|
||||
//args中包含level、row、column、url即可
|
||||
var Tile = function(args) {
|
||||
if (args) {
|
||||
import Kernel from './Kernel';
|
||||
import Object3D from './Object3D';
|
||||
import Enum from './Enum';
|
||||
import Elevation from './Elevation';
|
||||
import MathUtils from './Math';
|
||||
import TileMaterial from './TileMaterial';
|
||||
|
||||
//args中包含level、row、column、url即可
|
||||
var Tile = function (args) {
|
||||
if (args) {
|
||||
this.subTiledLayer = null;
|
||||
//type如果是GLOBE_TILE,表示其buffer已经设置为一般形式
|
||||
//type如果是TERRAIN_TILE,表示其buffer已经设置为高程形式
|
||||
@ -23,198 +28,197 @@ define(["world/Kernel", "world/Object3D", "world/Enum", "world/Elevation", "worl
|
||||
this.maxY = null;
|
||||
this.elevationInfo = null;
|
||||
Object3D.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
Tile.prototype = new Object3D();
|
||||
Tile.prototype.constructor = Tile;
|
||||
Tile.prototype.createVerticeData = function(args) {
|
||||
if (!args) {
|
||||
}
|
||||
};
|
||||
Tile.prototype = new Object3D();
|
||||
Tile.prototype.constructor = Tile;
|
||||
Tile.prototype.createVerticeData = function (args) {
|
||||
if (!args) {
|
||||
return;
|
||||
}
|
||||
this.setTileInfo(args);
|
||||
this.checkTerrain();
|
||||
};
|
||||
}
|
||||
this.setTileInfo(args);
|
||||
this.checkTerrain();
|
||||
};
|
||||
|
||||
// 根据传入的切片的层级以及行列号信息设置切片的经纬度范围 以及设置其纹理
|
||||
Tile.prototype.setTileInfo = function(args) {
|
||||
this.level = args.level;
|
||||
this.row = args.row;
|
||||
this.column = args.column;
|
||||
this.elevationLevel = Elevation.getAncestorElevationLevel(this.level);
|
||||
//经纬度范围
|
||||
var Egeo = MathUtils.getTileGeographicEnvelopByGrid(this.level, this.row, this.column);
|
||||
this.minLon = Egeo.minLon;
|
||||
this.minLat = Egeo.minLat;
|
||||
this.maxLon = Egeo.maxLon;
|
||||
this.maxLat = Egeo.maxLat;
|
||||
var minCoord = MathUtils.degreeGeographicToWebMercator(this.minLon, this.minLat);
|
||||
var maxCoord = MathUtils.degreeGeographicToWebMercator(this.maxLon, this.maxLat);
|
||||
//投影坐标范围
|
||||
this.minX = minCoord[0];
|
||||
this.minY = minCoord[1];
|
||||
this.maxX = maxCoord[0];
|
||||
this.maxY = maxCoord[1];
|
||||
var matArgs = {
|
||||
// 根据传入的切片的层级以及行列号信息设置切片的经纬度范围 以及设置其纹理
|
||||
Tile.prototype.setTileInfo = function (args) {
|
||||
this.level = args.level;
|
||||
this.row = args.row;
|
||||
this.column = args.column;
|
||||
this.elevationLevel = Elevation.getAncestorElevationLevel(this.level);
|
||||
//经纬度范围
|
||||
var Egeo = MathUtils.getTileGeographicEnvelopByGrid(this.level, this.row, this.column);
|
||||
this.minLon = Egeo.minLon;
|
||||
this.minLat = Egeo.minLat;
|
||||
this.maxLon = Egeo.maxLon;
|
||||
this.maxLat = Egeo.maxLat;
|
||||
var minCoord = MathUtils.degreeGeographicToWebMercator(this.minLon, this.minLat);
|
||||
var maxCoord = MathUtils.degreeGeographicToWebMercator(this.maxLon, this.maxLat);
|
||||
//投影坐标范围
|
||||
this.minX = minCoord[0];
|
||||
this.minY = minCoord[1];
|
||||
this.maxX = maxCoord[0];
|
||||
this.maxY = maxCoord[1];
|
||||
var matArgs = {
|
||||
level: this.level,
|
||||
url: this.url
|
||||
};
|
||||
this.material = new TileMaterial(matArgs);
|
||||
};
|
||||
this.material = new TileMaterial(matArgs);
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断是否满足现实Terrain的条件,若满足则转换为三维地形
|
||||
* 条件:
|
||||
* 1.当前显示的是GlobeTile
|
||||
* 2.该切片的level大于TERRAIN_LEVEL
|
||||
* 3.pich不为90
|
||||
* 4.当前切片的高程数据存在
|
||||
* 5.如果bForce为true,则表示强制显示为三维,不考虑level
|
||||
*/
|
||||
Tile.prototype.checkTerrain = function(bForce) {
|
||||
var globe = Kernel.globe;
|
||||
var a = bForce === true ? true : this.level >= Kernel.TERRAIN_LEVEL;
|
||||
var shouldShowTerrain = this.type != Enum.TERRAIN_TILE && a && globe && globe.camera && globe.camera.pitch != 90;
|
||||
if (shouldShowTerrain) {
|
||||
/**
|
||||
* 判断是否满足现实Terrain的条件,若满足则转换为三维地形
|
||||
* 条件:
|
||||
* 1.当前显示的是GlobeTile
|
||||
* 2.该切片的level大于TERRAIN_LEVEL
|
||||
* 3.pich不为90
|
||||
* 4.当前切片的高程数据存在
|
||||
* 5.如果bForce为true,则表示强制显示为三维,不考虑level
|
||||
*/
|
||||
Tile.prototype.checkTerrain = function (bForce) {
|
||||
var globe = Kernel.globe;
|
||||
var a = bForce === true ? true : this.level >= Kernel.TERRAIN_LEVEL;
|
||||
var shouldShowTerrain = this.type != Enum.TERRAIN_TILE && a && globe && globe.camera && globe.camera.pitch != 90;
|
||||
if (shouldShowTerrain) {
|
||||
//应该以TerrainTile显示
|
||||
if (!this.elevationInfo) {
|
||||
this.elevationInfo = Elevation.getExactElevation(this.level, this.row, this.column);
|
||||
this.elevationInfo = Elevation.getExactElevation(this.level, this.row, this.column);
|
||||
|
||||
// if(this.level - this.elevationLevel == 1){
|
||||
// //当该level与其elevationLevel只相差一级时,可以使用推倒的高程数据
|
||||
// this.elevationInfo = Elevation.getElevation(this.level,this.row,this.column);
|
||||
// if(this.elevationInfo){
|
||||
// console.log("Tile("+this.level+","+this.row+","+this.column+");sourceLevel:"+this.elevationInfo.sourceLevel+";elevationLevel:"+this.elevationLevel);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// //否则使用准确的高程数据
|
||||
// this.elevationInfo = Elevation.getExactElevation(this.level,this.row,this.column);
|
||||
// }
|
||||
// if(this.level - this.elevationLevel == 1){
|
||||
// //当该level与其elevationLevel只相差一级时,可以使用推倒的高程数据
|
||||
// this.elevationInfo = Elevation.getElevation(this.level,this.row,this.column);
|
||||
// if(this.elevationInfo){
|
||||
// console.log("Tile("+this.level+","+this.row+","+this.column+");sourceLevel:"+this.elevationInfo.sourceLevel+";elevationLevel:"+this.elevationLevel);
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// //否则使用准确的高程数据
|
||||
// this.elevationInfo = Elevation.getExactElevation(this.level,this.row,this.column);
|
||||
// }
|
||||
}
|
||||
var canShowTerrain = this.elevationInfo ? true : false;
|
||||
if (canShowTerrain) {
|
||||
//能够显示为TerrainTile
|
||||
this.handleTerrainTile();
|
||||
//能够显示为TerrainTile
|
||||
this.handleTerrainTile();
|
||||
} else {
|
||||
//不能够显示为TerrainTile
|
||||
this.visible = false;
|
||||
//this.handleGlobeTile();
|
||||
//不能够显示为TerrainTile
|
||||
this.visible = false;
|
||||
//this.handleGlobeTile();
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
if (this.type == Enum.UNKNOWN) {
|
||||
//初始type为UNKNOWN,还未初始化buffer,应该显示为GlobeTile
|
||||
this.handleGlobeTile();
|
||||
//初始type为UNKNOWN,还未初始化buffer,应该显示为GlobeTile
|
||||
this.handleGlobeTile();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//处理球面的切片
|
||||
Tile.prototype.handleGlobeTile = function() {
|
||||
this.type = Enum.GLOBE_TILE;
|
||||
if (this.level < Kernel.BASE_LEVEL) {
|
||||
//处理球面的切片
|
||||
Tile.prototype.handleGlobeTile = function () {
|
||||
this.type = Enum.GLOBE_TILE;
|
||||
if (this.level < Kernel.BASE_LEVEL) {
|
||||
var changeLevel = Kernel.BASE_LEVEL - this.level;
|
||||
this.segment = Math.pow(2, changeLevel);
|
||||
} else {
|
||||
} else {
|
||||
this.segment = 1;
|
||||
}
|
||||
this.handleTile();
|
||||
};
|
||||
//处理地形的切片
|
||||
Tile.prototype.handleTerrainTile = function() {
|
||||
this.type = Enum.TERRAIN_TILE;
|
||||
this.segment = 10;
|
||||
this.handleTile();
|
||||
};
|
||||
}
|
||||
this.handleTile();
|
||||
};
|
||||
//处理地形的切片
|
||||
Tile.prototype.handleTerrainTile = function () {
|
||||
this.type = Enum.TERRAIN_TILE;
|
||||
this.segment = 10;
|
||||
this.handleTile();
|
||||
};
|
||||
|
||||
//如果是GlobeTile,那么elevations为null
|
||||
//如果是TerrainTile,那么elevations是一个一维数组,大小是(segment+1)*(segment+1)
|
||||
Tile.prototype.handleTile = function() {
|
||||
this.visible = true;
|
||||
var vertices = [];
|
||||
var indices = [];
|
||||
var textureCoords = [];
|
||||
//如果是GlobeTile,那么elevations为null
|
||||
//如果是TerrainTile,那么elevations是一个一维数组,大小是(segment+1)*(segment+1)
|
||||
Tile.prototype.handleTile = function () {
|
||||
this.visible = true;
|
||||
var vertices = [];
|
||||
var indices = [];
|
||||
var textureCoords = [];
|
||||
|
||||
var deltaX = (this.maxX - this.minX) / this.segment;
|
||||
var deltaY = (this.maxY - this.minY) / this.segment;
|
||||
var deltaTextureCoord = 1.0 / this.segment;
|
||||
var changeElevation = this.type == Enum.TERRAIN_TILE && this.elevationInfo;
|
||||
//level不同设置的半径也不同
|
||||
var levelDeltaR = 0; //this.level * 100;
|
||||
//对WebMercator投影进行等间距划分格网
|
||||
var mercatorXs = []; //存储从最小的x到最大x的分割值
|
||||
var mercatorYs = []; //存储从最大的y到最小的y的分割值
|
||||
var textureSs = []; //存储从0到1的s的分割值
|
||||
var textureTs = []; //存储从1到0的t的分割值
|
||||
var i, j;
|
||||
var deltaX = (this.maxX - this.minX) / this.segment;
|
||||
var deltaY = (this.maxY - this.minY) / this.segment;
|
||||
var deltaTextureCoord = 1.0 / this.segment;
|
||||
var changeElevation = this.type == Enum.TERRAIN_TILE && this.elevationInfo;
|
||||
//level不同设置的半径也不同
|
||||
var levelDeltaR = 0; //this.level * 100;
|
||||
//对WebMercator投影进行等间距划分格网
|
||||
var mercatorXs = []; //存储从最小的x到最大x的分割值
|
||||
var mercatorYs = []; //存储从最大的y到最小的y的分割值
|
||||
var textureSs = []; //存储从0到1的s的分割值
|
||||
var textureTs = []; //存储从1到0的t的分割值
|
||||
var i, j;
|
||||
|
||||
for (i = 0; i <= this.segment; i++) {
|
||||
for (i = 0; i <= this.segment; i++) {
|
||||
mercatorXs.push(this.minX + i * deltaX);
|
||||
mercatorYs.push(this.maxY - i * deltaY);
|
||||
var b = i * deltaTextureCoord;
|
||||
textureSs.push(b);
|
||||
textureTs.push(1 - b);
|
||||
}
|
||||
//从左上到右下遍历填充vertices和textureCoords:从最上面一行开始自左向右遍历一行,然后再以相同的方式遍历下面一行
|
||||
for (i = 0; i <= this.segment; i++) {
|
||||
}
|
||||
//从左上到右下遍历填充vertices和textureCoords:从最上面一行开始自左向右遍历一行,然后再以相同的方式遍历下面一行
|
||||
for (i = 0; i <= this.segment; i++) {
|
||||
for (j = 0; j <= this.segment; j++) {
|
||||
var merX = mercatorXs[j];
|
||||
var merY = mercatorYs[i];
|
||||
var ele = changeElevation ? this.elevationInfo.elevations[(this.segment + 1) * i + j] : 0;
|
||||
var lonlat = MathUtils.webMercatorToDegreeGeographic(merX, merY);
|
||||
var p = MathUtils.geographicToCartesianCoord(lonlat[0], lonlat[1], Kernel.EARTH_RADIUS + ele + levelDeltaR).getArray();
|
||||
vertices = vertices.concat(p); //顶点坐标
|
||||
textureCoords = textureCoords.concat(textureSs[j], textureTs[i]); //纹理坐标
|
||||
var merX = mercatorXs[j];
|
||||
var merY = mercatorYs[i];
|
||||
var ele = changeElevation ? this.elevationInfo.elevations[(this.segment + 1) * i + j] : 0;
|
||||
var lonlat = MathUtils.webMercatorToDegreeGeographic(merX, merY);
|
||||
var p = MathUtils.geographicToCartesianCoord(lonlat[0], lonlat[1], Kernel.EARTH_RADIUS + ele + levelDeltaR).getArray();
|
||||
vertices = vertices.concat(p); //顶点坐标
|
||||
textureCoords = textureCoords.concat(textureSs[j], textureTs[i]); //纹理坐标
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//从左上到右下填充indices
|
||||
//添加的点的顺序:左上->左下->右下->右上
|
||||
//0 1 2; 2 3 0;
|
||||
/*对于一个面从外面向里面看的绘制顺序
|
||||
* 0 3
|
||||
*
|
||||
* 1 2*/
|
||||
for (i = 0; i < this.segment; i++) {
|
||||
//从左上到右下填充indices
|
||||
//添加的点的顺序:左上->左下->右下->右上
|
||||
//0 1 2; 2 3 0;
|
||||
/*对于一个面从外面向里面看的绘制顺序
|
||||
* 0 3
|
||||
*
|
||||
* 1 2*/
|
||||
for (i = 0; i < this.segment; i++) {
|
||||
for (j = 0; j < this.segment; j++) {
|
||||
var idx0 = (this.segment + 1) * i + j;
|
||||
var idx1 = (this.segment + 1) * (i + 1) + j;
|
||||
var idx2 = idx1 + 1;
|
||||
var idx3 = idx0 + 1;
|
||||
indices = indices.concat(idx0, idx1, idx2); // 0 1 2
|
||||
indices = indices.concat(idx2, idx3, idx0); // 2 3 0
|
||||
var idx0 = (this.segment + 1) * i + j;
|
||||
var idx1 = (this.segment + 1) * (i + 1) + j;
|
||||
var idx2 = idx1 + 1;
|
||||
var idx3 = idx0 + 1;
|
||||
indices = indices.concat(idx0, idx1, idx2); // 0 1 2
|
||||
indices = indices.concat(idx2, idx3, idx0); // 2 3 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(changeElevation){
|
||||
// //添加坐标原点的数据
|
||||
// var originVertice = [0,0,0];
|
||||
// var originTexture = [0,0];
|
||||
// vertices = vertices.concat(originVertice);
|
||||
// textureCoords = textureCoords.concat(originTexture);
|
||||
//
|
||||
// var idxOrigin = (this.segment+1)*(this.segment+1);
|
||||
// var idxLeftTop = 0;
|
||||
// var idxRightTop = this.segment;
|
||||
// var idxRightBottom = (this.segment+1)*(this.segment+1)-1;
|
||||
// var idxLeftBottom = idxRightBottom - this.segment;
|
||||
// indices = indices.concat(idxLeftTop,idxOrigin,idxLeftBottom);
|
||||
// indices = indices.concat(idxRightTop,idxOrigin,idxLeftTop);
|
||||
// indices = indices.concat(idxRightBottom,idxOrigin,idxRightTop);
|
||||
// indices = indices.concat(idxLeftBottom,idxOrigin,idxRightBottom);
|
||||
// }
|
||||
// if(changeElevation){
|
||||
// //添加坐标原点的数据
|
||||
// var originVertice = [0,0,0];
|
||||
// var originTexture = [0,0];
|
||||
// vertices = vertices.concat(originVertice);
|
||||
// textureCoords = textureCoords.concat(originTexture);
|
||||
//
|
||||
// var idxOrigin = (this.segment+1)*(this.segment+1);
|
||||
// var idxLeftTop = 0;
|
||||
// var idxRightTop = this.segment;
|
||||
// var idxRightBottom = (this.segment+1)*(this.segment+1)-1;
|
||||
// var idxLeftBottom = idxRightBottom - this.segment;
|
||||
// indices = indices.concat(idxLeftTop,idxOrigin,idxLeftBottom);
|
||||
// indices = indices.concat(idxRightTop,idxOrigin,idxLeftTop);
|
||||
// indices = indices.concat(idxRightBottom,idxOrigin,idxRightTop);
|
||||
// indices = indices.concat(idxLeftBottom,idxOrigin,idxRightBottom);
|
||||
// }
|
||||
|
||||
var infos = {
|
||||
var infos = {
|
||||
vertices: vertices,
|
||||
indices: indices,
|
||||
textureCoords: textureCoords
|
||||
};
|
||||
this.setBuffers(infos);
|
||||
};
|
||||
//重写Object3D的destroy方法
|
||||
Tile.prototype.destroy = function() {
|
||||
Object3D.prototype.destroy.apply(this, arguments);
|
||||
this.subTiledLayer = null;
|
||||
};
|
||||
this.setBuffers(infos);
|
||||
};
|
||||
//重写Object3D的destroy方法
|
||||
Tile.prototype.destroy = function () {
|
||||
Object3D.prototype.destroy.apply(this, arguments);
|
||||
this.subTiledLayer = null;
|
||||
};
|
||||
|
||||
return Tile;
|
||||
});
|
||||
export default Tile;
|
||||
@ -1,49 +1,47 @@
|
||||
define(["world/Utils", "world/Math"], function(Utils) {
|
||||
import Utils from './Utils';
|
||||
import MathUtils from './Math';
|
||||
|
||||
var TileGrid = function(level, row, column) {
|
||||
var TileGrid = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
this.level = level;
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
};
|
||||
TileGrid.prototype._requireMath = function(){
|
||||
return require("world/Math");
|
||||
};
|
||||
TileGrid.prototype.equals = function(other) {
|
||||
return other instanceof TileGrid && this.level == other.level && this.row == other.row && this.column == other.column;
|
||||
};
|
||||
TileGrid.prototype.getLeft = function() {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.LEFT);
|
||||
};
|
||||
TileGrid.prototype.getRight = function() {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.RIGHT);
|
||||
};
|
||||
TileGrid.prototype.getTop = function() {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.TOP);
|
||||
};
|
||||
TileGrid.prototype.getBottom = function() {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.BOTTOM);
|
||||
};
|
||||
TileGrid.prototype.getParent = function() {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridAncestor(this.level - 1, this.level, this.row, this.column);
|
||||
};
|
||||
TileGrid.prototype.getAncestor = function(ancestorLevel) {
|
||||
var MathUtils = this._requireMath();
|
||||
return MathUtils.getTileGridAncestor(ancestorLevel, this.level, this.row, this.column);
|
||||
};
|
||||
};
|
||||
|
||||
return TileGrid;
|
||||
});
|
||||
TileGrid.prototype.equals = function (other) {
|
||||
return other instanceof TileGrid && this.level == other.level && this.row == other.row && this.column == other.column;
|
||||
};
|
||||
|
||||
TileGrid.prototype.getLeft = function () {
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.LEFT);
|
||||
};
|
||||
|
||||
TileGrid.prototype.getRight = function () {
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.RIGHT);
|
||||
};
|
||||
|
||||
TileGrid.prototype.getTop = function () {
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.TOP);
|
||||
};
|
||||
|
||||
TileGrid.prototype.getBottom = function () {
|
||||
return MathUtils.getTileGridByBrother(this.level, this.row, this.column, MathUtils.BOTTOM);
|
||||
};
|
||||
|
||||
TileGrid.prototype.getParent = function () {
|
||||
return MathUtils.getTileGridAncestor(this.level - 1, this.level, this.row, this.column);
|
||||
};
|
||||
|
||||
TileGrid.prototype.getAncestor = function (ancestorLevel) {
|
||||
return MathUtils.getTileGridAncestor(ancestorLevel, this.level, this.row, this.column);
|
||||
};
|
||||
|
||||
export default TileGrid;
|
||||
@ -1,25 +1,29 @@
|
||||
define(["world/TextureMaterial", "world/Image"], function(TextureMaterial, Image1) {
|
||||
//TileMaterial继承自TextureMaterial
|
||||
var TileMaterial = function(args) {
|
||||
import TextureMaterial from './TextureMaterial';
|
||||
import Image1 from './Image';
|
||||
|
||||
//TileMaterial继承自TextureMaterial
|
||||
var TileMaterial = function (args) {
|
||||
if (args) {
|
||||
if (!args.image && typeof args.url == "string") {
|
||||
var tileImage = Image1.get(args.url);
|
||||
if (tileImage) {
|
||||
args.image = tileImage;
|
||||
delete args.url;
|
||||
if (!args.image && typeof args.url == "string") {
|
||||
var tileImage = Image1.get(args.url);
|
||||
if (tileImage) {
|
||||
args.image = tileImage;
|
||||
delete args.url;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.level = typeof args.level == "number" && args.level >= 0 ? args.level : 20;
|
||||
TextureMaterial.apply(this, arguments);
|
||||
this.level = typeof args.level == "number" && args.level >= 0 ? args.level : 20;
|
||||
TextureMaterial.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
TileMaterial.prototype = new TextureMaterial();
|
||||
TileMaterial.prototype.constructor = TileMaterial;
|
||||
TileMaterial.prototype.onLoad = function(event) {
|
||||
};
|
||||
|
||||
TileMaterial.prototype = new TextureMaterial();
|
||||
TileMaterial.prototype.constructor = TileMaterial;
|
||||
|
||||
TileMaterial.prototype.onLoad = function (event) {
|
||||
if (this.level <= Image1.MAX_LEVEL) {
|
||||
Image1.add(this.image.src, this.image);
|
||||
Image1.add(this.image.src, this.image);
|
||||
}
|
||||
TextureMaterial.prototype.onLoad.apply(this, arguments);
|
||||
};
|
||||
return TileMaterial;
|
||||
});
|
||||
};
|
||||
|
||||
export default TileMaterial;
|
||||
@ -1,61 +1,68 @@
|
||||
define(["world/Object3DComponents", "world/SubTiledLayer", "world/Utils"], function(Object3DComponents, SubTiledLayer, Utils) {
|
||||
var TiledLayer = function(args) {
|
||||
import Object3DComponents from './Object3DComponents';
|
||||
import SubTiledLayer from './SubTiledLayer';
|
||||
import Utils from './Utils';
|
||||
|
||||
var TiledLayer = function (args) {
|
||||
Object3DComponents.apply(this, arguments);
|
||||
};
|
||||
TiledLayer.prototype = new Object3DComponents();
|
||||
TiledLayer.prototype.constructor = TiledLayer;
|
||||
//重写
|
||||
TiledLayer.prototype.add = function(subTiledLayer) {
|
||||
};
|
||||
|
||||
TiledLayer.prototype = new Object3DComponents();
|
||||
TiledLayer.prototype.constructor = TiledLayer;
|
||||
|
||||
//重写
|
||||
TiledLayer.prototype.add = function (subTiledLayer) {
|
||||
if (!(subTiledLayer instanceof SubTiledLayer)) {
|
||||
throw "invalid subTiledLayer: not World.SubTiledLayer";
|
||||
throw "invalid subTiledLayer: not World.SubTiledLayer";
|
||||
}
|
||||
Object3DComponents.prototype.add.apply(this, arguments);
|
||||
subTiledLayer.tiledLayer = this;
|
||||
};
|
||||
//根据切片的层级以及行列号获取图片的url,抽象方法,供子类实现
|
||||
TiledLayer.prototype.getImageUrl = function(level, row, column) {
|
||||
};
|
||||
|
||||
//根据切片的层级以及行列号获取图片的url,抽象方法,供子类实现
|
||||
TiledLayer.prototype.getImageUrl = function (level, row, column) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(row)) {
|
||||
throw "invalid row";
|
||||
throw "invalid row";
|
||||
}
|
||||
if (!Utils.isNonNegativeInteger(column)) {
|
||||
throw "invalid column";
|
||||
throw "invalid column";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
//根据传入的level更新SubTiledLayer的数量
|
||||
TiledLayer.prototype.updateSubLayerCount = function(level) {
|
||||
};
|
||||
|
||||
//根据传入的level更新SubTiledLayer的数量
|
||||
TiledLayer.prototype.updateSubLayerCount = function (level) {
|
||||
if (!Utils.isNonNegativeInteger(level)) {
|
||||
throw "invalid level";
|
||||
throw "invalid level";
|
||||
}
|
||||
var subLayerCount = this.children.length;
|
||||
var deltaLevel = level + 1 - subLayerCount;
|
||||
var i, subLayer;
|
||||
if (deltaLevel > 0) {
|
||||
//需要增加子图层
|
||||
for (i = 0; i < deltaLevel; i++) {
|
||||
var args = {
|
||||
level: i + subLayerCount
|
||||
};
|
||||
subLayer = new SubTiledLayer(args);
|
||||
this.add(subLayer);
|
||||
}
|
||||
} else if (deltaLevel < 0) {
|
||||
//需要删除多余的子图层
|
||||
deltaLevel *= -1;
|
||||
for (i = 0; i < deltaLevel; i++) {
|
||||
var removeLevel = this.children.length - 1;
|
||||
//第0级和第1级不删除
|
||||
if (removeLevel >= 2) {
|
||||
subLayer = this.children[removeLevel];
|
||||
this.remove(subLayer);
|
||||
} else {
|
||||
break;
|
||||
//需要增加子图层
|
||||
for (i = 0; i < deltaLevel; i++) {
|
||||
var args = {
|
||||
level: i + subLayerCount
|
||||
};
|
||||
subLayer = new SubTiledLayer(args);
|
||||
this.add(subLayer);
|
||||
}
|
||||
} else if (deltaLevel < 0) {
|
||||
//需要删除多余的子图层
|
||||
deltaLevel *= -1;
|
||||
for (i = 0; i < deltaLevel; i++) {
|
||||
var removeLevel = this.children.length - 1;
|
||||
//第0级和第1级不删除
|
||||
if (removeLevel >= 2) {
|
||||
subLayer = this.children[removeLevel];
|
||||
this.remove(subLayer);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return TiledLayer;
|
||||
});
|
||||
};
|
||||
|
||||
export default TiledLayer;
|
||||
@ -1,149 +1,149 @@
|
||||
define({
|
||||
GREATER:"GREATER",
|
||||
GEQUAL:"GEQUAL",
|
||||
LESS:"LESS",
|
||||
LEQUAL:"LEQUAL",
|
||||
var Utils = {
|
||||
GREATER: "GREATER",
|
||||
GEQUAL: "GEQUAL",
|
||||
LESS: "LESS",
|
||||
LEQUAL: "LEQUAL",
|
||||
|
||||
isBool:function(v){
|
||||
isBool: function (v) {
|
||||
return typeof v == "boolean";
|
||||
},
|
||||
|
||||
isNumber:function(v){
|
||||
isNumber: function (v) {
|
||||
return typeof v == "number";
|
||||
},
|
||||
|
||||
isInteger:function(v){
|
||||
isInteger: function (v) {
|
||||
var isInt = false;
|
||||
var isNum = this.isNumber(v);
|
||||
if(isNum){
|
||||
if (isNum) {
|
||||
var numFloat = parseFloat(v);
|
||||
var numInt = parseInt(v);
|
||||
if(numFloat == numInt){
|
||||
if (numFloat == numInt) {
|
||||
isInt = true;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
isInt = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
isInt = false;
|
||||
}
|
||||
return isInt;
|
||||
},
|
||||
|
||||
judgeNumberBoundary:function(num,operator,boundry){
|
||||
if(!this.isNumber(num)){
|
||||
judgeNumberBoundary: function (num, operator, boundry) {
|
||||
if (!this.isNumber(num)) {
|
||||
throw "num is not number";
|
||||
}
|
||||
if(operator != this.GREATER && operator != this.GEQUAL && operator != this.LESS && operator != this.LEQUAL){
|
||||
if (operator != this.GREATER && operator != this.GEQUAL && operator != this.LESS && operator != this.LEQUAL) {
|
||||
throw "operator is invalid";
|
||||
}
|
||||
if(!this.isNumber(boundry)){
|
||||
if (!this.isNumber(boundry)) {
|
||||
throw "boundry is not number";
|
||||
}
|
||||
var b;
|
||||
if(operator == this.GREATER){
|
||||
if (operator == this.GREATER) {
|
||||
b = num > boundry;
|
||||
}
|
||||
else if(operator == this.GEQUAL){
|
||||
else if (operator == this.GEQUAL) {
|
||||
b = num >= boundry;
|
||||
}
|
||||
else if(operator == this.LESS){
|
||||
else if (operator == this.LESS) {
|
||||
b = num < boundry;
|
||||
}
|
||||
else if(operator == this.LEQUAL){
|
||||
else if (operator == this.LEQUAL) {
|
||||
b = num <= boundry;
|
||||
}
|
||||
return b;
|
||||
},
|
||||
|
||||
isPositive:function(v){
|
||||
return this.judgeNumberBoundary(v,this.GREATER,0);
|
||||
isPositive: function (v) {
|
||||
return this.judgeNumberBoundary(v, this.GREATER, 0);
|
||||
},
|
||||
|
||||
isNegative:function(v){
|
||||
return this.judgeNumberBoundary(v,this.LESS,0);
|
||||
isNegative: function (v) {
|
||||
return this.judgeNumberBoundary(v, this.LESS, 0);
|
||||
},
|
||||
|
||||
isNonNegative:function(v){
|
||||
return this.judgeNumberBoundary(v,this.GEQUAL,0);
|
||||
isNonNegative: function (v) {
|
||||
return this.judgeNumberBoundary(v, this.GEQUAL, 0);
|
||||
},
|
||||
|
||||
isNonPositive:function(v){
|
||||
return this.judgeNumberBoundary(v,this.LEQUAL,0);
|
||||
isNonPositive: function (v) {
|
||||
return this.judgeNumberBoundary(v, this.LEQUAL, 0);
|
||||
},
|
||||
|
||||
isPositiveInteger:function(v){
|
||||
isPositiveInteger: function (v) {
|
||||
return this.isPositive(v) && this.isInteger(v);
|
||||
},
|
||||
|
||||
isNonNegativeInteger:function(v){
|
||||
isNonNegativeInteger: function (v) {
|
||||
return this.isNonNegative(v) && this.isInteger;
|
||||
},
|
||||
|
||||
isString:function(v){
|
||||
isString: function (v) {
|
||||
return typeof v == "string";
|
||||
},
|
||||
|
||||
isArray:function(v){
|
||||
isArray: function (v) {
|
||||
return Object.prototype.toString.call(v) === '[object Array]';
|
||||
},
|
||||
|
||||
isFunction:function(v){
|
||||
isFunction: function (v) {
|
||||
return typeof v == "function";
|
||||
},
|
||||
|
||||
isNull:function(v){
|
||||
isNull: function (v) {
|
||||
return v === null;
|
||||
},
|
||||
|
||||
isUndefined:function(v){
|
||||
isUndefined: function (v) {
|
||||
return typeof v == "undefined";
|
||||
},
|
||||
|
||||
isNullOrUndefined:function(v){
|
||||
return this.isNull(v)||this.isUndefined(v);
|
||||
isNullOrUndefined: function (v) {
|
||||
return this.isNull(v) || this.isUndefined(v);
|
||||
},
|
||||
|
||||
isJsonObject:function(v){
|
||||
isJsonObject: function (v) {
|
||||
return typeof v == "object" && !this.isNull(v) && !this.isArray(v);
|
||||
},
|
||||
|
||||
isDom:function(v){
|
||||
isDom: function (v) {
|
||||
return v instanceof HTMLElement;
|
||||
},
|
||||
|
||||
forEach:function(arr,func){
|
||||
if(!(this.isArray(arr))){
|
||||
forEach: function (arr, func) {
|
||||
if (!(this.isArray(arr))) {
|
||||
throw "invalid arr";
|
||||
}
|
||||
if(!(this.isFunction(func))){
|
||||
if (!(this.isFunction(func))) {
|
||||
throw "invalid func";
|
||||
}
|
||||
if(this.isFunction(Array.prototype.forEach)){
|
||||
if (this.isFunction(Array.prototype.forEach)) {
|
||||
arr.forEach(func);
|
||||
}
|
||||
else{
|
||||
for(var i=0;i<arr.length;i++){
|
||||
func(arr[i],i,arr);
|
||||
else {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
func(arr[i], i, arr);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
filter:function(arr,func){
|
||||
if(!(this.isArray(arr))){
|
||||
filter: function (arr, func) {
|
||||
if (!(this.isArray(arr))) {
|
||||
throw "invalid arr";
|
||||
}
|
||||
if(!(this.isFunction(func))){
|
||||
if (!(this.isFunction(func))) {
|
||||
throw "invalid func";
|
||||
}
|
||||
var result = [];
|
||||
if(this.isFunction(Array.prototype.filter)){
|
||||
if (this.isFunction(Array.prototype.filter)) {
|
||||
result = arr.filter(func);
|
||||
}
|
||||
else{
|
||||
for(var i=0;i<arr.length;i++){
|
||||
if(func(arr[i],i,arr)){
|
||||
else {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (func(arr[i], i, arr)) {
|
||||
result.push(arr[i]);
|
||||
}
|
||||
}
|
||||
@ -151,38 +151,38 @@ define({
|
||||
return result;
|
||||
},
|
||||
|
||||
map:function(arr,func){
|
||||
if(!(this.isArray(arr))){
|
||||
map: function (arr, func) {
|
||||
if (!(this.isArray(arr))) {
|
||||
throw "invalid arr";
|
||||
}
|
||||
if(!(this.isFunction(func))){
|
||||
if (!(this.isFunction(func))) {
|
||||
throw "invalid func";
|
||||
}
|
||||
var result = [];
|
||||
if(this.isFunction(Array.prototype.map)){
|
||||
if (this.isFunction(Array.prototype.map)) {
|
||||
result = arr.map(func);
|
||||
}
|
||||
else{
|
||||
for(var i=0;i<arr.length;i++){
|
||||
result.push(func(arr[i],i,arr));
|
||||
else {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
result.push(func(arr[i], i, arr));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
some:function(arr,func){
|
||||
if(!(this.isArray(arr))){
|
||||
some: function (arr, func) {
|
||||
if (!(this.isArray(arr))) {
|
||||
throw "invalid arr";
|
||||
}
|
||||
if(!(this.isFunction(func))){
|
||||
if (!(this.isFunction(func))) {
|
||||
throw "invalid func";
|
||||
}
|
||||
if(this.isFunction(Array.prototype.some)){
|
||||
if (this.isFunction(Array.prototype.some)) {
|
||||
return arr.some(func);
|
||||
}
|
||||
else{
|
||||
for(var i=0;i<arr.length;i++){
|
||||
if(func(arr[i],i,arr)){
|
||||
else {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (func(arr[i], i, arr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -190,19 +190,19 @@ define({
|
||||
}
|
||||
},
|
||||
|
||||
every:function(arr,func){
|
||||
if(!(this.isArray(arr))){
|
||||
every: function (arr, func) {
|
||||
if (!(this.isArray(arr))) {
|
||||
throw "invalid arr";
|
||||
}
|
||||
if(!(this.isFunction(func))){
|
||||
if (!(this.isFunction(func))) {
|
||||
throw "invalid func";
|
||||
}
|
||||
if(this.isFunction(Array.prototype.every)){
|
||||
if (this.isFunction(Array.prototype.every)) {
|
||||
return arr.every(func);
|
||||
}
|
||||
else{
|
||||
for(var i=0;i<arr.length;i++){
|
||||
if(!func(arr[i],i,arr)){
|
||||
else {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (!func(arr[i], i, arr)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -211,24 +211,26 @@ define({
|
||||
},
|
||||
|
||||
//过滤掉数组中重复的元素
|
||||
filterRepeatArray:function(arr){
|
||||
if(!this.isArray(arr)){
|
||||
filterRepeatArray: function (arr) {
|
||||
if (!this.isArray(arr)) {
|
||||
throw "invalid arr: not Array";
|
||||
}
|
||||
var cloneArray = this.map(arr,function(item){
|
||||
var cloneArray = this.map(arr, function (item) {
|
||||
return item;
|
||||
});
|
||||
var simplifyArray = [];
|
||||
while(cloneArray.length > 0){
|
||||
while (cloneArray.length > 0) {
|
||||
var e = cloneArray[0];
|
||||
var exist = this.some(simplifyArray,function(item){
|
||||
var exist = this.some(simplifyArray, function (item) {
|
||||
return e.equals(item);
|
||||
});
|
||||
if(!exist){
|
||||
if (!exist) {
|
||||
simplifyArray.push(e);
|
||||
}
|
||||
cloneArray.splice(0,1);
|
||||
cloneArray.splice(0, 1);
|
||||
}
|
||||
return simplifyArray;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default Utils;
|
||||
@ -1,105 +1,101 @@
|
||||
define(["require", "world/Utils", "world/Vertice"], function(require, Utils) {
|
||||
import Utils from './Utils';
|
||||
import Vertice from './Vertice';
|
||||
|
||||
var Vector = function(x, y, z) {
|
||||
var Vector = function (x, y, z) {
|
||||
x = x !== undefined ? x : 0;
|
||||
y = y !== undefined ? y : 0;
|
||||
z = z !== undefined ? z : 0;
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
throw "invalid z";
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
};
|
||||
};
|
||||
|
||||
Vector.prototype = {
|
||||
Vector.prototype = {
|
||||
constructor: Vector,
|
||||
|
||||
_requireVertice: function(){
|
||||
return require("world/Vertice");
|
||||
|
||||
getVertice: function () {
|
||||
return new Vertice(this.x, this.y, this.z);
|
||||
},
|
||||
|
||||
getVertice: function() {
|
||||
var Vertice = this._requireVertice();
|
||||
return new Vertice(this.x, this.y, this.z);
|
||||
getArray: function () {
|
||||
return [this.x, this.y, this.z];
|
||||
},
|
||||
|
||||
getArray: function() {
|
||||
return [this.x, this.y, this.z];
|
||||
getCopy: function () {
|
||||
return new Vector(this.x, this.y, this.z);
|
||||
},
|
||||
|
||||
getCopy: function() {
|
||||
return new Vector(this.x, this.y, this.z);
|
||||
getOpposite: function () {
|
||||
return new Vector(-this.x, -this.y, -this.z);
|
||||
},
|
||||
|
||||
getOpposite: function() {
|
||||
return new Vector(-this.x, -this.y, -this.z);
|
||||
getLength: function () {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
},
|
||||
|
||||
getLength: function() {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
normalize: function () {
|
||||
var length = this.getLength();
|
||||
if (Math.abs(length) >= 0.000001) {
|
||||
this.x /= length;
|
||||
this.y /= length;
|
||||
this.z /= length;
|
||||
} else {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
normalize: function() {
|
||||
var length = this.getLength();
|
||||
if(Math.abs(length) >= 0.000001) {
|
||||
this.x /= length;
|
||||
this.y /= length;
|
||||
this.z /= length;
|
||||
} else {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setLength: function(length) {
|
||||
if (!Utils.isNumber(length)) {
|
||||
throw "invalid length";
|
||||
}
|
||||
this.normalize();
|
||||
this.x *= length;
|
||||
this.y *= length;
|
||||
this.z *= length;
|
||||
return this;
|
||||
setLength: function (length) {
|
||||
if (!Utils.isNumber(length)) {
|
||||
throw "invalid length";
|
||||
}
|
||||
this.normalize();
|
||||
this.x *= length;
|
||||
this.y *= length;
|
||||
this.z *= length;
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* 得到该向量的一个随机垂直向量
|
||||
* @return {*}
|
||||
*/
|
||||
getRandomVerticalVector: function() {
|
||||
var result;
|
||||
var length = this.getLength();
|
||||
if (length === 0) {
|
||||
result = new Vector(0, 0, 0);
|
||||
} else {
|
||||
var x2, y2, z2;
|
||||
if (this.x !== 0) {
|
||||
y2 = 1;
|
||||
z2 = 0;
|
||||
x2 = -this.y / this.x;
|
||||
} else if (this.y !== 0) {
|
||||
z2 = 1;
|
||||
x2 = 0;
|
||||
y2 = -this.z / this.y;
|
||||
} else if (this.z !== 0) {
|
||||
x2 = 1;
|
||||
y2 = 0;
|
||||
z2 = -this.x / this.z;
|
||||
getRandomVerticalVector: function () {
|
||||
var result;
|
||||
var length = this.getLength();
|
||||
if (length === 0) {
|
||||
result = new Vector(0, 0, 0);
|
||||
} else {
|
||||
var x2, y2, z2;
|
||||
if (this.x !== 0) {
|
||||
y2 = 1;
|
||||
z2 = 0;
|
||||
x2 = -this.y / this.x;
|
||||
} else if (this.y !== 0) {
|
||||
z2 = 1;
|
||||
x2 = 0;
|
||||
y2 = -this.z / this.y;
|
||||
} else if (this.z !== 0) {
|
||||
x2 = 1;
|
||||
y2 = 0;
|
||||
z2 = -this.x / this.z;
|
||||
}
|
||||
result = new Vector(x2, y2, z2);
|
||||
result.normalize();
|
||||
}
|
||||
result = new Vector(x2, y2, z2);
|
||||
result.normalize();
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -107,14 +103,14 @@ define(["require", "world/Utils", "world/Vertice"], function(require, Utils) {
|
||||
* @param other
|
||||
* @return {World.Vector}
|
||||
*/
|
||||
cross: function(other) {
|
||||
if (!(other instanceof Vector)) {
|
||||
throw "invalid other";
|
||||
}
|
||||
var x = this.y * other.z - this.z * other.y;
|
||||
var y = this.z * other.x - this.x * other.z;
|
||||
var z = this.x * other.y - this.y * other.x;
|
||||
return new Vector(x, y, z);
|
||||
cross: function (other) {
|
||||
if (!(other instanceof Vector)) {
|
||||
throw "invalid other";
|
||||
}
|
||||
var x = this.y * other.z - this.z * other.y;
|
||||
var y = this.z * other.x - this.x * other.z;
|
||||
var z = this.x * other.y - this.y * other.x;
|
||||
return new Vector(x, y, z);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -122,11 +118,11 @@ define(["require", "world/Utils", "world/Vertice"], function(require, Utils) {
|
||||
* @param other 另一个向量
|
||||
* @return {*} 数字
|
||||
*/
|
||||
dot: function(other) {
|
||||
if (!(other instanceof Vector)) {
|
||||
throw "invalid other";
|
||||
}
|
||||
return this.x * other.x + this.y * other.y + this.z * other.z;
|
||||
dot: function (other) {
|
||||
if (!(other instanceof Vector)) {
|
||||
throw "invalid other";
|
||||
}
|
||||
return this.x * other.x + this.y * other.y + this.z * other.z;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,7 +166,6 @@ define(["require", "world/Utils", "world/Vertice"], function(require, Utils) {
|
||||
var newVector = newVertice.getVector();
|
||||
return newVector;
|
||||
}*/
|
||||
};
|
||||
};
|
||||
|
||||
return Vector;
|
||||
});
|
||||
export default Vector;
|
||||
@ -1,69 +1,62 @@
|
||||
define(["require", "world/Utils", "world/Vector"], function(require, Utils) {
|
||||
import Utils from './Utils';
|
||||
import Vector from './Vector';
|
||||
|
||||
var Vertice = function(x, y, z) {
|
||||
var Vertice = function (x, y, z) {
|
||||
x = x !== undefined ? x : 0;
|
||||
y = y !== undefined ? y : 0;
|
||||
z = z !== undefined ? z : 0;
|
||||
if (!Utils.isNumber(x)) {
|
||||
throw "invalid x";
|
||||
throw "invalid x";
|
||||
}
|
||||
if (!Utils.isNumber(y)) {
|
||||
throw "invalid y";
|
||||
throw "invalid y";
|
||||
}
|
||||
if (!Utils.isNumber(z)) {
|
||||
throw "invalid z";
|
||||
throw "invalid z";
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
};
|
||||
};
|
||||
|
||||
Vertice.prototype = {
|
||||
Vertice.prototype = {
|
||||
constructor: Vertice,
|
||||
|
||||
_requireVector: function(){
|
||||
return require("world/Vector");
|
||||
minus: function (otherVertice) {
|
||||
if (!(otherVertice instanceof Vertice)) {
|
||||
throw "invalid otherVertice";
|
||||
}
|
||||
var x = this.x - otherVertice.x;
|
||||
var y = this.y - otherVertice.y;
|
||||
var z = this.z - otherVertice.z;
|
||||
return new Vector(x, y, z);
|
||||
},
|
||||
|
||||
minus: function(otherVertice) {
|
||||
var Vector = this._requireVector();
|
||||
if (!(otherVertice instanceof Vertice)) {
|
||||
throw "invalid otherVertice";
|
||||
}
|
||||
var x = this.x - otherVertice.x;
|
||||
var y = this.y - otherVertice.y;
|
||||
var z = this.z - otherVertice.z;
|
||||
return new Vector(x, y, z);
|
||||
plus: function (otherVector) {
|
||||
if (!(otherVector instanceof Vector)) {
|
||||
throw "invalid otherVector";
|
||||
}
|
||||
var x = this.x + otherVector.x;
|
||||
var y = this.y + otherVector.y;
|
||||
var z = this.z + otherVector.z;
|
||||
return new Vertice(x, y, z);
|
||||
},
|
||||
|
||||
plus: function(otherVector) {
|
||||
var Vector = this._requireVector();
|
||||
if (!(otherVector instanceof Vector)) {
|
||||
throw "invalid otherVector";
|
||||
}
|
||||
var x = this.x + otherVector.x;
|
||||
var y = this.y + otherVector.y;
|
||||
var z = this.z + otherVector.z;
|
||||
return new Vertice(x, y, z);
|
||||
getVector: function () {
|
||||
return new Vector(this.x, this.y, this.z);
|
||||
},
|
||||
|
||||
getVector: function() {
|
||||
var Vector = this._requireVector();
|
||||
return new Vector(this.x, this.y, this.z);
|
||||
getArray: function () {
|
||||
return [this.x, this.y, this.z];
|
||||
},
|
||||
|
||||
getArray: function() {
|
||||
return [this.x, this.y, this.z];
|
||||
getCopy: function () {
|
||||
return new Vertice(this.x, this.y, this.z);
|
||||
},
|
||||
|
||||
getCopy: function() {
|
||||
return new Vertice(this.x, this.y, this.z);
|
||||
},
|
||||
|
||||
getOpposite: function() {
|
||||
return new Vertice(-this.x, -this.y, -this.z);
|
||||
getOpposite: function () {
|
||||
return new Vertice(-this.x, -this.y, -this.z);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return Vertice;
|
||||
});
|
||||
export default Vertice;
|
||||
@ -1,66 +1,69 @@
|
||||
define(["world/Kernel", "world/Utils", "world/Event", "world/Scene", "world/PerspectiveCamera"],
|
||||
function(Kernel, Utils, Event, Scene, PerspectiveCamera) {
|
||||
import Kernel from './Kernel';
|
||||
import Utils from './Utils';
|
||||
import Event from './Event';
|
||||
import Scene from './Scene';
|
||||
import PerspectiveCamera from './PerspectiveCamera';
|
||||
|
||||
var WebGLRenderer = function(canvas, vertexShaderText, fragmentShaderText) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
var WebGLRenderer = function (canvas, vertexShaderText, fragmentShaderText) {
|
||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||
throw "invalid canvas: not HTMLCanvasElement";
|
||||
}
|
||||
if (!(Utils.isString(vertexShaderText) && vertexShaderText !== "")) {
|
||||
}
|
||||
if (!(Utils.isString(vertexShaderText) && vertexShaderText !== "")) {
|
||||
throw "invalid vertexShaderText";
|
||||
}
|
||||
if (!(Utils.isString(fragmentShaderText) && fragmentShaderText !== "")) {
|
||||
}
|
||||
if (!(Utils.isString(fragmentShaderText) && fragmentShaderText !== "")) {
|
||||
throw "invalid fragmentShaderText";
|
||||
}
|
||||
window.renderer = this; //之所以在此处设置window.renderer是因为要在tick函数中使用
|
||||
this.scene = null;
|
||||
this.camera = null;
|
||||
this.bAutoRefresh = false;
|
||||
Event.bindEvents(canvas);
|
||||
}
|
||||
window.renderer = this; //之所以在此处设置window.renderer是因为要在tick函数中使用
|
||||
this.scene = null;
|
||||
this.camera = null;
|
||||
this.bAutoRefresh = false;
|
||||
Event.bindEvents(canvas);
|
||||
|
||||
function initWebGL(canvas) {
|
||||
function initWebGL(canvas) {
|
||||
try {
|
||||
var contextList = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
|
||||
for (var i = 0; i < contextList.length; i++) {
|
||||
var g = canvas.getContext(contextList[i], {
|
||||
antialias: true
|
||||
});
|
||||
if (g) {
|
||||
window.gl = Kernel.gl = g;
|
||||
Kernel.canvas = canvas;
|
||||
break;
|
||||
var contextList = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
|
||||
for (var i = 0; i < contextList.length; i++) {
|
||||
var g = canvas.getContext(contextList[i], {
|
||||
antialias: true
|
||||
});
|
||||
if (g) {
|
||||
window.gl = Kernel.gl = g;
|
||||
Kernel.canvas = canvas;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
function getShader(gl, shaderType, shaderText) {
|
||||
function getShader(gl, shaderType, shaderText) {
|
||||
if (!shaderText) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
var shader = null;
|
||||
if (shaderType == "VERTEX_SHADER") {
|
||||
shader = gl.createShader(gl.VERTEX_SHADER);
|
||||
shader = gl.createShader(gl.VERTEX_SHADER);
|
||||
} else if (shaderType == "FRAGMENT_SHADER") {
|
||||
shader = gl.createShader(gl.FRAGMENT_SHADER);
|
||||
shader = gl.createShader(gl.FRAGMENT_SHADER);
|
||||
} else {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
gl.shaderSource(shader, shaderText);
|
||||
gl.compileShader(shader);
|
||||
|
||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
alert(gl.getShaderInfoLog(shader));
|
||||
console.error(gl.getShaderInfoLog(shader));
|
||||
gl.deleteShader(shader);
|
||||
return null;
|
||||
alert(gl.getShaderInfoLog(shader));
|
||||
console.error(gl.getShaderInfoLog(shader));
|
||||
gl.deleteShader(shader);
|
||||
return null;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
}
|
||||
|
||||
function initShaders(vertexShaderText, fragmentShaderText) {
|
||||
function initShaders(vertexShaderText, fragmentShaderText) {
|
||||
var vertexShader = getShader(Kernel.gl, "VERTEX_SHADER", vertexShaderText);
|
||||
var fragmentShader = getShader(Kernel.gl, "FRAGMENT_SHADER", fragmentShaderText);
|
||||
|
||||
@ -70,11 +73,11 @@ define(["world/Kernel", "world/Utils", "world/Event", "world/Scene", "world/Pers
|
||||
gl.linkProgram(shaderProgram);
|
||||
|
||||
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
|
||||
console.error("Could not link program!");
|
||||
gl.deleteProgram(shaderProgram);
|
||||
gl.deleteShader(vertexShader);
|
||||
gl.deleteShader(fragmentShader);
|
||||
return;
|
||||
console.error("Could not link program!");
|
||||
gl.deleteProgram(shaderProgram);
|
||||
gl.deleteShader(vertexShader);
|
||||
gl.deleteShader(fragmentShader);
|
||||
return;
|
||||
}
|
||||
|
||||
gl.useProgram(shaderProgram);
|
||||
@ -91,88 +94,88 @@ define(["world/Kernel", "world/Utils", "world/Event", "world/Scene", "world/Pers
|
||||
|
||||
//设置默认值
|
||||
var squareArray = [1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
];
|
||||
var squareMatrix = new Float32Array(squareArray); //ArrayBuffer
|
||||
gl.uniformMatrix4fv(gl.shaderProgram.uMVMatrix, false, squareMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
initWebGL(canvas);
|
||||
initWebGL(canvas);
|
||||
|
||||
if (!window.gl) {
|
||||
if (!window.gl) {
|
||||
alert("浏览器不支持WebGL或将WebGL禁用!");
|
||||
console.debug("浏览器不支持WebGL或将WebGL禁用!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
initShaders(vertexShaderText, fragmentShaderText);
|
||||
initShaders(vertexShaderText, fragmentShaderText);
|
||||
|
||||
gl.clearColor(255, 255, 255, 1.0);
|
||||
//gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.DEPTH_TEST); //此处禁用深度测试是为了解决两个不同层级的切片在拖动时一起渲染会导致屏闪的问题
|
||||
gl.depthFunc(gl.LEQUAL);
|
||||
gl.clearColor(255, 255, 255, 1.0);
|
||||
//gl.enable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.DEPTH_TEST); //此处禁用深度测试是为了解决两个不同层级的切片在拖动时一起渲染会导致屏闪的问题
|
||||
gl.depthFunc(gl.LEQUAL);
|
||||
|
||||
gl.enable(gl.CULL_FACE); //一定要启用裁剪,否则显示不出立体感
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.cullFace(gl.BACK); //裁剪掉背面
|
||||
gl.enable(gl.CULL_FACE); //一定要启用裁剪,否则显示不出立体感
|
||||
gl.frontFace(gl.CCW);
|
||||
gl.cullFace(gl.BACK); //裁剪掉背面
|
||||
|
||||
//gl.enable(gl.TEXTURE_2D);//WebGL: INVALID_ENUM: enable: invalid capability
|
||||
};
|
||||
//gl.enable(gl.TEXTURE_2D);//WebGL: INVALID_ENUM: enable: invalid capability
|
||||
};
|
||||
|
||||
WebGLRenderer.prototype = {
|
||||
constructor: WebGLRenderer,
|
||||
WebGLRenderer.prototype = {
|
||||
constructor: WebGLRenderer,
|
||||
|
||||
render: function(scene, camera) {
|
||||
render: function (scene, camera) {
|
||||
if (!(scene instanceof Scene)) {
|
||||
throw "invalid scene: not World.Scene";
|
||||
throw "invalid scene: not World.Scene";
|
||||
}
|
||||
if (!(camera instanceof PerspectiveCamera)) {
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
}
|
||||
gl.viewport(0, 0, Kernel.canvas.width, Kernel.canvas.height);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
camera.viewMatrix = null;
|
||||
camera.viewMatrix = camera.getViewMatrix();
|
||||
scene.draw(camera);
|
||||
},
|
||||
},
|
||||
|
||||
bindScene: function(scene) {
|
||||
bindScene: function (scene) {
|
||||
if (!(scene instanceof Scene)) {
|
||||
throw "invalid scene: not World.Scene";
|
||||
throw "invalid scene: not World.Scene";
|
||||
}
|
||||
this.scene = scene;
|
||||
},
|
||||
},
|
||||
|
||||
bindCamera: function(camera) {
|
||||
bindCamera: function (camera) {
|
||||
if (!(camera instanceof PerspectiveCamera)) {
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
throw "invalid camera: not World.PerspectiveCamera";
|
||||
}
|
||||
this.camera = camera;
|
||||
},
|
||||
},
|
||||
|
||||
tick: function() {
|
||||
tick: function () {
|
||||
if (Kernel.renderer instanceof WebGLRenderer) {
|
||||
if (Kernel.renderer.scene && Kernel.renderer.camera) {
|
||||
Kernel.renderer.render(Kernel.renderer.scene, Kernel.renderer.camera);
|
||||
}
|
||||
if (Kernel.renderer.scene && Kernel.renderer.camera) {
|
||||
Kernel.renderer.render(Kernel.renderer.scene, Kernel.renderer.camera);
|
||||
}
|
||||
|
||||
if (Kernel.renderer.bAutoRefresh) {
|
||||
window.requestAnimationFrame(Kernel.renderer.tick);
|
||||
}
|
||||
if (Kernel.renderer.bAutoRefresh) {
|
||||
window.requestAnimationFrame(Kernel.renderer.tick);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
setIfAutoRefresh: function(bAuto) {
|
||||
setIfAutoRefresh: function (bAuto) {
|
||||
if (!Utils.isBool(bAuto)) {
|
||||
throw "invalid bAuto: not bool";
|
||||
throw "invalid bAuto: not bool";
|
||||
}
|
||||
this.bAutoRefresh = bAuto;
|
||||
if (this.bAutoRefresh) {
|
||||
this.tick();
|
||||
this.tick();
|
||||
}
|
||||
}
|
||||
};
|
||||
return WebGLRenderer;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default WebGLRenderer;
|
||||
Loading…
x
Reference in New Issue
Block a user