Results 1 to 13 of 13

Thread: polypoints

  1. #1
    Super Member LightFreeze's Avatar
    Join Date
    Feb 2003
    Location
    Sunny Scotland
    Posts
    911

    polypoints

    I'm trying to insert some points into a polygon,

    the sdk says this

    Replace the point list of a polygon.

    err = polPnts( state, polygon, npoints, point_array )


    Python says this

    lwsdk.pris.modeler.polypoints(poly, points)



    Although that is in pris, which we don't have yet.

    What we have is

    mesh_edit_op.polyPoints(mesh_edit_op.state,plyID)

    which only takes 2 arguments, the mesh state and a poly id

    If you

    pp = mesh_edit_op.polyPoints(mesh_edit_op.state,plyID)

    pp has 2 methods which need arguments,
    pp.count()
    pp.index()

    I tried the new point count and an array of points ID's but no joy.

    Anyone had any success doing this or have any guesses on what to try?
    VueScripts.com
    __________________
    win32
    core2duo E6500
    GTX 260

  2. #2
    The trick might be that the sdk "polPnts( state, polygon, npoints, point_array )" translates to python "polPnts( state, polygon, point_array )" without the npoints argument.
    Here's a sample that worked for me. The first part was my original script to create a square then at the end it replaces the points of the polygon with new points to make it bigger.

    Code:
    #! /usr/bin/env python
    # -*- Mode: Python -*-
    # -*- coding: ascii -*-
    
    """
    This is a LightWave Command Sequence plug-in (Modeler) that creates
    a square then relaces the points.
    """
    
    import sys
    import lwsdk
    import math
    
    __author__     = "Clinton Reese"
    __date__       = "sep 28 2013"
    __copyright__  = "Copyright (C) 2011 Clinton's 3D Creations"
    __version__    = "1.0"
    __maintainer__ = "Clinton Reese"
    __email__      = "[email protected]"
    __status__     = "Example modified"
    __lwver__      = "11.5"
    
    class make_square(lwsdk.ICommandSequence):
        def __init__(self, context):
            super(make_square, self).__init__()
    
        # LWCommandSequence -----------------------------------
        def process(self, mod_command):
            edit_op_result = lwsdk.EDERR_NONE
            mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER)
            if not mesh_edit_op:
                print >>sys.stderr, 'Failed to engage mesh edit operations!'
                return lwsdk.AFUNC_OK
                
            ptID = []
            pt = [ -1.0, 0.0, -1.0 ]
            uv = [ 0.0, 0.0 ]
            rgb = [1.0, 0.0, 0.0]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            # different from c, dimension of vmap is not used?
            #mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[0], lwsdk.LWVMAP_TXUV,"MyUVMap", 2, uv)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[0], lwsdk.LWVMAP_TXUV, "MyUVMap", uv)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[0], lwsdk.LWVMAP_WGHT, "MyWeightMap", 0.0)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[0], lwsdk.LWVMAP_RGB, "MyVertexColorMap", rgb)
            
            pt = [ -1.0, 0.0, 1.0 ]
            uv = [ 0.0, 1.0 ]
            rgb = [0.0, 1.0, 0.0]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[1], lwsdk.LWVMAP_TXUV, "MyUVMap", uv)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[1], lwsdk.LWVMAP_WGHT, "MyWeightMap", 0.25)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[1], lwsdk.LWVMAP_RGB, "MyVertexColorMap", rgb)
            
            pt = [ 1.0, 0.0, 1.0 ]
            uv = [ 1.0, 1.0 ]
            rgb = [0.0, 0.0, 1.0]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[2], lwsdk.LWVMAP_TXUV, "MyUVMap", uv)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[2], lwsdk.LWVMAP_WGHT, "MyWeightMap", 0.75)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[2], lwsdk.LWVMAP_RGB, "MyVertexColorMap", rgb)
            
            pt = [ 1.0, 0.0, -1.0 ]
            uv = [ 1.0, 0.0 ]
            rgb = [1.0, 1.0, 1.0]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[3], lwsdk.LWVMAP_TXUV, "MyUVMap", uv)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[3], lwsdk.LWVMAP_WGHT, "MyWeightMap", 1.0)
            mesh_edit_op.pntVMap(mesh_edit_op.state, ptID[3], lwsdk.LWVMAP_RGB, "MyVertexColorMap", rgb)
            
            polygon = mesh_edit_op.addPoly(mesh_edit_op.state, lwsdk.LWPOLTYPE_FACE, None, "MySurface", ptID)
            
            #mesh_edit_op.pntVPMap would be used at this point to create discontinuous uv values for the polygons
            
            mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0)
            
            ninetyDegrees = math.pi/2.0
            #new_color = lwsdk.Color(0.0, 1.0, 1.0)
            new_color = [0.0, 1.0, 1.0]
            surface_funcs = lwsdk.LWSurfaceFuncs()
            surface = surface_funcs.first()
            while surface:
                if surface_funcs.name(surface) == "MySurface":
                    #try float for lw11.5 - worked
                    #surface_funcs.setFlt(surface, lwsdk.SURF_COLR, new_color)
                    surface_funcs.set_float(surface, lwsdk.SURF_COLR, new_color)
                    surface_funcs.set_float(surface, lwsdk.SURF_SMAN, ninetyDegrees)
                    break
                surface = surface_funcs.next()
            
            thecommand = mod_command.lookup(mod_command.data, "SETLAYER")
            i="1"
            cs_options = lwsdk.marshall_dynavalues(i)
            result = mod_command.execute(mod_command.data, thecommand, cs_options, lwsdk.OPSEL_USER)
    
            mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER)
            ptID = []
            pt = [ -1.5, 0.0, -1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ -1.5, 0.0, 1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ 1.5, 0.0, 1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ 1.5, 0.0, -1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            mesh_edit_op.polPnts( mesh_edit_op.state, polygon, ptID )
            mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0)
    
            return lwsdk.AFUNC_OK
    
    
    ServerTagInfo = [
                        ( "Python Basic Square", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
                        ( "Make Square", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
                        ( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
                    ]
    
    ServerRecord = { lwsdk.CommandSequenceFactory("LW_PyMakeSquare", make_square) : ServerTagInfo }

  3. #3
    Super Member LightFreeze's Avatar
    Join Date
    Feb 2003
    Location
    Sunny Scotland
    Posts
    911
    Thank You, that got it, never occurred to me that I was looking at the wrong one, thought it was another random name change.

    A bit further down the sdk is this,

    polyPoints( state, poly, out_points )
    Returns the vertices making up the specified polygon.
    VueScripts.com
    __________________
    win32
    core2duo E6500
    GTX 260

  4. #4
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    Chilton. What then do we do to deploy it in modeler?

  5. #5
    Quote Originally Posted by meshpig View Post
    Chilton. What then do we do to deploy it in modeler?
    Copy the code into a text file with a .py extension. Utilities>Python will run it. I think if you place the file in lightwave install path + \support\plugins\scripts\Python\Modeler\CommandSeq uence\ then modeler will find it automatically. If not use Utilities>Add Plugins to find and add it in. At this point it would be found in Utilities>Additional.

  6. #6
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    Wow that was easy, thanks We shall add it's biological distinctiveness to our own... as in haven't found a way into LWSDK yet.

  7. #7
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    - So here's the first dumb question: why the variation in rgb values until you get to "mysurface" with 000 255 255 or 0.0 1.0 1.0?

  8. #8
    Quote Originally Posted by meshpig View Post
    - So here's the first dumb question: why the variation in rgb values until you get to "mysurface" with 000 255 255 or 0.0 1.0 1.0?
    mysurface 0 1 1 is the cyan color of the square
    Remove the code that was added near the end to answer the original question:
    Code:
            mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER)
            ptID = []
            pt = [ -1.5, 0.0, -1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ -1.5, 0.0, 1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ 1.5, 0.0, 1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            pt = [ 1.5, 0.0, -1.5 ]
            ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt))
            mesh_edit_op.polPnts( mesh_edit_op.state, polygon, ptID )
            mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0)
    Then you can go to Map>Color>Vertex Paint to see the color map.

    or you can select the floating points, make a polygon then go to vertex paint.

    Oops, I just remembered. You can go to Surface Editor>Advanced and turn on the vertex color map there to see it in the viewport.

  9. #9
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    So that block of code generates the floating points but they don't appear to affect the color map?

  10. #10
    Quote Originally Posted by meshpig View Post
    So that block of code generates the floating points but they don't appear to affect the color map?
    That's right. They don't have any vertex maps - uv, vertex color or weightmap.

  11. #11
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    ... I mean they don't appear to affect the color map you eventually make. It still seems to rely on the polygonal vertices, the outer ones?

  12. #12
    Those vertices aren't a member of the color map, so they don't have any effect on it. Maybe I'm not understanding your question.

  13. #13
    Super Member
    Join Date
    Aug 2006
    Location
    S
    Posts
    3,511
    No no, it's me trying to comprehend the original question

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
  •