1 package com.badlogic.gdx.graphics.g3d.particles.values; 2 3 import com.badlogic.gdx.assets.AssetManager; 4 import com.badlogic.gdx.graphics.g3d.particles.ResourceData; 5 import com.badlogic.gdx.math.Vector3; 6 import com.badlogic.gdx.utils.Json; 7 import com.badlogic.gdx.utils.JsonValue; 8 9 /** Encapsulate the formulas to spawn a particle on a shape. 10 * @author Inferno */ 11 public abstract class SpawnShapeValue extends ParticleValue implements ResourceData.Configurable, Json.Serializable{ 12 13 public RangedNumericValue xOffsetValue, yOffsetValue, zOffsetValue; 14 15 public SpawnShapeValue(){ 16 xOffsetValue = new RangedNumericValue(); 17 yOffsetValue = new RangedNumericValue(); 18 zOffsetValue = new RangedNumericValue(); 19 } 20 21 public SpawnShapeValue(SpawnShapeValue spawnShapeValue){ 22 this(); 23 } 24 25 public abstract void spawnAux(Vector3 vector, float percent); 26 27 public final Vector3 spawn(Vector3 vector, float percent){ 28 spawnAux(vector, percent); 29 if (xOffsetValue.active) vector.x += xOffsetValue.newLowValue(); 30 if (yOffsetValue.active) vector.y += yOffsetValue.newLowValue(); 31 if (zOffsetValue.active) vector.z += zOffsetValue.newLowValue(); 32 return vector; 33 } 34 35 public void init (){} 36 public void start(){} 37 38 @Override 39 public void load (ParticleValue value) { 40 super.load(value); 41 SpawnShapeValue shape = (SpawnShapeValue) value; 42 xOffsetValue.load(shape.xOffsetValue); 43 yOffsetValue.load(shape.yOffsetValue); 44 zOffsetValue.load(shape.zOffsetValue); 45 } 46 47 public abstract SpawnShapeValue copy (); 48 49 @Override 50 public void write (Json json) { 51 super.write(json); 52 json.writeValue("xOffsetValue", xOffsetValue); 53 json.writeValue("yOffsetValue", yOffsetValue); 54 json.writeValue("zOffsetValue", zOffsetValue); 55 } 56 57 @Override 58 public void read (Json json, JsonValue jsonData) { 59 super.read(json, jsonData); 60 xOffsetValue = json.readValue("xOffsetValue", RangedNumericValue.class, jsonData); 61 yOffsetValue = json.readValue("yOffsetValue", RangedNumericValue.class, jsonData); 62 zOffsetValue = json.readValue("zOffsetValue", RangedNumericValue.class, jsonData); 63 } 64 65 @Override 66 public void save (AssetManager manager, ResourceData data) {} 67 @Override 68 public void load (AssetManager manager, ResourceData data) {} 69 70 71 }