Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
Cube created by vertices and triangles as mesh renders different than normal cube?

For something I want to do with these cubes I need to create the mesh myself so I know which vertices are which and am able to manipulate the geometry.

But why does my scripted cube (on the left) look so different in shading than the Unity one?

Both use the same material.

problem

I guess it has something to do with the Phong?

This is the code I use to create my own cube:

private void CreateCube() 
{

    GameObject cubeObject;
    cubeObject = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity);

    Vector3[] vertices;
    int[] triangles;

    vertices = new Vector3[8];

    // BOTTOM VERTICES
    vertices[0] = new Vector3(0, 0, 0); //BBL
    vertices[1] = new Vector3(1, 0, 0); //BBR
    vertices[2] = new Vector3(0, 0, 1); //BTL
    vertices[3] = new Vector3(1, 0, 1); //BTR
    // TOP VERTICES
    vertices[4] = new Vector3(0, 1, 0); //TBL
    vertices[5] = new Vector3(1, 1, 0); //TBR
    vertices[6] = new Vector3(0, 1, 1); //TTL
    vertices[7] = new Vector3(1, 1, 1); //TTR

    triangles = new int[36];

    // BOTTOM TRIANGLES
    triangles[0] = 1; //BBR
    triangles[1] = 2; //BTL
    triangles[2] = 0; //BBL
    triangles[4] = 2; //BTL
    triangles[3] = 3; //BTR
    triangles[5] = 1; //BBR
    
    // TOP TRIANGLES
    triangles[6] = 4; //TBL
    triangles[7] = 6; //TTL
    triangles[8] = 7; //TTR
    triangles[9] = 5; //TBR
    triangles[10] = 4; //TBL
    triangles[11] = 7; //TTR

    // BACK TRIANGLES
    triangles[12] = 5; //TBR
    triangles[13] = 0; //BBL
    triangles[14] = 4; //TBL
    triangles[15] = 1; //BBR   
    triangles[16] = 0; //BBL
    triangles[17] = 5; //TBR

    // FRONT TRIANGLES
    triangles[18] = 6; //TTL
    triangles[19] = 2; //BTL
    triangles[20] = 3; //BTR
    triangles[21] = 6; //TTL
    triangles[22] = 3; //BTR 
    triangles[23] = 7; //TTR

    // LEFT TRIANGLES
    triangles[24] = 6; //TTL
    triangles[25] = 4; //TBL 
    triangles[26] = 2; //BTL
    triangles[27] = 0; //BBL 
    triangles[28] = 2; //BTL 
    triangles[29] = 4; //TBL 

    // RIGHT TRIANGLES
    triangles[32] = 7; //TTR
    triangles[31] = 5; //TBR
    triangles[30] = 1; //BBR  
    triangles[35] = 1; //BBR  
    triangles[34] = 3; //BTR 
    triangles[33] = 7; //TTR

    Mesh cubeMesh = new Mesh(); 

    cubeObject.GetComponent<MeshFilter>().sharedMesh = cubeMesh;

    cubeMesh.Clear();
    cubeMesh.vertices = vertices;
    cubeMesh.triangles = triangles;

    cubeMesh.RecalculateNormals();
}

The prefab is just a GameObject with an empty Mesh Filter and a Mesh Renderer with a material attached (Default-Material).

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda