Results 1 to 8 of 8

Thread: Script idea: Spawnpoint placement

  1. #1

    Script idea: Spawnpoint placement

    For animators, it'd be uber handy to have this functionality:

    1) Place a null named "spawnpoint" and place it near where you are working.

    2) Have available a command which will send the selected object to the spawnpoint using world coordinates.

    So, whenever something new is loaded into the scene, you'd be able to select an object or multiple objects and send them all to the spawn point.

    I never really liked the parent in place trick for placing things in scenes.
    Professional-level 3d training: Ryan's Lightwave Learning
    Plugin Developer: RR Tools for Lightwave
    IKB manual

  2. #2
    Registered User tyrot's Avatar
    Join Date
    Mar 2006
    Location
    in lights
    Posts
    2,062
    +1

  3. #3
    automator of tasks xchrisx's Avatar
    Join Date
    Jul 2003
    Location
    Nevada
    Posts
    593
    Blog Entries
    6
    feel free to try this. I wrote i while being half awake at 3am so if there are any bugs let me know . hopefully its straight forward to use. I also commented it, so if someone wants to pick it apart feel free.


    save as "spawnpoint.ls"
    Code:
    @warnings
    @version 2.2
    @script generic
    @name spawnpoint
    
    /*
        by chris peterson
        chrisepeterson@gmail.com
        http://www.chrisepeterson.com
        july 20, 2013
        
        This script will create a key for the selected objects at the spawn point location
    	either at frame 0 or the current frame.
    	
    	original request: http://forums.newtek.com/showthread.php?136536-Script-idea-Spawnpoint-placement
    */
    
    generic
    {
    	foundSpawn = false;
    	spawnPointPosition = @<0,0,0>@;
    	autoKeyWasOn = false;
    	
    	curSelection = Scene().getSelect(MESH);
    	if(size(curSelection) > 0) // make sure selection is not empty
    	{
    		vTime = recall("vTime",1);
    		vSpawnPoint = recall("vSpawnPoint",nil);
    		vSpawnTime = recall("vSpawnTime",1);
    		
    		reqbegin("Spawn Point");
    		reqsize(341,180);
    
    		c1 = ctlmeshitems("Spawn Point",vSpawnPoint);
    		ctlposition(c1,26,25,292,18);
    		
    		c2 = ctlchoice("Use Spawn At",vSpawnTime,@"Frame 0","Current Frame"@);
    		ctlposition(c2,12,56,306,25);
    
    		c3 = ctlchoice(" Key Frame At",vTime,@"Frame 0","Current Frame"@);
    		ctlposition(c3,12,82,306,25);
    
    		return if !reqpost();
    
    		vSpawnPoint = getvalue(c1);
    		vSpawnTime = getvalue(c2);
    		vTime = getvalue(c3);
    		store("vTime", vTime);
    		store("vSpawnTime", vSpawnTime);
    
    		reqend();
    	
    	
    		// If nil was selected in the pulldown list of objects
    		if(vSpawnPoint == nil)
    		{
    			warn("No spawn point chosen.");
    			return;
    		}
    		
    		SelectAllObjects();
    		allObjectSelection = Scene().getSelect(MESH); // get a list of all objects in the scene to find the spawn point
    		for(i=1;i<=size(allObjectSelection);i++) // loop through all object list
    		{
    			if(allObjectSelection[i].name == vSpawnPoint.name)
    			{	
    				// found spawn point, set the flag that we found it and get its position at frame 0
    				if (vSpawnTime == 1)
    				{
    					// If they want to use spawn point at frame 0
    					spawnPointPosition = allObjectSelection[i].getWorldPosition(0);
    				}
    				else
    				{
    					// If they want to use spawn point at the current frame
    					spawnPointPosition = allObjectSelection[i].getWorldPosition(Scene().currenttime);
    				}
    				foundSpawn = true;
    			}
    		}
    		
    		if(foundSpawn == true) // if there is a spawn point
    		{
    			if(Scene().generalopts[7]) // check to see if autokey is on
    			{
    				AutoKey();
    				autoKeyWasOn = true;
    			}
    			for(k=1;k<=size(curSelection);k++)
    			{
    				SelectItem(curSelection[k].id);	// select the object
    				Position(spawnPointPosition);// set the position
    				if(vTime == 1)
    				{
    					// If they want to create a key at frame 0
    					CreateKey(0);
    				}
    				else
    				{
    					// If they want to create a key at current frame
    					CreateKey(Scene().currenttime);
    				}
    			}
    			if(autoKeyWasOn) // check to see if autokey was on and if it was, turn it back on now
    			{
    				AutoKey();
    			}
    		}
    		else
    		{
    			info("There is no spawn point in the scene.");
    		}
    		
    		
    		// Reselect the original selection
    		SelectItem(curSelection[1].id);
    		if(size(curSelection) > 1)
    		{
    			for(j=2;j<=size(curSelection);j++)
    			{
    				AddToSelection(curSelection[j].id);
    			}	
    		}
    	}
    	
    }
    My Lscript Collection | LinkedIn
    3D Generalist IGT

  4. #4
    Registered User tyrot's Avatar
    Join Date
    Mar 2006
    Location
    in lights
    Posts
    2,062
    mighty chris strikes back! wow

  5. #5
    This is killer! Thank you so much for the script and source code!

    I made some small changes to the source code to tailor the script to my needs:

    -I removed the UI and removed the if statements such that the program always assumes my choices will be the same (The spawn point is always named "Spawn Point", and that I always want objects to be sent to a location using frame 0). This way, all I have to do is drop a null object called "Spawn Point" into a scene, position it, and anything I have selected when the script is run will be sent there without prompting.

    -I put the source code for these changes here in case anyone prefers a non-UI version.

    Your script is also a handy reference/learning tool for things I consider commonly needed functions. Again, thank you!

    EDIT: Your original code should be submitted to the Lightwave plugin database... it is that useful.

    Code:
    @warnings
    @version 2.2
    @script generic
    @name spawnpoint
    
    /*
        by chris peterson
        chrisepeterson@gmail.com
        http://www.chrisepeterson.com
        july 20, 2013
        
        This script will create a key for the selected objects at the spawn point location
    	either at frame 0 or the current frame.
    	
    	original request: http://forums.newtek.com/showthread.php?136536-Script-idea-Spawnpoint-placement
    	
    	MODIFICATION by Ryan Roye:
    	
    	This script has been slightly modified from the original and does not prompt the user for options. 
    	USAGE: Create a null called "Spawn Point", and using the spawnpoint script will send any selected items to that null at frame 0.
    	
    */
    
    generic
    {
    	foundSpawn = false;
    	spawnPointPosition = @<0,0,0>@;
    	autoKeyWasOn = false;
    	
    	curSelection = Scene().getSelect(MESH);
    	if(size(curSelection) > 0) // make sure selection is not empty
    	{
    		vTime = recall("vTime",1);
    		vSpawnPoint = recall("vSpawnPoint",nil);
    		vSpawnTime = recall("vSpawnTime",1);
    		
    		reqbegin("Spawn Point");
    		reqsize(341,180);
    
    		c1 = ctlmeshitems("Spawn Point",vSpawnPoint);
    		ctlposition(c1,26,25,292,18);
    		
    		c2 = ctlchoice("Use Spawn At",vSpawnTime,@"Frame 0"@);
    		ctlposition(c2,12,56,306,25);
    
    		c3 = ctlchoice(" Key Frame At",vTime,@"Frame 0"@);
    		ctlposition(c3,12,82,306,25);
    
    		//return if !reqpost();
    
    		vSpawnPoint = getvalue(c1);
    		vSpawnTime = getvalue(c2);
    		vTime = getvalue(c3);
    		store("vTime", vTime);
    		store("vSpawnTime", vSpawnTime);
    
    		reqend();
    		
    		SelectAllObjects();
    		allObjectSelection = Scene().getSelect(MESH); // get a list of all objects in the scene to find the spawn point
    		for(i=1;i<=size(allObjectSelection);i++) // loop through all object list
    		{
    			if(allObjectSelection[i].name == "Spawn Point")
    			{	
    				// found spawn point, set the flag that we found it and get its position at frame 0
    					// If they want to use spawn point at frame 0
    					spawnPointPosition = allObjectSelection[i].getWorldPosition(0);
    				foundSpawn = true;
    			}
    		}
    		
    		if(foundSpawn == true) // if there is a spawn point
    		{
    			if(Scene().generalopts[7]) // check to see if autokey is on
    			{
    				AutoKey();
    				autoKeyWasOn = true;
    			}
    			for(k=1;k<=size(curSelection);k++)
    			{
    				SelectItem(curSelection[k].id);	// select the object
    				Position(spawnPointPosition);// set the position
    					// If they want to create a key at frame 0
    					CreateKey(0);
    			}
    			if(autoKeyWasOn) // check to see if autokey was on and if it was, turn it back on now
    			{
    				AutoKey();
    			}
    		}
    		else
    		{
    			info("There is no spawn point in the scene.");
    		}
    		
    		
    		// Reselect the original selection
    		SelectItem(curSelection[1].id);
    		if(size(curSelection) > 1)
    		{
    			for(j=2;j<=size(curSelection);j++)
    			{
    				AddToSelection(curSelection[j].id);
    			}	
    		}
    	}
    	
    }
    Last edited by Ryan Roye; 07-20-2013 at 12:52 PM.
    Professional-level 3d training: Ryan's Lightwave Learning
    Plugin Developer: RR Tools for Lightwave
    IKB manual

  6. #6
    automator of tasks xchrisx's Avatar
    Join Date
    Jul 2003
    Location
    Nevada
    Posts
    593
    Blog Entries
    6
    Glad it helped.
    My Lscript Collection | LinkedIn
    3D Generalist IGT

  7. #7
    Valiant NewTeKnight Matt's Avatar
    Join Date
    Feb 2003
    Location
    San Antonio, Texas, USA
    Posts
    12,944
    Ahhh you beat me to it Chris!

    Nice work and thanks for helping the community out like this!
    LightWave UX Designer
    LightWave 3D Group
    A Division of NewTek Inc.
    ______________________________________________
    www.pixsim.co.uk : LightWave Video Tutorials & Tools

    "Beautiful things are easier to use" - Don Norman


  8. #8
    automator of tasks xchrisx's Avatar
    Join Date
    Jul 2003
    Location
    Nevada
    Posts
    593
    Blog Entries
    6
    I like to give back to the community when I can
    My Lscript Collection | LinkedIn
    3D Generalist IGT

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •