Jump to content

Looping llSetLinkPrimitiveParams for local positioning and rotation


CadenzaInVivace
 Share

You are about to reply to a thread that has been inactive for 3198 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to "animate" (though it's only 1 frame) a rather prim-heavy object through a HUD I made (HUD does other things, like texturing). Every single link of each state of the object is positioned manually, so I was wondering if there's a quicker way to save the local position/rotation of each link, other than writing a huge wall of:

count = llGetNumberOfPrims();
    
	integer j;
	
    for ( j=1; j<=count; ++j)
		
		vector LocalPos = llGetLocalPos();
		vector LocalRot = llGetLocalRot();
		llSay(0, (string)j + " position:" + (string)LocalPos);
		llSay(0, (string)j + " rotation:" + (string)LocalRot);
		
	}

}

 

After retrieving its local pos/rot then dumping it, then manually write it in:

if (selection == "state1")
{
	llSetLinkPrimitiveParamsFast(1, [
                PRIM_LOCAL_POS, <x,y,z>,
				PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(2, [
                PRIM_LOCAL_POS, <x,y,z>,
				PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(3, [
                PRIM_LOCAL_POS, <x,y,z>,
				PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(14, [
                PRIM_LOCAL_POS, <x,y,z>,
				PRIM_LOCAL_ROT, <x,y,z>]);
				
	...//tons more links
	...
				
}

else if (selection == "state2") //note the link numbers affected for each state may be different
{
	llSetLinkPrimitiveParamsFast(3, [
                PRIM_LOCAL_POS, <x,y,z>,
		PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(15, [
                PRIM_LOCAL_POS, <x,y,z>,
		PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(17, [
                PRIM_LOCAL_POS, <x,y,z>,
		PRIM_LOCAL_ROT, <x,y,z>]);
				
	llSetLinkPrimitiveParamsFast(10, [
                PRIM_LOCAL_POS, <x,y,z>,
		PRIM_LOCAL_ROT, <x,y,z>]);
				
	...//tons more links
	...
				
}

The links for each state are different, though some may overlap, there's no pattern since I'm manually positioning each individual link myself for each state.

Is there a quicker way, or shorter way, to do this other than code in every single POS/ROT by hand? The script will be really really long if I have to write in 2 vector sets for each link for each state. Is there some way to automatically retrieve the POS/ROT from llGetLocalPos/llGetLocalRot, identify what link it is, then translate it into a llSetLocalRot function for the correct link?

Link to comment
Share on other sites

For starters, you can get the two bits of information a lot quicker by using lists and asking for both bits of information at once, such as

list params = llGetLinkPrimitiveParams(linknum, [PRIM_POS_LOCAL, PRIM_ROT_LOCAL]);

//This then can be converted to a string bystring details = llDumpList2String(params, ",");//And the string can then be written to the description field for each child byllSetLinkPrimitiveParams(linknum, [OBJECT_DESC, [details]);

 

This method gives you a way of accessing the default position and rotation of each child should you need to set everything back to a sane starting point.

 

But what I recommend you try is making up a strided list of the local pos and rots for each child of the linkset,

// declare as a global

list allParams = [];// ( then assume numPrims to have been set to the number of prims)for( ii = 1; ii <= numPrims; ii++){ list params = llGetLinkPrimitiveParams(ii, [PRIM_POS_LOCAL, PRIM_ROT_LOCAL]); allParams += params;}// later on when you want to set pos and rot for child thisPrim

primInd = thisPrim - 1; // remember list element 0&1 is for prim 1, 2&3 prim 2list posAndRot = [PRIM_POS_LOCAL, llList2Vector(allParams, primInd*2),
PRIM_ROT_LOCAL, llList2Rot(allParams, primInd*2+1)];
llSetLinkPrimitiveParamsFast(thisPrim, posAndRot);

 

 The messy part occurs because the list elements start from 0, but in linksets, the prim numbers start from 1, therefore the prim number has to be decremented first before doubling it to get to the correct starting point in the list. You can if you want compact all that into the list generation line itself, but it isn't so clear to see what is going on.

 

You could also maintain several lists this way, each containing the prims in different positions, and choose between them

 

 

Link to comment
Share on other sites

See also PRIM_LINK_TARGET which will enable one long parameter list for each animation state, so only a single call is needed to llSetLinkPrimitiveParamsFast() instead of looping through each link.

Collecting all the parameters into that list, however, will involve looping through each link, and possibly removing any links that remain unchanged through the animation.

Also, I'm not sure about starting with link #1, the root prim, which is kinda different, depending on what this object is intended to do.

Link to comment
Share on other sites

You got in there in mid-edit while I was de-typoing my post :)

I agree that PRIM_LINK_TARGET would be the ultimate way for the OP to go, but I was posting in the middle of tea and phone calls and kept it simple.

 

Yes also to prim 1 and asking for local figures, if it's attached it does work with locals, but I can't remember now what the pos and rot local returns when the link set is rezzed not worn, and I'm not inworld to actually check. My recollection is that the pos and rot are the same as when PRIM_POSITION and PRIM_ROTATION are used.

 

That's like 5 edits to get rid of typos, I really must get myself a secretary to take dictation, mustn't I?

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3198 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...