Page 1 of 1

BuildMeshTangents() error in semisphere mesh

Posted: Mon Oct 27, 2025 8:40 pm
by minimy
Some body cam explain me, why cant apply BuildMeshTangents() to this semisphere mesh? :shock:

Code: Select all

      CreateMesh(mesh)
      ; vértices de la cúpula (la del trueno no, otra..)
      For i = 0 To latSteps
        theta = (i / latSteps) * (#PI / 2) 
        For j = 0 To lonSteps
          phi = (j / lonSteps) * 2 * #PI 
          x = ra * Sin(theta) * Cos(phi)
          y = ra * Cos(theta)
          z = ra * Sin(theta) * Sin(phi)
          u = phi / (2 * #PI)
          v = theta / (#PI / 2)
          MeshVertex(x,y,z, u,v, $ffffff)
        Next
      Next
      ; caras (triánguladas)
      For i = 0 To latSteps - 1
        For j = 0 To lonSteps - 1
          p0 = i * (lonSteps + 1) + j
          p1 = p0 + 1
          p2 = p0 + (lonSteps + 1)
          p3 = p2 + 1
          ; Triángulo 1
          MeshFace(p1,p2,p0)
          ; Triángulo 2
          MeshFace(p3,p2,p1)
        Next
      Next
      If tapa
        ; vértice central inferior
        MeshVertex(0, 0, 0, 0.5, 0.5, $ffffff)
        ; triángulos de la tapa inferior con vértices nuevos y UV planar para que se vea como debe ser
        nv = (latSteps+1)*(lonSteps+1)
        centerIndex=nv
        nv+1
        theta.f = #PI / 2
        For j = 0 To lonSteps - 1
          phi = (j / lonSteps) * 2 * #PI
          x = ra  * Sin(theta) * Cos(phi)
          z = ra  * Sin(theta) * Sin(phi)
          u = (-x / (2 * ra)) + 0.5
          v = (z / (2 * ra)) + 0.5
          MeshVertex(x, 0, z, u, v, $ffffff)
          p0 = nv
          nv+1
          ; más triángulos jeje
          phi = ((j + 1) / lonSteps) * 2 * #PI
          x = ra * Sin(theta) * Cos(phi)
          z = ra * Sin(theta) * Sin(phi)
          u = (-x / (2 * ra)) + 0.5
          v = (z / (2 * ra)) + 0.5
          MeshVertex(x, 0, z, u, v, $ffffff)
          p1 = nv
          nv+1
          MeshFace(p0, p1, centerIndex)
        Next
      EndIf
      FinishMesh(#True)
      NormalizeMesh(mesh)
;       BuildMeshTangents(mesh)

Re: BuildMeshTangents() error in semisphere mesh

Posted: Mon Oct 27, 2025 9:04 pm
by miso
It's not a runnable program, so I could not test it. (and have no time to make it run)

Wild guess: there are no normal and tangent properties created. Add normal 0,0,0 to your meshvertex command after the color. When finished, normalize and add the tangents.

Edit: tested, that is the problem.

BuildMeshTangents() SOLVED - error in semisphere mesh

Posted: Mon Oct 27, 2025 10:28 pm
by minimy
Add normal 0,0,0
Yes! solved! You`re right!
I think a not defined param is 0 by default, but not :lol:
Thank you very much miso!