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
3 changes: 3 additions & 0 deletions data/Dwelling.r2019.om_v5.5.0.vim
Git LFS file not shown
11 changes: 11 additions & 0 deletions src/cs/vim/Vim.Format.Core/CascadeElementRemapAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Vim.Format
{
[AttributeUsage(AttributeTargets.Class)]
public class CascadeElementRemapAttribute : Attribute
{
public CascadeElementRemapAttribute()
{ }
}
}
64 changes: 52 additions & 12 deletions src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public static string ValidateCanConcatBuffers(this INamedBuffer thisBuffer, INam
return thisPrefix;
}

public static T[] RemapData<T>(this T[] self, List<int> remapping = null)
=> remapping?.Select(x => self[x])?.ToArray() ?? self;

public static IBuffer ToBuffer<T>(this T[] array) where T : unmanaged
=> new Buffer<T>(array);

Expand Down Expand Up @@ -97,29 +94,72 @@ public static IBuffer CreateDefaultDataColumnBuffer(int length, string typePrefi
}
}

public static IBuffer CopyDataColumn(this IBuffer dataColumn, string typePrefix, List<int> remapping = null)
public static IBuffer RemapOrSelfDataColumn(this IBuffer dataColumn, string typePrefix, List<int> remapping = null)
{
switch (typePrefix)
{
case (VimConstants.IntColumnNameTypePrefix):
return (dataColumn.Data as int[]).RemapData(remapping).ToBuffer();
return (dataColumn.Data as int[]).RemapOrSelf(remapping).ToBuffer();
case (VimConstants.LongColumnNameTypePrefix):
return (dataColumn.Data as long[]).RemapData(remapping).ToBuffer();
return (dataColumn.Data as long[]).RemapOrSelf(remapping).ToBuffer();
case (VimConstants.DoubleColumnNameTypePrefix):
return (dataColumn.Data as double[]).RemapData(remapping).ToBuffer();
return (dataColumn.Data as double[]).RemapOrSelf(remapping).ToBuffer();
case (VimConstants.FloatColumnNameTypePrefix):
return (dataColumn.Data as float[]).RemapData(remapping).ToBuffer();
return (dataColumn.Data as float[]).RemapOrSelf(remapping).ToBuffer();
case (VimConstants.ByteColumnNameTypePrefix):
return (dataColumn.Data as byte[]).RemapData(remapping).ToBuffer();
return (dataColumn.Data as byte[]).RemapOrSelf(remapping).ToBuffer();
default:
throw new Exception($"{nameof(CopyDataColumn)} - {UnknownNamedBufferPrefix}");
throw new Exception($"{nameof(RemapOrSelfDataColumn)} - {UnknownNamedBufferPrefix}");
}
}

public static INamedBuffer CopyDataColumn(this INamedBuffer dataColumn, List<int> remapping = null)
public static INamedBuffer RemapOrSelfDataColumn(this INamedBuffer dataColumn, List<int> remapping = null)
{
var typePrefix = dataColumn.GetTypePrefix();
return new NamedBuffer(dataColumn.CopyDataColumn(typePrefix, remapping), dataColumn.Name);
return new NamedBuffer(dataColumn.RemapOrSelfDataColumn(typePrefix, remapping), dataColumn.Name);
}

public static T[] RemapOrSelf<T>(this T[] source, List<int> remapping = null)
{
if (remapping == null)
return source;

var dst = new T[remapping.Count];

for (var i = 0; i < dst.Length; ++i)
{
var remappedIndex = remapping[i];
dst[i] = source[remappedIndex];
}

return dst;
}

public static T[] Copy<T>(this T[] source, List<int> remapping = null)
{
T[] result;

if (remapping == null)
{
// Copy from the source.
result = new T[source.Length];

for (var i = 0; i < result.Length; ++i)
result[i] = source[i];
}
else
{
// Copy from the remapping.
result = new T[remapping.Count];

for (var i = 0; i < result.Length; ++i)
{
var remappedIndex = remapping[i];
result[i] = source[remappedIndex];
}
}

return result;
}

public static IBuffer Concat<T>(this IBuffer thisBuffer, IBuffer otherBuffer) where T : unmanaged
Expand Down
3 changes: 3 additions & 0 deletions src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static IEnumerable<FieldInfo> GetRelationFields(this Type t)
public static string GetEntityTableName(this Type t)
=> (t.GetCustomAttribute(typeof(TableNameAttribute)) as TableNameAttribute)?.Name;

public static bool HasCascadeElementRemap(this Type t)
=> (t.GetCustomAttribute(typeof(CascadeElementRemapAttribute)) as CascadeElementRemapAttribute) != null;

public static (string IndexColumnName, string LocalFieldName) GetIndexColumnInfo(this FieldInfo fieldInfo)
{
if (!fieldInfo.Name.StartsWith("_"))
Expand Down
6 changes: 4 additions & 2 deletions src/cs/vim/Vim.Format.Core/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Vim.Math3d;
using Vim.BFast;
using System.IO;
using Vim.G3d;
using Vim.Util;

namespace Vim.Format
Expand Down Expand Up @@ -83,14 +84,15 @@ public DocumentBuilder AddShapes(IEnumerable<Shape> sb)
public DocumentBuilder AddAsset(INamedBuffer b)
=> AddAsset(b.Name, b.ToBytes());

public DocumentBuilder AddInstance(Matrix4x4 transform, int meshIndex, int parentIndex = -1)
public DocumentBuilder AddInstance(Matrix4x4 transform, int meshIndex, InstanceFlags flags, int parentIndex = -1)
{
Instances.Add(
new Instance()
{
Transform = transform,
MeshIndex = meshIndex,
ParentIndex = parentIndex
ParentIndex = parentIndex,
InstanceFlags = flags,
}
);

Expand Down
40 changes: 0 additions & 40 deletions src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,6 @@ public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMesh m)
public static void AddMesh(this DocumentBuilder db, IMesh m)
=> db.AddMesh(m.ToDocumentBuilderSubdividedMesh());

public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List<int> nodeIndexRemapping = null)
{
var name = table.Name;
var tb = db.CreateTableBuilder(name);

foreach (var col in table.IndexColumns.Values.ToEnumerable())
{
tb.AddIndexColumn(col.Name, col.GetTypedData().RemapData(nodeIndexRemapping));
}

foreach (var col in table.DataColumns.Values.ToEnumerable())
{
tb.AddDataColumn(col.Name, col.CopyDataColumn(nodeIndexRemapping));
}

foreach (var col in table.StringColumns.Values.ToEnumerable())
{
var strings = col.GetTypedData().Select(i => table.Document.StringTable.ElementAtOrDefault(i, null));
tb.AddStringColumn(col.Name, strings.ToArray().RemapData(nodeIndexRemapping));
}

return tb;
}

public static DocumentBuilder CopyTablesFrom(this DocumentBuilder db, Document doc, List<int> nodeIndexRemapping = null)
{
foreach (var table in doc.EntityTables.Values.ToEnumerable())
{
var name = table.Name;

// Don't copy tables that are computed automatically
if (VimConstants.ComputedTableNames.Contains(name))
continue;

db.CreateTableCopy(table, name == TableNames.Node ? nodeIndexRemapping : null);
}

return db;
}

public static SerializableEntityTable ToSerializableEntityTable(this EntityTableBuilder tb,
IReadOnlyDictionary<string, int> stringLookup)
{
Expand Down
44 changes: 1 addition & 43 deletions src/cs/vim/Vim.Format.Core/Geometry/IScene.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Vim.LinqArray;
using Vim.LinqArray;
using Vim.Math3d;

namespace Vim.Format.Geometry
Expand All @@ -18,50 +17,9 @@ public interface IScene
/// </summary>
public interface ISceneNode
{
int Id { get; }
IScene Scene { get; }
Matrix4x4 Transform { get; }
int MeshIndex { get; }
IMesh GetMesh();
ISceneNode Parent { get; }

// TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge.
IArray<ISceneNode> Children { get; }
}

public class SceneNodeComparer : EqualityComparer<ISceneNode>, IComparer<ISceneNode>
{
public static readonly SceneNodeComparer Instance = new SceneNodeComparer();

public int Compare(ISceneNode x, ISceneNode y)
=> x.Id - y.Id;
public override bool Equals(ISceneNode x, ISceneNode y)
=> x.Id == y.Id;
public override int GetHashCode(ISceneNode obj)
=> obj.Id;
}

public class NullNode : ISceneNode
{
public static NullNode Instance = new NullNode();
public static List<ISceneNode> ListInstance = new List<ISceneNode>() { Instance };
public int Id => -1;
public IScene Scene => null;
public Matrix4x4 Transform => Matrix4x4.Identity;
public int MeshIndex => 0;
public ISceneNode Parent => null;
public IArray<ISceneNode> Children => null;
public IMesh GetMesh() => null;
}

public class IdNode : ISceneNode
{
public int Id { get; set; }
public IScene Scene => null;
public Matrix4x4 Transform => Matrix4x4.Identity;
public int MeshIndex => 0;
public ISceneNode Parent => null;
public IArray<ISceneNode> Children => null;
public IMesh GetMesh() => null;
}
}
14 changes: 0 additions & 14 deletions src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ public static IEnumerable<IMesh> TransformedMeshes(this IScene scene)
public static IMesh ToIMesh(this IScene scene)
=> scene.TransformedMeshes().Merge();

public static bool HasLoop(this ISceneNode n)
{
if (n == null) return false;
var visited = new HashSet<ISceneNode>();
for (; n != null; n = n.Parent)
{
if (visited.Contains(n))
return true;
visited.Add(n);
}

return false;
}

public static IMesh MergedGeometry(this IScene scene)
=> scene.Nodes.ToEnumerable().MergedGeometry();

Expand Down
Loading
Loading