2017-11-03 13:07:45 +01:00
|
|
|
/**
|
|
|
|
* Raw ParticleEngine API object - should always correspond with the ParticleEngine Schema
|
|
|
|
* @param id
|
|
|
|
* @param name
|
2017-11-05 09:36:09 +01:00
|
|
|
* @param materials
|
|
|
|
* @param position
|
2017-11-03 13:07:45 +01:00
|
|
|
* @param direction
|
|
|
|
* @param particlesPerSecond
|
|
|
|
* @param distanceType
|
|
|
|
* @param minDistance
|
|
|
|
* @param maxDistance
|
|
|
|
* @param scaleType
|
|
|
|
* @param minScale
|
|
|
|
* @param maxScale
|
|
|
|
* @param rotationType
|
|
|
|
* @param minRotation
|
|
|
|
* @param maxRotation
|
|
|
|
* @param parentEntity
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.ParticleEngine = function(
|
|
|
|
id,
|
|
|
|
name,
|
2017-11-05 10:51:46 +01:00
|
|
|
meshes,
|
2017-11-05 09:36:09 +01:00
|
|
|
materials,
|
|
|
|
position,
|
2017-11-03 13:07:45 +01:00
|
|
|
direction,
|
2017-11-05 10:51:46 +01:00
|
|
|
lookAt,
|
2017-11-03 13:07:45 +01:00
|
|
|
particlesPerSecond,
|
2017-11-05 10:51:46 +01:00
|
|
|
frequency,
|
|
|
|
elapsed,
|
2017-11-03 13:07:45 +01:00
|
|
|
distanceType,
|
|
|
|
minDistance,
|
|
|
|
maxDistance,
|
|
|
|
scaleType,
|
|
|
|
minScale,
|
|
|
|
maxScale,
|
|
|
|
rotationType,
|
|
|
|
minRotation,
|
|
|
|
maxRotation,
|
|
|
|
parentEntity
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'ParticleEngine (' + this.id + ')';
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
2017-11-05 10:51:46 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(meshes)) {
|
|
|
|
meshes = [];
|
|
|
|
}
|
|
|
|
this.meshes = meshes;
|
|
|
|
|
2017-11-05 09:36:09 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
|
|
|
materials = [];
|
2017-11-03 13:07:45 +01:00
|
|
|
}
|
2017-11-05 09:36:09 +01:00
|
|
|
this.materials = materials;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
|
|
|
position = new GameLib.API.Vector3(0, 0, 0);
|
|
|
|
}
|
|
|
|
this.position = position;
|
2017-11-03 13:07:45 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
|
|
|
direction = new GameLib.API.Vector3(0, 0, 1);
|
|
|
|
}
|
|
|
|
this.direction = direction;
|
|
|
|
|
2017-11-05 10:51:46 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
|
|
|
|
lookAt = new GameLib.API.Vector3(0, 0, -1);
|
|
|
|
}
|
|
|
|
this.lookAt = lookAt;
|
|
|
|
|
2017-11-03 13:07:45 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(particlesPerSecond)) {
|
|
|
|
particlesPerSecond = 1;
|
|
|
|
}
|
|
|
|
this.particlesPerSecond = particlesPerSecond;
|
|
|
|
|
2017-11-05 10:51:46 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(frequency)) {
|
|
|
|
frequency = Number(1 / Number(particlesPerSecond));
|
|
|
|
}
|
|
|
|
this.frequency = frequency;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(elapsed)) {
|
|
|
|
elapsed = 0;
|
|
|
|
}
|
|
|
|
this.elapsed = elapsed;
|
|
|
|
|
2017-11-03 13:07:45 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(distanceType)) {
|
|
|
|
distanceType = GameLib.D3.ParticleEngine.DISTANCE_TYPE_CONSTANT;
|
|
|
|
}
|
|
|
|
this.distanceType = distanceType;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
|
|
|
minDistance = 1;
|
|
|
|
}
|
|
|
|
this.minDistance = minDistance;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(maxDistance)) {
|
|
|
|
maxDistance = 1;
|
|
|
|
}
|
|
|
|
this.maxDistance = maxDistance;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(scaleType)) {
|
|
|
|
scaleType = GameLib.D3.ParticleEngine.SCALE_TYPE_CONSTANT;
|
|
|
|
}
|
|
|
|
this.scaleType = scaleType;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(minScale)) {
|
|
|
|
minScale = null;
|
|
|
|
}
|
|
|
|
this.minScale = minScale;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(maxScale)) {
|
|
|
|
maxScale = null;
|
|
|
|
}
|
|
|
|
this.maxScale = maxScale;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(rotationType)) {
|
|
|
|
rotationType = GameLib.D3.ParticleEngine.ROTATION_TYPE_CONSTANT;
|
|
|
|
}
|
|
|
|
this.rotationType = rotationType;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(minRotation)) {
|
|
|
|
minRotation = 0;
|
|
|
|
}
|
|
|
|
this.minRotation = minRotation;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(maxRotation)) {
|
|
|
|
maxRotation = 0;
|
|
|
|
}
|
|
|
|
this.maxRotation = maxRotation;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.API.ParticleEngine.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.D3.API.ParticleEngine.prototype.constructor = GameLib.D3.API.ParticleEngine;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an API ParticleEngine from an Object ParticleEngine
|
|
|
|
* @param objectParticleEngine
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.ParticleEngine.FromObject = function(objectParticleEngine) {
|
|
|
|
|
2017-11-05 10:51:46 +01:00
|
|
|
var apiMeshes = [];
|
|
|
|
if (objectParticleEngine.meshes) {
|
|
|
|
apiMeshes = objectParticleEngine.meshes.map(
|
|
|
|
function (objectMesh) {
|
|
|
|
if (objectMesh instanceof Object) {
|
|
|
|
return GameLib.D3.API.Mesh.FromObject(objectMesh);
|
|
|
|
} else {
|
|
|
|
return objectMesh
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-05 09:36:09 +01:00
|
|
|
var apiMaterials = [];
|
|
|
|
if (objectParticleEngine.materials) {
|
|
|
|
apiMaterials = objectParticleEngine.materials.map(
|
|
|
|
function (objectMaterial) {
|
|
|
|
if (objectMaterial instanceof Object) {
|
|
|
|
return GameLib.D3.API.Material.FromObject(objectMaterial);
|
2017-11-03 13:07:45 +01:00
|
|
|
} else {
|
2017-11-05 09:36:09 +01:00
|
|
|
return objectMaterial
|
2017-11-03 13:07:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return new GameLib.D3.API.ParticleEngine(
|
|
|
|
objectParticleEngine.id,
|
|
|
|
objectParticleEngine.name,
|
2017-11-05 10:51:46 +01:00
|
|
|
apiMeshes,
|
2017-11-05 09:36:09 +01:00
|
|
|
apiMaterials,
|
|
|
|
GameLib.API.Vector3.FromObject(objectParticleEngine.position),
|
2017-11-03 13:07:45 +01:00
|
|
|
GameLib.API.Vector3.FromObject(objectParticleEngine.direction),
|
2017-11-05 10:51:46 +01:00
|
|
|
GameLib.API.Vector3.FromObject(objectParticleEngine.lookAt),
|
2017-11-03 13:07:45 +01:00
|
|
|
objectParticleEngine.particlesPerSecond,
|
2017-11-05 10:51:46 +01:00
|
|
|
objectParticleEngine.frequency,
|
|
|
|
objectParticleEngine.elapsed,
|
2017-11-03 13:07:45 +01:00
|
|
|
objectParticleEngine.distanceType,
|
|
|
|
objectParticleEngine.minDistance,
|
|
|
|
objectParticleEngine.maxDistance,
|
|
|
|
objectParticleEngine.scaleType,
|
|
|
|
objectParticleEngine.minScale,
|
|
|
|
objectParticleEngine.maxScale,
|
|
|
|
objectParticleEngine.rotationType,
|
|
|
|
objectParticleEngine.minRotation,
|
|
|
|
objectParticleEngine.maxRotation,
|
|
|
|
objectParticleEngine.parentEntity
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|