10-22-2014, 08:53 PM
considering you only need extract the vertex index from VPos, why not use array:fold instead of to convert the array to a lists which from the tuple element you want get the index?
Considering the use of the API by the wings3d itself I think that use wings_va is the right way to avoid problems with any change made to vertex color attribute.
If the implementation is made in a importer I think it's possible to improve it a little by removing a intermediate function call - the parameters are copied once less: (that makes sense?! )
it came from wings_vaet_vertex_color_1. maybe you could test it.
Code:
...
MyAcc = fun(Vi, _Value, We) ->
wings_va:set_vertex_color(gb_sets:singleton(Vi), lists:nth(Vi+1,Vc) , Acc)
end,
We1 = array:foldl(MyAcc, We, VPos)
...
If the implementation is made in a importer I think it's possible to improve it a little by removing a intermediate function call - the parameters are copied once less: (that makes sense?! )
Code:
...
#we{vp=VPos} = We = wings_we_build:we(Fs, Vs, He),
MyAcc = fun(Vi, _Value, #we{lv=Lva0,rv=Rva0} = We0) ->
{Lva,Rva} = wings_vertex:fold(
fun(Edge, _Face, Rec0, {Lv,Rv}) ->
case Rec0 of
#edge{vs=Vi} ->
{set_color(Edge, Color, Lv),Rv};
#edge{ve=Vi} ->
{Lv,set_color(Edge, Color, Rv)}
end,
end, {Lva0,Rva0}, Vi, We),
We0#we{lv=Lva,rv=Rva}
end,
We1 = array:foldl(MyAcc, We, VPos),
...