Depending on exactly what we want to do with the UV coordinates ... the mapping could be as simple as ...
The issue with the above is that it does not address what happens when an arbitrary triangle crosses the U=1.0 boundary. That could be detected and handled properly if we iterated using FACES and if we assumed that the mesh was somewhat dense ... which is surely the case if we are trying to make a planet or moon.
Here is anther interesting UV mapping consideration ... I might need to look into ... not sure how Wings3D sets or handles UVs over-runs.
http://gamedev.stackexchange.com/questio...-less-than
Code:
command({vertex,{manifoldlab,spherical_y}}, #st{sel=[{WeID,Set}]}=St) ->
wings_io:hourglass(),
#we{} = We = gb_trees:get(WeID, St#st.shapes),
[{_,MinY,_}=_Min,_Max] = wings_vertex:bounding_box(We),
{_,Dy,_} = e3d_vec:sub(_Max,_Min),
TWOPI = 2.0*math:pi(),
MyAcc = fun(Vi, #we{}=Acc) ->
{X,Y,Z} = wings_vertex:pos(Vi,We),
U0 = (math:atan2(X,Z) + math:pi())/TWOPI, % range 0 - 1.0
U = min(U0,1.0000),
Temp = max(min(Y/(0.5*Dy),1.0),-1.0),
V = (math:asin(Temp) + math:pi()/2.0)/math:pi(),
set_vtx_uv(Vi, {U,V}, Acc)
end,
We2 = gb_sets:fold(MyAcc, We, Set),
wings_shape:replace(WeID,We2,St);
The issue with the above is that it does not address what happens when an arbitrary triangle crosses the U=1.0 boundary. That could be detected and handled properly if we iterated using FACES and if we assumed that the mesh was somewhat dense ... which is surely the case if we are trying to make a planet or moon.
Here is anther interesting UV mapping consideration ... I might need to look into ... not sure how Wings3D sets or handles UVs over-runs.
http://gamedev.stackexchange.com/questio...-less-than