This repository was archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathobjects.js
More file actions
190 lines (134 loc) · 3.99 KB
/
Copy pathobjects.js
File metadata and controls
190 lines (134 loc) · 3.99 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
var utils = require("../utils/utils.js");
var material = require("../utils/material.js");
var THREE = require("../three.js");
const AnimationManager = require("../animation/AnimationManager.js");
function Objects(){
}
Objects.prototype = {
// standard 1px line with gl
line: function(obj){
obj = utils._validate(obj, this._defaults.line);
//project to world and normalize
var straightProject = utils.lnglatsToWorld(obj.geometry);
var normalized = utils.normalizeVertices(straightProject);
//flatten array for buffergeometry
var flattenedArray = utils.flattenVectors(normalized.vertices);
var positions = new Float32Array(flattenedArray); // 3 vertices per point
var geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
// material
var material = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 21 } );
var line = new THREE.Line( geometry, material );
line.options = options || {};
line.position.copy(normalized.position)
return line
},
extrusion: function(options){
},
_addMethods: function(obj, fixed){
var root = this;
if (fixed) {
}
else {
if (!obj.coordinates) obj.coordinates = [0,0,0];
// Bestow this mesh with animation superpowers and keeps track of its movements in the global animation queue
root.animationManager.enroll(obj);
obj.setCoords = function(lnglat){
/** Place the given object on the map, centered around the provided longitude and latitude
The object's internal coordinates are assumed to be in meter-offset format, meaning
1 unit represents 1 meter distance away from the provided coordinate.
*/
// If object already added, scale the model so that its units are interpreted as meters at the given latitude
if (obj.userData.units === 'meters'){
var s = utils.projectedUnitsPerMeter(lnglat[1]);
obj.scale.set(s,s,s);
}
obj.coordinates = lnglat;
obj.set({position:lnglat})
return obj;
}
obj.setRotation = function(xyz) {
if (typeof xyz === 'number') xyz = {z: xyz}
var r = {
x: utils.radify(xyz.x) || obj.rotation.x,
y: utils.radify(xyz.y) || obj.rotation.y,
z: utils.radify(xyz.z) || obj.rotation.z
}
obj._setObject({rotation: [r.x, r.y, r.z]})
}
}
obj.add = function(){
root.world.add(obj);
if (!fixed) obj.set({position:obj.coordinates});
return obj;
}
obj.remove = function(){
root.world.remove(obj);
root.map.repaint = true;
}
obj.duplicate = function(a) {
var dupe = obj.clone();
dupe.userData = obj.userData;
root._addMethods(dupe);
return dupe
}
return obj
},
_makeGroup: function(obj, options){
var geoGroup = new THREE.Group();
geoGroup.userData = options || {};
geoGroup.userData.isGeoGroup = true;
var isArrayOfObjects = obj.length;
if (isArrayOfObjects) for (o of obj) geoGroup.add(o)
else geoGroup.add(obj);
utils._flipMaterialSides(obj);
return geoGroup
},
animationManager: new AnimationManager,
_defaults: {
line: {
geometry: null,
color: 'black',
width:1,
opacity:1
},
sphere: {
position: [0,0,0],
radius: 1,
sides: 20,
units: 'scene',
material: 'MeshBasicMaterial'
},
tube: {
geometry: null,
radius: 1,
sides:6,
material: 'MeshBasicMaterial'
},
extrusion:{
footprint: null,
base: 0,
top: 100,
color:'black',
material: 'MeshBasicMaterial',
scaleToLatitude: false
},
loadObj:{
obj: null,
mtl: null,
rotation: 0,
scale: 1,
units: 'scene'
},
Object3D: {
obj: null,
units: 'scene'
}
},
geometries:{
line: ['LineString'],
tube: ['LineString'],
sphere: ['Point'],
}
}
module.exports = exports = Objects;