-
Notifications
You must be signed in to change notification settings - Fork 8
/
globe.html
163 lines (142 loc) · 5.83 KB
/
globe.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<head>
<title>Ingress Model Sandbox</title>
<script src="../node_modules/gl-matrix/dist/gl-matrix.js"></script>
<script src="../dist/ingress-model-viewer.js"></script>
<script src="https://cdn.rawgit.com/eligrey/FileSaver.js/5733e40e5af936eb3f48554cf6a8a7075d71d18a/FileSaver.min.js"></script>
<style>
html, body {
height: 100%;
width: 100%;
position: relative;
margin: 0;
}
</style>
</head>
<body>
<canvas id="screen" style="position: absolute; left: 0; top: 0; width: 100%; height: 100%"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('screen'), engine,
radius = 100,
artifactInfos = null,
controls,
shoninShards = null;
canvas.width = document.body.offsetWidth;
canvas.height = document.body.offsetHeight;
var LatLngToWorld = function(drawable, lat, lng) {
var mat = mat4.create();
mat4.rotateY(mat, mat, lng * Math.PI / 180);
mat4.rotateZ(mat, mat, (lat - 90) * Math.PI / 180);
mat4.translate(mat, mat, [0, radius * 1.01, 0]);
mat4.multiply(drawable.local, mat, drawable.local);
};
var addRotatingDrawable = function(drawable, lat, lng) {
LatLngToWorld(drawable, lat, lng);
drawable.onUpdate = rotate;
engine.objectRenderer.addDrawable(drawable);
};
var addShardPortal = function(lat, lng, team, shards) {
var portal = new IMV.Drawables.World.Portal(),
green = new IMV.Drawables.World.ArtifactsGreenGlow(),
purple = new IMV.Drawables.World.ArtifactsPurpleGlow(),
shardDrawables = [];
shards.forEach(function(el) {
var shard = new shoninShards[el]();
addRotatingDrawable(shard, lat, lng);
});
portal.uniforms.u_baseColor = vec4.clone(IMV.Constants.teamColors[team]);
addRotatingDrawable(portal, lat, lng);
green.uniforms.u_baseColor = vec4.clone(IMV.Constants.teamColors[team]);
addRotatingDrawable(green, lat, lng);
purple.uniforms.u_baseColor = vec4.clone(IMV.Constants.artifactGlowColors.Shonin.Purple);
addRotatingDrawable(purple, lat, lng);
};
var addTargetPortal = function(lat, lng, team) {
var portal = new IMV.Drawables.World.Portal(),
target = new IMV.Drawables.World.ArtifactsTargetGlow(),
green = new IMV.Drawables.World.ArtifactsGreenGlow(),
red = new IMV.Drawables.World.ArtifactsRedGlow(),
purple = new IMV.Drawables.World.ArtifactsPurpleGlow();
target.uniforms.u_baseColor = vec4.clone(IMV.Constants.artifactGlowColors.Shonin.Target);
addRotatingDrawable(target, lat, lng);
portal.uniforms.u_baseColor = vec4.clone(IMV.Constants.teamColors[team]);
addRotatingDrawable(portal, lat, lng);
green.uniforms.u_baseColor = vec4.clone(IMV.Constants.teamColors[team]);
addRotatingDrawable(green, lat, lng);
red.uniforms.u_baseColor = vec4.clone(IMV.Constants.artifactGlowColors.Shonin.Red);
addRotatingDrawable(red, lat, lng);
purple.uniforms.u_baseColor = vec4.clone(IMV.Constants.artifactGlowColors.Shonin.Purple);
addRotatingDrawable(purple, lat, lng);
};
var updateCamera = function() {
controls.updateView();
engine.updateView();
window.requestAnimationFrame(updateCamera);
};
var init = function(assets, shonin) {
engine = new IMV.Engine(canvas, assets, true);
controls = new IMV.Controls.Orbit(canvas, engine.camera, radius * 3, {
distanceMin: radius,
distanceMax: 5 * radius
}),
engine.camera.setPosition([radius * 3, 0.0, 0.0]).lookAt([0.0, 0.0, 0.0]).setFar(radius * 5).setFieldOfView(Math.PI / 3);
engine.assetManager.addAssets(shonin);
shoninShards = IMV.Utilities.generateArtifacts('Shonin', 31, true);
engine.updateView();
//engine.preload().then(function() {
var globe, atmosphere, world;
globe = new IMV.Drawables.TexturedSphere('WorldTexture', radius, 50, 50);
atmosphere = new IMV.Drawables.Atmosphere(radius, 50, 50);
engine.objectRenderer.addDrawable(globe);
globe.onUpdate = rotate;
atmosphere.onUpdate = rotate;
if(artifactInfos) {
artifactInfos[0].targetInfos.forEach(function(obj) {
var arr = obj.portalInfo;
var team = obj.team;
addTargetPortal(arr[2] / 1E6, arr[3] / 1E6, team);
});
artifactInfos[0].fragmentInfos.forEach(function(obj) {
var arr = obj.portalInfo,
team = arr[1] === 'R' ? 'RESISTANCE' :
(arr[1] === 'E' ? 'ENLIGHTENED' : 'NEUTRAL');
addShardPortal(arr[2] / 1E6, arr[3] / 1E6, team, obj.fragments);
});
var testLink = new IMV.Drawables.SphericalPortalLink(
radius,
[artifactInfos[0].targetInfos[0].portalInfo[2] / 1E6, artifactInfos[0].targetInfos[0].portalInfo[3] / 1E6],
[artifactInfos[0].targetInfos[1].portalInfo[2] / 1E6, artifactInfos[0].targetInfos[1].portalInfo[3] / 1E6],
vec4.clone(IMV.Constants.teamColors.LOKI)
)
testLink.onUpdate = rotate;
engine.objectRenderer.addDrawable(testLink);
}
engine.objectRenderer.addDrawable(atmosphere);
engine.render(0);
controls.enable();
window.requestAnimationFrame(updateCamera);
console.log('ready');
//}).catch(function(err) {
// console.error(err);
//});
};
var rotate = function(delta) {
mat4.rotateY(this.world, this.world, delta / 5000);
this.updateMatrix();
return true;
};
IMV.AssetLoader.loadResource('/manifest/assets.json', 'text').then(function(val) {
var assets = JSON.parse(val);
return IMV.AssetLoader.loadResource('/manifest/shonin.json', 'text').then(function(val) {
var shonin = JSON.parse(val);
return IMV.AssetLoader.loadResource('/snapshot.json', 'text').then(function(val) {
artifactInfos = JSON.parse(val);
init(assets, shonin);
engine.draw(0);
});
});
});
</script>
</body>
</html>