PDA

View Full Version : quickly add points


mradfo21
12-20-2010, 10:45 PM
hello everyone. i'm a lighting artist so my background isnt in computer programming - i hope you'll bare with me :)

I'm trying to come up with a way to efficicenty add points to models so they can have the same number of verticies and be used for blendshapes (this is just one part of a larger task)

i've come up with a way but it is dreadfully slow. right now i'm doing comparison's inside a while loop to determine the number of verticies - then performing a "polyPoke" on faces untill the vert count matches up. this takes FOREVER to run and this is just with two objects of similar topology - im potentially looking at objects with a million vert difference later on.

any suggestions for a quicker way? I've thought about writing a function that will generate different split polygon commands (only dividng one edge) - maybe that will be faster?

anyways, heres the code i wrote ( formatting is correct - pasting not a good idea..):





import pymel.core as pm
import random

def subdivideRandomFace(obj):
randFaceNum = str(random.randint(0,pm.polyEvaluate(obj, v = True)))
randFace = obj + ".f["+randFaceNum+"]"
pm.polyPoke(randFace, ch = 0)
return(randFace)


leadObj = pm.ls(sl = True)[0]
compareObj = pm.ls(sl = True)[1]

leadVertNum = pm.polyEvaluate(leadObj, v =True)
compareVertNum = pm.polyEvaluate(compareObj, v = True)

while leadVertNum != compareVertNum:
leadVertNum = pm.polyEvaluate(leadObj, v =True)
compareVertNum = pm.polyEvaluate(compareObj, v = True)
if leadVertNum == compareVertNum:
print "same number of verticies"
print "lead object vert = ", leadVertNum, " and compare object vert = ", compareVertNum
else:
print "different number of verticies"
print "lead object vert = ", leadVertNum, " and compare object vert = ", compareVertNum
subdivideRandomFace(leadObj)

mlefevre
12-20-2010, 11:14 PM
hi,

out of curiosity, does this actually work for you, once both objects share the same vert count? - i would have assumed it wouldn't, since the vertex order wouldn't be the same, but im not sure of the context.

NaughtyNathan
12-20-2010, 11:55 PM
I'm with Matt on this one, but either way, doing the same history operation multiple times in a loop on individual components is far slower and less efficient then performing ONE history opreration on a list of components.

try to make your loop simply construct the items to act upon, and then at the end simply act on them all simultaneously (once).

:nathaN

mradfo21
12-21-2010, 01:36 AM
matt your probably right - only one way to see..

great tip guys !!! thx !

mlefevre
12-21-2010, 05:22 PM
hi,

this takes an average of 18 seconds for a difference of 1.6 million vertices. (10 seconds for 1.1 million)
my computer died when i tried it on 6 million :(


{
int $undoState = 0;
if(`undoInfo -q -state`)
$undoState = 1; undoInfo -state 0;

$startTime = `timerX`;
string $sel[] = `ls -sl`;
int $src[] = `polyEvaluate -vertex $sel[0]`;
int $tgt[] = `polyEvaluate -vertex $sel[1]`;
int $faces[] = `polyEvaluate -face $sel[1]`;
int $i = $src[0] - $tgt[0];

if($i>0)
{
while($i>0)
{
if($i > $faces[0])
{
polyPoke -ch 0 ($sel[1] + ".f[0:" + ($faces[0]-1) + "]");
int $count[] = `polyEvaluate -vertex $sel[1]`;
$i -= ($count[0] - $tgt[0]);
}
else
{
polyPoke -ch 0 ($sel[1] + ".f[0:" + ($i-1) + "]");
$i=0;
}

$tgt = `polyEvaluate -vertex $sel[1]`;
$faces = `polyEvaluate -face $sel[1]`;
}

$totalTime = `timerX -startTime $startTime`;
print ("Total Time: "+$totalTime+"\n");
}
else
{ warning("pick source, then target.\n"); }

if($undoState)
undoInfo -state 1;
}

CGTalk Moderation
12-21-2010, 05:22 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.