@@ -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
0 commit comments