ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LoopRez 스크립트 사용방법
    웹프로그래밍/LSL(세컨드라이프) 2008. 6. 25. 13:15
    반응형

    주름치마 나 진주목걸이 같은

    같은모양이 원형으로 반복적으로 구성된 아이템을 만들경우

    하나하나 만들어서 붙이기가 정말 힘들다.


    그러한 작업을 쉽게해주는 스크립트 이다.(무료로 공개되어 있는 스크립트이다)


     ////////////////////////////////////////////////////////////////////////////////
    // LoopRez v0.6, by Ged Larsen, 20 December 2006
    //
    // - rez a number of objects in an ellipse, whose size is determined by xRadius and yRadius
    // - all facing "outwards", along a tangent to the ellipse
    // - can set how much the objects flare outwards
    // - properly handles object rotation corrections (for example, X-axis 180 degree rotation helps for flexi-prim skirts)
    // - can also get a 'saddle' bend, to generate a bend that might help for necklaces (from Ariane Brodie)
    //
    // To use:
    // 1) create a prim that will contain this script and the object to use
    // 2) put the script into the prim
    // 3) create an object that will be used, and name it "Object"
    // 4) put "Object" into the prim containing the script, by dragging it from your inventory
    // 5) get out of Edit Mode, and touch the prim
    //
    // Random note:
    // - this version does NOT insure equal spacing of objects along the perimeter of the ellipse
    // - i.e., objects "bunch up" at the long ends of an ellipse; the effect should be acceptable for non-extreme ellipses
    // - even spacing of objects can be accomplished, but requires simulation of integral calculus, which slows down the script
    //
    // References:
    // - tangent formulas from: http://mathworld.wolfram.com/Ellipse.html


    ////////////////////////////////////////////////////////////////////////////////
    // CONFIGURATION PARAMETERS, change these to your liking

    string objectName = "test_obj"; // object to use; will need to be in the inventory of the prim containing this script
    integer numObjects = 12; // how many objects
    float xRadius = 0.6; // ellipse x-axis radius in meters
    float yRadius = 1.0; // ellipse y-axis radius in meters
    float flareAngle = 30.0; // how many DEGREES the bottom of object will flare outwards, the "poof" factor
    float bendCoefficient = 0.0; // makes a "saddle shape", bends DOWN this number of meters at extremes of X-axis
    vector rotOffset = <0.0, 0.0, 0.0>; // rotation offset in DEGREES -- fixes the rotation of ALL objects; for flexi prims, often you will want <180.0,>
    vector posOffset = <0.0, 0.0, 2.0>; // position offset


    ////////////////////////////////////////////////////////////////////////////////
    // No need to mess with anything below here

    makeLoop()
    {
    integer n; // which object is being placed
    float theta; // angle in radians
    vector pos; // position
    rotation rot; // rotation in quaternion format

    for(n = 0; n < numObjects; n++) {

    theta = TWO_PI * ( (float)n / (float)numObjects );

    pos.x = xRadius * llCos(theta); // ellipse: 2x xRadius meters wide
    pos.y = yRadius * llSin(theta); // ellipse: 2x yRadius meters wide
    pos.z = -bendCoefficient*llCos(theta)*llCos(theta); // saddle shape, bending downwards on X-axis
    pos = pos + llGetPos() + posOffset;

    rot = llEuler2Rot(<rotOffset.x*DEG_TO_RAD, rotOffset.y*DEG_TO_RAD, rotOffset.z*DEG_TO_RAD>); // user-chosen rotation offset correction
    rot = rot * llEuler2Rot(<0, -1*flareAngle*DEG_TO_RAD, 0>); // flare generation (poof)

    // the following make the objects face outwards properly for an ellipse; using theta alone is only correct for a circle
    // the scary formula calculates a unit vector TANGENTIAL to the ellipse, and llRotBetween is used to figure out how much the object needs to rotate to lie parallel to the tangent
    rot = rot * llRotBetween(<0.0,1.0,0.0>, <-1.0 * xRadius * llSin(theta) / ( llSqrt ( (yRadius*yRadius * llCos(theta) * llCos(theta)) + (xRadius*xRadius * llSin(theta) * llSin(theta))) ),yRadius * llCos(theta) / ( llSqrt ( (yRadius*yRadius * llCos(theta) * llCos(theta)) + (xRadius*xRadius * llSin(theta) * llSin(theta))) ),0.0>);
    if ( n== (numObjects/2) ) // LSL's implementation of llRotBetween at theta = pi radians is reversed at 180 degrees, so this manually corrects it
    rot = rot * llEuler2Rot( <0,PI,0> );

    llRezObject(objectName, pos, ZERO_VECTOR, rot, 0);
    }
    }

    default
    {
    touch_start(integer total_number)
    {
    if (llDetectedOwner(0) == llGetOwner())
    {
    makeLoop();
    }
    }
    }


    [사용법]

    1. 아무 오브젝트를 만들어 컨텐츠에 위 스크립트를 넣어놓고 필요할때 사용한다.

    - 나중에 알기쉽게 오브젝트 이름을 "LoopRez_obj" 등으로 해놓는다.


    2. 새로만들 오브젝트 한조각을 만든다.

    - 진주목걸이 라면 진주 한알.


    3. 1번의 LoopRez_obj를 바닥에 꺼내놓고 컨텐츠탭에 2번의 오브젝트를 집어넣는다.


    4. LoopRez_obj의 컨텐츠탭의 스크립트를 수정한다.

    - string objectName = "test_obj" // test_obj 를 2번에서 만든 오브젝트 이름으로 교체한다.

    - integer numObjects = 12; // 연속적으로 만들 오브젝트갯수
    - float xRadius = 0.6; // X 방향 반지름
    - float yRadius = 1.0; // Y 방향 반지름
    - float flareAngle = 30.0; // 오브젝트의 기울기 각도
    - float bendCoefficient = 0.0; // makes a "saddle shape", bends DOWN this number of meters at extremes of X-axis
    - vector rotOffset = <0.0, 0.0, 0.0>; // rotation offset in DEGREES -- fixes the rotation of ALL objects; for flexi prims, often you will want <180.0,>
    - vector posOffset = <0.0, 0.0, 2.0>; // position offset


    5. 편집상황을 종료하고 LoopRez 오브젝트를 한번 클릭한다.


    6. LoopRez 오브젝트 위로 4번의 조건에 따라 새로운 오브젝트가 만들어진다.

    - 이 결과물을 따로 Take 하여 사용하면 된다.

    반응형

    댓글

Designed by Tistory.