I tried for example, to make "Mapping a cube to a sphere"but I get a bug first face, in a circle, and the whole cube is the hemisphere, I’m a very long time trying to find a solution, but could not.Therefore, I ask for help from the community, from the bottom to bring the code
using UnityEngine;
using System.Collections;
public class PlanetLod : MonoBehaviour
{
private Mesh m;
void Start()
{
m = GetComponent<MeshFilter>().mesh;
float radius = 2.0f;
Vector3[] vertices = m.vertices;
Vector3[] verticesN = m.vertices;
Vector3[] normals = m.normals;
for (int i = 0; i < vertices.Length; i++)
{
Vector3 spherePoint = vertices*.normalized;*
-
Vector3 position = CubeToSphere(spherePoint.x, spherePoint.y, spherePoint.z);*
_ verticesN*= position;_
_ }*_
* m.vertices = verticesN;*
* m.RecalculateNormals();*
* m.RecalculateBounds();*
* }*
* private Vector3 CubeToSphere(float x, float y, float z)*
* {*
_ float sx = x * Mathf.Sqrt(1.0f - y * y * 0.5f - z * z * 0.5f + y * y * z * z / 3.0f);
float sy = y * Mathf.Sqrt(1.0f - z * z * 0.5f - x * x * 0.5f + z * z * x * x / 3.0f);
float sz = z * Mathf.Sqrt(1.0f - x * x * 0.5f - y * y * 0.5f + x * x * y * y / 3.0f);_
* return new Vector3(sx, sy, sz);*
* }*
}