Skip to content

Commit

Permalink
Fix creating deep-copy of MeshWithMaterialRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Klara committed Jan 9, 2025
1 parent 742bf2a commit eed275c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Assets/Scripts/model/core/MeshWithMaterialRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,21 @@ public void AnimateScaleFrom(float fromScale)
/// <param name="other">The other MeshWithMaterialRenderer</param>
public void SetupAsCopyOf(MeshWithMaterialRenderer other)
{
meshes = new List<MeshWithMaterial>(other.meshes);
meshes = CopyMeshes(other.meshes);
worldSpace = other.worldSpace;
smoother = new SmoothMoves(other.smoother);
}

private List<MeshWithMaterial> CopyMeshes(List<MeshWithMaterial> other)
{
var newList = new List<MeshWithMaterial>(other.Count);
foreach (var mwm in other)
{
newList.Add(mwm.Copy());
}
return newList;
}

public Vector3 GetCurrentAnimatedScale()
{
return smoother.GetScale();
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/model/render/MeshWithMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ public MeshWithMaterial(Mesh mesh, MaterialAndColor materialAndColor)
this.mesh = mesh;
this.materialAndColor = materialAndColor;
}

public MeshWithMaterial Copy()
{
var m = new Mesh
{
vertices = mesh.vertices,
normals = mesh.normals,
triangles = mesh.triangles,
colors32 = mesh.colors32
};
return new MeshWithMaterial(m, materialAndColor.Clone());
}
}
}

0 comments on commit eed275c

Please sign in to comment.