WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   2D or 3D array help? (https://forum.worldviz.com/showthread.php?t=1831)

durf 02-20-2009 07:50 AM

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

farshizzo 02-20-2009 10:57 AM

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)



All times are GMT -7. The time now is 12:25 PM.

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