97 lines
1.8 KiB
JavaScript
97 lines
1.8 KiB
JavaScript
|
/**
|
||
|
* Creates a Clock object
|
||
|
* @param graphics
|
||
|
* @param apiClock R3.API.Clock
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.Clock = function(
|
||
|
graphics,
|
||
|
apiClock
|
||
|
) {
|
||
|
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiClock)) {
|
||
|
apiClock = {};
|
||
|
}
|
||
|
|
||
|
R3.API.Clock.call(
|
||
|
this,
|
||
|
apiClock.id,
|
||
|
apiClock.name,
|
||
|
apiClock.parentEntity
|
||
|
);
|
||
|
|
||
|
R3.Component.call(this);
|
||
|
} ;
|
||
|
|
||
|
R3.Clock.prototype = Object.create(R3.Component.prototype);
|
||
|
R3.Clock.prototype.constructor = R3.Clock;
|
||
|
|
||
|
/**
|
||
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||
|
* @returns {THREE.Clock}
|
||
|
*/
|
||
|
R3.Clock.prototype.createInstance = function() {
|
||
|
|
||
|
this.instance = new THREE.Clock();
|
||
|
|
||
|
R3.Component.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
R3.Clock.prototype.updateInstance = function() {
|
||
|
|
||
|
};
|
||
|
|
||
|
R3.Clock.prototype.getDelta = function() {
|
||
|
|
||
|
var delta = this.instance.getDelta();
|
||
|
|
||
|
/**
|
||
|
* clamp the delta to 1/60
|
||
|
*/
|
||
|
|
||
|
if (delta > (1 / 30.0)) {
|
||
|
// console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time');
|
||
|
delta = (1 / 30.0);
|
||
|
}
|
||
|
|
||
|
return delta;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a R3.Clock to a new R3.API.Clock
|
||
|
* @returns {R3.API.Clock}
|
||
|
*/
|
||
|
R3.Clock.prototype.toApiObject = function() {
|
||
|
|
||
|
return new R3.API.Clock(
|
||
|
this.id,
|
||
|
this.name,
|
||
|
R3.Utils.IdOrNull(this.parentEntity)
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts from an Object camera to a R3.Clock
|
||
|
* @param graphics R3.Graphics
|
||
|
* @param objectClock Object
|
||
|
* @returns {R3.Clock}
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.Clock.FromObject = function(graphics, objectClock) {
|
||
|
|
||
|
var apiClock = R3.API.Clock.FromObject(objectClock);
|
||
|
|
||
|
return new R3.Clock(
|
||
|
graphics,
|
||
|
apiClock
|
||
|
);
|
||
|
|
||
|
};
|