/** * Raw ParticleEngine API object - should always correspond with the ParticleEngine Schema * @param id * @param name * @param meshes * @param materials * @param position * @param rotation * @param direction * @param lookAt * @param particlesPerSecond * @param frequency * @param elapsed * @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, meshes, materials, position, rotation, scale, direction, lookAt, particlesPerSecond, frequency, elapsed, 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(meshes)) { meshes = []; } this.meshes = meshes; if (GameLib.Utils.UndefinedOrNull(materials)) { materials = []; } this.materials = materials; if (GameLib.Utils.UndefinedOrNull(position)) { position = new GameLib.API.Vector3(0, 0, 0); } this.position = position; if (GameLib.Utils.UndefinedOrNull(rotation)) { rotation = new GameLib.API.Vector3(0, 0, 0); } this.rotation = rotation; if (GameLib.Utils.UndefinedOrNull(scale)) { scale = new GameLib.API.Vector3(1, 1, 1); } this.scale = scale; if (GameLib.Utils.UndefinedOrNull(direction)) { direction = new GameLib.API.Vector3(0, 0, 1); } this.direction = direction; if (GameLib.Utils.UndefinedOrNull(lookAt)) { lookAt = new GameLib.API.Vector3(0, 0, -1); } this.lookAt = lookAt; if (GameLib.Utils.UndefinedOrNull(particlesPerSecond)) { particlesPerSecond = 1; } this.particlesPerSecond = particlesPerSecond; if (GameLib.Utils.UndefinedOrNull(frequency)) { frequency = Number(1 / Number(particlesPerSecond)); } this.frequency = frequency; if (GameLib.Utils.UndefinedOrNull(elapsed)) { elapsed = 0; } this.elapsed = elapsed; if (GameLib.Utils.UndefinedOrNull(distanceType)) { distanceType = GameLib.D3.ParticleEngine.DISTANCE_TYPE_CONSTANT; } this.distanceType = distanceType; if (GameLib.Utils.UndefinedOrNull(minDistance)) { minDistance = 0; } 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 apiMeshes = []; if (objectParticleEngine.meshes) { apiMeshes = objectParticleEngine.meshes.map( function (objectMesh) { if (objectMesh instanceof Object) { return GameLib.D3.API.Mesh.FromObject(objectMesh); } else { return objectMesh } } ) } var apiMaterials = []; if (objectParticleEngine.materials) { apiMaterials = objectParticleEngine.materials.map( function (objectMaterial) { if (objectMaterial instanceof Object) { return GameLib.D3.API.Material.FromObject(objectMaterial); } else { return objectMaterial } } ) } return new GameLib.D3.API.ParticleEngine( objectParticleEngine.id, objectParticleEngine.name, apiMeshes, apiMaterials, GameLib.API.Vector3.FromObject(objectParticleEngine.position), GameLib.API.Vector3.FromObject(objectParticleEngine.rotation), GameLib.API.Vector3.FromObject(objectParticleEngine.scale), GameLib.API.Vector3.FromObject(objectParticleEngine.direction), GameLib.API.Vector3.FromObject(objectParticleEngine.lookAt), objectParticleEngine.particlesPerSecond, objectParticleEngine.frequency, objectParticleEngine.elapsed, objectParticleEngine.distanceType, objectParticleEngine.minDistance, objectParticleEngine.maxDistance, objectParticleEngine.scaleType, objectParticleEngine.minScale, objectParticleEngine.maxScale, objectParticleEngine.rotationType, objectParticleEngine.minRotation, objectParticleEngine.maxRotation, objectParticleEngine.parentEntity ); };