Skip to content

Commit

Permalink
add DVector.copy, SetVerticesMeshChange
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed May 28, 2018
1 parent 652ebcf commit 053728b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/DVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public DVector(IEnumerable<T> init)
iCurBlockUsed = 0;
Blocks = new List<T[]>();
Blocks.Add(new T[nBlockSize]);
// AAAHHH this could be so more efficient...
foreach (T v in init)
Add(v);
}
Expand Down Expand Up @@ -179,6 +178,24 @@ public void resize(int count) {
}


public void copy(DVector<T> copyIn)
{
if (this.Blocks != null && copyIn.Blocks.Count == this.Blocks.Count) {
int N = copyIn.Blocks.Count;
for (int k = 0; k < N; ++k)
Array.Copy(copyIn.Blocks[k], this.Blocks[k], copyIn.Blocks[k].Length);
iCurBlock = copyIn.iCurBlock;
iCurBlockUsed = copyIn.iCurBlockUsed;
} else {
resize(copyIn.size);
int N = copyIn.Blocks.Count;
for (int k = 0; k < N; ++k)
Array.Copy(copyIn.Blocks[k], this.Blocks[k], copyIn.Blocks[k].Length);
iCurBlock = copyIn.iCurBlock;
iCurBlockUsed = copyIn.iCurBlockUsed;
}
}



public T this[int i]
Expand Down
54 changes: 54 additions & 0 deletions mesh/DMesh3Changes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,60 @@ void initialize_buffers(DMesh3 mesh, MeshComponents components)



/// <summary>
/// Mesh change for full-mesh vertex deformations - more efficient than ModifyVerticesMeshChange.
/// Note that this does not enforce that vertex count does not change!
/// </summary>
public class SetVerticesMeshChange
{
public DVector<double> OldPositions, NewPositions;
public DVector<float> OldNormals, NewNormals;
public DVector<float> OldColors, NewColors;
public DVector<float> OldUVs, NewUVs;

public Action<SetVerticesMeshChange> OnApplyF;
public Action<SetVerticesMeshChange> OnRevertF;

public SetVerticesMeshChange()
{
}

public void Apply(DMesh3 mesh)
{
if ( NewPositions != null )
mesh.VerticesBuffer.copy(NewPositions);
if (mesh.HasVertexNormals && NewNormals != null)
mesh.NormalsBuffer.copy(NewNormals);
if (mesh.HasVertexColors&& NewColors != null)
mesh.ColorsBuffer.copy(NewColors);
if (mesh.HasVertexUVs && NewUVs != null)
mesh.UVBuffer.copy(NewUVs);
if (OnApplyF != null)
OnApplyF(this);
}


public void Revert(DMesh3 mesh)
{
if ( OldPositions != null )
mesh.VerticesBuffer.copy(OldPositions);
if (mesh.HasVertexNormals && OldNormals != null)
mesh.NormalsBuffer.copy(OldNormals);
if (mesh.HasVertexColors && OldColors != null)
mesh.ColorsBuffer.copy(OldColors);
if (mesh.HasVertexUVs && OldUVs != null)
mesh.UVBuffer.copy(OldUVs);
if (OnRevertF != null)
OnRevertF(this);
}
}










Expand Down

0 comments on commit 053728b

Please sign in to comment.