| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public class PlaneShape : ParametrizedShape<PlaneShape.Model> |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | new public class Model : BaseShape.Model |
| | 12 | | { |
| | 13 | | public float[] uvs; |
| 117 | 14 | | public float width = 1f; // Plane |
| 117 | 15 | | public float height = 1f; // Plane |
| | 16 | |
|
| 45 | 17 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 18 | | } |
| | 19 | |
|
| 105 | 20 | | public PlaneShape() { model = new Model(); } |
| | 21 | |
|
| 0 | 22 | | public override int GetClassId() { return (int) CLASS_ID.PLANE_SHAPE; } |
| | 23 | |
|
| | 24 | | public override Mesh GenerateGeometry() |
| | 25 | | { |
| 35 | 26 | | var model = (Model) this.model; |
| | 27 | |
|
| 35 | 28 | | Mesh mesh = PrimitiveMeshBuilder.BuildPlane(1f); |
| 35 | 29 | | if (model.uvs != null && model.uvs.Length > 0) |
| | 30 | | { |
| 3 | 31 | | mesh.uv = Utils.FloatArrayToV2List(model.uvs); |
| | 32 | | } |
| | 33 | |
|
| 35 | 34 | | return mesh; |
| | 35 | | } |
| | 36 | |
|
| | 37 | | protected override bool ShouldGenerateNewMesh(BaseShape.Model previousModel) |
| | 38 | | { |
| 45 | 39 | | if (currentMesh == null) |
| 37 | 40 | | return true; |
| | 41 | |
|
| 8 | 42 | | PlaneShape.Model newPlaneModel = (PlaneShape.Model) this.model; |
| 8 | 43 | | PlaneShape.Model oldPlaneModel = (PlaneShape.Model) previousModel; |
| | 44 | |
|
| 8 | 45 | | if (newPlaneModel.uvs != null && oldPlaneModel.uvs != null) |
| | 46 | | { |
| 8 | 47 | | if (newPlaneModel.uvs.Length != oldPlaneModel.uvs.Length) |
| 2 | 48 | | return true; |
| | 49 | |
|
| 12 | 50 | | for (int i = 0; i < newPlaneModel.uvs.Length; i++) |
| | 51 | | { |
| 0 | 52 | | if (newPlaneModel.uvs[i] != oldPlaneModel.uvs[i]) |
| 0 | 53 | | return true; |
| | 54 | | } |
| 6 | 55 | | } |
| | 56 | | else |
| | 57 | | { |
| 0 | 58 | | if (newPlaneModel.uvs != oldPlaneModel.uvs) |
| 0 | 59 | | return true; |
| | 60 | | } |
| | 61 | |
|
| 6 | 62 | | return newPlaneModel.width != oldPlaneModel.width || newPlaneModel.height != oldPlaneModel.height; |
| | 63 | | } |
| | 64 | | } |
| | 65 | | } |