Notifications
Clear all
[Closed] map channel to edit normals : need speed
Mar 30, 2014 11:38 pm
Hello there,
So, i’m trying to convert a map channel to vertex normals.
It works, but it’s slow (94sec for the sample file), and the time it takes is exponential. I guess there’s a lot of place for optimization.For instance, all polyop in the loop…
I upload a sample mesh here (max 2012)
https://dl.dropboxusercontent.com/u/13762052/cgtalk/mesh_normals.rar
I used bits from DenisT…
chan = 4
tObj = $
time01 = timestamp()
--return a tvert.pos from vert
fn getMapPos node chan vert =
(
-- if not polyop.getmapsupport node chan do polyop.setmapsupport node chan on
f = ((polyop.getfacesusingvert node vert) as array)[1]--get only 1 face used by vert
vv = polyop.getfaceverts node f
tv = polyop.getmapface node chan f
id = tv[finditem vv vert]
polyop.getMapVert node chan id
)
normal_array = #{}
setCommandPanelTaskMode mode:#modify
collapseStack tObj
mod_normals = Edit_Normals ()
addmodifier tObj mod_normals
_ConvertVertexSelection = mod_normals.ConvertVertexSelection
_Setnormal = mod_normals.Setnormal
numNorm = mod_normals.GetNumNormals()
mod_normals.SetSelection #{1..numNorm}
mod_normals.Unify()
mod_normals.MakeExplicit()
for i=1 to tObj.numverts do
(
normVal = getMapPos tObj chan i
disableRefMsgs();
_ConvertVertexSelection #{i} normal_array
normID = (normal_array as array)[1]--get 1 normal for the vert
_Setnormal normID normVal
enableRefMsgs();
)
update tObj
time02 = timestamp()
gc()
format "took %
" ((time02-time01)/1000)
On my channel 4 stand all my normals vector. Each face is exploded (result from a projection from another mesh). I can't weld them because obviously i lose the .z information.
I only have 1 normal per vertex, so i thought i could make small optimisation by looking in only 1 mapface.
Thanks for hints !
Edit: ok, with
disableRefMsgs();
enableRefMsgs();
It takes 6 sec instead of 94.
1 Reply
Mar 30, 2014 11:38 pm
Just found out your Mini challenge #2 was specificaly about it.
http://forums.cgsociety.org/showthread.php?t=981154
Cool!