Results 1 to 8 of 8

Thread: I need a simple planar uv script

  1. #1
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199

    I need a simple planar uv script

    I've no idea where to begin, but I need to make a simple script that takes the selected points and applies a planar uv along z axis.
    That is without requester boxes, and the texture map can be any name.
    I have to do this many times so I'd rather assign this to a shortcut that points to that script instead of going through the create uv map procedure every time.
    Same as with new UV map procedure, top vertex should have a v=1 value and bottom vertex should have v=0.
    I don't care about the U values, they can all be zero.

    Can someone please help me with this?
    Thanks a bunch!
    Last edited by Dennik; 02-28-2011 at 01:08 PM.

  2. #2
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199
    Ok I'm moving very very slowly by myself as I have no lscript experience, but I'd like to have this ready hopefully soon.

    I'll be adding some code slowly as I progress.

    Code:
    main
    {
    selmode(USER); 
    pntCnt = pointcount();
    if(pntCnt == 0)
        error("No points selected.");
    
    info (pntCnt);//number of points selected.
    }
    next would be finding highest and lowest Y point values to be able to normalize each point within the UV range.
    Last edited by Dennik; 02-28-2011 at 02:58 PM.

  3. #3
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199
    Ok I decided to apply a weight map on these points instead. That was actually my intention for this, so the whole deal is to just normalize the selected points y values and apply those as % weight map on each point. I was originally doing this through uv2weight but since I can do it directly that's even better!

    Code:
    @version 2.6
    @warnings
    @script modeler
    
    main
    {
    
    selmode(USER); 
    pntCnt = pointcount();
    if(pntCnt == 0)
        error("No points selected.");
    
    editbegin();
    myVmap = VMap(VMWEIGHT,"weight1",1);
    hi_y=0.0;
    lo_y=0.0;
        for (currPnt=1;currPnt<=pntCnt;currPnt++)
        {
        point_c=pointinfo(points[currPnt]).y;//find coordinates of current point
            if (hi_y<point_c)
            {
            hi_y=point_c;
            }
            if (lo_y>point_c)
            {
            lo_y=point_c;
            }
        }
    
    editend();
    info (hi_y);
    
    }
    Ok here is the min max calculation so far. Seems to be working.
    Last edited by Dennik; 02-28-2011 at 08:49 PM.

  4. #4
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199
    Well its late and I have no idea how to create a new weight map or set its value for each point. I hope someone can give me a hint tomorrow!

  5. #5
    Im not very sure, but maybe this can help:

    The VMap Object Agent can also create user-defined vertex maps
    in Modeler. The method used is nearly identical to the method for
    creating a new vertex map from a pre-defined type. To generate a
    custom vertex map, you must provide a custom map type instead
    of a pre-defined type identifier. Custom map types are a unique
    four-character sequence, housed in an initialization block.
    For example, to generate a vertex map of type NMBK, named
    my_normals, with two data elements per point, you use the
    following code:

    @define VMAP_NMBK @'N','M','B','K'@

    normMap = VMap(VMAP_NMBK,"my_normals",2);

    this is from the lscriptreference.pdf site 133

  6. #6
    Worms no more! Free fun! Dodgy's Avatar
    Join Date
    Feb 2003
    Location
    Sydney
    Posts
    8,273
    http://www.mikegreen.name/Lscripts.h...ages_To_Planes

    This has some example code for creating a vmap from scratch. It used to be the case you had to create the Vmap in a separate editbegin() session to modifying it to have it work (hence how my code does it), but they fixed that in a later 9 release.
    Push the software, don't let it push YOU!
    My own plugins and work:www.mikegreen.name
    LaptopSetup:corei7 2.4GHz nvidia GT 650M 8Gig win8 64
    WorkSetup:core i7 3.4Ghz nvidia Quadro 2000 12Gig Ram Win7

  7. #7
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199
    Thank you both for your suggestions!
    I have to do some reading. Still very new to this... Before I learn anything much I'll probably have to scrap it and move to Python in the next release. hehe.

  8. #8
    Registered User Dennik's Avatar
    Join Date
    Jul 2003
    Location
    Winston Salem NC
    Posts
    199
    Well, that was easier than what I expected. Done!

    Again, what this does is to create a gradient weight based on point selection normalized y values. Couldn't find a plugin that does exactly that so I made one!

    Code:
    main
    {
    
    selmode(USER); 
    pntCnt = pointcount();
    if(pntCnt == 0)
        error("No points selected.");
    
    editbegin();
    myVmap = VMap(VMWEIGHT,"weight1",1);
    hi_y=pointinfo(points[1]).y;
    lo_y=hi_y;
        for (currPnt=1;currPnt<=pntCnt;currPnt++)//loop to find min max Y values
        {
        point_c=pointinfo(points[currPnt]).y;//find coordinates of current point
            if (hi_y<point_c)
            {
            hi_y=point_c;
            }
            if (lo_y>point_c)
            {
            lo_y=point_c;
            }
        }
        
        for (currPnt=1;currPnt<=pntCnt;currPnt++)//Loop to set weight map values
        {
            vmapvalue=(pointinfo(points[currPnt]).y-lo_y)*(1/(hi_y-lo_y));
            myVmap.setValue(points[currPnt],vmapvalue);
        }
    
    editend();
    
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •