Skip to content

Commit eb27c6c

Browse files
authored
Merge branch 'master' into bugfix/1322032-create-shadowmesh-problem
2 parents 3da781a + 6a3bbeb commit eb27c6c

5 files changed

Lines changed: 31 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Bug Fixes
1111

1212
- [case: 1322032] Fixing wrong ProBuilderMesh colors on domain reload when null.
13+
- [case: 1322150] Fixing torus and sphere UV generation when creating New Shape.
14+
- [case: 1320936] Fixing 'ProBuilderize' action creating empty submeshes.
1315

1416
### Changes
1517

Runtime/Core/ProBuilderMeshFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public void ToMesh(MeshTopology preferredTopology = MeshTopology.Triangles)
324324

325325
Submesh[] submeshes = Submesh.GetSubmeshes(facesInternal, materialCount, preferredTopology);
326326

327-
mesh.subMeshCount = materialCount;
327+
mesh.subMeshCount = submeshes.Length;
328328

329329
for (int i = 0; i < mesh.subMeshCount; i++)
330330
{

Runtime/Core/Submesh.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public static Submesh[] GetSubmeshes(IEnumerable<Face> faces, int submeshCount,
113113
List<int>[] quads = wantsQuads ? new List<int>[submeshCount] : null;
114114
List<int>[] tris = new List<int>[submeshCount];
115115
int maxSubmeshIndex = submeshCount - 1;
116+
int maxSubmeshIndexUsed = -1;
116117

117118
for (int i = 0; i < submeshCount; i++)
118119
{
@@ -128,13 +129,14 @@ public static Submesh[] GetSubmeshes(IEnumerable<Face> faces, int submeshCount,
128129
continue;
129130

130131
int submeshIndex = Math.Clamp(face.submeshIndex, 0, maxSubmeshIndex);
131-
132+
maxSubmeshIndexUsed = UnityEngine.Mathf.Max(submeshIndex,maxSubmeshIndexUsed);
132133
if (wantsQuads && face.IsQuad())
133134
quads[submeshIndex].AddRange(face.ToQuad());
134135
else
135136
tris[submeshIndex].AddRange(face.indexesInternal);
136137
}
137138

139+
submeshCount = maxSubmeshIndexUsed + 1;
138140
var submeshes = new Submesh[submeshCount];
139141

140142
switch (preferredTopology)

Runtime/Shapes/Sphere.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,12 @@ public override void CopyShape(Shape shape)
7373
public override Bounds UpdateBounds(ProBuilderMesh mesh, Vector3 size, Quaternion rotation, Bounds bounds)
7474
{
7575
bounds = mesh.mesh.bounds;
76-
Vector3 boxSize = bounds.size;
77-
boxSize.x = boxSize.y = boxSize.z = Mathf.Max(boxSize.x, Mathf.Max(boxSize.y, boxSize.z));
78-
bounds.size = boxSize;
7976
return bounds;
8077
}
8178

8279
public override Bounds RebuildMesh(ProBuilderMesh mesh, Vector3 size, Quaternion rotation)
8380
{
84-
var radius = System.Math.Min(System.Math.Min(Mathf.Abs(size.x), Mathf.Abs(size.y)), Mathf.Abs(size.z));
85-
//avoid to create a degenerated sphere with a radius set to 0
86-
radius = radius < 0.001f ? 0.001f : radius;
87-
81+
var radius = .5f;
8882
// http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
8983

9084
Vector3[] v = new Vector3[k_IcosphereTriangles.Length];
@@ -110,7 +104,7 @@ public override Bounds RebuildMesh(ProBuilderMesh mesh, Vector3 size, Quaternion
110104
{
111105
f[i / 3] = new Face(new int[3] { i, i + 1, i + 2 });
112106
f[i / 3].smoothingGroup = m_Smooth ? 1 : 0;
113-
f[i / 3].manualUV = true;
107+
f[i / 3].manualUV = false;
114108

115109
// Get the bottom most vertex of the whole shape. We'll use it as a pivot point.
116110
for (int j = 0; j < f[i / 3].indexes.Count; ++j)
@@ -124,6 +118,26 @@ public override Bounds RebuildMesh(ProBuilderMesh mesh, Vector3 size, Quaternion
124118
}
125119
}
126120
}
121+
122+
for (int i = 0; i < f.Length; i++)
123+
{
124+
var nrm = Math.Normal(v[f[i].indexesInternal[0]], v[f[i].indexesInternal[1]], v[f[i].indexesInternal[2]]);
125+
var axis = Projection.VectorToProjectionAxis(nrm);
126+
127+
if (axis == ProjectionAxis.X)
128+
f[i].textureGroup = 2;
129+
else if (axis == ProjectionAxis.Y)
130+
f[i].textureGroup = 3;
131+
else if (axis == ProjectionAxis.Z)
132+
f[i].textureGroup = 4;
133+
else if (axis == ProjectionAxis.XNegative)
134+
f[i].textureGroup = 5;
135+
else if (axis == ProjectionAxis.YNegative)
136+
f[i].textureGroup = 6;
137+
else if (axis == ProjectionAxis.ZNegative)
138+
f[i].textureGroup = 7;
139+
}
140+
127141
mesh.unwrapParameters = new UnwrapParameters()
128142
{
129143
packMargin = 30f

Runtime/Shapes/Torus.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using UnityEditor;
3+
using UnityEngine.ProBuilder.MeshOperations;
34

45
namespace UnityEngine.ProBuilder.Shapes
56
{
@@ -119,6 +120,8 @@ public override Bounds RebuildMesh(ProBuilderMesh mesh, Vector3 size, Quaternion
119120
mesh.TranslateVerticesInWorldSpace(mesh.mesh.triangles, mesh.transform.TransformDirection(-mesh.mesh.bounds.center));
120121
mesh.Refresh();
121122

123+
UVEditing.ProjectFacesBox(mesh, mesh.facesInternal);
124+
122125
return UpdateBounds(mesh, size, rotation, new Bounds());
123126
}
124127

0 commit comments

Comments
 (0)