elation-engine 0.9.127 → 0.10.0

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.
@@ -3,7 +3,7 @@ engine-systems-render-view>canvas {
3
3
  z-index: 1;
4
4
  }
5
5
  .engine_systems_render_css3d {
6
- position:fixed;
6
+ position:absolute;
7
7
  top: 0;
8
8
  left: 0;
9
9
  z-index: 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elation-engine",
3
3
  "description": "WebGL/WebVR engine written in Javascript",
4
- "version": "0.9.127",
4
+ "version": "0.10.0",
5
5
  "main": "",
6
6
  "author": "James Baicoianu",
7
7
  "license": "MIT",
@@ -45631,7 +45631,7 @@
45631
45631
  // ensure there is a value node
45632
45632
  if ( ! targetObject ) {
45633
45633
 
45634
- console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
45634
+ //console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
45635
45635
  return;
45636
45636
 
45637
45637
  }
@@ -15,7 +15,7 @@ elation.require("engine.things.controller", function() {
15
15
  try {
16
16
  this.performThink(this.thinkers[i], ev.data);
17
17
  } catch (e) {
18
- console.log(e.stack);
18
+ console.log(e);
19
19
  }
20
20
  }
21
21
  }
@@ -220,15 +220,16 @@ elation.require(['ui.window', 'ui.panel', 'ui.toggle', 'ui.slider', 'ui.label',
220
220
  }
221
221
  this.initialized = true;
222
222
  }
223
- this.addCommands = function(context, commands) {
224
- this.contexts[context] = commands;
223
+ this.addCommands = function(context, commands, target=null) {
224
+ if (!this.contexts[context]) this.contexts[context] = new Map();
225
+ this.contexts[context].set(target, commands);
225
226
  }
226
227
  this.addContexts = function(contexts) {
227
228
  for (var k in contexts) {
228
229
  this.addContext(k, contexts[k]);
229
230
  }
230
231
  }
231
- this.addContext = function(context, contextargs) {
232
+ this.addContext = function(context, contextargs, target=null) {
232
233
  var commands = {};
233
234
  var bindings = {};
234
235
  var states = {};
@@ -240,10 +241,11 @@ elation.require(['ui.window', 'ui.panel', 'ui.toggle', 'ui.slider', 'ui.label',
240
241
  commands[k] = contextargs[k][1];
241
242
  states[k] = 0;
242
243
  }
243
- this.addCommands(context, commands);
244
+ this.addCommands(context, commands, target);
244
245
  this.addBindings(context, bindings);
245
- this.contextstates[context] = states;
246
- console.log("[controls] added control context: " + context);
246
+ if (!this.contextstates[context]) this.contextstates[context] = new Map();
247
+ this.contextstates[context].set(target, states);
248
+ console.log("[controls] added control context: " + context, target, states);
247
249
 
248
250
  // FIXME - context state object should be a JS class, with reset() as a member function
249
251
  states._reset = function() {
@@ -257,9 +259,14 @@ elation.require(['ui.window', 'ui.panel', 'ui.toggle', 'ui.slider', 'ui.label',
257
259
  return states;
258
260
  }
259
261
  this.activateContext = function(context, target) {
260
- if (this.activecontexts.indexOf(context) == -1) {
262
+ let idx = this.activecontexts.indexOf(context);
263
+ if (idx == -1) {
261
264
  console.log('[controls] activate control context ' + context);
262
265
  this.activecontexts.unshift(context);
266
+ } else {
267
+ // Move context to top of the context stack if it's already active
268
+ this.activecontexts.splice(idx, 1);
269
+ this.activecontexts.unshift(context);
263
270
  }
264
271
  if (target) {
265
272
  this.contexttargets[context] = target;
@@ -307,19 +314,37 @@ elation.require(['ui.window', 'ui.panel', 'ui.toggle', 'ui.slider', 'ui.label',
307
314
  //console.log('fired!', firedev);
308
315
  for (var j = 0; j < this.activecontexts.length; j++) {
309
316
  var context = this.activecontexts[j];
310
- var contextstate = this.contextstates[context] || {};
317
+ let target = this.contexttargets[context] || null;
318
+ var contextstate;
319
+ if (this.contextstates[context]) {
320
+ if (target && this.contextstates[context].has(target)) {
321
+ contextstate = this.contextstates[context].get(target);
322
+ } else {
323
+ contextstate = this.contextstates[context].get(target);
324
+ }
325
+ }
326
+ if (!contextstate) contextstate = {};
311
327
  if (this.bindings[context] && this.bindings[context][this.changes[i]]) {
312
328
  var action = this.bindings[context][this.changes[i]];
313
- if (this.contexts[context][action]) {
329
+ let contextdef;
330
+ if (this.contexts[context]) {
331
+ if (this.contexts[context].has(target)) {
332
+ contextdef = this.contexts[context].get(target);
333
+ } else {
334
+ contextdef = this.contexts[context].get(null);
335
+ }
336
+ }
337
+ if (!contextdef) contextdef = {};
338
+ if (contextdef[action]) {
314
339
  contextstate[action] = this.state[this.changes[i]];
315
340
  //var ev = {timeStamp: now, type: this.changes[i], value: this.state[this.changes[i]], data: contextstate};
316
341
  var ev = {timeStamp: now, type: action, value: this.state[this.changes[i]], data: contextstate};
317
342
  //console.log('call it', this.changes[i], this.bindings[context][this.changes[i]], this.state[this.changes[i]]);
318
343
  if (this.contexttargets[context]) {
319
344
  ev.target = this.contexttargets[context];
320
- this.contexts[context][action].call(ev.data, ev);
345
+ contextdef[action].call(ev.data, ev);
321
346
  } else {
322
- this.contexts[context][action](ev);
347
+ contextdef[action](ev);
323
348
  }
324
349
  break; // Event was handled, no need to check other active contexts
325
350
  } else {
@@ -406,7 +406,7 @@ elation.require([
406
406
  //console.log(logprefix + "\t- added new " + type + ": " + name, currentobj);
407
407
  }
408
408
  } catch (e) {
409
- console.error(e.stack);
409
+ console.error(e);
410
410
  }
411
411
  return currentobj;
412
412
  }
@@ -54,14 +54,16 @@ elation.component.add("engine.things.generic", function() {
54
54
  'acceleration': { type: 'vector3', default: [0, 0, 0], comment: 'Object acceleration (m/s^2)' },
55
55
  'angular': { type: 'vector3', default: [0, 0, 0], comment: 'Object angular velocity (radians/sec)' },
56
56
  'angularacceleration': { type: 'vector3', default: [0, 0, 0], comment: 'Object angular acceleration (radians/sec^2)' },
57
- 'mass': { type: 'float', default: 0.0, comment: 'Object mass (kg)' },
57
+ 'mass': { type: 'float', default: 0.0, comment: 'Object mass (kg)', set: this.updatePhysics },
58
58
  'exists': { type: 'bool', default: true, comment: 'Exists' },
59
59
  'visible': { type: 'bool', default: true, comment: 'Is visible' },
60
60
  'physical': { type: 'bool', default: true, comment: 'Simulate physically' },
61
61
  'collidable': { type: 'bool', default: true, comment: 'Can crash into other things' },
62
- 'restitution': { type: 'float', default: 0.5, comment: 'Amount of energy preserved after each bounce', set: this.updatePhysics },
63
- 'dynamicfriction':{ type: 'float', default: 0.0, comment: 'Dynamic friction inherent to this object', set: this.updatePhysics },
64
- 'staticfriction': { type: 'float', default: 0.0, comment: 'Static friction inherent to this object', set: this.updatePhysics },
62
+ 'restitution': { type: 'float', default: 0.8, comment: 'Amount of energy preserved after each bounce', set: this.updatePhysics },
63
+ 'dynamicfriction':{ type: 'float', default: 0.2, comment: 'Dynamic friction inherent to this object', set: this.updatePhysics },
64
+ 'staticfriction': { type: 'float', default: 0.2, comment: 'Static friction inherent to this object', set: this.updatePhysics },
65
+ 'rollingfriction': { type: 'float', default: 0.5, comment: 'Rolling friction inherent to this object', set: this.updatePhysics },
66
+
65
67
  //'fog': { type: 'bool', default: true, comment: 'Affected by fog' },
66
68
  'shadow': { type: 'bool', default: true, refreshMaterial: true, comment: 'Casts and receives shadows' },
67
69
  'wireframe': { type: 'bool', default: false, refreshMaterial: true, comment: 'Render this object as a wireframe' },
@@ -754,6 +756,7 @@ elation.component.add("engine.things.generic", function() {
754
756
  material: {
755
757
  dynamicfriction: this.properties.dynamicfriction,
756
758
  staticfriction: this.properties.staticfriction,
759
+ rollingfriction: this.properties.rollingfriction,
757
760
  },
758
761
  object: this
759
762
  });
@@ -1919,9 +1922,11 @@ elation.component.add("engine.things.generic", function() {
1919
1922
  }
1920
1923
  this.updatePhysics = function() {
1921
1924
  if (this.objects.dynamics) {
1925
+ this.objects.dynamics.mass = this.properties.mass;
1922
1926
  this.objects.dynamics.restitution = this.restitution;
1923
1927
  this.objects.dynamics.material.dynamicfriction = this.dynamicfriction;
1924
1928
  this.objects.dynamics.material.staticfriction = this.staticfriction;
1929
+ this.objects.dynamics.material.rollingfriction = this.rollingfriction;
1925
1930
  }
1926
1931
  }
1927
1932
  });
@@ -15,6 +15,7 @@ elation.require(['engine.things.generic', 'engine.things.camera', 'engine.things
15
15
  jumpstrength: { type: 'float', default: 300.0 },
16
16
  jumptime: { type: 'float', default: 150 },
17
17
  movefriction: { type: 'float', default: 4.0 },
18
+ drag: { type: 'float', default: 0 },
18
19
  defaultplayer: { type: 'boolean', default: true },
19
20
  startposition: { type: 'vector3', default: new THREE.Vector3() },
20
21
  startorientation: { type: 'quaternion', default: new THREE.Quaternion() },
@@ -22,7 +23,7 @@ elation.require(['engine.things.generic', 'engine.things.camera', 'engine.things
22
23
  walking: { type: 'boolean', default: true },
23
24
  running: { type: 'boolean', default: false },
24
25
  flying: { type: 'boolean', default: false, set: function(key, value) { this.properties.flying = value; this.toggle_flying(value); }},
25
- dynamicfriction:{ type: 'float', default: 2.0, comment: 'Dynamic friction inherent to this object' },
26
+ dynamicfriction:{ type: 'float', default: 4.0, comment: 'Dynamic friction inherent to this object' },
26
27
  staticfriction: { type: 'float', default: 1.9, comment: 'Static friction inherent to this object' },
27
28
  fov: { type: 'float', default: 75, set: this.updateCamera },
28
29
  turnhead: { type: 'boolean', default: false, set: this.updateHeadLock },
@@ -189,6 +190,7 @@ elation.require(['engine.things.generic', 'engine.things.camera', 'engine.things
189
190
  }
190
191
  this.createForces = function() {
191
192
  this.frictionForce = this.objects.dynamics.addForce("friction", this.properties.movefriction);
193
+ this.dragForce = this.objects.dynamics.addForce("drag", this.properties.drag);
192
194
  this.gravityForce = this.objects.dynamics.addForce("gravity", this.gravityVector);
193
195
  this.moveForce = this.objects.dynamics.addForce("static", {});
194
196
  this.jumpForce = this.objects.dynamics.addForce("static", {});
@@ -333,7 +335,6 @@ elation.require(['engine.things.generic', 'engine.things.camera', 'engine.things
333
335
  this.frictionForce.update(this.properties.movefriction);
334
336
  if (this.controlstate['jump']) {
335
337
  this.jumpForce.update(new THREE.Vector3(0, this.jumpstrength, 0));
336
- //console.log('jump up!', this.jumpForce.force.toArray());
337
338
  setTimeout(elation.bind(this, function() {
338
339
  this.jumpForce.update(new THREE.Vector3(0, 0, 0));
339
340
  }), this.jumptime);
@@ -686,7 +687,8 @@ elation.require(['engine.things.generic', 'engine.things.camera', 'engine.things
686
687
  var intersects = _caster.intersectObjects(objects, true);
687
688
  if (intersects.length > 0) {
688
689
  for (var i = 0; i < intersects.length; i++) {
689
- if (intersects[i].distance <= 1 + this.fatness/* && (intersects[i].object.userData.thing && intersects[i].object.userData.thing !== this) */) {
690
+ let thing = intersects[i].object.userData.thing;
691
+ if (thing && thing !== this && intersects[i].distance <= 1 + this.fatness) {
690
692
  return intersects[i];
691
693
  }
692
694
  }