| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using System; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Components |
| | 8 | | { |
| | 9 | | public class CylinderShape : ParametrizedShape<CylinderShape.Model> |
| | 10 | | { |
| | 11 | | [System.Serializable] |
| | 12 | | new public class Model : BaseShape.Model |
| | 13 | | { |
| 33 | 14 | | public float radiusTop = 1f; |
| 33 | 15 | | public float radiusBottom = 1f; |
| 33 | 16 | | public float segmentsHeight = 1f; |
| 33 | 17 | | public float segmentsRadial = 36f; |
| | 18 | | public bool openEnded = false; |
| | 19 | | public float? radius; |
| 33 | 20 | | public float arc = 360f; |
| | 21 | |
|
| 16 | 22 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 23 | | } |
| | 24 | |
|
| 24 | 25 | | public CylinderShape() { model = new Model(); } |
| | 26 | |
|
| 0 | 27 | | public override int GetClassId() { return (int) CLASS_ID.CYLINDER_SHAPE; } |
| | 28 | |
|
| | 29 | | public override Mesh GenerateGeometry() |
| | 30 | | { |
| 6 | 31 | | var model = (Model) this.model; |
| 6 | 32 | | return PrimitiveMeshBuilder.BuildCylinder(50, model.radiusTop, model.radiusBottom, 2f, 0f, true, false); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | protected override bool ShouldGenerateNewMesh(BaseShape.Model newModel) |
| | 36 | | { |
| 16 | 37 | | if (currentMesh == null) |
| 10 | 38 | | return true; |
| | 39 | |
|
| 6 | 40 | | Model newCylinderModel = newModel as Model; |
| 6 | 41 | | var model = (Model) this.model; |
| 6 | 42 | | return newCylinderModel.radius != model.radius |
| | 43 | | || newCylinderModel.radiusTop != model.radiusTop |
| | 44 | | || newCylinderModel.radiusBottom != model.radiusBottom |
| | 45 | | || newCylinderModel.segmentsHeight != model.segmentsHeight |
| | 46 | | || newCylinderModel.segmentsRadial != model.segmentsRadial |
| | 47 | | || newCylinderModel.openEnded != model.openEnded |
| | 48 | | || newCylinderModel.arc != model.arc; |
| | 49 | | } |
| | 50 | | } |
| | 51 | | } |