Lscript Question

Kryslin

Active member
Ok, another question...

Both selPoint() and selPolygon() have a minor parameter of POINTNDX and POLYNDX, respectively.

What is this? What array am I supplying indices to the selection command? Is this global, or relative to the selection I may be working with? I'm more curious than anything...

I mean, I get POINTID and POLYID, and I normally use these all the time, inside an editbegin() and editend() pair. So what are these poly and point indices?
 

ernpchan

Active member
I believe is it the id of the point/polygon. I would assume it's global to the model since ids don't change dynamically.
 

Sensei

TrueArt Support
Points can be identified by index (starting from 0..point_count-1) or by LWPntID pointer.
Polygons can be identified by index (starting from 0...poly_count-1) or by LWPolID pointer.
If you have address (i.e. outside of 0..count-1) it's the second one.
 

Matt

Valiant NewTeKnight
This is not an exhaustive list, but this is a scratch pad of some poly / point stuff (it's not a script you can run as is, just a collection of stuff) that I kept lying around, might help.

Code:
@version 2.13
@warnings
@name "Point and Polygon Routines"

main
{
    // Selected including nothing selected = all selected rule
    selmode( USER );

    // Direct selections only
    selmode(DIRECT);

    // Selected everything regardless of selection
    selmode( GLOBAL );

    // 0 = Point / 1 = Poly / 2 = Volume / 3 = Edge
    selection_mode = getmode("SELECTION");

    // 0 = Off / 1 = On
    symmetry_mode = getmode("SYMMETRY");

    // 0 = Mouse / 1 = Pivot / 2 = Selection / 3 = Pivot
    action_center_mode = getmode("ACTIONCENTER");

    // Get the point count
    point_count = pointcount();

    // Need minimum of two points
    if(point_count < 2)
    {
        error("You need to select at least 2 points");
    }

    // Get selected poly information
    selectedPolys = polycount();

    // Total number of selected polygons
    selectedTotalPolys = selectedPolys[1];

    // Total number of selected polygons with 1 point
    selected1PointPolys = selectedPolys[2];

    // Total number of selected polygons with 2 points
    selected2PointPolys = selectedPolys[3];

    // Total number of selected polygons with 3 points
    selected3PointPolys = selectedPolys[4];

    // Total number of selected polygons with 4 points
    selected4PointPolys = selectedPolys[5];

    // Total number of selected polygons more than 4 points
    selectedMoreThan4PointPolys = selectedPolys[6];



    // Storing polygon information
    var polyIDs         = nil;
    var polyTypes       = nil;
    var polyPartTags    = nil;

    editbegin();
    foreach(poly, polygons)
    {
        polyIDs         += poly;
        polyTypes       += poly.type();
        polyPartTags    += poly.tag("PART");
    }
    editend();


@script modeler
@warnings
@name "Part Name"

main
{
    selmode(DIRECT);
    selectedItems = polycount();

    if(selectedItems[1] == 0)
    {
        error("Nothing Selected");
    }

    editbegin();
        for(loop = 1; loop <= selectedItems[1]; loop++)
        {
            partName = polygons[loop].tag("PART");

            info("Part Name: ", partName);
        }
    editend();
}


    // Inspecting polygon information
    var polyNumber = 1;

    editbegin();
    // Get ID of polygon
    polyID              = polygons[polyNumber];

    // Number of points that make up the poly
    numPointsInPoly     = polypointcount( polygons[polyNumber] );

    // The vector for the poly normal
    polyNormal          = polynormal( polygons[polyNumber] );

    // Get the surface assigned to the poly
    polyInformation     = polyinfo( polygons[polyNumber] );
    polySurface         = polyInformation[1];

    // Store point IDs and positions for polygon
    // Starts at 2 because the surface name is the first entry in the array that polyinfo() returns
    // Every entry in the array after that is the point ID
    for(loop = 2; loop <= numPointsInPoly; loop++)
    {
        polyPointIDArray    += polyInformation[loop];

        // Point into gets the points XYZ location
        polyPointPosArray   += pointinfo(polyInformation[loop]);
    }

    editend();



    // Selecting and deselecting poly selections

    // Select a poly by its ID
    selpolygon( SET, POLYID, polyIDs[1] );

    // Select all polys by their ID using a custom function
    select_poly_ids( polyIDs );

    // Select all polys
    selpolygon( SET );

    // Deselect a poly by its ID
    selpolygon( CLEAR, POLYID, polyIDs[1] );

    // Deselect all polys by their ID using a custom function
    deselect_poly_ids( polyIDs );

    // Clear all polys
    selpolygon( CLEAR );

    // Invert selections
    selinvert();

    // Hiding selected polys
    selhide( SELECTED  );

    // Hiding unselected polys
    selhide( UNSELECTED  );

    // Unhiding hidden polys
    selunhide();



    // Selecting and deselecting point selections

    // Select a point by its ID
    selpoint( SET, POLYID, polyPointIDArray[1] );

    // Select all points by their ID using a custom function
    select_point_ids( polyPointIDArray );

    // Select all points
    selpoint( SET );

    // Deselect a point by its ID
    selpoint( CLEAR, POINTID, polyPointIDArray[1] );

    // Deselect all points by their ID using a custom function
    deselect_point_ids( polyPointIDArray );

    // Clear all points
    selpoint( CLEAR );
}

select_poly_ids: polyIDArray
{
    for(loop = 1; loop <= polyIDArray.size(); loop++)
    {
        selpolygon( SET, POLYID, polyIDArray[loop] );
    }
}

deselect_poly_ids: polyIDArray
{
    for(loop = 1; loop <= polyIDArray.size(); loop++)
    {
        selpolygon( CLEAR, POLYID, polyIDArray[loop] );
    }
}

select_point_ids: pointIDArray
{
    for(loop = 1; loop <= pointIDArray.size(); loop++)
    {
        selpoint( SET, POINTID, pointIDArray[loop] );
    }
}

deselect_point_ids: pointIDArray
{
    for(loop = 1; loop <= pointIDArray.size(); loop++)
    {
        selpoint( CLEAR, POINTID, pointIDArray[loop] );
    }
}
 

Kryslin

Active member
Matt: handy stuff, that.

Re: getmode("SYMMETRY"); ... is there an equivalent to set / toggle the symmetry mode?

Still, regards to the indices question... where are those indices coming from, what are they referencing? This looks like something that will require experimentation, which means I have to wait until I can go up and down stairs to get to the work station... I hate recovering from surgery.
 

KANUSO

New member
The indices are simply the indices from the Arrays, taht are generated by LScript when you enter the editmode (editbegin).
By entering the editmode in LScript, the engine creates 2 Arrays.
1 named "polygons" and one named "points". The indices are simply the index of an element in these Arrays.

I hope this will help.

Regards
KANUSO
 

Kryslin

Active member
Here's an interesting one...

Is it possible to read a bone's weightmap in lscript? It appears you can set one - BoneWeightMapName("name"); - but I don't see anything that looks like you can read the name of the weight map...

Here's why I'm asking : I have a tool, that assigns weight maps symmetrically, giving identifiers for Right and Left for bones and weight maps. My last revision had added buttons to move up and down the hierarchy, and assign & move to the next bone. I want to add "Next Unassigned" to the buttons, so that you can move to the next bone that doesn't have a weight map assigned to it.

If it isn't possible, then I have another candidate for conversion to Python.
 

jwiede

Electron wrangler
Here's an interesting one...

Is it possible to read a bone's weightmap in lscript? It appears you can set one - BoneWeightMapName("name"); - but I don't see anything that looks like you can read the name of the weight map...

Here's why I'm asking : I have a tool, that assigns weight maps symmetrically, giving identifiers for Right and Left for bones and weight maps. My last revision had added buttons to move up and down the hierarchy, and assign & move to the next bone. I want to add "Next Unassigned" to the buttons, so that you can move to the next bone that doesn't have a weight map assigned to it.

If it isn't possible, then I have another candidate for conversion to Python.

Possibly mitigated since, but according to this thread, in 2006 Dodgy was asking Newtek to fix lack of read access to that info (as well as some other important info access issues).
 
Last edited:

Sensei

TrueArt Support
Is it possible to read a bone's weightmap in lscript?

In Python it's possible to get weight map assigned to specified bone using Bone Info.
sdk/lwpython2015.3.zip/python2015/globalboneinfo.html
 

Kryslin

Active member
JWeide: From what I can tell, based on going through the lscript release docs, It hasn't been added. However, until someone from Newtek comes up and says "Hey, its there, here's a code snippet..." then I'm off to Python...

Sensei : Yeah, I saw that in the Python SDK docs. Looks like I'm moving my Weight assignment tool over to Python...
 

jwiede

Electron wrangler
JWeide: From what I can tell, based on going through the lscript release docs, It hasn't been added. However, until someone from Newtek comes up and says "Hey, its there, here's a code snippet..." then I'm off to Python...
Python approach is direct, might as well use it.
 

Kryslin

Active member
As on offhand question, is ther a command sequence string for any of the following?
-Toggle Symmetry
-Weld 2.0
-Weld Avg 2.0

The lscript built in weld() and weldavg() don't respect symmetry, but the updated modeler detail tools do.
 
Top Bottom