PDA

View Full Version : access to the modifier : increase the speed


prettyPixel
03-06-2005, 03:50 PM
I have found a little trick to increase the speed in my script because the acces to the modifier Unwrap is really slow.

It's mentioned in the help file as "Increasing Performance when searching for Interfaces and Methods"
This is really faster !

The trick consist to assign variable instead of the modifier in a for...loop.
for example (before and without optimisation)
startTime=timeStamp()
for obj in selection do
(
addModifier obj (Unwrap_UVW ())
for f=1 to obj.numFaces do
(
nVerts=obj.modifiers[1].unwrap.numberPointsInFace f
for v=1 to nVerts do
(
idx=obj.modifiers[1].unwrap.getVertexIndexFromFace f v
coord=obj.modifiers[1].unwrap.GetVertexPosition 0f idx
coord+=[0.5,0.5,0]
obj.modifiers[1].unwrap.setFaceVertex coord f v false
)--for v
)--for f
obj.modifiers[1].enabledInViews=true
)--for obj
endTime=timeStamp()
format "\nProcessing took % seconds\n" ((endTime-startTime) / 1000.0)
max views redraw
Processing took 0.796 seconds (with a box of 10x10x10)


And after optimisation:
startTime=timeStamp()
for obj in selection do
(
addModifier obj (Unwrap_UVW ())
-- define shortcuts
objUnwrap=obj.modifiers[1].unwrap
uvNbPointsInFace=objUnwrap.numberPointsInFace
uvGetVtxPos=objUnwrap.GetVertexPosition
uvGetVtxFromFace=objUnwrap.getVertexIndexFromFace
uvSetFaceVtx=objUnwrap.setFaceVertex
for f=1 to obj.numFaces do
(
nVerts=uvNbPointsInFace f
for v=1 to nVerts do
(
idx=uvGetVtxFromFace f v
coord=uvGetVtxPos 0f idx
coord+=[0.5,0.5,0]
uvSetFaceVtx coord f v false
)--for v
)--for f
obj.modifiers[1].enabledInViews=true
)--for obj
endTime=timeStamp()
format "\nProcessing took % seconds\n" ((endTime-startTime) / 1000.0)
max views redraw
Processing took 0.11 seconds


0.796/0.11 = 7.2 xfaster !

It's in the manual but I discover it today :)
Is it necessary to read the documentation? mmmhh? ... noooo

CGTalk Moderation
03-06-2005, 03:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.