pgl 0.0.5 → 5.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/LICENSE.md +20 -0
- package/README.md +46 -11
- package/dist/cli-run.d.ts +3 -0
- package/dist/cli-run.d.ts.map +1 -0
- package/dist/cli-run.js +7 -0
- package/dist/cli-run.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/fwd/@dataplan/json/index.d.ts +1 -0
- package/fwd/@dataplan/json/index.js +1 -0
- package/fwd/@dataplan/pg/adaptors/pg/index.d.ts +1 -0
- package/fwd/@dataplan/pg/adaptors/pg/index.js +1 -0
- package/fwd/@dataplan/pg/index.d.ts +1 -0
- package/fwd/@dataplan/pg/index.js +1 -0
- package/fwd/grafast/envelop/index.d.ts +1 -0
- package/fwd/grafast/envelop/index.js +1 -0
- package/fwd/grafast/graphql/index.d.ts +1 -0
- package/fwd/grafast/graphql/index.js +1 -0
- package/fwd/grafast/index.d.ts +1 -0
- package/fwd/grafast/index.js +1 -0
- package/fwd/grafserv/express/v4/index.d.ts +1 -0
- package/fwd/grafserv/express/v4/index.js +1 -0
- package/fwd/grafserv/fastify/v4/index.d.ts +1 -0
- package/fwd/grafserv/fastify/v4/index.js +1 -0
- package/fwd/grafserv/index.d.ts +1 -0
- package/fwd/grafserv/index.js +1 -0
- package/fwd/grafserv/koa/v2/index.d.ts +1 -0
- package/fwd/grafserv/koa/v2/index.js +1 -0
- package/fwd/grafserv/node/index.d.ts +1 -0
- package/fwd/grafserv/node/index.js +1 -0
- package/fwd/grafserv/ruru/cli/index.d.ts +1 -0
- package/fwd/grafserv/ruru/cli/index.js +1 -0
- package/fwd/grafserv/ruru/index.d.ts +1 -0
- package/fwd/grafserv/ruru/index.js +1 -0
- package/fwd/grafserv/ruru/server/index.d.ts +1 -0
- package/fwd/grafserv/ruru/server/index.js +1 -0
- package/fwd/graphile-build/index.d.ts +2 -0
- package/fwd/graphile-build/index.js +1 -0
- package/fwd/graphile-build-pg/index.d.ts +1 -0
- package/fwd/graphile-build-pg/index.js +1 -0
- package/fwd/graphile-build-pg/pg-introspection/index.d.ts +1 -0
- package/fwd/graphile-build-pg/pg-introspection/index.js +1 -0
- package/fwd/pg-sql2/index.d.ts +1 -0
- package/fwd/pg-sql2/index.js +1 -0
- package/fwd/postgraphile/presets/amber/index.d.ts +1 -0
- package/fwd/postgraphile/presets/amber/index.js +1 -0
- package/fwd/postgraphile/presets/relay/index.d.ts +1 -0
- package/fwd/postgraphile/presets/relay/index.js +1 -0
- package/fwd/postgraphile/presets/v4/index.d.ts +1 -0
- package/fwd/postgraphile/presets/v4/index.js +1 -0
- package/fwd/postgraphile/utils/index.d.ts +1 -0
- package/fwd/postgraphile/utils/index.js +1 -0
- package/fwd/tamedevil/index.d.ts +1 -0
- package/fwd/tamedevil/index.js +1 -0
- package/package.json +202 -12
- package/.npmignore +0 -2
- package/LICENSE +0 -21
- package/examples/cube.js +0 -97
- package/examples/points.js +0 -82
- package/examples/shaders/flat-surface.fshader +0 -5
- package/examples/shaders/flat-surface.vshader +0 -72
- package/examples/shaders/matrices.fshader +0 -5
- package/examples/shaders/matrices.vshader +0 -12
- package/examples/shaders/model-and-view.fshader +0 -5
- package/examples/shaders/model-and-view.vshader +0 -23
- package/examples/shaders/pgl.fshader +0 -5
- package/examples/shaders/pgl.vshader +0 -53
- package/examples/shaders/simple.fshader +0 -5
- package/examples/shaders/simple.vshader +0 -8
- package/index.js +0 -23
- package/lib/camera.js +0 -222
- package/lib/geom.js +0 -256
- package/lib/light.js +0 -27
- package/lib/line.js +0 -10
- package/lib/mesh.js +0 -266
- package/lib/pgl-utils.js +0 -76
- package/lib/plask-utils.js +0 -46
- package/lib/renderer.js +0 -418
- package/lib/scene.js +0 -167
- package/lib/triangle.js +0 -73
- package/lib/vertex.js +0 -17
- package/test/index.js +0 -53
package/lib/geom.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Various function to programatically create geometry
|
|
3
|
-
*
|
|
4
|
-
* @TODO
|
|
5
|
-
* + Add others eg. sphere
|
|
6
|
-
* + Be able to pass sizes in to the create the geometry
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var plask = require('plask');
|
|
10
|
-
|
|
11
|
-
module.exports.points = function() {
|
|
12
|
-
var meshType = 'POINTS';
|
|
13
|
-
var type = 'points';
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
type : type,
|
|
17
|
-
meshType : meshType
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
module.exports.axes = function() {
|
|
23
|
-
var meshType = 'LINES';
|
|
24
|
-
var type = 'axes';
|
|
25
|
-
var lines = [
|
|
26
|
-
[-10, 0.0, 0.0, 10, 0.0, 0.0],
|
|
27
|
-
[0.0, -10, 0.0, 0.0, 10, 0.0],
|
|
28
|
-
[0.0, 0.0, -10, 0.0, 0.0, 10]
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
var vertices = [-10,0.0,0.0,
|
|
32
|
-
10,0.0,0.0,
|
|
33
|
-
0.0,-10,0.0,
|
|
34
|
-
0.0,10,0.0,
|
|
35
|
-
0.0,0.0,-10,
|
|
36
|
-
0.0,0.0,10];
|
|
37
|
-
|
|
38
|
-
var lineColors = [
|
|
39
|
-
[1, 1, 0],
|
|
40
|
-
[0, 1 ,0],
|
|
41
|
-
[0, 0, 1]
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
type : type,
|
|
46
|
-
meshType : meshType,
|
|
47
|
-
vertices : vertices,
|
|
48
|
-
lines : lines,
|
|
49
|
-
lineColors : lineColors
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
module.exports.line = function(start, end) {
|
|
54
|
-
var meshType = 'LINES';
|
|
55
|
-
var type = 'single-line';
|
|
56
|
-
var vertices = [];
|
|
57
|
-
var lines = [];
|
|
58
|
-
var lineColors = [];
|
|
59
|
-
|
|
60
|
-
lines.push([start.x, start.y, start.z, end.x, end.y, end.z]);
|
|
61
|
-
lineColors.push([1.0, 0, 0]);
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
type : type,
|
|
65
|
-
meshType : meshType,
|
|
66
|
-
vertices : vertices,
|
|
67
|
-
lines : lines,
|
|
68
|
-
lineColors : lineColors
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
module.exports.planeGrid = function(params) {
|
|
73
|
-
//@TODO pass in surface vector and extent - parametric surfaces
|
|
74
|
-
var meshType = 'LINES';
|
|
75
|
-
var vertices = [];
|
|
76
|
-
var lines = [];
|
|
77
|
-
var lineColors = [];
|
|
78
|
-
|
|
79
|
-
var minX = -10 || params.minX;
|
|
80
|
-
var maxX = 10 || params.maxX;
|
|
81
|
-
var minZ = -10 || params.minZ;
|
|
82
|
-
var maxZ = 10 || params.maxZ;
|
|
83
|
-
var step = 1 || params.step;
|
|
84
|
-
|
|
85
|
-
for(var i = minX; i <= maxX; i += step) {
|
|
86
|
-
lines.push([i, 0, minZ, i, 0, maxZ]);
|
|
87
|
-
lineColors.push([0.643, 0.643, 0.643]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
for(var j = minZ; j <= maxZ; j += step) {
|
|
91
|
-
lines.push([minX, 0, j, maxX, 0, j]);
|
|
92
|
-
lineColors.push([0.643, 0.643, 0.643]);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
meshType : meshType,
|
|
97
|
-
vertices : vertices,
|
|
98
|
-
lines : lines,
|
|
99
|
-
lineColors : lineColors
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
module.exports.cube = function() {
|
|
104
|
-
var meshType = 'TRIANGLES';
|
|
105
|
-
// cube geom just return ordered vertices for triangles
|
|
106
|
-
var type = 'cube';
|
|
107
|
-
var vertices = [];
|
|
108
|
-
var triangleElements = [];
|
|
109
|
-
|
|
110
|
-
// Triangle vertices
|
|
111
|
-
var triangleIndices = [
|
|
112
|
-
// Front face
|
|
113
|
-
// 0 1 2
|
|
114
|
-
-1.0, -1.0, 1.0,
|
|
115
|
-
1.0, -1.0, 1.0,
|
|
116
|
-
1.0, 1.0, 1.0,
|
|
117
|
-
|
|
118
|
-
// 0 2 3
|
|
119
|
-
-1.0, -1.0, 1.0,
|
|
120
|
-
1.0, 1.0, 1.0,
|
|
121
|
-
-1.0, 1.0, 1.0,
|
|
122
|
-
|
|
123
|
-
// Back face
|
|
124
|
-
//4, 5, 6,
|
|
125
|
-
-1.0, -1.0, -1.0,
|
|
126
|
-
-1.0, 1.0, -1.0,
|
|
127
|
-
1.0, 1.0, -1.0,
|
|
128
|
-
|
|
129
|
-
//4, 6, 7,
|
|
130
|
-
-1.0, -1.0, -1.0,
|
|
131
|
-
1.0, 1.0, -1.0,
|
|
132
|
-
1.0, -1.0, -1.0,
|
|
133
|
-
|
|
134
|
-
// Top face
|
|
135
|
-
//8, 9, 10,
|
|
136
|
-
-1.0, 1.0, -1.0,
|
|
137
|
-
-1.0, 1.0, 1.0,
|
|
138
|
-
1.0, 1.0, 1.0,
|
|
139
|
-
|
|
140
|
-
//8, 10, 11,
|
|
141
|
-
-1.0, 1.0, -1.0,
|
|
142
|
-
1.0, 1.0, 1.0,
|
|
143
|
-
1.0, 1.0, -1.0,
|
|
144
|
-
|
|
145
|
-
// Bottom face
|
|
146
|
-
//12, 13, 14,
|
|
147
|
-
-1.0, -1.0, -1.0,
|
|
148
|
-
1.0, -1.0, -1.0,
|
|
149
|
-
1.0, -1.0, 1.0,
|
|
150
|
-
|
|
151
|
-
//12, 14, 15,
|
|
152
|
-
-1.0, -1.0, -1.0,
|
|
153
|
-
1.0, -1.0, 1.0,
|
|
154
|
-
-1.0, -1.0, 1.0,
|
|
155
|
-
|
|
156
|
-
// Right face
|
|
157
|
-
//16, 17, 18,
|
|
158
|
-
1.0, -1.0, -1.0,
|
|
159
|
-
1.0, 1.0, -1.0,
|
|
160
|
-
1.0, 1.0, 1.0,
|
|
161
|
-
|
|
162
|
-
//16, 18, 19,
|
|
163
|
-
1.0, -1.0, -1.0,
|
|
164
|
-
1.0, 1.0, 1.0,
|
|
165
|
-
1.0, -1.0, 1.0,
|
|
166
|
-
|
|
167
|
-
//Left face
|
|
168
|
-
//20, 21, 22,
|
|
169
|
-
-1.0, -1.0, -1.0,
|
|
170
|
-
-1.0, -1.0, 1.0,
|
|
171
|
-
-1.0, 1.0, 1.0,
|
|
172
|
-
|
|
173
|
-
//20, 22, 23
|
|
174
|
-
-1.0, -1.0, -1.0,
|
|
175
|
-
-1.0, 1.0, 1.0,
|
|
176
|
-
-1.0, 1.0, -1.0
|
|
177
|
-
];
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// Triangle vertices
|
|
181
|
-
var triangles = [
|
|
182
|
-
// Front face
|
|
183
|
-
// 0 1 2
|
|
184
|
-
[-1.0, -1.0, 1.0,
|
|
185
|
-
1.0, -1.0, 1.0,
|
|
186
|
-
1.0, 1.0, 1.0],
|
|
187
|
-
|
|
188
|
-
// 0 2 3
|
|
189
|
-
[-1.0, -1.0, 1.0,
|
|
190
|
-
1.0, 1.0, 1.0,
|
|
191
|
-
-1.0, 1.0, 1.0],
|
|
192
|
-
|
|
193
|
-
// Back face
|
|
194
|
-
//4, 5, 6,
|
|
195
|
-
[-1.0, -1.0, -1.0,
|
|
196
|
-
-1.0, 1.0, -1.0,
|
|
197
|
-
1.0, 1.0, -1.0],
|
|
198
|
-
|
|
199
|
-
//4, 6, 7,
|
|
200
|
-
[-1.0, -1.0, -1.0,
|
|
201
|
-
1.0, 1.0, -1.0,
|
|
202
|
-
1.0, -1.0, -1.0],
|
|
203
|
-
|
|
204
|
-
// Top face
|
|
205
|
-
//8, 9, 10,
|
|
206
|
-
[-1.0, 1.0, -1.0,
|
|
207
|
-
-1.0, 1.0, 1.0,
|
|
208
|
-
1.0, 1.0, 1.0],
|
|
209
|
-
|
|
210
|
-
//8, 10, 11,
|
|
211
|
-
[-1.0, 1.0, -1.0,
|
|
212
|
-
1.0, 1.0, 1.0,
|
|
213
|
-
1.0, 1.0, -1.0],
|
|
214
|
-
|
|
215
|
-
// Bottom face
|
|
216
|
-
//12, 13, 14,
|
|
217
|
-
[-1.0, -1.0, -1.0,
|
|
218
|
-
1.0, -1.0, -1.0,
|
|
219
|
-
1.0, -1.0, 1.0],
|
|
220
|
-
|
|
221
|
-
//12, 14, 15,
|
|
222
|
-
[-1.0, -1.0, -1.0,
|
|
223
|
-
1.0, -1.0, 1.0,
|
|
224
|
-
-1.0, -1.0, 1.0],
|
|
225
|
-
|
|
226
|
-
// Right face
|
|
227
|
-
//16, 17, 18,
|
|
228
|
-
[ 1.0, -1.0, -1.0,
|
|
229
|
-
1.0, 1.0, -1.0,
|
|
230
|
-
1.0, 1.0, 1.0],
|
|
231
|
-
|
|
232
|
-
//16, 18, 19,
|
|
233
|
-
[ 1.0, -1.0, -1.0,
|
|
234
|
-
1.0, 1.0, 1.0,
|
|
235
|
-
1.0, -1.0, 1.0],
|
|
236
|
-
|
|
237
|
-
//Left face
|
|
238
|
-
//20, 21, 22,
|
|
239
|
-
[-1.0, -1.0, -1.0,
|
|
240
|
-
-1.0, -1.0, 1.0,
|
|
241
|
-
-1.0, 1.0, 1.0],
|
|
242
|
-
|
|
243
|
-
//20, 22, 23
|
|
244
|
-
[-1.0, -1.0, -1.0,
|
|
245
|
-
-1.0, 1.0, 1.0,
|
|
246
|
-
-1.0, 1.0, -1.0]
|
|
247
|
-
];
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
type : type,
|
|
251
|
-
meshType : meshType,
|
|
252
|
-
vertices : vertices,
|
|
253
|
-
triangleIndices : triangleIndices,
|
|
254
|
-
triangles : triangles
|
|
255
|
-
};
|
|
256
|
-
};
|
package/lib/light.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Basic light object
|
|
3
|
-
* Position and colour. That is all.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var plask = require('plask');
|
|
7
|
-
|
|
8
|
-
function light(params) {
|
|
9
|
-
|
|
10
|
-
if(!params) {
|
|
11
|
-
this.position = new plask.Vec3();
|
|
12
|
-
this.ambientColor = new plask.Vec3(1.0, 1.0, 1.0);
|
|
13
|
-
this.diffuseColor = new plask.Vec3(1.0, 1.0, 1.0);
|
|
14
|
-
} else {
|
|
15
|
-
this.position = new plask.Vec3(params.position.x, params.position.y, params.position.z) || new plask.Vec3();
|
|
16
|
-
this.ambientColor = params.ambientVec || new plask.Vec3(1.0, 1.0, 1.0);
|
|
17
|
-
this.diffuseColor = params.diffuseVec || new plask.Vec3(1.0, 1.0, 1.0);
|
|
18
|
-
this.scene = params.scene;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.scene.on('camera', function() {
|
|
22
|
-
// console.log('light : camera added');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = light;
|
package/lib/line.js
DELETED
package/lib/mesh.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base 3D object.
|
|
3
|
-
* An array of triangles or lines
|
|
4
|
-
* Should be able to use as the base object for inheritance with for example
|
|
5
|
-
* different mesh generation algorithms.
|
|
6
|
-
*
|
|
7
|
-
* @TODO
|
|
8
|
-
* + Hit detection
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
var util = require('util');
|
|
12
|
-
var plask = require('plask');
|
|
13
|
-
var vertex = require('./vertex');
|
|
14
|
-
var line = require('./line');
|
|
15
|
-
var triangle = require('./triangle');
|
|
16
|
-
var vertex = require('./vertex');
|
|
17
|
-
var geom = require('./geom');
|
|
18
|
-
|
|
19
|
-
var mesh = function( params ) {
|
|
20
|
-
|
|
21
|
-
var self = this;
|
|
22
|
-
this.scene = params.scene;
|
|
23
|
-
|
|
24
|
-
this.timestamp = new Date().getTime();
|
|
25
|
-
this.index = this.scene.meshes.length + 1;
|
|
26
|
-
this.name = params.name || '';
|
|
27
|
-
this.type = params.geometry.type;
|
|
28
|
-
this.meshType = params.geometry.meshType;
|
|
29
|
-
|
|
30
|
-
this.vertices = [];
|
|
31
|
-
|
|
32
|
-
this.wireframe = false || params.wireframe;
|
|
33
|
-
this.pointMesh = false || params.pointMesh;
|
|
34
|
-
|
|
35
|
-
// If a geometry object was passed in to create the mesh use it
|
|
36
|
-
if(params.geometry.meshType === 'TRIANGLES') {
|
|
37
|
-
this.meshType = 'TRIANGLES';
|
|
38
|
-
this.triangles = [];
|
|
39
|
-
var triangles = params.geometry.triangles;
|
|
40
|
-
var material = params.material || { ambient : new plask.Vec3(0.0, 1.0, 0.0), diffuse : new plask.Vec3(0.0, 1.0, 0.0) };
|
|
41
|
-
|
|
42
|
-
triangles.forEach(function(triangle) {
|
|
43
|
-
self.addTriangle({
|
|
44
|
-
vertices : triangle,
|
|
45
|
-
material : material
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if(params.geometry.meshType === 'LINES') {
|
|
51
|
-
this.meshType = 'LINES';
|
|
52
|
-
this.lines = [];
|
|
53
|
-
this.vertices = params.geometry.vertices;
|
|
54
|
-
var lines = params.geometry.lines;
|
|
55
|
-
|
|
56
|
-
var materialDiffuse = new plask.Vec3(0.0, 1.0, 0.0);
|
|
57
|
-
|
|
58
|
-
lines.forEach(function(line, index) {
|
|
59
|
-
self.addLine({
|
|
60
|
-
vertices : line,
|
|
61
|
-
material : {
|
|
62
|
-
diffuse : params.geometry.lineColors[index] || materialDiffuse
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if(params.geometry.meshType === 'POINTS') {
|
|
69
|
-
this.meshType = 'POINTS';
|
|
70
|
-
this.points = [];
|
|
71
|
-
this.pointSize = params.pointSize;
|
|
72
|
-
this.pointMesh = true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Setup matrix uniforms
|
|
76
|
-
this.viewWorld = this.scene.viewCurrent.dup();
|
|
77
|
-
this.model = new plask.Mat4();
|
|
78
|
-
|
|
79
|
-
this.position = params.position || new plask.Vec3(0, 0, 0);
|
|
80
|
-
this.model.translate(this.position.x, this.position.y, this.position.z);
|
|
81
|
-
|
|
82
|
-
// Do we have a rotation?
|
|
83
|
-
// @TODO set this.rotX, this.rotY, this.rotZ from params
|
|
84
|
-
this.rotation = new plask.Mat4();
|
|
85
|
-
|
|
86
|
-
// Keep the global eye/view
|
|
87
|
-
this.scene.on('camera', function(eye) {
|
|
88
|
-
self.eyeCurrent = eye.eye;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Set listeners for events from the scene
|
|
92
|
-
this.scene.on('mouse', function(e) {
|
|
93
|
-
// Only deal with it if ctrl is pressed and it has been picked from the scene
|
|
94
|
-
if(!e.ctrl && !this.picked) {
|
|
95
|
-
return;
|
|
96
|
-
} else {
|
|
97
|
-
switch(e.type) {
|
|
98
|
-
case 'scrollWheel':
|
|
99
|
-
break;
|
|
100
|
-
case 'leftMouseDown':
|
|
101
|
-
self.mouseDown(e);
|
|
102
|
-
break;
|
|
103
|
-
case 'leftMouseDragged':
|
|
104
|
-
self.rotate(e);
|
|
105
|
-
break;
|
|
106
|
-
case 'leftMouseUp':
|
|
107
|
-
self.mouseUp(e);
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
this.mouse = {
|
|
114
|
-
down : false,
|
|
115
|
-
x : null,
|
|
116
|
-
y : null
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// Should the cached float array for this mesh be regenerated
|
|
120
|
-
this.dirty = true;
|
|
121
|
-
|
|
122
|
-
// Is this object picked by default
|
|
123
|
-
this.picked = params.picked || false;
|
|
124
|
-
|
|
125
|
-
this.scene.emit('mesh', self);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// INTERACTION
|
|
130
|
-
mesh.prototype.mouseDown = function(e) {
|
|
131
|
-
if(this.picked) {
|
|
132
|
-
this.mouse.down = true;
|
|
133
|
-
|
|
134
|
-
// Map the mouse events position to -1/+1
|
|
135
|
-
this.mouse.x = (2.0 * e.x / this.scene.winWidth) - 1;
|
|
136
|
-
this.mouse.y = -1 * (2.0 * e.y / this.scene.winHeight) + 1;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
mesh.prototype.rotate = function(e) {
|
|
141
|
-
|
|
142
|
-
// Rotate around the axis perpendicular to the direction of the mouse drag
|
|
143
|
-
// assume ctrl pressed
|
|
144
|
-
if(!this.mouse.down) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if(this.picked) {
|
|
149
|
-
|
|
150
|
-
var sensitivity = 0.1;
|
|
151
|
-
|
|
152
|
-
// Map the mouse events position to -1/+1
|
|
153
|
-
var currMouseX = (2.0 * e.x / this.scene.winWidth) - 1;
|
|
154
|
-
var currMouseY = -1 * (2.0 * e.y / this.scene.winHeight) + 1;
|
|
155
|
-
|
|
156
|
-
// Get the start and end vectors for screen space for the mouse drag
|
|
157
|
-
var start = new plask.Vec3(this.mouse.x, this.mouse.y, 0);
|
|
158
|
-
var end = new plask.Vec3(currMouseX, currMouseY, 0);
|
|
159
|
-
|
|
160
|
-
// Convert from screen to world space
|
|
161
|
-
var startWorld = this.eyeCurrent.mulVec3(start);
|
|
162
|
-
var endWorld = this.eyeCurrent.mulVec3(end);
|
|
163
|
-
|
|
164
|
-
// Calculate a single vector for the drag in world space
|
|
165
|
-
var dragVecWorld = new plask.Vec3().sub2(endWorld, startWorld);
|
|
166
|
-
|
|
167
|
-
// Calculate the magnitude of the drag vector using the dx, dy acceleration component
|
|
168
|
-
var mag = dragVecWorld.length();
|
|
169
|
-
|
|
170
|
-
var diffVec = new plask.Vec3(e.dx, e.dy, 0);
|
|
171
|
-
var diffVecWorld = this.eyeCurrent.mulVec3(diffVec);
|
|
172
|
-
var diffVecWorldMag = diffVecWorld.length();
|
|
173
|
-
|
|
174
|
-
var dragMag = diffVecWorldMag * mag * sensitivity;
|
|
175
|
-
|
|
176
|
-
// Calculate the vector perpendicular to the drag vecto
|
|
177
|
-
var dragVecWorldPerp = new plask.Vec3( startWorld.y * endWorld.z - startWorld.z*endWorld.y,
|
|
178
|
-
startWorld.z*endWorld.x - startWorld.x*endWorld.z,
|
|
179
|
-
startWorld.x*endWorld.y - startWorld.y*endWorld.x);
|
|
180
|
-
|
|
181
|
-
dragVecWorldPerp.normalize();
|
|
182
|
-
|
|
183
|
-
// Apply the new rotation
|
|
184
|
-
var newRot = new plask.Mat4();
|
|
185
|
-
newRot.rotate(dragMag, dragVecWorldPerp.x, dragVecWorldPerp.y, dragVecWorldPerp.z);
|
|
186
|
-
|
|
187
|
-
// Apply the new rotation to the accumulated rotation
|
|
188
|
-
newRot.mul(this.rotation);
|
|
189
|
-
|
|
190
|
-
// Set model to identity
|
|
191
|
-
this.model.reset();
|
|
192
|
-
|
|
193
|
-
// Apply translation to position
|
|
194
|
-
this.model.translate(this.position.x, this.position.y, this.position.z);
|
|
195
|
-
|
|
196
|
-
this.rotation = newRot;
|
|
197
|
-
this.model.mul(this.rotation);
|
|
198
|
-
|
|
199
|
-
this.mouse.x = (2.0 * e.x / this.scene.winWidth) - 1;
|
|
200
|
-
this.mouse.y = -1 * (2.0 * e.y / this.scene.winHeight) + 1;
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
mesh.prototype.mouseUp = function(e) {
|
|
207
|
-
this.mouse.down = false;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// GEOMETRY
|
|
212
|
-
mesh.prototype.addVertex = function(x, y, z) {
|
|
213
|
-
var v = new vertex(x, y, z);
|
|
214
|
-
this.vertices.push(v);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
mesh.prototype.addTriangle = function(params) {
|
|
218
|
-
|
|
219
|
-
var vertices = params.vertices;
|
|
220
|
-
var material = params.material;
|
|
221
|
-
|
|
222
|
-
var vertexA = new vertex(vertices[0], vertices[1], vertices[2]);
|
|
223
|
-
var vertexB = new vertex(vertices[3], vertices[4], vertices[5]);
|
|
224
|
-
var vertexC = new vertex(vertices[6], vertices[7], vertices[8]);
|
|
225
|
-
|
|
226
|
-
var tri = new triangle({
|
|
227
|
-
vertices : [vertexA, vertexB, vertexC],
|
|
228
|
-
material : material
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
this.vertices.push(vertexA, vertexB, vertexC);
|
|
232
|
-
this.triangles.push(tri);
|
|
233
|
-
|
|
234
|
-
this.dirty = true;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
mesh.prototype.addLine = function(params) {
|
|
238
|
-
|
|
239
|
-
var vertices = params.vertices;
|
|
240
|
-
var material = params.material;
|
|
241
|
-
|
|
242
|
-
var vertexA = new vertex(vertices[0], vertices[1], vertices[2]);
|
|
243
|
-
var vertexB = new vertex(vertices[3], vertices[4], vertices[5]);
|
|
244
|
-
|
|
245
|
-
var l = new line({
|
|
246
|
-
vertices : [vertexA, vertexB],
|
|
247
|
-
material : material
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
this.vertices.push(vertexA, vertexB);
|
|
251
|
-
this.lines.push(l);
|
|
252
|
-
|
|
253
|
-
this.dirty = true;
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
mesh.prototype.addPoint = function(params) {
|
|
257
|
-
|
|
258
|
-
this.points.push({
|
|
259
|
-
position : params.position,
|
|
260
|
-
material : params.material
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
this.dirty = true;
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
module.exports = mesh;
|
package/lib/pgl-utils.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Some utility functions which don't require plask
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
|
|
7
|
-
degToRad : function (degrees) {
|
|
8
|
-
return degrees * (Math.PI/180);
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
radToDeg : function(radians) {
|
|
12
|
-
return (Math.PI/180) / radians;
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
hexToRGB : function( hex ) {
|
|
16
|
-
|
|
17
|
-
var hexString = hex;
|
|
18
|
-
|
|
19
|
-
if(hexString.charAt(0) === '#') {
|
|
20
|
-
hexString = hexString.substring(1, hexString.length);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var redHex = hexString.charAt(0) + hexString.charAt(1);
|
|
24
|
-
var blueHex = hexString.charAt(2) + hexString.charAt(3);
|
|
25
|
-
var greenHex = hexString.charAt(4) + hexString.charAt(5);
|
|
26
|
-
|
|
27
|
-
var redInt = parseInt(redHex, 16);
|
|
28
|
-
var blueInt = parseInt(blueHex, 16);
|
|
29
|
-
var greenInt = parseInt(greenHex, 16);
|
|
30
|
-
|
|
31
|
-
var redLerped = redInt * (1/255);
|
|
32
|
-
var blueLerped = blueInt * (1/255);
|
|
33
|
-
var greenLerped = greenInt * (1/255);
|
|
34
|
-
|
|
35
|
-
return [redLerped, blueLerped, greenLerped];
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
merge : function(settings, defaults) {
|
|
39
|
-
var obj = {};
|
|
40
|
-
|
|
41
|
-
if(settings) {
|
|
42
|
-
for(var setting in defaults) {
|
|
43
|
-
if(settings[setting]) {
|
|
44
|
-
obj[setting] = settings[setting];
|
|
45
|
-
} else {
|
|
46
|
-
obj[setting] = defaults[setting];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
obj = defaults;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return obj;
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
geoCarte : function(lat, lon) {
|
|
57
|
-
// Approximate radius of the earth 6371km
|
|
58
|
-
var R = 6378137.0;
|
|
59
|
-
|
|
60
|
-
var cosLat = Math.cos(this.degToRad(lat));
|
|
61
|
-
var sinLat = Math.sin(this.degToRad(lat));
|
|
62
|
-
var cosLon = Math.cos(this.degToRad(lon));
|
|
63
|
-
var sinLon = Math.sin(this.degToRad(lon));
|
|
64
|
-
|
|
65
|
-
var f = 1.0 / 298.257224;
|
|
66
|
-
var C = 1.0 / Math.sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat);
|
|
67
|
-
var S = (1.0 - f) * (1.0 - f) * C;
|
|
68
|
-
var h = 0.0;
|
|
69
|
-
|
|
70
|
-
var x = (R * C + h) * cosLat * cosLon;
|
|
71
|
-
var y = (R * C + h) * cosLat * sinLon;
|
|
72
|
-
var z = (R * S + h) * sinLat;
|
|
73
|
-
|
|
74
|
-
return [x, y, z];
|
|
75
|
-
}
|
|
76
|
-
};
|
package/lib/plask-utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Some utility functions which require plask
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var plask = require('plask');
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
|
|
9
|
-
toInverseMat3 : function(mat4) {
|
|
10
|
-
var m = new plask.Mat3();
|
|
11
|
-
var x11 = mat4.a11, x12 = mat4.a12, x13 = mat4.a13,
|
|
12
|
-
x21 = mat4.a21, x22 = mat4.a22, x23 = mat4.a23,
|
|
13
|
-
x31 = mat4.a31, x32 = mat4.a32, x33 = mat4.a33;
|
|
14
|
-
|
|
15
|
-
var b11 = x22 * x33 - x23 * x32,
|
|
16
|
-
b12 = x32 * x13 - x33 * x12,
|
|
17
|
-
b13 = x12 * x23 - x13 * x22,
|
|
18
|
-
b21 = x23 * x31 - x21 * x33,
|
|
19
|
-
b22 = x33 * x11 - x31 * x13,
|
|
20
|
-
b23 = x13 * x21 - x11 * x23,
|
|
21
|
-
b31 = x21 * x32 - x22 * x31,
|
|
22
|
-
b32 = x31 * x12 - x32 * x11,
|
|
23
|
-
b33 = x11 * x22 - x12 * x21;
|
|
24
|
-
|
|
25
|
-
var det = x11 * b11 + x21 * b12 + x31 * b13;
|
|
26
|
-
var invdet;
|
|
27
|
-
|
|
28
|
-
if (!det){
|
|
29
|
-
return console.log('det is zero');
|
|
30
|
-
}
|
|
31
|
-
else{
|
|
32
|
-
invdet = 1 / det;
|
|
33
|
-
m.set3x3r(b11 * invdet,
|
|
34
|
-
b12 * invdet,
|
|
35
|
-
b13 * invdet,
|
|
36
|
-
b21 * invdet,
|
|
37
|
-
b22 * invdet,
|
|
38
|
-
b23 * invdet,
|
|
39
|
-
b31 * invdet,
|
|
40
|
-
b32 * invdet,
|
|
41
|
-
b33 * invdet);
|
|
42
|
-
return m;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
};
|