public override ProBuilderMesh Build(bool isPreview = false) { var mesh = ShapeGenerator.GenerateTorus( EditorUtility.newShapePivotLocation, s_Rows, s_Columns, s_Radius, s_TubeRadius, s_Smooth, s_HorizontalCirumference, s_VerticalCircumference, true); UVEditing.ProjectFacesBox(mesh, mesh.facesInternal); return(mesh); }
public override ProBuilderMesh Build(bool preview = false) { // To keep the preview snappy, shared indexes aren't built in IcosahadreonGenerator var mesh = ShapeGenerator.GenerateIcosahedron( EditorUtility.newShapePivotLocation, s_Radius, s_Subdivisions, !preview); if (!preview) { UVEditing.ProjectFacesBox(mesh, mesh.facesInternal); } for (int i = 0; i < mesh.facesInternal.Length; i++) { mesh.facesInternal[i].manualUV = true; } return(mesh); }
public override Bounds RebuildMesh(ProBuilderMesh mesh, Vector3 size, Quaternion rotation) { var meshSize = Math.Abs(rotation * size); var xOuterRadius = Mathf.Clamp(meshSize.x / 2f, .01f, 2048f); var yOuterRadius = Mathf.Clamp(meshSize.z / 2f, .01f, 2048f); int clampedRows = Mathf.Clamp(m_Rows + 1, 4, 128); int clampedColumns = Mathf.Clamp(m_Columns + 1, 4, 128); float clampedTubeRadius = Mathf.Clamp(m_TubeRadius, .01f, Mathf.Min(xOuterRadius, yOuterRadius) - .001f); xOuterRadius -= clampedTubeRadius; yOuterRadius -= clampedTubeRadius; float clampedHorizontalCircumference = Mathf.Clamp(m_HorizontalCircumference, .01f, 360f); float clampedVerticalCircumference = Mathf.Clamp(m_VerticalCircumference, .01f, 360f); List <Vector3> vertices = new List <Vector3>(); int col = clampedColumns - 1; float clampedRadius = xOuterRadius; Vector3[] cir = GetCirclePoints(clampedRows, clampedTubeRadius, clampedVerticalCircumference, Quaternion.Euler(0, 0, 0), clampedRadius); Vector2 ellipseCoord; for (int i = 1; i < clampedColumns; i++) { vertices.AddRange(cir); float angle = (i / (float)col) * clampedHorizontalCircumference; //Compute the coordinates of the current point ellipseCoord = new Vector2(xOuterRadius * Mathf.Cos(Mathf.Deg2Rad * angle), yOuterRadius * Mathf.Sin(Mathf.Deg2Rad * angle)); //Compute the tangent direction to know how to orient the current slice var tangent = new Vector2(-ellipseCoord.y / (yOuterRadius * yOuterRadius), ellipseCoord.x / (xOuterRadius * xOuterRadius)); Quaternion rot = Quaternion.Euler(Vector3.up * Vector2.SignedAngle(Vector2.up, tangent.normalized)); //Get the slice/circle that must be placed at this position cir = GetCirclePoints(clampedRows, clampedTubeRadius, clampedVerticalCircumference, rot, new Vector3(ellipseCoord.x, 0, -ellipseCoord.y)); vertices.AddRange(cir); } List <Face> faces = new List <Face>(); int fc = 0; // faces for (int i = 0; i < (clampedColumns - 1) * 2; i += 2) { for (int n = 0; n < clampedRows - 1; n++) { int a = (i + 0) * ((clampedRows - 1) * 2) + (n * 2); int b = (i + 1) * ((clampedRows - 1) * 2) + (n * 2); int c = (i + 0) * ((clampedRows - 1) * 2) + (n * 2) + 1; int d = (i + 1) * ((clampedRows - 1) * 2) + (n * 2) + 1; faces.Add(new Face(new int[] { a, b, c, b, d, c })); faces[fc].smoothingGroup = m_Smooth ? 1 : -1; faces[fc].manualUV = true; fc++; } } for (int i = 0; i < vertices.Count; ++i) { vertices[i] = rotation * vertices[i]; } mesh.RebuildWithPositionsAndFaces(vertices, faces); mesh.TranslateVerticesInWorldSpace(mesh.mesh.triangles, mesh.transform.TransformDirection(-mesh.mesh.bounds.center)); mesh.Refresh(); UVEditing.ProjectFacesBox(mesh, mesh.facesInternal); return(UpdateBounds(mesh, size, rotation, new Bounds())); }