Spawn locators on object verts?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 05 May 2013   #1
Spawn locators on object verts?

Hi, does anyone know how to spawn locators on an objects vertices? I'd like to create an array of lights in after effects and need locators where the polygons verts are. Thanks
 
Old 05 May 2013   #2
I posted a question about my attempts to do this with cubes is here:
http://forums.cgsociety.org/showthr...?f=89&t=1060020
The script I used with the fix suggested by haggi and Naughty Nathan is here:
{
	// select verts and run
	
	string $allVerts[] = `ls -sl -fl`;
	string $eachVert;
        int $i = 1;
    
     for ($eachVert in $allVerts)
     {
	//Get vertex world position
	float $vertPos[] = `pointPosition -w $eachVert`;
	
	//Create a cube for each vert
        string $cube[] = `polyCube -name ("vertCube_"+$i+"_PLY")`;
	
	//Sets the translates of the locators to the stored variables
	setAttr ($cube[0] + ".translateX") $vertPos[0];
	setAttr ($cube[0] + ".translateY") $vertPos[1];
	setAttr ($cube[0] + ".translateZ") $vertPos[2];
	$i++;
     }
}


I think you can take it from there.
Hope that helps
~Ben
 
Old 05 May 2013   #3
Thanks Ben. I tried to modify it to work with a locator but no dice (i'm new to MEL). Could you please point me in the right direction?
 
Old 05 May 2013   #4
no worries, the basic idea is that anything with a $ in front is a variable so the actual name of it doesn't matter...the value of the variable is all that matters.
In this case all you need to do is change the line:
string $cube[] = `polyCube -name ("vertCube_"+$i+"_PLY")`;

to

string $cube[] = `spaceLocator -name ("vert_"+$i+"_LOC")`;

Technically, you don't even need to change the -name section, but this should give you an idea how to customize the names of your locators.
Hope that helps.
~Ben
 
Old 05 May 2013   #5
i posted an answer on your reddit post:


 // copy the script to a mel window, change start/end frames, select your vertices and run
 int $start = 0;
 int $end = 10;
 string $vertices[] = `ls -sl -fl`;
 string $locators[];
 for($v in $vertices){

     string $newLoc[] = `spaceLocator`;
     $locators[size($locators)] = $newLoc[0];
 }
 for($i=$start;$i<=$end;$i++){
     currentTime $i;
     for($j = 0; $j<size($vertices);$j++){
         float $pos[] = `xform -q -ws -t $vertices[$j]`;
         setAttr ($locators[$j]+".translate") $pos[0] $pos[1] $pos[2];
         setKeyframe ($locators[$j]+".translate");
     }
 }
__________________
maya@reddit r/maya
 
Old 05 May 2013   #6
Whoa, I didn't know time was involved.
Deep thoughts.
 
Old 05 May 2013   #7
Thank you both, the scripts work like a treat!
 
Old 05 May 2013   #8
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:08 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.