WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   How to add texture to a polygon (https://forum.worldviz.com/showthread.php?t=2955)

tsgk 09-10-2010 07:48 AM

How to add texture to a polygon
 
Hello,

I am trying to create a textured on-the-fly polygon but have not much luck yet.

The polygon I am using has the following vertices:

Code:

viz.startLayer(viz.POLYGON)
       
       
        viz.vertex(x+(1.5), 0.02, 0)
       
        viz.vertex(x+(1.5), 0.02, straight_road)
        i = 0
        while i < 3142:
                x2[i] = (r-(1.5))*cos(right_array[i])
                z2[i] = (r-(1.5))*sin(right_array[i])
                viz.vertex(x2[i]+r, 0.02, z2[i]+9)
                i += 1
       

        viz.vertex(r-(1.5), 0.02, 9)
        viz.vertex(r-(1.5), 0.02, 0)
        viz.vertex(x+(1.5), 0.02, 0)

        myPolygon = viz.endLayer()

The while loop is used to generate a semi-circular side to the polygon.

I am not sure how to apply the
Code:

viz.texcoord
command since at the best with four [x,y] coordinates I can draw a square.

Is there a way of adding a .jpg or .bmp file as a texture in this kind of shape? What I intend of using is a seamless texture image that will repeat itself, so the orientation will not be important.

Any help will be greatly appreciated!!

George

Gladsomebeast 09-17-2010 12:28 PM

Texturing an on-the-fly object is possible. You'll want to set the texture coordinate assosiated with each vertex with the viz.texcoord command. Apply a texture to the completed object with
Code:

roadTexture = viz.add('road.jpg')
myPolygon.texture(roadTexture)

Texture coordinates go from 0 to 1; [0,0] representing the lower left pixle of the texture, [1,1] upper right (I think). Each pixel of the texture is overlayed on your myPolygon verticies according to the verticie's assosated texture coordinate. If you assign texture coordinates over 1, then you will want to set the wrap mode of the texture to get it to tile, rather than just smear the last pixel in your texture.

Code:

viz.startLayer(viz.POLYGON)

viz.texcoord(0,2)
viz.vertex(-1,1,0)

viz.texcoord(2,2)
viz.vertex(1,1,0)

viz.texcoord(2,0)
viz.vertex(1,-1,0)

viz.texcoord(0,0)
viz.vertex(-1,-1,0)

q = viz.endLayer()
t = viz.add('ball.jpg')
t.wrap(viz.WRAP_S,viz.REPEAT)
t.wrap(viz.WRAP_T,viz.REPEAT)
q.texture(t)



All times are GMT -7. The time now is 05:10 PM.

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