Как сделать (отображение кубической сферы) одной сеткой в ​​Unity С#C#

Место общения программистов C#
Ответить
Anonymous
 Как сделать (отображение кубической сферы) одной сеткой в ​​Unity С#

Сообщение Anonymous »

Я имею в виду, что при использовании (отображение кубической сферы) мы используем 6 плоскостей и нормализуем их, чтобы получить сферу,
но это не меняет того, что сфера состоит из 6 разделенных ячеек, поэтому, когда я пытаюсь изменить вершины С помощью инструмента «Кисть» в Unity я разделил лица. мне нужен способ получить вершины без дубликатов и границы граней, сшитые и триангулированные. и в любом случае спасибо.
Вот код, который я использую, если кому-то интересно (код, сгенерированный AI).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereGenerator : MonoBehaviour
{
public int resolution = 10; // Resolution for each face of the cube
public float radius = 1f; // Radius of the sphere

private void Start()
{
GenerateCubeSphere();
}

void GenerateCubeSphere()
{
MeshFilter meshFilter = GetComponent();
Mesh mesh = new Mesh();
mesh.name = "CubeSphere";

// Create the cube vertices and triangles
List vertices = new List();
List triangles = new List();

// Generate the 6 faces of the cube
CreateFace(Vector3.up, vertices, triangles); // Top
CreateFace(Vector3.down, vertices, triangles); // Bottom
CreateFace(Vector3.left, vertices, triangles); // Left
CreateFace(Vector3.right, vertices, triangles); // Right
CreateFace(Vector3.forward, vertices, triangles); // Front
CreateFace(Vector3.back, vertices, triangles); // Back

// Normalize the vertices to form a sphere
for (int i = 0; i < vertices.Count; i++)
{
vertices = vertices.normalized * radius;
}

// Assign the vertices and triangles to the mesh
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.RecalculateNormals(); // For smooth shading

// Assign the generated mesh to the MeshFilter
meshFilter.mesh = mesh;
}

// Function to create one face of the cube
void CreateFace(Vector3 normal, List vertices, List triangles)
{
// Determine the axes for the face
Vector3 axisA = new Vector3(normal.y, normal.z, normal.x); // Axis orthogonal to the face normal
Vector3 axisB = Vector3.Cross(normal, axisA);

// Create a grid for this face
int vertexIndexStart = vertices.Count;
for (int y = 0; y

Подробнее здесь: https://stackoverflow.com/questions/790 ... ty-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»