Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CSUtilities
Submodule CSUtilities updated 40 files
+20 −21 CSMath.Tests/AssertUtils.cs
+25 −26 CSMath.Tests/BoundingBoxTests.cs
+63 −64 CSMath.Tests/CSMathRandom.cs
+20 −21 CSMath.Tests/Geometry/Line2DTests.cs
+20 −21 CSMath.Tests/Geometry/Line3DTests.cs
+7 −8 CSMath.Tests/QuaternionTests.cs
+5 −6 CSMath.Tests/TestVariables.cs
+78 −79 CSMath.Tests/TransformTests.cs
+14 −15 CSMath.Tests/VectorExtensionsTests.cs
+40 −41 CSMath.Tests/VectorTestCaseFactory.cs
+120 −121 CSMath.Tests/VectorTests.cs
+10 −11 CSMath.Tests/XYTest.cs
+4 −5 CSMath.Tests/XYZMTest.cs
+14 −15 CSMath.Tests/XYZTest.cs
+229 −230 CSMath/BoundingBox.cs
+7 −8 CSMath/BoundingBoxExtent.cs
+1 −0 CSMath/CSMath.projitems
+110 −111 CSMath/Geometry/CurveExtensions.cs
+26 −27 CSMath/Geometry/ICurve.cs
+18 −19 CSMath/Geometry/ILine.cs
+29 −30 CSMath/Geometry/Line2D.cs
+51 −52 CSMath/Geometry/Line3D.cs
+41 −42 CSMath/Geometry/LineExtensions.cs
+13 −14 CSMath/IVector.cs
+218 −219 CSMath/Matrix3.cs
+13 −14 CSMath/Matrix3.operators.cs
+64 −65 CSMath/Matrix4.Operators.cs
+828 −829 CSMath/Matrix4.cs
+287 −237 CSMath/Quaternion.cs
+12 −0 CSMath/Quaternion.operators.cs
+252 −253 CSMath/Transform.cs
+373 −374 CSMath/VectorExtensions.cs
+171 −172 CSMath/XY.cs
+120 −121 CSMath/XY.operators.cs
+185 −186 CSMath/XYZ.cs
+124 −125 CSMath/XYZ.operators.cs
+126 −127 CSMath/XYZM.cs
+100 −101 CSMath/XYZM.operators.cs
+2 −4 CSUtilities/Extensions/StreamExtensions.cs
+2 −4 CSUtilities/Extensions/StringBuilderExtensions.cs
6 changes: 6 additions & 0 deletions src/MeshIO/Entities/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Camera : Entity
/// </summary>
public double AspectRatio { get; set; }

/// <summary>
/// Gets or sets the distance to the far clipping plane for the camera or view frustum.
/// </summary>
public double FarPlane { get; set; } = 1;

/// <summary>
Expand All @@ -37,6 +40,9 @@ public class Camera : Entity
/// too low may result in rendering artifacts due to depth buffer precision limitations.</remarks>
public double NearPlane { get; set; } = 0;

/// <summary>
/// Gets or sets the orthographic zoom level for the view.
/// </summary>
public XY OrthographicZoom { get; set; }

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/MeshIO/Entities/Light.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace MeshIO.Entities;

public class Light : Entity
{
}
public class Light : Entity
{
}
17 changes: 7 additions & 10 deletions src/MeshIO/Entities/Primitives/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace MeshIO.Entities.Primitives;

/// <summary>
/// Represents a three-dimensional box defined by its center point and dimensions along the X, Y, and Z axes.
/// </summary>
public class Box : Primitive
{
/// <summary>
Expand Down Expand Up @@ -64,12 +67,6 @@ public Box(BoundingBox boundingBox)
}

/// <inheritdoc/>
/// <remarks>
/// The current implementation returns a mesh with no shared vertices and the following layers:<br/>
/// <see cref="LayerElementNormal"/><br/>
/// <see cref="LayerElementUV"/><br/>
/// configured with <see cref="MappingMode.ByVertex"/> and <see cref=" ReferenceMode.Direct"/>
/// </remarks>
public override Mesh ToMesh()
{
List<XYZ> vertices = new List<XYZ>();
Expand All @@ -86,16 +83,16 @@ public override Mesh ToMesh()
this.createFace(0, 1, 2, 1, -1, this.LengthX, this.LengthY, this.LengthZ, vertices, normals, uvs, polygons, ref currQuad);
this.createFace(0, 1, 2, -1, -1, this.LengthX, this.LengthY, 0.0 - this.LengthZ, vertices, normals, uvs, polygons, ref currQuad);

return this.createMesh(vertices, normals, uvs, polygons.Cast<Polygon>().ToList());
return this.createMesh(vertices, normals, uvs, polygons);
}

private void createFace(
int index0, int index1, int index2,
int dir1, int dir2,
double length, double height, double width,
List<XYZ> vertices,
List<XYZ> normals,
List<XY> uvs,
List<XYZ> vertices,
List<XYZ> normals,
List<XY> uvs,
List<Quad> polygons,
ref int currQuad)
{
Expand Down
126 changes: 126 additions & 0 deletions src/MeshIO/Entities/Primitives/Plane.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using CSMath;
using MeshIO.Entities.Geometries;
using System.Collections.Generic;

namespace MeshIO.Entities.Primitives;

/// <summary>
/// Represents a planar primitive defined by a center point, normal vector, length, and width.
/// </summary>
public class Plane : Primitive
{
/// <summary>
/// Gets or sets the center point of the plane.
/// </summary>
public XYZ Center { get; set; } = XYZ.Zero;

/// <summary>
/// Gets or sets the length of the plane along the local Z axis.
/// </summary>
public double Length { get; set; } = 1.0;

/// <summary>
/// Gets or sets the number of segments along the length of the plane.
/// </summary>
public int LengthSegments { get; set; } = 1;

/// <summary>
/// Gets or sets the normal vector of the plane.
/// </summary>
public XYZ Normal { get; set; } = XYZ.AxisY;

/// <summary>
/// Gets or sets the width of the plane along the local X axis.
/// </summary>
public double Width { get; set; } = 1.0;

/// <summary>
/// Gets or sets the number of segments along the width of the plane.
/// </summary>
public int WidthSegments { get; set; } = 1;

/// <summary>
/// Initializes a new instance of the <see cref="Plane"/> class with an empty name.
/// </summary>
public Plane() : this(string.Empty)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Plane"/> class with the specified name.
/// </summary>
/// <param name="name">The name of the plane.</param>
public Plane(string name) : base(name)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Plane"/> class with the specified name, center, normal, length, and width.
/// </summary>
/// <param name="name">The name of the plane.</param>
/// <param name="center">The center point of the plane.</param>
/// <param name="normal">The normal vector of the plane.</param>
/// <param name="length">The length of the plane.</param>
/// <param name="width">The width of the plane.</param>
public Plane(string name, XYZ center, XYZ normal, double length, double width) : base(name)
{
Center = center;
Normal = normal;
Length = length;
Width = width;
}

/// <inheritdoc/>
public override Mesh ToMesh()
{
List<XYZ> vertices = new List<XYZ>();
List<XYZ> normals = new List<XYZ>();
List<XY> uvs = new List<XY>();
List<Quad> polygons = new List<Quad>();

double lengthStep = Length / (double)LengthSegments;
double widthStep = Width / (double)WidthSegments;
double halfLength = Length * 0.5;
double halfWidth = Width * 0.5;

for (int i = 0; i <= LengthSegments; i++)
{
double z = i * lengthStep - halfLength;
for (int j = 0; j <= WidthSegments; j++)
{
double x = j * widthStep - halfWidth;
vertices.Add(new XYZ(x, 0.0, z));
uvs.Add(new XY(
(double)i / (double)LengthSegments,
(double)j / (double)WidthSegments));

if (i > 0 && j > 0)
{
int stride = LengthSegments + 1;
polygons.Add(new Quad(
i * stride + j - 1,
i * stride + j,
(i - 1) * stride + j,
(i - 1) * stride + j - 1));
}
}
}

if (!Normal.Normalize().IsEqual(XYZ.AxisY))
{
Quaternion rotation = Quaternion.FromRotation(XYZ.AxisY, Normal.Normalize());
for (int k = 0; k < vertices.Count; k++)
{
vertices[k] = rotation * vertices[k];
}

normals.Add(rotation * XYZ.AxisY);
}
else
{
normals.Add(XYZ.AxisY);
}

return this.createMesh(vertices, normals, uvs, polygons);
}
}
31 changes: 20 additions & 11 deletions src/MeshIO/Entities/Primitives/Primitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,43 @@

namespace MeshIO.Entities.Primitives;

/// <summary>
/// The base class of all primitives, which can be converted to mesh. It is also an entity, so it has a name and can be added to a scene.
/// </summary>
public abstract class Primitive : Entity
{
/// <summary>
/// The geometry is visible or not
/// This geometry can cast shadow or not
/// </summary>
public bool IsVisible { get; set; } = true;
public bool CastShadows { get; set; } = true;

/// <summary>
/// This geometry can cast shadow or not
/// The geometry is visible or not
/// </summary>
public bool CastShadows { get; set; } = true;
public bool IsVisible { get; set; } = true;

/// <summary>
/// This geometry can receive shadow or not
/// </summary>
public bool ReceiveShadows { get; set; } = true;

protected Primitive(string name) : base(name)
{
}

/// <summary>
/// Process this primitive into a mesh
/// Convert this primitive to mesh. The mesh will be added to the scene, and the primitive will be removed from the scene. So after calling this method, the primitive will not exist in the scene, but the mesh will exist in the scene. If you want to keep the primitive in the scene, you can call this method and then add the primitive back to the scene.
/// </summary>
/// <remarks>
/// The current implementation returns a mesh with no shared vertices and the following layers:<br/>
/// <see cref="LayerElementNormal"/><br/>
/// <see cref="LayerElementUV"/><br/>
/// configured with <see cref="MappingMode.ByVertex"/> and <see cref=" ReferenceMode.Direct"/>
/// </remarks>
/// <returns></returns>
public abstract Mesh ToMesh();

public Primitive() : this(string.Empty) { }

public Primitive(string name) : base(name) { }

protected Mesh createMesh(List<XYZ> vertices, List<XYZ> normals, List<XY> uvs, List<Polygon> polygons)
protected Mesh createMesh(IEnumerable<XYZ> vertices, IEnumerable<XYZ> normals, IEnumerable<XY> uvs, IEnumerable<Polygon> polygons)
{
Mesh mesh = new Mesh(this.Name);

Expand All @@ -53,4 +62,4 @@ protected Mesh createMesh(List<XYZ> vertices, List<XYZ> normals, List<XY> uvs, L

return mesh;
}
}
}
Loading
Loading