Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!

Monday 4 February 2013

LScript - Modeler_Poke

LScript (Modeler) that replicates poke in Maya to split polygons with an averaged center.

Changes

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Poke

    Modeler_Poke.ls

*/

@version 2.2
@warnings
@script modeler
@name *Poke

    // Title
    sTitle = "*Poke";

    // Version
    sVersion = "v1.1";

main
{
    // Selection - Polygon (DIRECT)
    selmode(DIRECT);
    iPolyCount = polycount();

    if(iPolyCount[1] < 1) error("No polygons selected.");

    undogroupbegin(); // Undo

    editbegin();

    if(iPolyCount[1] >= 1)
      { 
       
      foreach(aPolygon,polygons)
       {
        aPoints = polyinfo(aPolygon); 
        rempoly(aPolygon);
        vAverage = <0.0,0.0,0.0>;
        for(iPointCount = 2; iPointCount <= sizeof(aPoints); iPointCount++)
          {
          vAverage += pointinfo(aPoints[iPointCount]);  
          }
        // Resize by points
        vAverage *= 1 / (sizeof(aPoints) - 1);
        // Make new point
        iAverage = addpoint(vAverage); // Returns ID

        // Add polygons
        for(iPointCount = 2; iPointCount <= sizeof(aPoints) - 1; iPointCount++)
          {
          aNewPolygon[1] = aPoints[iPointCount]; 
          aNewPolygon[2] = aPoints[iPointCount + 1]; 
          aNewPolygon[3] = iAverage; 
          addpolygon(aNewPolygon);  
          }
        aNewPolygon[1] = aPoints[sizeof(aPoints)]; 
        aNewPolygon[2] = aPoints[2]; 
        aNewPolygon[3] = iAverage; 
        addpolygon(aNewPolygon);             
        }

      }

    editend();

    undogroupend(); // Undo

    info(iPolyCount[1]," poly(s) poked.");
}


All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

4 comments: