OK ... it is fixed now. But I get to use my triangles ... and I was correct to use a nice foamy triangle mesh. There are reasons why it is better to have aribitrary than to have quad dominant arrangement following lat and long lines. I fixed the seam UVs.
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(),
timer_start(make_uvs),
MyAcc = fun(Fi,Acc) ->
Vs = wings_face:vertices_cw(Fi,We),
MyInner = fun(Vi, _Acc) ->
{X,Y,Z} = wings_vertex:pos(Vi,We),
U = (math:atan2(X,Z) + math:pi())/TWOPI, % range 0 - 1.0b
Temp = max(min(Y/(0.5*Dy),1.0),-1.0),
V = (math:asin(Temp) + math:pi()/2.0)/math:pi(),
[{U,V,Vi}|_Acc]
end,
UVs = lists:foldl(MyInner,[],Vs),
[{Fi,lists:sort(UVs)}|Acc]
end,
List = gb_sets:fold(MyAcc, [], wings_vertex:covered_faces(Set,We)),
timer_stop(make_uvs),
timer_report(make_uvs),
timer_start(apply_uvs),
MyApply = fun({Fi, UVs0}, Acc) ->
UVs =
case UVs0 of
[{U1,V1,Vi1},{U2,V2,Vi2},{U3,V3,Vi3}]
when (U1 =< 0.25 andalso 0.75 =< U2) ->
%erlang:display("Fix U1 !"),
[{U1+1.0,V1,Vi1},{U2,V2,Vi2},{U3,V3,Vi3}];
[{U1,V1,Vi1},{U2,V2,Vi2},{U3,V3,Vi3}]
when (U1 =< 0.25 andalso 0.75 =< U3) ->
%erlang:display("Fix U1,U2!"),
[{U1+1.0,V1,Vi1},{U2+1.0,V2,Vi2},{U3,V3,Vi3}];
_ -> UVs0
end,
MyApply2 = fun({U,V,Vi}, _Acc) ->
wings_va:set_vtx_face_uvs(Vi, [Fi], {U,V}, _Acc)
end,
lists:foldl(MyApply2, Acc, UVs)
end,
We2 = lists:foldl(MyApply, We, List),
timer_stop(apply_uvs),
timer_report(apply_uvs),
wings_shape:replace(WeID,We2,St);