Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/cs/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter

# Code-block preferences
csharp_prefer_braces = when_multiline:error
resharper_remove_redundant_braces_highlighting=none
csharp_prefer_simple_using_statement = true

# Expression-level preferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using System.Text;

namespace Vim.Format.CodeGen
namespace Vim.Util
{
public class CodeBuilder
{
Expand Down
1 change: 1 addition & 0 deletions src/cs/vim/Vim.Format.CodeGen/ObjectModelCppGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using Vim.Format.ObjectModel;
using Vim.Util;

namespace Vim.Format.CodeGen;

Expand Down
1 change: 1 addition & 0 deletions src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using Vim.Format.ObjectModel;
using Vim.Util;

namespace Vim.Format.CodeGen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using Vim.Format.ObjectModel;
using Vim.Util;

namespace Vim.Format.CodeGen;

Expand Down
2 changes: 1 addition & 1 deletion src/cs/vim/Vim.Format.Core/AssetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static IEnumerable<INamedBuffer> GetTextures(this Document d)
/// </summary>
public static FileInfo ExtractAsset(this INamedBuffer assetBuffer, FileInfo fileInfo)
{
Util.IO.CreateFileDirectory(fileInfo.FullName);
IO.CreateFileDirectory(fileInfo.FullName);
using (var stream = fileInfo.Create())
assetBuffer.Write(stream);
return fileInfo;
Expand Down
66 changes: 31 additions & 35 deletions src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,39 @@ public class Material
/// </summary>
public class Mesh
{
protected List<Vector3> _vertices = new List<Vector3>();
public IReadOnlyList<Vector3> Vertices => _vertices;

protected List<int> _indices = new List<int>();
public IReadOnlyList<int> Indices => _indices;

protected List<int> _faceMaterials = new List<int>();
public IReadOnlyList<int> FaceMaterials => _faceMaterials;

protected List<Vector4> _colors = new List<Vector4>();
public IReadOnlyList<Vector4> Colors => _colors;

protected List<Vector2> _uvs = new List<Vector2>();
public IReadOnlyList<Vector2> UVs => _uvs;

public Mesh(List<Vector3> vertices = null, List<int> indices = null, List<int> faceMaterials = null, List<Vector4> colors = null, List<Vector2> uvs = null)
public List<Vector3> Vertices { get; set; }
public List<int> Indices { get; set; }
public List<int> FaceMaterials { get; set; }
public List<Vector4> Colors { get; set; }
public List<Vector2> UVs { get; set; }

public Mesh(
List<Vector3> vertices = null,
List<int> indices = null,
List<int> faceMaterials = null,
List<Vector4> colors = null,
List<Vector2> uvs = null)
{
_vertices = vertices ?? new List<Vector3>();
_indices = indices ?? new List<int>();
Vertices = vertices ?? new List<Vector3>();
Indices = indices ?? new List<int>();

if (_indices.Any(i => i < 0 && i >= _vertices.Count))
if (Indices.Any(i => i < 0 && i >= Vertices.Count))
throw new Exception($"Invalid mesh. Indices out of vertex range.");

if (_indices.Count % 3 != 0)
if (Indices.Count % 3 != 0)
throw new Exception("indices.Count must be a multiple of 3.");

_faceMaterials = faceMaterials ?? new List<int>(Enumerable.Repeat(-1, _indices.Count / 3));
FaceMaterials = faceMaterials ?? new List<int>(Enumerable.Repeat(-1, Indices.Count / 3));

if (_faceMaterials.Count * 3 != _indices.Count)
if (FaceMaterials.Count * 3 != Indices.Count)
throw new Exception("faceMaterials.Count must be indices.Count * 3");

_colors = colors ?? new List<Vector4>();
_uvs = uvs ?? new List<Vector2>();
Colors = colors ?? new List<Vector4>();
UVs = uvs ?? new List<Vector2>();
}

public void SetMeshMaterial(int material)
=> _faceMaterials = Enumerable.Repeat(material, _indices.Count / 3).ToList();
=> FaceMaterials = Enumerable.Repeat(material, Indices.Count / 3).ToList();

public void AppendFaces(IList<int> indices, IList<int> materials)
{
Expand All @@ -88,17 +84,17 @@ public void AppendFaces(IList<int> indices, IList<int> materials)

public void AppendFace(int v0, int v1, int v2, int material)
{
_indices.Add(v0);
_indices.Add(v1);
_indices.Add(v2);
_faceMaterials.Add(material);
Indices.Add(v0);
Indices.Add(v1);
Indices.Add(v2);
FaceMaterials.Add(material);
}

public void AppendVertices(IEnumerable<Vector3> vertices)
=> _vertices.AddRange(vertices);
=> Vertices.AddRange(vertices);

public void AppendUVs(IEnumerable<Vector2> uvs)
=> _uvs.AddRange(uvs);
=> UVs.AddRange(uvs);

public SubdividedMesh Subdivide()
=> new SubdividedMesh(this);
Expand All @@ -109,10 +105,10 @@ public SubdividedMesh Subdivide()
/// </summary>
public class SubdividedMesh
{
public IReadOnlyList<int> Indices { get; private set; }
public IReadOnlyList<Vector3> Vertices { get; private set; }
public IReadOnlyList<int> SubmeshesIndexOffset { get; private set; }
public IReadOnlyList<int> SubmeshMaterials { get; private set; }
public IReadOnlyList<int> Indices { get; }
public IReadOnlyList<Vector3> Vertices { get; }
public IReadOnlyList<int> SubmeshesIndexOffset { get; }
public IReadOnlyList<int> SubmeshMaterials { get; }

public SubdividedMesh(Mesh mesh)
{
Expand Down
Loading
Loading