r3-legacy/src/game-lib-d3-api-particle.js

184 lines
4.8 KiB
JavaScript
Raw Normal View History

/**
* Raw Particle API object - should always correspond with the Particle Schema
* @param id
* @param name
* @param lifeTime
* @param elapsed
* @param mesh
* @param positionOffsetType
* @param positionOffset
* @param positionOffsetFn
* @param directionType
* @param rotation
* @param scale
* @param direction
* @param directionFn
* @param scaleFn
* @param scaleType
* @param rotationType
* @param rotationFn
* @param parentEngine
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Particle = function(
id,
name,
lifeTime,
elapsed,
mesh,
positionOffsetType,
positionOffset,
positionOffsetFn,
directionType,
direction,
directionFn,
scaleType,
scale,
scaleFn,
rotationType,
rotation,
rotationFn,
parentEngine,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Particle (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(lifeTime)) {
lifeTime = 10;
}
this.lifeTime = lifeTime;
if (GameLib.Utils.UndefinedOrNull(elapsed)) {
elapsed = 0;
}
this.elapsed = elapsed;
if (GameLib.Utils.UndefinedOrNull(mesh)) {
mesh = null;
}
this.mesh = mesh;
if (GameLib.Utils.UndefinedOrNull(positionOffsetType)) {
positionOffsetType = GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT;
}
this.positionOffsetType = positionOffsetType;
if (GameLib.Utils.UndefinedOrNull(positionOffset)) {
positionOffset = new GameLib.API.Vector3(0, 0, 0);
}
this.positionOffset = positionOffset;
if (GameLib.Utils.UndefinedOrNull(positionOffsetFn)) {
positionOffsetFn = '//@ sourceURL=positionOffsetFn.js';
}
this.positionOffsetFn = positionOffsetFn;
if (GameLib.Utils.UndefinedOrNull(directionType)) {
directionType = GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT;
}
this.directionType = directionType;
if (GameLib.Utils.UndefinedOrNull(direction)) {
direction = new GameLib.API.Vector3(0, 1, 0);
}
this.direction = direction;
if (GameLib.Utils.UndefinedOrNull(directionFn)) {
directionFn = '//@ sourceURL=directionFn.js';
}
this.directionFn = directionFn;
if (GameLib.Utils.UndefinedOrNull(scaleType)) {
scaleType = GameLib.D3.Particle.SCALE_TYPE_CONSTANT;
}
this.scaleType = scaleType;
if (GameLib.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.API.Vector3(1, 1, 1);
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(scaleFn)) {
scaleFn = '//@ sourceURL=scaleFn.js';
}
this.scaleFn = scaleFn;
if (GameLib.Utils.UndefinedOrNull(rotationType)) {
rotationType = GameLib.D3.Particle.ROTATION_TYPE_CONSTANT;
}
this.rotationType = rotationType;
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = new GameLib.API.Vector3(0, 0, 0);
}
this.rotation = rotation;
if (GameLib.Utils.UndefinedOrNull(rotationFn)) {
rotationFn = '//@ sourceURL=rotationFn.js';
}
this.rotationFn = rotationFn;
if (GameLib.Utils.UndefinedOrNull(parentEngine)) {
parentEngine = null;
}
this.parentEngine = parentEngine;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Particle.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Particle.prototype.constructor = GameLib.D3.API.Particle;
/**
* Creates an API Particle from an Object Particle
* @param objectParticle
* @constructor
*/
GameLib.D3.API.Particle.FromObject = function(objectParticle) {
var apiMesh = null;
if (objectParticle.mesh) {
if (objectParticle.mesh instanceof Object) {
apiMesh = GameLib.D3.API.Mesh.FromObject(objectParticle.mesh);
} else {
apiMesh = objectParticle.mesh;
}
}
return new GameLib.D3.API.Particle(
objectParticle.id,
objectParticle.name,
objectParticle.lifeTime,
objectParticle.elapsed,
apiMesh,
objectParticle.positionOffsetType,
GameLib.API.Vector3.FromObject(objectParticle.positionOffset),
objectParticle.positionOffsetFn,
objectParticle.directionType,
GameLib.API.Vector3.FromObject(objectParticle.direction),
objectParticle.directionFn,
objectParticle.scaleType,
GameLib.API.Vector3.FromObject(objectParticle.scale),
objectParticle.scaleFn,
objectParticle.rotationType,
GameLib.API.Vector3.FromObject(objectParticle.rotation),
objectParticle.rotationFn,
objectParticle.parentEngine,
objectParticle.parentEntity
);
};