![]() |
|
|
|
#1
|
|||
|
|||
|
2D or 3D array help?
Hello,
I want to create an array in a 3D enviroment. I have a wrl file that I want to be positioned on a flat surface multiple times. Will call the wrl file "blocks". I would imagine that I would need some for loop to construct this but I am a little unaware of how python does this. I am use to Java and C++ creations of 2D arrays so I would imagine that the 3D array would have an x, y and z for positioning. I want to construct these blocks 40 x 30 side by side on the same plane. I do not want to overlap them either. Could I please get some examples on how to construct this. Or is there a user friendly website that I could be pointed to. I am new to python so my knowledge base is limited to how python works. Thanks Much |
|
#2
|
|||
|
|||
|
Here is an example script that shows how to create a 2D array of objects and position them in a grid structure. Let me know if anything is unclear.
Code:
import viz
viz.go()
#Width, height of grid
GRID_SIZE = [10,5]
#Spacing between grid items
GRID_SPACING = 1.0
#2D array of blocks
blocks = []
#Iterate over x-axis
for x in range(GRID_SIZE[0]):
column = []
#Iterate over y-axis
for y in range(GRID_SIZE[1]):
#Create block (copy file from cache)
b = viz.add('white_ball.wrl',cache=viz.CACHE_COPY)
#Position block in grid
b.setPosition(x*GRID_SPACING,0,y*GRID_SPACING)
#Add block to current column
column.append(b)
blocks.append(column)
#Set color of block (3,1) to red
blocks[3][1].color(viz.RED)
#Add environment
import vizshape
vizshape.addGrid(color=[0.2]*3)
viz.clearcolor(viz.GRAY)
#Setup camera navigation
import vizcam
cam = vizcam.PivotNavigate(center=(0,0,0))
cam.rotateTo(0,10,-20)
|
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pick porblem with arrays | shivanangel | Vizard | 3 | 08-27-2007 10:10 AM |
| Avatars in an array and link/unlink | betancourtb82 | Vizard | 7 | 09-05-2006 04:06 PM |
| Multidimensional Arrays | betancourtb82 | Vizard | 12 | 05-04-2006 02:13 PM |
| Copy objects in an array to another array | Johannes | Vizard | 3 | 04-29-2005 02:37 PM |
| spinto | cade_mccall | Vizard | 3 | 09-09-2004 04:37 PM |