| | 1 | | using DCL.Helpers; |
| | 2 | | using DCL.Models; |
| | 3 | | using UnityEngine; |
| | 4 | | using Decentraland.Sdk.Ecs6; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | namespace DCL.Components |
| | 8 | | { |
| | 9 | | public class PlaneShape : ParametrizedShape<PlaneShape.Model> |
| | 10 | | { |
| | 11 | | [System.Serializable] |
| | 12 | | public new class Model : BaseShape.Model |
| | 13 | | { |
| | 14 | | public float[] uvs; |
| 123 | 15 | | public float width = 1f; // Plane |
| 123 | 16 | | public float height = 1f; // Plane |
| | 17 | |
|
| | 18 | | public override BaseModel GetDataFromJSON(string json) => |
| 49 | 19 | | Utils.SafeFromJson<Model>(json); |
| | 20 | |
|
| | 21 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) |
| | 22 | | { |
| 0 | 23 | | if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.PlaneShape) |
| 0 | 24 | | return Utils.SafeUnimplemented<PlaneShape, Model>(expected: ComponentBodyPayload.PayloadOneofCase.Pl |
| | 25 | |
|
| 0 | 26 | | var pb = new Model(); |
| 0 | 27 | | if (pbModel.PlaneShape.Uvs is { Count: > 0 }) pb.uvs = pbModel.PlaneShape.Uvs.ToArray(); |
| 0 | 28 | | if (pbModel.PlaneShape.HasHeight) pb.height = pbModel.PlaneShape.Height; |
| 0 | 29 | | if (pbModel.PlaneShape.HasWidth) pb.width = pbModel.PlaneShape.Width; |
| 0 | 30 | | if (pbModel.PlaneShape.HasVisible) pb.visible = pbModel.PlaneShape.Visible; |
| 0 | 31 | | if (pbModel.PlaneShape.HasWithCollisions) pb.withCollisions = pbModel.PlaneShape.WithCollisions; |
| 0 | 32 | | if (pbModel.PlaneShape.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.PlaneShape.IsPointerBlocker; |
| | 33 | |
|
| 0 | 34 | | return pb; |
| | 35 | | } |
| | 36 | | } |
| | 37 | |
|
| 108 | 38 | | public PlaneShape() { model = new Model(); } |
| | 39 | |
|
| 0 | 40 | | public override int GetClassId() { return (int) CLASS_ID.PLANE_SHAPE; } |
| | 41 | |
|
| | 42 | | public override Mesh GenerateGeometry() |
| | 43 | | { |
| 36 | 44 | | var model = (Model) this.model; |
| | 45 | |
|
| 36 | 46 | | Mesh mesh = PrimitiveMeshBuilder.BuildPlane(1f); |
| 36 | 47 | | if (model.uvs != null && model.uvs.Length > 0) |
| | 48 | | { |
| 3 | 49 | | mesh.uv = Utils.FloatArrayToV2List(model.uvs); |
| | 50 | | } |
| | 51 | |
|
| 36 | 52 | | return mesh; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | protected override bool ShouldGenerateNewMesh(BaseShape.Model previousModel) |
| | 56 | | { |
| 49 | 57 | | if (currentMesh == null) |
| 38 | 58 | | return true; |
| | 59 | |
|
| 11 | 60 | | PlaneShape.Model newPlaneModel = (PlaneShape.Model) this.model; |
| 11 | 61 | | PlaneShape.Model oldPlaneModel = (PlaneShape.Model) previousModel; |
| | 62 | |
|
| 11 | 63 | | if (newPlaneModel.uvs != null && oldPlaneModel.uvs != null) |
| | 64 | | { |
| 11 | 65 | | if (newPlaneModel.uvs.Length != oldPlaneModel.uvs.Length) |
| 2 | 66 | | return true; |
| | 67 | |
|
| 18 | 68 | | for (int i = 0; i < newPlaneModel.uvs.Length; i++) |
| | 69 | | { |
| 0 | 70 | | if (newPlaneModel.uvs[i] != oldPlaneModel.uvs[i]) |
| 0 | 71 | | return true; |
| | 72 | | } |
| | 73 | | } |
| | 74 | | else |
| | 75 | | { |
| 0 | 76 | | if (newPlaneModel.uvs != oldPlaneModel.uvs) |
| 0 | 77 | | return true; |
| | 78 | | } |
| | 79 | |
|
| 9 | 80 | | return newPlaneModel.width != oldPlaneModel.width || newPlaneModel.height != oldPlaneModel.height; |
| | 81 | | } |
| | 82 | | } |
| | 83 | | } |