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.
Files changed (85) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +46 -11
  4. package/dist/cli-run.d.ts +3 -0
  5. package/dist/cli-run.d.ts.map +1 -0
  6. package/dist/cli-run.js +7 -0
  7. package/dist/cli-run.js.map +1 -0
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +5 -0
  11. package/dist/index.js.map +1 -0
  12. package/fwd/@dataplan/json/index.d.ts +1 -0
  13. package/fwd/@dataplan/json/index.js +1 -0
  14. package/fwd/@dataplan/pg/adaptors/pg/index.d.ts +1 -0
  15. package/fwd/@dataplan/pg/adaptors/pg/index.js +1 -0
  16. package/fwd/@dataplan/pg/index.d.ts +1 -0
  17. package/fwd/@dataplan/pg/index.js +1 -0
  18. package/fwd/grafast/envelop/index.d.ts +1 -0
  19. package/fwd/grafast/envelop/index.js +1 -0
  20. package/fwd/grafast/graphql/index.d.ts +1 -0
  21. package/fwd/grafast/graphql/index.js +1 -0
  22. package/fwd/grafast/index.d.ts +1 -0
  23. package/fwd/grafast/index.js +1 -0
  24. package/fwd/grafserv/express/v4/index.d.ts +1 -0
  25. package/fwd/grafserv/express/v4/index.js +1 -0
  26. package/fwd/grafserv/fastify/v4/index.d.ts +1 -0
  27. package/fwd/grafserv/fastify/v4/index.js +1 -0
  28. package/fwd/grafserv/index.d.ts +1 -0
  29. package/fwd/grafserv/index.js +1 -0
  30. package/fwd/grafserv/koa/v2/index.d.ts +1 -0
  31. package/fwd/grafserv/koa/v2/index.js +1 -0
  32. package/fwd/grafserv/node/index.d.ts +1 -0
  33. package/fwd/grafserv/node/index.js +1 -0
  34. package/fwd/grafserv/ruru/cli/index.d.ts +1 -0
  35. package/fwd/grafserv/ruru/cli/index.js +1 -0
  36. package/fwd/grafserv/ruru/index.d.ts +1 -0
  37. package/fwd/grafserv/ruru/index.js +1 -0
  38. package/fwd/grafserv/ruru/server/index.d.ts +1 -0
  39. package/fwd/grafserv/ruru/server/index.js +1 -0
  40. package/fwd/graphile-build/index.d.ts +2 -0
  41. package/fwd/graphile-build/index.js +1 -0
  42. package/fwd/graphile-build-pg/index.d.ts +1 -0
  43. package/fwd/graphile-build-pg/index.js +1 -0
  44. package/fwd/graphile-build-pg/pg-introspection/index.d.ts +1 -0
  45. package/fwd/graphile-build-pg/pg-introspection/index.js +1 -0
  46. package/fwd/pg-sql2/index.d.ts +1 -0
  47. package/fwd/pg-sql2/index.js +1 -0
  48. package/fwd/postgraphile/presets/amber/index.d.ts +1 -0
  49. package/fwd/postgraphile/presets/amber/index.js +1 -0
  50. package/fwd/postgraphile/presets/relay/index.d.ts +1 -0
  51. package/fwd/postgraphile/presets/relay/index.js +1 -0
  52. package/fwd/postgraphile/presets/v4/index.d.ts +1 -0
  53. package/fwd/postgraphile/presets/v4/index.js +1 -0
  54. package/fwd/postgraphile/utils/index.d.ts +1 -0
  55. package/fwd/postgraphile/utils/index.js +1 -0
  56. package/fwd/tamedevil/index.d.ts +1 -0
  57. package/fwd/tamedevil/index.js +1 -0
  58. package/package.json +202 -12
  59. package/.npmignore +0 -2
  60. package/LICENSE +0 -21
  61. package/examples/cube.js +0 -97
  62. package/examples/points.js +0 -82
  63. package/examples/shaders/flat-surface.fshader +0 -5
  64. package/examples/shaders/flat-surface.vshader +0 -72
  65. package/examples/shaders/matrices.fshader +0 -5
  66. package/examples/shaders/matrices.vshader +0 -12
  67. package/examples/shaders/model-and-view.fshader +0 -5
  68. package/examples/shaders/model-and-view.vshader +0 -23
  69. package/examples/shaders/pgl.fshader +0 -5
  70. package/examples/shaders/pgl.vshader +0 -53
  71. package/examples/shaders/simple.fshader +0 -5
  72. package/examples/shaders/simple.vshader +0 -8
  73. package/index.js +0 -23
  74. package/lib/camera.js +0 -222
  75. package/lib/geom.js +0 -256
  76. package/lib/light.js +0 -27
  77. package/lib/line.js +0 -10
  78. package/lib/mesh.js +0 -266
  79. package/lib/pgl-utils.js +0 -76
  80. package/lib/plask-utils.js +0 -46
  81. package/lib/renderer.js +0 -418
  82. package/lib/scene.js +0 -167
  83. package/lib/triangle.js +0 -73
  84. package/lib/vertex.js +0 -17
  85. package/test/index.js +0 -53
package/lib/renderer.js DELETED
@@ -1,418 +0,0 @@
1
- /**
2
- * Main WebGL renderer
3
- * Tightly bound with the Plask WebGL implementation.
4
- *
5
- * @TODO
6
- * + Shader attributes are hardcoded on creation, these should be queried from the mprogram obj
7
- * + is the caching of buffer objects working?
8
- */
9
-
10
- var plask = require('plask');
11
- var plaskUtils = require('./plask-utils');
12
- var pglUtils = require('./pgl-utils');
13
-
14
- var mesh;
15
- var light = {};
16
-
17
- var gl, mprogram;
18
- var buffersForAttributes = {};
19
-
20
- function create( params ) {
21
-
22
- var gl = params.gl;
23
- var mprogram = plask.gl.MagicProgram.createFromBasename(gl, params.shaderPath, params.shaderName);
24
-
25
- gl.viewport(0, 0, params.width, params.height);
26
- gl.clearDepth(1.0);
27
- gl.enable(gl.DEPTH_TEST);
28
- gl.depthFunc(gl.LEQUAL);
29
-
30
- this.gl = gl;
31
- this.mprogram = mprogram;
32
-
33
- // @TODO Get these out of the mprogram
34
- // but the attributes are strings in the render function
35
-
36
- this.buffersForAttributes = {
37
- 'location_aVertexPosition': {
38
- itemSize : 3,
39
- arrayData : null,
40
- cacheData : null
41
- },
42
- 'location_aAmbient': {
43
- itemSize : 3,
44
- arrayData : null,
45
- cacheData : null
46
- },
47
- 'location_aDiffuse' : {
48
- itemSize : 3,
49
- arrayData : null,
50
- cacheData : null
51
- },
52
- 'location_aVertexNormal' : {
53
- itemSize : 3,
54
- arrayData : null,
55
- cacheData : null
56
- },
57
- 'location_aVertexCentroid' : {
58
- itemSize : 3,
59
- arrayData : null,
60
- cacheData : null
61
- }
62
- };
63
- }
64
-
65
-
66
- // A scene object contains the meshes to be drawn, any lights and a simple camera object
67
- function render( scene ) {
68
-
69
- var gl = this.gl;
70
- var mprogram = this.mprogram;
71
-
72
- mprogram.use();
73
-
74
- gl.clearColor(1.0, 1.0, 1.0, 1.0);
75
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
76
-
77
- // push the curernt mv into the stack scene.mvStack
78
- var viewGlobal = scene.viewCurrent.dup();
79
-
80
- // reset mv stack
81
- scene.mvStack = [];
82
- scene.mvStack.push(viewGlobal);
83
-
84
- for(var meshIndex = 0; meshIndex < scene.meshes.length; meshIndex++) {
85
-
86
- var globMat = scene.mvStack[0];
87
-
88
- var mesh = scene.meshes[meshIndex];
89
-
90
- // apply rotations and translations from the mesh object
91
- // dup mv multiply by mvMesh
92
- var mvLocal = new plask.Mat4();
93
- mvLocal.mul2(globMat, mesh.model);
94
-
95
- // push this into the mesh stach
96
- scene.mvStack.push(mvLocal);
97
-
98
- // Set the shader attribute to the top in the matrix stack
99
- // At the end of the render loop for this mesh pop the stack
100
- mprogram.set_uMVMatrix( mvLocal );
101
-
102
- // Set the projection matrix and light position + color
103
- mprogram.set_uPMatrix( scene.cameras[0].perspMat );
104
-
105
- // // Set the position and colour values for the light
106
- mprogram.set_uLightPosition( scene.lights[0].position );
107
- mprogram.set_uLightAmbient( scene.lights[0].ambientColor );
108
- mprogram.set_uLightDiffuse( scene.lights[0].diffuseColor );
109
-
110
- var numVertices = 0;
111
- var numItems = 0;
112
-
113
- var i = 0, k = 0;
114
- var triangle, vertex;
115
- var buffer, itemSize;
116
-
117
- var vecColourAmbient;
118
- var vecColourDiffuse;
119
- var vertexIndex = 0;
120
-
121
- // var norm = scene.meshes[0].normMat;
122
- var norm;
123
-
124
- switch(mesh.meshType) {
125
-
126
- case 'TRIANGLES':
127
-
128
- // How many vertices are there?
129
- numVertices = mesh.triangles.length * 3;
130
- numItems = numVertices * 3;
131
-
132
- // Boolean to switch shading
133
- mprogram.set_uWireframe(mesh.wireframe);
134
-
135
- // Set normal matrix
136
- norm = plaskUtils.toInverseMat3( mvLocal );
137
- norm.transpose();
138
- mprogram.set_uNMatrix( norm );
139
-
140
- mprogram.set_uPointMesh(mesh.pointMesh);
141
-
142
- if(mesh.dirty) {
143
-
144
- for(var attribute in this.buffersForAttributes) {
145
-
146
- // dirty cache i want you, dirty cache i need you
147
- // reset values of i and k
148
- i = 0; k = 0;
149
- triangle = null;
150
- vertex = null;
151
- vecColourAmbient = null;
152
- vecColourDiffuse = null;
153
-
154
- // Create buffer object
155
- itemSize = this.buffersForAttributes[attribute].itemSize;
156
- this.buffersForAttributes[attribute].arrayData = createBuffer(numVertices, itemSize);
157
- buffer = this.buffersForAttributes[attribute].arrayData;
158
-
159
- this.buffersForAttributes[attribute].cacheData = createCache(numVertices, itemSize);
160
-
161
- vertexIndex = 0;
162
-
163
- for(i = 0; i < mesh.triangles.length; i++) {
164
- triangle = mesh.triangles[i];
165
-
166
- for(k = 0; k < triangle.vertices.length; k++) {
167
- vertex = triangle.vertices[k];
168
-
169
- switch(attribute) {
170
- case 'location_aVertexPosition':
171
- setBufferData(vertexIndex, this.buffersForAttributes[attribute], vertex);
172
- break;
173
-
174
- case 'location_aAmbient':
175
- // vecColourAmbient = utils.hexToRGB(triangle.material.ambient); ////// actually need to convert to a vector
176
- setBufferData(vertexIndex, this.buffersForAttributes[attribute], triangle.material.ambient);
177
- break;
178
-
179
- case 'location_aDiffuse':
180
- // vecColourDiffuse = utils.hexToRGB(triangle.material.diffuse);
181
- setBufferData(vertexIndex, this.buffersForAttributes[attribute], triangle.material.diffuse);
182
- break;
183
-
184
- case 'location_aVertexNormal':
185
- setBufferData(vertexIndex, this.buffersForAttributes[attribute], triangle.normal);
186
- break;
187
-
188
- case 'location_aVertexCentroid':
189
- setBufferData(vertexIndex, this.buffersForAttributes[attribute], triangle.centroid);
190
- break;
191
-
192
- }
193
- vertexIndex++;
194
- }
195
-
196
- }
197
-
198
- // Upload attribute buffer data
199
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
200
- gl.bufferData(gl.ARRAY_BUFFER, buffer.data, gl.STATIC_DRAW);
201
-
202
- gl.enableVertexAttribArray(mprogram[attribute]);
203
- gl.vertexAttribPointer(mprogram[attribute], buffer.itemSize, gl.FLOAT, false, 0, 0);
204
-
205
- }
206
-
207
- // @TODO
208
- // mesh.dirty = false; // can't do this because buffer needs to get reused for other meshes
209
- // dirty flag can be used to avoid unecessary updates
210
-
211
- } else {
212
-
213
- // The mesh geometry is clean so set directly from the cached Float32Array
214
- for(var cacheAttribute in this.buffersForAttributes) {
215
-
216
- // @TODO
217
- // mprogram.location not set return with an error
218
-
219
- var cacheArray = this.buffersForAttributes[cacheAttribute].cacheData;
220
-
221
- itemSize = this.buffersForAttributes[cacheAttribute].itemSize;
222
- buffer = this.buffersForAttributes[cacheAttribute].arrayData;
223
-
224
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
225
- gl.bufferData(gl.ARRAY_BUFFER, cacheArray.data, gl.STATIC_DRAW);
226
-
227
- gl.enableVertexAttribArray(mprogram.location_aVertexPosition);
228
- gl.vertexAttribPointer(mprogram[cacheAttribute], buffer.itemSize, gl.FLOAT, false, 0, 0);
229
- }
230
-
231
- }
232
-
233
- // Draw the triangles
234
- gl.drawArrays(gl.TRIANGLES, 0, numItems);
235
-
236
- break;
237
-
238
- case 'LINES':
239
-
240
- var line;
241
-
242
- // How many vertices are there?
243
- numVertices = mesh.lines.length * 2;
244
- numItems = numVertices * 3;
245
-
246
- mprogram.set_uMVMatrix( mvLocal );
247
- mprogram.set_uWireframe(mesh.wireframe);
248
-
249
- mprogram.set_uPointMesh(mesh.pointMesh);
250
-
251
- if(mesh.dirty) {
252
- for(var lineAttribute in this.buffersForAttributes) {
253
-
254
- itemSize = this.buffersForAttributes[lineAttribute].itemSize;
255
- this.buffersForAttributes[lineAttribute].arrayData = createBuffer(numVertices, itemSize);
256
- buffer = this.buffersForAttributes[lineAttribute].arrayData;
257
-
258
- this.buffersForAttributes[lineAttribute].cacheData = createCache(numVertices, itemSize);
259
-
260
- vertexIndex = 0;
261
-
262
- for (i = 0; i < mesh.lines.length; i++) {
263
-
264
- line = mesh.lines[i];
265
-
266
- for(k = 0; k < line.vertices.length; k++) {
267
-
268
- vertex = line.vertices[k];
269
-
270
- switch(lineAttribute) {
271
- case 'location_aVertexPosition':
272
- setBufferData(vertexIndex, this.buffersForAttributes[lineAttribute], vertex);
273
- break;
274
- case 'location_aDiffuse':
275
- setBufferData(vertexIndex, this.buffersForAttributes[lineAttribute], line.material.diffuse);
276
- break;
277
- }
278
- vertexIndex++;
279
- }
280
- }
281
-
282
- // Upload attribute buffer data
283
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
284
- gl.bufferData(gl.ARRAY_BUFFER, buffer.data, gl.STATIC_DRAW);
285
-
286
- gl.enableVertexAttribArray(mprogram[lineAttribute]);
287
- gl.vertexAttribPointer(mprogram[lineAttribute], buffer.itemSize, gl.FLOAT, false, 0, 0);
288
-
289
- }
290
-
291
- } else {
292
- // need to set buffers for each object array ....?
293
- }
294
-
295
- gl.drawArrays(gl.LINES, 0, numItems);
296
-
297
- break;
298
-
299
- case 'POINTS':
300
- var point;
301
-
302
- numVertices = mesh.points.length;
303
- numItems = numVertices * 3;
304
-
305
- mprogram.set_uMVMatrix( mvLocal );
306
- mprogram.set_uPointMesh(mesh.pointMesh);
307
-
308
- if(mesh.pointMesh) {
309
- mprogram.set_uPointSize(mesh.pointSize);
310
- }
311
-
312
- if(mesh.dirty) {
313
- for(var pointAttribute in this.buffersForAttributes) {
314
-
315
- itemSize = this.buffersForAttributes[pointAttribute].itemSize;
316
- this.buffersForAttributes[pointAttribute].arrayData = createBuffer(numVertices, itemSize);
317
- buffer = this.buffersForAttributes[pointAttribute].arrayData;
318
-
319
- this.buffersForAttributes[pointAttribute].cacheData = createCache(numVertices, itemSize);
320
-
321
- vertexIndex = 0;
322
-
323
- for (i = 0; i < mesh.points.length; i++) {
324
-
325
- point = mesh.points[i];
326
-
327
- switch(pointAttribute) {
328
- case 'location_aVertexPosition':
329
- setBufferData(vertexIndex, this.buffersForAttributes[pointAttribute], point.position);
330
- break;
331
- case 'location_aDiffuse':
332
- setBufferData(vertexIndex, this.buffersForAttributes[pointAttribute], point.material.diffuse);
333
- break;
334
- }
335
- vertexIndex++;
336
-
337
- }
338
-
339
- // Upload attribute buffer data
340
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
341
- gl.bufferData(gl.ARRAY_BUFFER, buffer.data, gl.STATIC_DRAW);
342
-
343
- gl.enableVertexAttribArray(mprogram[pointAttribute]);
344
- gl.vertexAttribPointer(mprogram[pointAttribute], buffer.itemSize, gl.FLOAT, false, 0, 0);
345
-
346
- }
347
-
348
- } else {
349
- // need to set buffers for each object array ....?
350
- }
351
-
352
- gl.drawArrays(gl.POINTS, 0, numItems);
353
-
354
- break;
355
-
356
- } // close case switch for the mesh type
357
-
358
- // pop the stack
359
- scene.mvStack.pop();
360
-
361
- } // close for each on meshes in the scene
362
-
363
- }
364
-
365
-
366
- function createBuffer(numItems, itemSize, floatArray) {
367
- var gl = module.exports.gl;
368
- var data = new Float32Array(numItems * itemSize);
369
- var buffer = gl.createBuffer();
370
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
371
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
372
-
373
- return {
374
- buffer : buffer,
375
- numItems : numItems,
376
- data : data,
377
- itemSize : itemSize
378
- };
379
- }
380
-
381
- function createCache(numItems, itemSize) {
382
- var data = new Float32Array(numItems * itemSize);
383
-
384
- return {
385
- data : data,
386
- numItems : numItems,
387
- itemSize : itemSize
388
- };
389
- }
390
-
391
- function setBufferData(index, buffer, value) {
392
- if(typeof value === 'number') {
393
- buffer.arrayData.data[index * buffer.itemSize] = value;
394
- buffer.cacheData.data[index * buffer.itemSize] = value;
395
- } else if(value instanceof plask.Vec3) {
396
- buffer.arrayData.data[index * buffer.itemSize] = value.x;
397
- buffer.arrayData.data[index * buffer.itemSize + 1] = value.y;
398
- buffer.arrayData.data[index * buffer.itemSize + 2] = value.z;
399
-
400
- buffer.cacheData.data[index * buffer.itemSize] = value.x;
401
- buffer.cacheData.data[index * buffer.itemSize + 1] = value.y;
402
- buffer.cacheData.data[index * buffer.itemSize + 2] = value.z;
403
- } else if(typeof value === 'object') {
404
- for(var i = value.length - 1; i >=0; i--) {
405
- buffer.arrayData.data[index * buffer.itemSize + i] = value[i];
406
- buffer.cacheData.data[index * buffer.itemSize + i] = value[i];
407
- }
408
- }
409
-
410
- }
411
-
412
-
413
- module.exports = {
414
- gl : gl,
415
- mprogram : mprogram,
416
- create : create,
417
- render : render
418
- };
package/lib/scene.js DELETED
@@ -1,167 +0,0 @@
1
- /**
2
- * A scene graph object.
3
- * The scene does not maintain hierarchy it just facilitates event emission and
4
- * response between child objects. It also keeps a current eye / view matrix to pass to the renderer
5
- * this is set whenever the camera emits an update event.
6
- *
7
- * @TODO
8
- * + Throttle the event emission rate?
9
- * + move the model view stack onto the renderer?
10
- *
11
- */
12
-
13
- var util = require('util');
14
- var EventEmitter = require('events').EventEmitter;
15
-
16
- var plask = require('plask');
17
-
18
- var pglUtils = require('./pgl-utils');
19
- var camera = require('./camera');
20
- var light = require('./light');
21
- var mesh = require('./mesh');
22
- var geom = require('./geom');
23
-
24
- var scene = function() {
25
- var self = this;
26
-
27
- this.winWidth = null;
28
- this.winHeight = null;
29
-
30
- EventEmitter.call(this);
31
- this.lights = [];
32
- this.cameras = [];
33
- this.meshes = [];
34
-
35
- // add a transform stack to push onto and pop from when rendering
36
- this.mvStack = [];
37
-
38
- this.viewCurrent = new plask.Mat4();
39
- this.eyeCurrent = new plask.Mat4();
40
-
41
- // When the camera sends eye matrix updates store it and set the inverse to a view matrix
42
- this.on('camera', function(camera) {
43
- self.eyeCurrent = camera.eye;
44
- self.viewCurrent = camera.eye.dup().invert();
45
- });
46
-
47
- this.on('mesh', function(mesh) {
48
- console.log('mesh added : ' + mesh.name);
49
- });
50
- };
51
-
52
- util.inherits(scene, EventEmitter);
53
-
54
- scene.prototype.setWindow = function(width, height) {
55
- this.winWidth = width;
56
- this.winHeight = height;
57
- };
58
-
59
- scene.prototype.addLight = function(params) {
60
-
61
- var l;
62
-
63
- if(!params){
64
- l = new light();
65
- } else {
66
- params.scene = this;
67
- l = new light(params);
68
- }
69
-
70
- this.lights.push(l);
71
- };
72
-
73
- scene.prototype.addCamera = function(params) {
74
- // @TODO add different camera types, different focal lengths
75
- // orthographic and perspective to swap out on command
76
- // var c = new camera(width, height, location);
77
- var c;
78
-
79
- if(!params) {
80
- c = new camera();
81
- } else {
82
- c = new camera({
83
- width : params.width,
84
- height : params.height,
85
- position : params.position,
86
- scene : this
87
- });
88
- }
89
-
90
- this.cameras.push(c);
91
-
92
- this.setWindow(params.width, params.height);
93
- };
94
-
95
- // Objects
96
-
97
- scene.prototype.addMesh = function(mesh) {
98
- this.meshes.push(mesh);
99
- };
100
-
101
-
102
- scene.prototype.addFloor = function(args) {
103
-
104
- var gridDefaults = {
105
- minX : -10,
106
- maxX : 10,
107
- minZ : -10,
108
- maxZ : 10,
109
- step : 1
110
- };
111
-
112
- var gridParams;
113
-
114
- if(args) {
115
- gridParams = args.gridSettings;
116
- }
117
-
118
- var gridSettings = pglUtils.merge(gridParams, gridDefaults);
119
-
120
- var gridGeom = new geom.planeGrid(gridSettings);
121
-
122
- var floorMesh = new mesh({
123
- geometry : gridGeom,
124
- scene : this,
125
- name : 'floor',
126
- position: new plask.Vec3(0, 0, 0),
127
- wireframe : true
128
- });
129
-
130
- this.addMesh(floorMesh);
131
- };
132
-
133
- scene.prototype.addAxes = function() {
134
-
135
- var axes = new mesh({
136
- geometry : new geom.axes(),
137
- scene : this,
138
- name : 'axes',
139
- position : new plask.Vec3(0, 0, 0),
140
- wireframe : true
141
- });
142
-
143
- this.addMesh(axes);
144
- };
145
-
146
- // Interaction
147
-
148
- scene.prototype.handleMouse = function(e) {
149
- // alternative would be to split out the mouse vectors here?
150
- // process the event to emit just relevent data for the scene object to respond
151
- // emit rotQuat events?
152
- this.emit('mouse', e);
153
- };
154
-
155
- scene.prototype.handleKey = function(e) {
156
- // currently only reset the camera target with 'r'
157
- this.emit('key', e);
158
- };
159
-
160
- // @TODO target or scene.mesh = a flag to show whichever mesh is active
161
- // each one chooses whether to respond if it has been picked
162
-
163
- scene.prototype.update = function() {
164
- // anything animating on a timer
165
- };
166
-
167
- module.exports = scene;
package/lib/triangle.js DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * Triangle object
3
- * @TODO
4
- * + module.exports style differs from the others, make consistent
5
- *
6
- */
7
-
8
- var plask = require('plask');
9
- var vertex = require('./vertex');
10
-
11
- function triangle(params) {
12
-
13
- params = params || {};
14
-
15
- var vertices = params.vertices;
16
-
17
- this.material = params.material;
18
-
19
- var vertexA = vertices[0],
20
- vertexB = vertices[1],
21
- vertexC = vertices[2];
22
-
23
- // create the vertices buffer here
24
- this.verticesArray = [vertexA.x, vertexA.y, vertexA.z,
25
- vertexB.x, vertexB.y, vertexB.z,
26
- vertexC.x, vertexC.y, vertexC.z];
27
-
28
- this.vertexA = vertexA;
29
- this.vertexB = vertexB;
30
- this.vertexC = vertexC;
31
-
32
- this.vertices = [];
33
-
34
- this.vertices.push([vertexA.x, vertexA.y, vertexA.z]);
35
- this.vertices.push([vertexB.x, vertexB.y, vertexB.z]);
36
- this.vertices.push([vertexC.x, vertexC.y, vertexC.z]);
37
-
38
- this.u = new plask.Vec3();
39
- this.v = new plask.Vec3();
40
-
41
- this.centroid = this.computeCentroid();
42
- this.normal = this.computeNormal();
43
- }
44
-
45
- triangle.prototype = {
46
- computeCentroid : function() {
47
-
48
- var centroidVertices = [];
49
-
50
- centroidVertices[0] = this.vertexA.x + this.vertexB.x + this.vertexC.x;
51
- centroidVertices[1] = this.vertexA.y + this.vertexB.y + this.vertexC.y;
52
- centroidVertices[2] = this.vertexA.z + this.vertexB.z + this.vertexC.z;
53
-
54
- var centroid = new plask.Vec3(centroidVertices[0], centroidVertices[1], centroidVertices[2]);
55
-
56
- centroid.scale(1/3);
57
-
58
- return centroid;
59
- },
60
- computeNormal : function() {
61
- this.u.sub2(this.vertexA, this.vertexB);
62
- this.v.sub2(this.vertexC, this.vertexA);
63
-
64
- var normal = new plask.Vec3();
65
-
66
- normal.cross2(this.u, this.v);
67
- normal.normalize();
68
-
69
- return normal;
70
- }
71
- };
72
-
73
- module.exports = triangle;
package/lib/vertex.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Simple vertex
3
- * Inherits from the plask.Vec3 object
4
- * @TODO
5
- * + add normals for interpolated shading over triangles/faces
6
- */
7
-
8
- var plask = require('plask');
9
- var util = require('util');
10
-
11
- function vertex(x, y, z) {
12
- plask.Vec3.apply(this, arguments);
13
- }
14
-
15
- util.inherits(vertex, plask.Vec3);
16
-
17
- module.exports = vertex;