Skip to content
Open
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Internal

- [UUM-138957] Removed ProBuilder Runtime tests references to UnityEditor.

### Changes

- [UUM-138960] Removed a large utility dictionary to reduce binary size and runtime memory overhead.

### Fixed
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using UnityEngine.ProBuilder.MeshOperations;
using UnityEngine.ProBuilder.Shapes;

class ProBuilderizeTests : TemporaryAssetTest
class MeshImporterTests : TemporaryAssetTest
{
[Test]
public static void ImportCube_MatchesDefaultCube()
Expand Down Expand Up @@ -50,20 +50,20 @@ public static void ImportQuads_MatchesWindingOrder()
Assert.IsNotNull(source);

var instance = (GameObject)UObject.Instantiate(source);
var mf = instance.gameObject.GetComponent<MeshFilter>();
var mr = instance.gameObject.GetComponent<MeshRenderer>();
var mf = instance.gameObject.GetComponent<MeshFilter>();
var mr = instance.gameObject.GetComponent<MeshRenderer>();
var result = new GameObject().AddComponent<ProBuilderMesh>();
var importer = new MeshImporter(mf.sharedMesh, mr.sharedMaterials, result);
var importer = new MeshImporter(mf.sharedMesh, mr.sharedMaterials, result);

Assert.DoesNotThrow(() =>
Assert.DoesNotThrow(() =>
{
importer.Import(new MeshImportSettings()
{
importer.Import(new MeshImportSettings()
{
quads = true,
smoothing = false,
smoothingAngle = 1f
});
quads = true,
smoothing = false,
smoothingAngle = 1f
});
});

result.Rebuild();

Expand Down
94 changes: 0 additions & 94 deletions Tests/Framework/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,53 +85,6 @@ public static string temporarySavedAssetsDirectory
get { return k_TempDirectory; }
}

public class BuiltInPrimitives : IDisposable, IEnumerable<ProBuilderMesh>
{
ProBuilderMesh[] m_Shapes;

public static ProBuilderMesh[] GetBasicShapes()
{
var shapes = Enum.GetValues(typeof(ShapeType)) as ShapeType[];
ProBuilderMesh[] primitives = new ProBuilderMesh[shapes.Length];

for (int i = 0, c = shapes.Length; i < c; i++)
{
primitives[i] = ShapeGenerator.CreateShape(shapes[i]);
primitives[i].GetComponent<MeshFilter>().sharedMesh.name = shapes[i].ToString();
}
return primitives;
}

public BuiltInPrimitives()
{
m_Shapes = GetBasicShapes();
}

public int Count { get { return m_Shapes.Length; } }

public ProBuilderMesh this[int i]
{
get { return m_Shapes[i]; }
set { m_Shapes[i] = value; }
}

public void Dispose()
{
for (int i = 0, c = m_Shapes.Length; i < c; i++)
UObject.DestroyImmediate(m_Shapes[i].gameObject);
}

IEnumerator<ProBuilderMesh> IEnumerable<ProBuilderMesh>.GetEnumerator()
{
return ((IEnumerable<ProBuilderMesh>)m_Shapes).GetEnumerator();
}

public IEnumerator GetEnumerator()
{
return m_Shapes.GetEnumerator();
}
}

public class IgnoreAssertScope : IDisposable
{
bool m_SavedState;
Expand All @@ -158,14 +111,6 @@ static string ToAssetPath(string path)
return path.Replace("\\", "/").Replace(Application.dataPath, "Assets/");
}

public static void AssertSequenceEqual<T>(IList<T> left, IList<T> right)
{
Assert.AreEqual(left.Count, right.Count, "Count");

for (int i = 0, c = left.Count; i < c; i++)
Assert.AreEqual(left[i], right[i], "index " + i);
}

public static void AssertMeshAttributesValid(Mesh mesh)
{
int vertexCount = mesh.vertexCount;
Expand Down Expand Up @@ -529,45 +474,6 @@ public static Material greenMaterial
get { return AssetDatabase.LoadAssetAtPath<Material>(k_GreenMaterialPath); }
}

public static SimpleTuple<ProBuilderMesh, Face> CreateCubeWithNonContiguousMergedFace()
{
var cube = ShapeFactory.Instantiate<Cube>();

Assume.That(cube, Is.Not.Null);

int index = 1;
Face a = cube.faces[0], b = cube.faces[index++];
Assume.That(a, Is.Not.Null);
Assume.That(b, Is.Not.Null);

while (FacesAreAdjacent(cube, a, b) && index < cube.faceCount)
b = cube.faces[index++];

Assume.That(FacesAreAdjacent(cube, a, b), Is.False);

var res = MergeElements.Merge(cube, new Face[] { a, b });

return new SimpleTuple<ProBuilderMesh, Face>(cube, res);
}

static bool FacesAreAdjacent(ProBuilderMesh mesh, Face a, Face b)
{
for (int i = 0, c = a.edgesInternal.Length; i < c; i++)
{
var ea = mesh.GetSharedVertexHandleEdge(a.edgesInternal[i]);

for (int n = 0; n < b.edgesInternal.Length; n++)
{
var eb = mesh.GetSharedVertexHandleEdge(b.edgesInternal[n]);

if (ea == eb)
return true;
}
}

return false;
}

public static void AssertMeshIsValid(ProBuilderMesh mesh)
{
Assert.That(mesh, Is.Not.Null);
Expand Down
4 changes: 3 additions & 1 deletion Tests/Framework/Unity.ProBuilder.Tests.Framework.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions Tests/Runtime/MeshOps/BridgeEdgesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
using UnityEngine.ProBuilder.Shapes;
using UnityEngine.ProBuilder.Tests;
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
using UnityEngine.ProBuilder.Tests.Framework;
#endif

static class BridgeEdgesTests
{
Expand All @@ -21,16 +24,16 @@ public static void Bridge_TwoEdges_CreatesQuad()
cube.ToMesh();
cube.Refresh();

#if PB_CREATE_TEST_MESH_TEMPLATES
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
TestUtility.SaveAssetTemplate(cube.mesh, cube.name);
#endif
TestUtility.AssertMeshAttributesValid(cube.mesh);
var template = TestUtility.GetAssetTemplate<Mesh>(cube.name);
RuntimeUtility.AssertMeshAttributesValid(cube.mesh);
var template = Resources.Load<Mesh>(RuntimeUtility.GetResourcesPath<Mesh>(cube.name));
Assert.IsNotNull(template);
TestUtility.AssertAreEqual(template, cube.mesh);
RuntimeUtility.AssertAreEqual(template, cube.mesh);

UnityEngine.Object.DestroyImmediate(cube);
}
Object.DestroyImmediate(cube.gameObject);
}

[Test]
public static void Bridge_TwoConnectedEdges_CreatesTriangle()
Expand All @@ -45,14 +48,14 @@ public static void Bridge_TwoConnectedEdges_CreatesTriangle()
cube.ToMesh();
cube.Refresh();

#if PB_CREATE_TEST_MESH_TEMPLATES
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
TestUtility.SaveAssetTemplate(cube.mesh, cube.name);
#endif
TestUtility.AssertMeshAttributesValid(cube.mesh);
var template = TestUtility.GetAssetTemplate<Mesh>(cube.name);
RuntimeUtility.AssertMeshAttributesValid(cube.mesh);
var template = Resources.Load<Mesh>(RuntimeUtility.GetResourcesPath<Mesh>(cube.name));
Assert.IsNotNull(template);
TestUtility.AssertAreEqual(template, cube.mesh);
RuntimeUtility.AssertAreEqual(template, cube.mesh);

UnityEngine.Object.DestroyImmediate(cube);
Object.DestroyImmediate(cube.gameObject);
}
}
9 changes: 4 additions & 5 deletions Tests/Runtime/MeshOps/CalculateNormalsTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UObject = UnityEngine.Object;
using NUnit.Framework;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.Tests.Framework;
using UnityEngine.ProBuilder.Tests;

static class CalculateNormalsTests
{
Expand All @@ -13,7 +12,7 @@ static class CalculateNormalsTests
[Test]
public static void Calculate_HardNormals_AreNormalized()
{
using (var shapes = new TestUtility.BuiltInPrimitives())
using (var shapes = new RuntimeUtility.BuiltInPrimitives())
{
foreach (var pb in (IEnumerable<ProBuilderMesh>)shapes)
{
Expand All @@ -35,7 +34,7 @@ public static void Calculate_HardNormals_AreNormalized()
[Test]
public static void Calculate_SoftNormals_AreNormalized()
{
using (var shapes = new TestUtility.BuiltInPrimitives())
using (var shapes = new RuntimeUtility.BuiltInPrimitives())
{
foreach (var pb in (IEnumerable<ProBuilderMesh>)shapes)
{
Expand All @@ -57,7 +56,7 @@ public static void Calculate_SoftNormals_AreNormalized()
[Test]
public static void Calculate_SoftNormals_AreSoft()
{
using (var shapes = new TestUtility.BuiltInPrimitives())
using (var shapes = new RuntimeUtility.BuiltInPrimitives())
{
foreach (var pb in (IEnumerable<ProBuilderMesh>)shapes)
{
Expand Down
21 changes: 11 additions & 10 deletions Tests/Runtime/MeshOps/CollapseVerticesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
using UnityEngine.ProBuilder.Shapes;
using UnityEngine.ProBuilder.Tests;
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
using UnityEngine.ProBuilder.Tests.Framework;
#endif

static class CollapseVerticesTests
{
Expand All @@ -18,14 +21,13 @@ public static void CollapseToFirst_MatchesTemplate()
cube.ToMesh();
cube.Refresh();

#if PB_CREATE_TEST_MESH_TEMPLATES
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
TestUtility.SaveAssetTemplate(cube.mesh, cube.name);
#endif

TestUtility.AssertMeshAttributesValid(cube.mesh);
var template = TestUtility.GetAssetTemplate<Mesh>(cube.name);
RuntimeUtility.AssertMeshAttributesValid(cube.mesh);
var template = Resources.Load<Mesh>(RuntimeUtility.GetResourcesPath<Mesh>(cube.name));
Assert.IsNotNull(template);
TestUtility.AssertAreEqual(template, cube.mesh);
RuntimeUtility.AssertAreEqual(template, cube.mesh);

Object.DestroyImmediate(cube);
}
Expand All @@ -39,14 +41,13 @@ public static void CollapseToCenter_MatchesTemplate()
cube.ToMesh();
cube.Refresh();

#if PB_CREATE_TEST_MESH_TEMPLATES
#if UNITY_EDITOR && PB_CREATE_TEST_MESH_TEMPLATES
TestUtility.SaveAssetTemplate(cube.mesh, cube.name);
#endif

TestUtility.AssertMeshAttributesValid(cube.mesh);
var template = TestUtility.GetAssetTemplate<Mesh>(cube.name);
RuntimeUtility.AssertMeshAttributesValid(cube.mesh);
var template = Resources.Load<Mesh>(RuntimeUtility.GetResourcesPath<Mesh>(cube.name));
Assert.IsNotNull(template);
TestUtility.AssertAreEqual(template, cube.mesh);
RuntimeUtility.AssertAreEqual(template, cube.mesh);

UnityEngine.Object.DestroyImmediate(cube);
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/Runtime/MeshOps/CombineMeshesTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
using UObject = UnityEngine.Object;
using NUnit.Framework;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.Tests.Framework;
using UnityEngine.ProBuilder.MeshOperations;
using UnityEngine.ProBuilder.Shapes;

Expand Down
Loading