PDA

View Full Version : polypoints



LightFreeze
09-28-2013, 01:40 PM
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?

clintonman
09-28-2013, 07:48 PM
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.


#! /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.sta te, 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.sta te, 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.sta te, 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.sta te, 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.sta te, pt))
pt = [ -1.5, 0.0, 1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, pt))
pt = [ 1.5, 0.0, 1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, pt))
pt = [ 1.5, 0.0, -1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, 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 }

LightFreeze
09-29-2013, 12:59 AM
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.

meshpig
09-29-2013, 11:21 PM
Chilton. What then do we do to deploy it in modeler?

clintonman
10-01-2013, 09:50 AM
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.

meshpig
10-02-2013, 12:12 AM
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.

meshpig
10-02-2013, 12:18 AM
- 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?

clintonman
10-02-2013, 09:40 AM
- 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:

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.sta te, pt))
pt = [ -1.5, 0.0, 1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, pt))
pt = [ 1.5, 0.0, 1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, pt))
pt = [ 1.5, 0.0, -1.5 ]
ptID.append(mesh_edit_op.addPoint(mesh_edit_op.sta te, 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.

meshpig
10-04-2013, 12:29 AM
So that block of code generates the floating points but they don't appear to affect the color map?

clintonman
10-04-2013, 08:29 AM
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.

meshpig
10-05-2013, 04:17 AM
... 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?

clintonman
10-05-2013, 07:36 AM
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.

meshpig
10-07-2013, 12:04 AM
No no, it's me trying to comprehend the original question :)