WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-06-2013, 12:46 PM
Nyhood Nyhood is offline
Member
 
Join Date: Sep 2013
Posts: 1
Creating objects with VizLayers and returning creates duplicates....?

Code:
import viz
import vizact
import vizshape
from math import sin, cos, tan, pi

viz.go()

def createCube(cubeSize=2):
	viz.startLayer(viz.QUADS) 
	#front
	viz.vertex(0,0,0)
	viz.vertex(cubeSize,0,0) 
	viz.vertex(cubeSize,cubeSize,0) 
	viz.vertex(0,cubeSize,0) 
	
	#bottom
	viz.vertexColor(viz.RED)
	viz.vertex(0,0,0)
	viz.vertex(cubeSize,0,0)
	viz.vertex(cubeSize,0,cubeSize)
	viz.vertex(0,0,cubeSize)
	
	#left
	viz.vertexColor(viz.YELLOW)
	viz.vertex(0,0,0)
	viz.vertex(0,cubeSize,0)
	viz.vertex(0,cubeSize,cubeSize)
	viz.vertex(0,0,cubeSize)
	
	#right
	viz.vertexColor(viz.BLUE)
	viz.vertex(cubeSize,0,0)
	viz.vertex(cubeSize,cubeSize,0)
	viz.vertex(cubeSize,cubeSize,cubeSize)
	viz.vertex(cubeSize,0,cubeSize)
	
	#back
	viz.vertexColor(viz.GRAY)
	viz.vertex(0,0,cubeSize)
	viz.vertex(cubeSize,0,cubeSize) 
	viz.vertex(cubeSize,cubeSize,cubeSize) 
	viz.vertex(0,cubeSize,cubeSize) 
	
	#top
	viz.vertexColor(viz.GREEN)
	viz.vertex(0,cubeSize,0)
	viz.vertex(cubeSize,cubeSize,0)
	viz.vertex(cubeSize,cubeSize,cubeSize)
	viz.vertex(0,cubeSize,cubeSize)
	cube = viz.endLayer() 

	#rotate = vizact.spin(x=0,y=45,z=0,speed=90)
	#myQuad.addAction(rotate)
	return cube

def createCylinder(radius=3,height=5,detail=10):
	angleIncrement = 360/detail;
	
	#create a group of everything
	cylinder = viz.addGroup()
	
	viz.startLayer(viz.POLYGON)
	#viz.vertex(0,0,0)
	for i in range(detail):
		x = radius * cos(((i*angleIncrement)*pi)/180)
		y = radius * sin(((i*angleIncrement)*pi)/180)
#		x = radius * cos(i*angleIncrement)
#		y = radius * sin(i*angleIncrement)
		print("x is " + str(x))
		print("y is " + str(y))
		viz.normal(x,0,y)
		viz.vertex(x,0,y)
	bottom = viz.endLayer(parent=cylinder)
	
	
#make the top
	viz.startLayer(viz.POLYGON)
	#viz.vertex(0,height,0)
	for i in range(detail):
		x = radius * cos(((i*angleIncrement)*pi)/180)
		y = radius * sin(((i*angleIncrement)*pi)/180)
		viz.vertex(x,height,y)
	top = viz.endLayer(parent=cylinder)
	
	#now make all the sides
	viz.startLayer(viz.QUAD_STRIP)
	viz.vertexColor(viz.GRAY)
	for i in range(detail):
		x = radius * cos(((i*angleIncrement)*pi)/180)
		y = radius * sin(((i*angleIncrement)*pi)/180)
		viz.vertex(x,0,y)
		viz.vertex(x,height,y)
	
	x = radius * cos(((0*angleIncrement)*pi)/180)
	y = radius * sin(((0*angleIncrement)*pi)/180)
	viz.vertex(x,0,y)
	viz.vertex(x,height,y)
	sides = viz.endLayer(parent=cylinder)

	return cylinder

box1 = createCube(9);
box1.setPosition(0,5,0)

head = createCube(2)
head.addParent(box1)
head.setEuler(180,0,0)
head.setPosition(3,8,0)

arm1 = createCylinder(1,9,20)
arm1.addParent(box1)
arm1.setPosition(-3,-2,3)
arm1.setEuler(0,0,-20)

arm2 = createCylinder(1,9,20)
arm2.addParent(box1)
arm2.setPosition(11,-2,3)
arm2.setEuler(0,0,20)
I am creating objects and assigning them to values through function return values. For some reason, everything I create is duplicated somehow and I'm at a loss. Am I already placing the object, then placing it again by assigning it to a value? New to Python and WorldViz.
Reply With Quote
  #2  
Old 09-11-2013, 01:41 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Try using setParent instead of addParent. When you use addParent the object will still retain its current parents.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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