Could someone please have a look at my first attempt to unwrap UV's to see if it's going into the right direction ?
It rotates each triangle towards the front and uses one of the previous rendered coordinates to shift it.
(It only works on a part of a Sphere at the moment, but it's the main idea that counts.)
Anybody any idea if this could go into the right direction ?
It rotates each triangle towards the front and uses one of the previous rendered coordinates to shift it.
(It only works on a part of a Sphere at the moment, but it's the main idea that counts.)
;very messy code, i know ;i hope the graphical output is a bit more clear. osel = -1 Type memt Field x0 Field y0 Field x1 Field y1 Field x2 Field y2 End Type Graphics3D 640, 480, 0, 3 SetBuffer BackBuffer() camera = CreateCamera() mesh = CreateSphere() PositionEntity camera, 0, 0, -5 WireFrame True orgmesh = CopyMesh(mesh) HideEntity orgmesh test_second_triangle = False For twosearch = 1 To 2 Delete Each memt ttest = True sel = 0 init = sel x2# = 0 y2# = 0 x0# = 0 y0# = 0 x1# = 0 y1# = 0 oldx = 0 oldy = 0 orgx = 0 orgy = 0 nomore = True While Not KeyDown( 1 ) FreeEntity mesh mesh = CopyMesh(orgmesh) surf = GetSurface(mesh, 1) v0 = TriangleVertex(surf, sel, 0) v1 = TriangleVertex(surf, sel, 1) v2 = TriangleVertex(surf, sel, 2) n0x# = VertexNX(surf, v0) n0y# = VertexNY(surf, v0) n0z# = VertexNZ(surf, v0) n1x# = VertexNX(surf, v1) n1y# = VertexNY(surf, v1) n1z# = VertexNZ(surf, v1) n2x# = VertexNX(surf, v2) n2y# = VertexNY(surf, v2) n2z# = VertexNZ(surf, v2) nx# = (n0x + n1x + n2x) / 3 ny# = (n0y + n1y + n2y) / 3 nz# = (n0z + n1z + n2z) / 3 ang1 = ATan2(nx, nz) RotateMesh mesh, 0, ang1, 0 UpdateNormals mesh n0x# = VertexNX(surf, v0) n0y# = VertexNY(surf, v0) n0z# = VertexNZ(surf, v0) n1x# = VertexNX(surf, v1) n1y# = VertexNY(surf, v1) n1z# = VertexNZ(surf, v1) n2x# = VertexNX(surf, v2) n2y# = VertexNY(surf, v2) n2z# = VertexNZ(surf, v2) nx# = (n0x + n1x + n2x) / 3 ny# = (n0y + n1y + n2y) / 3 nz# = (n0z + n1z + n2z) / 3 ang2 = ATan2(ny, nz) RotateMesh mesh, ang2, 0, 0 UpdateNormals mesh ; PositionMesh mesh, (Float(sel) / Float(CountTriangles(surf))) - 0.5, 0, 0 n0x# = VertexNX(surf, v0) n0y# = VertexNY(surf, v0) n0z# = VertexNZ(surf, v0) n1x# = VertexNX(surf, v1) n1y# = VertexNY(surf, v1) n1z# = VertexNZ(surf, v1) n2x# = VertexNX(surf, v2) n2y# = VertexNY(surf, v2) n2z# = VertexNZ(surf, v2) nx# = (n0x + n1x + n2x) / 3 ny# = (n0y + n1y + n2y) / 3 nz# = (n0z + n1z + n2z) / 3 RenderWorld v0x# = VertexX(surf, v0) v0y# = VertexY(surf, v0) v0z# = VertexZ(surf, v0) TFormPoint v0x, v0y, v0z, mesh, 0 CameraProject camera, TFormedX(), TFormedY(), TFormedZ() x0 = ProjectedX() y0 = ProjectedY() v1x# = VertexX(surf, v1) v1y# = VertexY(surf, v1) v1z# = VertexZ(surf, v1) TFormPoint v1x, v1y, v1z, mesh, 0 CameraProject camera, TFormedX(), TFormedY(), TFormedZ() x1 = ProjectedX() y1 = ProjectedY() v2x# = VertexX(surf, v2) v2y# = VertexY(surf, v2) v2z# = VertexZ(surf, v2) TFormPoint v2x, v2y, v2z, mesh, 0 CameraProject camera, TFormedX(), TFormedY(), TFormedZ() x2 = ProjectedX() y2 = ProjectedY() If sel = init Then If ttest Then orgx = x0: orgy = y0: ttest = False x1 = (x1 - x0) + oldx + orgx y1 = (y1 - y0) + oldy + orgy x2 = (x2 - x0) + oldx + orgx y2 = (y2 - y0) + oldy + orgy x0 = (x0 - x0) + oldx + orgx y0 = (y0 - y0) + oldy + orgy Color 255, 0, 0 Line x0, y0, x1, y1 Line x1, y1, x2, y2 Line x2, y2, x0, y0 Color 255, 255, 255 Text x0, y0, v0, True, True Text x1, y1, v1, True, True Text x2, y2, v2, True, True If sel <> osel Then osel = sel m.memt = New memt m\x0 = x0 m\y0 = y0 m\x1 = x1 m\y1 = y1 m\x2 = x2 m\y2 = y2 End If Color 255, 0, 0 For m.memt = Each memt Line m\x0, m\y0, m\x1, m\y1 Line m\x1, m\y1, m\x2, m\y2 Line m\x2, m\y2, m\x0, m\y0 Next Color 255, 255, 255 x0 = x0 - orgx y0 = y0 - orgy x1 = x1 - orgx y1 = y1 - orgy x2 = x2 - orgx y2 = y2 - orgy search1 = 0 ; search2 = 16 otest = test test = False If (v0 = search1) Or (v1 = search1) Or (v2 = search1) Then test = True ;If (v0 = search2) Or (v1 = search2) Or (v2 = search2) Then test = True ; End If If test Then If Not otest Then FlushKeys() ; Text 0, 0, nx + "," + ny + "," + nz ; Text 0, 20, sel ; Text 0, 40, v0 + "," + v1 + "," + v2 ; If test Then Text 0, 60, "!!!!found!!!!" Text 0, 0, "Press Right Arrow to proceed" Text 0, 20, "Press Esc to exit" Flip test = Not KeyDown(29) If test Then leftkey = KeyHit(203) rightkey = KeyHit(205) Else leftkey = KeyDown(203) rightkey = KeyDown(205) End If nomore = False If leftkey Then If sel > 0 Then sel = sel - 1 ; If rightkey Then If sel < CountTriangles(surf) - 1 Then sel = sel + 1 If rightkey Then osel = sel For t = 0 To CountTriangles(surf) vv = TriangleVertex(surf, t, 0) If test_second_triangle Then If vv = v2 Then sel = t oldx = x2: oldy = y2 Else If vv = v1 Then sel = t oldx = x1: oldy = y1 End If Next If sel = osel Then nomore = True End If If nomore Then Exit Wend If KeyDown(1) Then End test_second_triangle = True Next FlushKeys() Color 255, 255, 255 Text 320, 440, "Press spacebar to continue", True, True Flip Repeat Until KeyHit(57) End
Anybody any idea if this could go into the right direction ?