|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Diagnostics.CodeAnalysis; |
4 |
| -using System.Runtime.Serialization; |
5 |
| -using System.Text.Json.Serialization; |
6 |
| -using JsonSubTypes; |
7 |
| -using Newtonsoft.Json; |
8 |
| - |
9 |
| -namespace CodeCave.Threejs.Entities |
10 |
| -{ |
11 |
| - /// <summary> |
12 |
| - /// Geometry is a user-friendly alternative to BufferGeometry. |
13 |
| - /// Geometries store attributes (vertex positions, faces, colors, etc.) |
14 |
| - /// using objects like Vector3 or Color that are easier to read and edit, |
15 |
| - /// but less efficient than typed arrays. |
16 |
| - /// |
17 |
| - /// Prefer <see cref="BufferGeometry"/> for large or serious projects. |
18 |
| - /// </summary> |
19 |
| - [Serializable] |
20 |
| - [DataContract] |
21 |
| - [Newtonsoft.Json.JsonConverter(typeof(JsonSubtypes), nameof(Type))] |
22 |
| - [JsonSubtypes.KnownSubType(typeof(BoxGeometry), nameof(BoxGeometry))] |
23 |
| - [System.Text.Json.Serialization.JsonConverter(typeof(Utf8Json.PolymorphicJsonConverter<Geometry>))] |
24 |
| - public partial class Geometry : IEquatable<Geometry> |
25 |
| - { |
26 |
| - /// <summary>Initializes a new instance of the <see cref="Geometry"/> class.</summary> |
27 |
| - /// <param name="uuid">The UUID of this object instance.</param> |
28 |
| - [JsonConstructor] |
29 |
| - public Geometry(string uuid) |
30 |
| - { |
31 |
| - Uuid = uuid ?? Guid.NewGuid().ToString(); |
32 |
| - Data = new GeometryData(); |
33 |
| - } |
34 |
| - |
35 |
| - /// <summary>Gets the type of this object, it always equals 'Geometry'.</summary> |
36 |
| - /// <value>The 'Geometry' type.</value> |
37 |
| - [DataMember(Name = "type")] |
38 |
| - [JsonProperty("type")] |
39 |
| - [JsonPropertyName("type")] |
40 |
| - public virtual string Type => nameof(Geometry); |
41 |
| - |
42 |
| - /// <summary> |
43 |
| - /// Gets the UUID of this object instance. |
44 |
| - /// </summary> |
45 |
| - /// <value> |
46 |
| - /// The UUID. This gets automatically assigned and shouldn't be edited. |
47 |
| - /// </value> |
48 |
| - [DataMember(Name = "uuid")] |
49 |
| - [JsonProperty("uuid")] |
50 |
| - [JsonPropertyName("uuid")] |
51 |
| - public string Uuid { get; internal set; } |
52 |
| - |
53 |
| - [DataMember(Name = "data")] |
54 |
| - [JsonProperty("data")] |
55 |
| - [JsonPropertyName("data")] |
56 |
| - public virtual GeometryData Data { get; internal set; } |
57 |
| - |
58 |
| - /// <summary>Adds the point to the vertices.</summary> |
59 |
| - /// <param name="vertex">The vertex.</param> |
60 |
| - [SuppressMessage( |
61 |
| - "StyleCop.CSharp.OrderingRules", |
62 |
| - "SA1201:Elements should appear in the correct order", |
63 |
| - Justification = "The class below is private, so it will never be OK.")] |
64 |
| - public void AddPoint(Vector3 vertex) |
65 |
| - { |
66 |
| - if (vertex is null) |
67 |
| - throw new ArgumentNullException(nameof(vertex)); |
68 |
| - |
69 |
| - Data.Vertices.Add(vertex.X); |
70 |
| - Data.Vertices.Add(vertex.Y); |
71 |
| - Data.Vertices.Add(vertex.Z); |
72 |
| - } |
73 |
| - |
74 |
| - /// <summary>Adds the point to the vertices.</summary> |
75 |
| - /// <param name="x">The x coordinate.</param> |
76 |
| - /// <param name="y">The y coordinate.</param> |
77 |
| - /// <param name="z">The z coordinate.</param> |
78 |
| - public void AddPoint(double x, double y, double z) |
79 |
| - { |
80 |
| - Data.Vertices.Add(x); |
81 |
| - Data.Vertices.Add(y); |
82 |
| - Data.Vertices.Add(z); |
83 |
| - } |
84 |
| - |
85 |
| - /// <summary>Adds a faces from its vertices.</summary> |
86 |
| - /// <param name="vertices">The vertices of a face.</param> |
87 |
| - public void AddFace(params int[] vertices) |
88 |
| - { |
89 |
| - Data.Faces.AddRange(vertices); |
90 |
| - } |
91 |
| - |
92 |
| - public override bool Equals(object obj) => obj is Geometry geometry && Equals(geometry); |
93 |
| - |
94 |
| - public bool Equals(Geometry other) => Uuid.Equals(other?.Uuid, StringComparison.OrdinalIgnoreCase); |
95 |
| - |
96 |
| - public override int GetHashCode() |
97 |
| - { |
98 |
| - return 2083305506 + EqualityComparer<string>.Default.GetHashCode(Uuid); |
99 |
| - } |
100 |
| - } |
101 |
| -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics.CodeAnalysis; |
| 4 | +using System.Runtime.Serialization; |
| 5 | +using System.Text.Json.Serialization; |
| 6 | +using JsonSubTypes; |
| 7 | +using Newtonsoft.Json; |
| 8 | + |
| 9 | +namespace CodeCave.Threejs.Entities |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Geometry is a user-friendly alternative to BufferGeometry. |
| 13 | + /// Geometries store attributes (vertex positions, faces, colors, etc.) |
| 14 | + /// using objects like Vector3 or Color that are easier to read and edit, |
| 15 | + /// but less efficient than typed arrays. |
| 16 | + /// |
| 17 | + /// Prefer <see cref="BufferGeometry"/> for large or serious projects. |
| 18 | + /// </summary> |
| 19 | + [Serializable] |
| 20 | + [DataContract] |
| 21 | + [Newtonsoft.Json.JsonConverter(typeof(JsonSubtypes), nameof(Type))] |
| 22 | + [JsonSubtypes.KnownSubType(typeof(BoxGeometry), nameof(BoxGeometry))] |
| 23 | + [System.Text.Json.Serialization.JsonConverter(typeof(Utf8Json.PolymorphicJsonConverter<Geometry>))] |
| 24 | + public partial class Geometry : IEquatable<Geometry> |
| 25 | + { |
| 26 | + /// <summary>Initializes a new instance of the <see cref="Geometry"/> class.</summary> |
| 27 | + /// <param name="uuid">The UUID of this object instance.</param> |
| 28 | + [Newtonsoft.Json.JsonConstructor] |
| 29 | + [System.Text.Json.Serialization.JsonConstructor] |
| 30 | + public Geometry(string uuid) |
| 31 | + { |
| 32 | + Uuid = uuid ?? Guid.NewGuid().ToString(); |
| 33 | + Data = new GeometryData(); |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary>Gets the type of this object, it always equals 'Geometry'.</summary> |
| 37 | + /// <value>The 'Geometry' type.</value> |
| 38 | + [DataMember(Name = "type")] |
| 39 | + [JsonProperty("type")] |
| 40 | + [JsonPropertyName("type")] |
| 41 | + public virtual string Type => nameof(Geometry); |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Gets the UUID of this object instance. |
| 45 | + /// </summary> |
| 46 | + /// <value> |
| 47 | + /// The UUID. This gets automatically assigned and shouldn't be edited. |
| 48 | + /// </value> |
| 49 | + [DataMember(Name = "uuid")] |
| 50 | + [JsonProperty("uuid")] |
| 51 | + [JsonPropertyName("uuid")] |
| 52 | + public string Uuid { get; internal set; } |
| 53 | + |
| 54 | + [DataMember(Name = "data")] |
| 55 | + [JsonProperty("data")] |
| 56 | + [JsonPropertyName("data")] |
| 57 | + public virtual GeometryData Data { get; internal set; } |
| 58 | + |
| 59 | + /// <summary>Adds the point to the vertices.</summary> |
| 60 | + /// <param name="vertex">The vertex.</param> |
| 61 | + [SuppressMessage( |
| 62 | + "StyleCop.CSharp.OrderingRules", |
| 63 | + "SA1201:Elements should appear in the correct order", |
| 64 | + Justification = "The class below is private, so it will never be OK.")] |
| 65 | + public void AddPoint(Vector3 vertex) |
| 66 | + { |
| 67 | + if (vertex is null) |
| 68 | + throw new ArgumentNullException(nameof(vertex)); |
| 69 | + |
| 70 | + Data.Vertices.Add(vertex.X); |
| 71 | + Data.Vertices.Add(vertex.Y); |
| 72 | + Data.Vertices.Add(vertex.Z); |
| 73 | + } |
| 74 | + |
| 75 | + /// <summary>Adds the point to the vertices.</summary> |
| 76 | + /// <param name="x">The x coordinate.</param> |
| 77 | + /// <param name="y">The y coordinate.</param> |
| 78 | + /// <param name="z">The z coordinate.</param> |
| 79 | + public void AddPoint(double x, double y, double z) |
| 80 | + { |
| 81 | + Data.Vertices.Add(x); |
| 82 | + Data.Vertices.Add(y); |
| 83 | + Data.Vertices.Add(z); |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary>Adds a faces from its vertices.</summary> |
| 87 | + /// <param name="vertices">The vertices of a face.</param> |
| 88 | + public void AddFace(params int[] vertices) |
| 89 | + { |
| 90 | + Data.Faces.AddRange(vertices); |
| 91 | + } |
| 92 | + |
| 93 | + public void AddUVs(params double[] uvs) |
| 94 | + { |
| 95 | + Data.UVs.AddRange(uvs); |
| 96 | + } |
| 97 | + |
| 98 | + public override bool Equals(object obj) => obj is Geometry geometry && Equals(geometry); |
| 99 | + |
| 100 | + public bool Equals(Geometry other) => Uuid.Equals(other?.Uuid, StringComparison.OrdinalIgnoreCase); |
| 101 | + |
| 102 | + public override int GetHashCode() |
| 103 | + { |
| 104 | + return 2083305506 + EqualityComparer<string>.Default.GetHashCode(Uuid); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments