particle engine
parent
e2a1aebc1e
commit
424ac0169d
|
@ -280,6 +280,7 @@ GameLib.Component.COMPONENT_SYSTEM_STORAGE = 0x48;
|
|||
GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION = 0x49;
|
||||
GameLib.Component.COMPONENT_FOG = 0x50;
|
||||
GameLib.Component.COMPONENT_MESH_LINE = 0x51;
|
||||
GameLib.Component.COMPONENT_PARTICLE_ENGINE = 0x52;
|
||||
|
||||
/**
|
||||
* Returns string name for component number
|
||||
|
@ -364,6 +365,7 @@ GameLib.Component.GetComponentName = function(number) {
|
|||
case 0x49 : return 'GameLib.D3.System.Visualization';
|
||||
case 0x50 : return 'GameLib.D3.Fog';
|
||||
case 0x51 : return 'GameLib.D3.Mesh.Line';
|
||||
case 0x52 : return 'GameLib.D3.ParticleEngine';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Raw ParticleEngine API object - should always correspond with the ParticleEngine Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param images
|
||||
* @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,
|
||||
images,
|
||||
direction,
|
||||
particlesPerSecond,
|
||||
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;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(images)) {
|
||||
images = [];
|
||||
}
|
||||
this.images = images;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
||||
direction = new GameLib.API.Vector3(0, 0, 1);
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(particlesPerSecond)) {
|
||||
particlesPerSecond = 1;
|
||||
}
|
||||
this.particlesPerSecond = particlesPerSecond;
|
||||
|
||||
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) {
|
||||
|
||||
var apiImages = [];
|
||||
if (objectParticleEngine.images) {
|
||||
apiImages = objectParticleEngine.images.map(
|
||||
function (objectImage) {
|
||||
if (objectImage instanceof Object) {
|
||||
return GameLib.D3.API.Image.FromObject(objectImage);
|
||||
} else {
|
||||
return objectImage
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return new GameLib.D3.API.ParticleEngine(
|
||||
objectParticleEngine.id,
|
||||
objectParticleEngine.name,
|
||||
apiImages,
|
||||
GameLib.API.Vector3.FromObject(objectParticleEngine.direction),
|
||||
objectParticleEngine.particlesPerSecond,
|
||||
objectParticleEngine.distanceType,
|
||||
objectParticleEngine.minDistance,
|
||||
objectParticleEngine.maxDistance,
|
||||
objectParticleEngine.scaleType,
|
||||
objectParticleEngine.minScale,
|
||||
objectParticleEngine.maxScale,
|
||||
objectParticleEngine.rotationType,
|
||||
objectParticleEngine.minRotation,
|
||||
objectParticleEngine.maxRotation,
|
||||
objectParticleEngine.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Creates a camera object
|
||||
* Creates a Camera object
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiCamera GameLib.D3.API.Camera
|
||||
* @constructor
|
||||
|
@ -247,7 +247,7 @@ GameLib.D3.Camera.prototype.toApiObject = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object camera to a GameLib.D3.Camera
|
||||
* Converts from an Object Camera to a GameLib.D3.Camera
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectCamera Object
|
||||
* @returns {GameLib.D3.Camera}
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
* Creates a ParticleEngine object
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiParticleEngine GameLib.D3.API.ParticleEngine
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ParticleEngine = function(
|
||||
graphics,
|
||||
apiParticleEngine
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiParticleEngine)) {
|
||||
apiParticleEngine = {};
|
||||
}
|
||||
|
||||
if (apiParticleEngine instanceof GameLib.D3.ParticleEngine) {
|
||||
return apiParticleEngine;
|
||||
}
|
||||
|
||||
GameLib.D3.API.ParticleEngine.call(
|
||||
this,
|
||||
apiParticleEngine.id,
|
||||
apiParticleEngine.name,
|
||||
apiParticleEngine.images,
|
||||
apiParticleEngine.direction,
|
||||
apiParticleEngine.particlesPerSecond,
|
||||
apiParticleEngine.distanceType,
|
||||
apiParticleEngine.minDistance,
|
||||
apiParticleEngine.maxDistance,
|
||||
apiParticleEngine.scaleType,
|
||||
apiParticleEngine.minScale,
|
||||
apiParticleEngine.maxScale,
|
||||
apiParticleEngine.rotationType,
|
||||
apiParticleEngine.minRotation,
|
||||
apiParticleEngine.maxRotation,
|
||||
apiParticleEngine.parentEntity
|
||||
);
|
||||
|
||||
this.images = this.images.map(
|
||||
function(image) {
|
||||
if (image instanceof GameLib.D3.API.Image) {
|
||||
return new GameLib.D3.Image(
|
||||
graphics,
|
||||
image
|
||||
)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (this.direction instanceof GameLib.API.Vector3) {
|
||||
this.direction = new GameLib.Vector3(
|
||||
graphics,
|
||||
this.direction,
|
||||
this
|
||||
);
|
||||
} else {
|
||||
console.warn('direction not instance of API.Vector3');
|
||||
throw new Error('direction not instance of API.Vector3');
|
||||
}
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_PARTICLE_ENGINE,
|
||||
{
|
||||
images : [GameLib.D3.Image]
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.ParticleEngine.prototype = Object.create(GameLib.D3.API.ParticleEngine.prototype);
|
||||
GameLib.D3.ParticleEngine.prototype.constructor = GameLib.D3.ParticleEngine;
|
||||
|
||||
GameLib.D3.ParticleEngine.DISTANCE_TYPE_CONSTANT = 0x1;
|
||||
GameLib.D3.ParticleEngine.SCALE_TYPE_CONSTANT = 0x1;
|
||||
GameLib.D3.ParticleEngine.ROTATION_TYPE_CONSTANT = 0x1;
|
||||
|
||||
/**
|
||||
* We don't use a 3rd party particle engine right now
|
||||
* @returns true
|
||||
*/
|
||||
GameLib.D3.ParticleEngine.prototype.createInstance = function() {
|
||||
|
||||
this.instance = true;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.ParticleEngine.prototype.updateInstance = function() {
|
||||
this.instance = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.ParticleEngine to a new GameLib.D3.API.ParticleEngine
|
||||
* @returns {GameLib.D3.API.ParticleEngine}
|
||||
*/
|
||||
GameLib.D3.ParticleEngine.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.D3.API.ParticleEngine(
|
||||
|
||||
this.id,
|
||||
this.name,
|
||||
this.images.map(
|
||||
function(image){
|
||||
return GameLib.Utils.IdOrNull(image);
|
||||
}
|
||||
),
|
||||
this.direction.toApiObject(),
|
||||
this.particlesPerSecond,
|
||||
this.distanceType,
|
||||
this.minDistance,
|
||||
this.maxDistance,
|
||||
this.scaleType,
|
||||
this.minScale,
|
||||
this.maxScale,
|
||||
this.rotationType,
|
||||
this.minRotation,
|
||||
this.maxRotation,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object ParticleEngine to a GameLib.D3.ParticleEngine
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectParticleEngine Object
|
||||
* @returns {GameLib.D3.ParticleEngine}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ParticleEngine.FromObject = function(graphics, objectParticleEngine) {
|
||||
|
||||
var apiParticleEngine = GameLib.D3.API.ParticleEngine.FromObject(objectParticleEngine);
|
||||
|
||||
return new GameLib.D3.ParticleEngine(
|
||||
graphics,
|
||||
apiParticleEngine
|
||||
);
|
||||
|
||||
};
|
Loading…
Reference in New Issue