WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   object on the fly--how to change color of particular vertex (https://forum.worldviz.com/showthread.php?t=4511)

hzhao 03-07-2013 09:10 AM

object on the fly--how to change color of particular vertex
 
With the following code, I created an object on-the-fly, a green polygon. Then I want to create a vertical transparent stripe, that is, set vertex 2 and 5 to be transparent. But the code doesn't work this way. Why? Thanks!

viz.startLayer(viz.POLYGON)
viz.vertexColor(viz.GREEN)

viz.vertex(0.0,0.0,0.0)
viz.vertex(0.5,0.0,0.0)
viz.vertex(0.6,0.0,0.0)
viz.vertex(1.0,0.0,0.0)
viz.vertex(1.0,1.0,0.0)
viz.vertex(0.6,1.0,0.0)
viz.vertex(0.5,1.0,0.0)
viz.vertex(0.0,1.0,0.0)
target=viz.endLayer()

target.dynamic()

target.setVertexColor(2,[0,0,1,0.2])
target.setVertexColor(5,[0,0,1,0.2])

hzhao 03-07-2013 12:36 PM

What I want to do is to vary transparency within an object. How to do that ?

farshizzo 03-20-2013 08:42 AM

Many OpenGL drivers will internally break up POLYGON shapes into triangles. Try using QUADS instead.
Code:

viz.startLayer(viz.QUADS)
viz.vertexColor(viz.GREEN)
viz.vertex(0.0,0.0,0.0)
viz.vertex(0.5,0.0,0.0)
viz.vertex(0.5,1.0,0.0)
viz.vertex(0.0,1.0,0.0)

viz.vertex(0.5,0.0,0.0)
viz.vertex(0.6,0.0,0.0)
viz.vertex(0.6,1.0,0.0)
viz.vertex(0.5,1.0,0.0)

viz.vertex(0.6,0.0,0.0)
viz.vertex(1.0,0.0,0.0)
viz.vertex(1.0,1.0,0.0)
viz.vertex(0.6,1.0,0.0)
target=viz.endLayer()

target.dynamic()

target.setVertexColor(5,[0,0,1,0.2])
target.setVertexColor(6,[0,0,1,0.2])
target.setVertexColor(8,[0,0,1,0.2])
target.setVertexColor(11,[0,0,1,0.2])

Depending on your needs, you might be able to just use an alpha texture on a single quad to achieve the transparency.


All times are GMT -7. The time now is 07:12 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC