1 package com.badlogic.gdx.graphics.g3d.particles.values; 2 3 import com.badlogic.gdx.math.Vector3; 4 import com.badlogic.gdx.utils.Json; 5 import com.badlogic.gdx.utils.JsonValue; 6 7 /** The base class of all the {@link SpawnShapeValue} values which spawn the 8 * particles on a geometric primitive. 9 * @author Inferno */ 10 public abstract class PrimitiveSpawnShapeValue extends SpawnShapeValue { 11 protected static final Vector3 TMP_V1 = new Vector3(); 12 static public enum SpawnSide { 13 both, top, bottom 14 } 15 public ScaledNumericValue spawnWidthValue, 16 spawnHeightValue, 17 spawnDepthValue; 18 protected float spawnWidth, spawnWidthDiff; 19 protected float spawnHeight, spawnHeightDiff; 20 protected float spawnDepth, spawnDepthDiff; 21 boolean edges = false; 22 23 public PrimitiveSpawnShapeValue(){ 24 spawnWidthValue = new ScaledNumericValue(); 25 spawnHeightValue = new ScaledNumericValue(); 26 spawnDepthValue = new ScaledNumericValue(); 27 } 28 29 public PrimitiveSpawnShapeValue(PrimitiveSpawnShapeValue value){ 30 super(value); 31 spawnWidthValue = new ScaledNumericValue(); 32 spawnHeightValue = new ScaledNumericValue(); 33 spawnDepthValue = new ScaledNumericValue(); 34 } 35 36 @Override 37 public void setActive (boolean active) { 38 super.setActive(active); 39 spawnWidthValue.setActive(true); 40 spawnHeightValue.setActive(true); 41 spawnDepthValue.setActive(true); 42 } 43 44 public boolean isEdges () { 45 return edges; 46 } 47 48 public void setEdges (boolean edges) { 49 this.edges = edges; 50 } 51 52 public ScaledNumericValue getSpawnWidth () { 53 return spawnWidthValue; 54 } 55 56 public ScaledNumericValue getSpawnHeight () { 57 return spawnHeightValue; 58 } 59 60 public ScaledNumericValue getSpawnDepth () { 61 return spawnDepthValue; 62 } 63 64 public void setDimensions(float width, float height, float depth){ 65 spawnWidthValue.setHigh(width); 66 spawnHeightValue.setHigh(height); 67 spawnDepthValue.setHigh(depth); 68 } 69 70 @Override 71 public void start () { 72 spawnWidth = spawnWidthValue.newLowValue(); 73 spawnWidthDiff = spawnWidthValue.newHighValue(); 74 if (!spawnWidthValue.isRelative()) spawnWidthDiff -= spawnWidth; 75 76 spawnHeight = spawnHeightValue.newLowValue(); 77 spawnHeightDiff = spawnHeightValue.newHighValue(); 78 if (!spawnHeightValue.isRelative()) spawnHeightDiff -= spawnHeight; 79 80 spawnDepth = spawnDepthValue.newLowValue(); 81 spawnDepthDiff = spawnDepthValue.newHighValue(); 82 if (!spawnDepthValue.isRelative()) spawnDepthDiff -= spawnDepth; 83 } 84 85 @Override 86 public void load (ParticleValue value) { 87 super.load(value); 88 PrimitiveSpawnShapeValue shape = (PrimitiveSpawnShapeValue) value; 89 edges = shape.edges; 90 spawnWidthValue.load(shape.spawnWidthValue); 91 spawnHeightValue.load(shape.spawnHeightValue); 92 spawnDepthValue.load(shape.spawnDepthValue); 93 } 94 95 @Override 96 public void write (Json json) { 97 super.write(json); 98 json.writeValue("spawnWidthValue", spawnWidthValue); 99 json.writeValue("spawnHeightValue", spawnHeightValue); 100 json.writeValue("spawnDepthValue", spawnDepthValue); 101 json.writeValue("edges", edges); 102 } 103 104 @Override 105 public void read (Json json, JsonValue jsonData) { 106 super.read(json, jsonData); 107 spawnWidthValue = json.readValue("spawnWidthValue", ScaledNumericValue.class, jsonData); 108 spawnHeightValue = json.readValue("spawnHeightValue", ScaledNumericValue.class, jsonData); 109 spawnDepthValue = json.readValue("spawnDepthValue", ScaledNumericValue.class, jsonData); 110 edges = json.readValue("edges", boolean.class, jsonData); 111 } 112 113 } 114