Difference between revisions of "Open Prim Animator/Import-Export"
(comments for names property.) |
(moar documentation) |
||
Line 14: | Line 14: | ||
*/ | */ | ||
list names; | list names; | ||
//! place-holder for all prim positions | |||
list pos; | list pos; | ||
//! place-holder for all prim rotations | |||
list rot; | list rot; | ||
//! place-holder for all prim scales | |||
list size; | list size; | ||
//! used to communicate with the core OPA script to trigger an import. | |||
key import = "6b78fcc8-e147-4105-99a6-ff19b4bf559d"; | key import = "6b78fcc8-e147-4105-99a6-ff19b4bf559d"; | ||
//! used to communicate with the core OPA script to trigger an export. | |||
key export = "7c2ca168-2b64-4836-8727-8e62b78dbd44"; | key export = "7c2ca168-2b64-4836-8727-8e62b78dbd44"; | ||
//! spits out the export document to chat so the user can copypasta to a notecard to allow the animation frames to be persisted. | |||
export_string(string _export_string){ | export_string(string _export_string){ | ||
integer s = 249; | integer s = 249; | ||
Line 32: | Line 42: | ||
} | } | ||
//! unlike (string)foo, truncate_float() attempts to "minify" the string so keep the size of the export document down. | |||
/** | |||
* 1.0 would be converted to "1" | |||
* 0.1 would be converted to ".1" | |||
*/ | |||
string truncate_float(float foo){ | string truncate_float(float foo){ | ||
if(foo == 0.0){ | if(foo == 0.0){ | ||
Line 48: | Line 63: | ||
} | } | ||
//! unlike (string)foo, truncate_vector() attempts to "minify" the string so keep the size of the export document down. | |||
//! @see truncate_float() | |||
string truncate_vector(vector foo){ | string truncate_vector(vector foo){ | ||
if(foo == ZERO_VECTOR){ | if(foo == ZERO_VECTOR){ | ||
Line 59: | Line 76: | ||
} | } | ||
//! unlike (string)foo, truncate_rotation() attempts to "minify" the string so keep the size of the export document down. | |||
string truncate_rotation(rotation foo){ | string truncate_rotation(rotation foo){ | ||
if(foo == ZERO_ROTATION){ | if(foo == ZERO_ROTATION){ |
Revision as of 03:40, 14 December 2011
<lsl> //! @brief Animation export script for http://wiki.secondlife.com/wiki/Open_Prim_Animator /**
- @author SignpostMarv Martin
- /
//! Storing the names in exports allows us to remap links according to their current state /**
- we want to store the names because there are circumstances where the link order can change-
- TPV object import/export
- accidentally delinking objects etc.
- Once an import has been parsed, the script checks it against the current object state to avoid the wrong prims being animated.
- Since OPA doesn't animate prim cut/twist etc., this is essential to avoid any messed up animations.
- /
list names;
//! place-holder for all prim positions list pos;
//! place-holder for all prim rotations list rot;
//! place-holder for all prim scales list size;
//! used to communicate with the core OPA script to trigger an import. key import = "6b78fcc8-e147-4105-99a6-ff19b4bf559d";
//! used to communicate with the core OPA script to trigger an export. key export = "7c2ca168-2b64-4836-8727-8e62b78dbd44";
//! spits out the export document to chat so the user can copypasta to a notecard to allow the animation frames to be persisted. export_string(string _export_string){
integer s = 249; while(llStringLength(_export_string) > s){ llOwnerSay("\n" + llGetSubString(_export_string,0,(s-1))); _export_string = llGetSubString(_export_string,s,-1); } if(llStringLength(_export_string) > 0){ llOwnerSay("\n" + _export_string); }
}
//! unlike (string)foo, truncate_float() attempts to "minify" the string so keep the size of the export document down. /**
- 1.0 would be converted to "1"
- 0.1 would be converted to ".1"
- /
string truncate_float(float foo){
if(foo == 0.0){ return "0"; }else if(foo == (float)((integer)foo)){ return (string)((integer)foo); } string bar = (string)foo; while(llGetSubString(bar,-1,-1) == "0"){ bar = llGetSubString(bar,0,-2); } if(llGetSubString(bar,-1,-1) == "."){ bar = llGetSubString(bar,0,-2); } return bar;
}
//! unlike (string)foo, truncate_vector() attempts to "minify" the string so keep the size of the export document down. //! @see truncate_float() string truncate_vector(vector foo){
if(foo == ZERO_VECTOR){ return "<0,0,0>"; } string bar = "<"; bar += truncate_float(foo.x) + ","; bar += truncate_float(foo.y) + ","; bar += truncate_float(foo.z) + ">"; return bar;
}
//! unlike (string)foo, truncate_rotation() attempts to "minify" the string so keep the size of the export document down. string truncate_rotation(rotation foo){
if(foo == ZERO_ROTATION){ return "<0,0,0,1>"; } string bar = "<"; bar += truncate_float(foo.x) + ","; bar += truncate_float(foo.y) + ","; bar += truncate_float(foo.z) + ","; bar += truncate_float(foo.s) + ">"; return bar;
}
default{
link_message(integer s, integer n, string m, key k){ if(k == export){ integer i; integer j; if(n == 1){ names = llParseString2List(m,["|"],[]); }else if(n == 2){ pos = llParseString2List(m,["|"],[]); j=llGetListLength(pos); for(i=0;i<j;++i){ pos = llListReplaceList(pos,[(vector)llList2String(pos,i)],i,i); } }else if(n == 3){ rot = llParseString2List(m,["|"],[]); j=llGetListLength(rot); for(i=0;i<j;++i){ rot = llListReplaceList(rot,[(rotation)llList2String(rot,i)],i,i); } }else if(n == 4){ size = llParseString2List(m,["|"],[]); j=llGetListLength(size); for(i=0;i<j;++i){ size = llListReplaceList(size,[(vector)llList2String(size,i)],i,i); } } if(names != [] && pos != [] && rot != [] && size != []){
llOwnerSay("Exporting:"); export_string("rootscale:" + truncate_vector(llGetScale())); export_string("names:" + llDumpList2String(names,"|")); list bar = []; j= llGetListLength(pos); for(i=0;i<j;++i){ bar += truncate_vector(llList2Vector(pos,i)); } export_string("pos:" + llDumpList2String(bar,"|")); bar = []; for(i=0;i<j;++i){ bar += truncate_rotation(llList2Rot(rot,i)); } export_string("rot:" + llDumpList2String(bar,"|")); bar = []; for(i=0;i<j;++i){ bar += truncate_vector(llList2Vector(size,i)); } export_string("size:" + llDumpList2String(bar,"|")); bar = []; llMessageLinked(LINK_THIS,0,"XDmenu",NULL_KEY); llResetScript(); } }else if(k == import && n == -1){ llOwnerSay("importing"); integer i; integer j=llGetListLength(pos); for(i=0;i<j;++i){ llMessageLinked(s,i,llDumpList2String([llList2Vector(pos,i),llList2Rot(rot,i),llList2Vector(size,i)],"|"),import); } llMessageLinked(LINK_THIS,0,"XDmenu",NULL_KEY); llResetScript(); } }
} </lsl>