| | 1 | | using DCL.Helpers; |
| | 2 | | using DCL.Models; |
| | 3 | | using UnityEngine; |
| | 4 | | using Decentraland.Sdk.Ecs6; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public class CylinderShape : ParametrizedShape<CylinderShape.Model> |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | public new class Model : BaseShape.Model |
| | 12 | | { |
| 39 | 13 | | public float radiusTop = 1f; |
| 39 | 14 | | public float radiusBottom = 1f; |
| 39 | 15 | | public float segmentsHeight = 1f; |
| 39 | 16 | | public float segmentsRadial = 36f; |
| | 17 | | public bool openEnded; |
| | 18 | | public float? radius; |
| 39 | 19 | | public float arc = 360f; |
| | 20 | |
|
| | 21 | | public override BaseModel GetDataFromJSON(string json) => |
| 20 | 22 | | Utils.SafeFromJson<Model>(json); |
| | 23 | |
|
| | 24 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) |
| | 25 | | { |
| 0 | 26 | | if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.CylinderShape) |
| 0 | 27 | | return Utils.SafeUnimplemented<CylinderShape, Model>(expected: ComponentBodyPayload.PayloadOneofCase |
| | 28 | |
|
| 0 | 29 | | var pb = new Model(); |
| 0 | 30 | | if (pbModel.CylinderShape.HasArc) pb.arc = pbModel.CylinderShape.Arc; |
| 0 | 31 | | if (pbModel.CylinderShape.HasRadius) pb.radius = pbModel.CylinderShape.Radius; |
| 0 | 32 | | if (pbModel.CylinderShape.HasOpenEnded) pb.openEnded = pbModel.CylinderShape.OpenEnded; |
| 0 | 33 | | if (pbModel.CylinderShape.HasRadiusBottom) pb.radiusBottom = pbModel.CylinderShape.RadiusBottom; |
| 0 | 34 | | if (pbModel.CylinderShape.HasRadiusTop) pb.radiusTop = pbModel.CylinderShape.RadiusTop; |
| 0 | 35 | | if (pbModel.CylinderShape.HasSegmentsHeight) pb.segmentsHeight = pbModel.CylinderShape.SegmentsHeight; |
| 0 | 36 | | if (pbModel.CylinderShape.HasSegmentsRadial) pb.segmentsRadial = pbModel.CylinderShape.SegmentsRadial; |
| 0 | 37 | | if (pbModel.CylinderShape.HasVisible) pb.visible = pbModel.CylinderShape.Visible; |
| 0 | 38 | | if (pbModel.CylinderShape.HasWithCollisions) pb.withCollisions = pbModel.CylinderShape.WithCollisions; |
| 0 | 39 | | if (pbModel.CylinderShape.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.CylinderShape.IsPointerBloc |
| | 40 | |
|
| 0 | 41 | | return pb; |
| | 42 | | } |
| | 43 | | } |
| | 44 | |
|
| 9 | 45 | | public CylinderShape() |
| | 46 | | { |
| 9 | 47 | | model = new Model(); |
| 9 | 48 | | } |
| | 49 | |
|
| | 50 | | public override int GetClassId() => |
| 0 | 51 | | (int) CLASS_ID.CYLINDER_SHAPE; |
| | 52 | |
|
| | 53 | | public override Mesh GenerateGeometry() |
| | 54 | | { |
| 7 | 55 | | var model = (Model) this.model; |
| 7 | 56 | | return PrimitiveMeshBuilder.BuildCylinder(50, model.radiusTop, model.radiusBottom, 2f, 0f, true, false); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | protected override bool ShouldGenerateNewMesh(BaseShape.Model newModel) |
| | 60 | | { |
| 20 | 61 | | if (currentMesh == null) |
| 11 | 62 | | return true; |
| | 63 | |
|
| 9 | 64 | | Model newCylinderModel = newModel as Model; |
| 9 | 65 | | var model = (Model) this.model; |
| 9 | 66 | | return newCylinderModel.radius != model.radius |
| | 67 | | || newCylinderModel.radiusTop != model.radiusTop |
| | 68 | | || newCylinderModel.radiusBottom != model.radiusBottom |
| | 69 | | || newCylinderModel.segmentsHeight != model.segmentsHeight |
| | 70 | | || newCylinderModel.segmentsRadial != model.segmentsRadial |
| | 71 | | || newCylinderModel.openEnded != model.openEnded |
| | 72 | | || newCylinderModel.arc != model.arc; |
| | 73 | | } |
| | 74 | | } |
| | 75 | | } |