WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-24-2009, 02:25 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
.clone() or .copy()

Hello,

Im writing a program that adds a node3d and lets the node run for 3.5 seconds and then removes the node3d when its triggered by some speed. The node is also looping animation(IE it appears then disappears, then does it over and over again).

The problem Im having is its causing my program to slow down and get laggy. When i try .clone() it takes wherever the orginal node is in its loop and starts it from that point. When i try .copy() the node never starts its animation. The node appears but never loops.

I just want it to run faster.

This is the way I have the code right now. Its goes slow when I run this.
Code:
if obj.speed > 1 and obj.speed < 2.5:
     def showFlower():
	flower1 = viz.add('flower_grow_01.wrl')  #ADDS
	flower1.scale(.06,.06,.06)

	x,y,z = ball1.getPosition()
				
	if z < 0:
             	flower1.setPosition([x,0,-10])
	if z >= 0:
		flower1.setPosition([x,0,10])
				
	a,b,c = int1.getEuler()  #add
	flower1.setEuler(a,0,0)  #add
				
	yield viztask.waitTime( 3.5 )
	flower1.remove()                      #REMOVES 
				
viztask.schedule( showFlower() )
Any help is much appreciated.

Thanks
Reply With Quote
  #2  
Old 03-24-2009, 08:46 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
sorry the viztask.schedule should be tabed over one space
Reply With Quote
  #3  
Old 03-25-2009, 04:10 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
I'm sorry, I don't really understand the question here. Can you post some code that I can copy and run that replicates your problem.
Reply With Quote
  #4  
Old 03-25-2009, 05:15 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
Sure Ill post the code Friday when I am in.
Reply With Quote
  #5  
Old 03-27-2009, 04:02 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
Well I tried to upload a .wrl file and it wouldn't let me. So pretty much this file has moving animation to it that loops. It also has 5 skins of color on it as well. The program runs slow. Im trying to figure out how to make it run faster. Instead of adding and removing the image, I tried copy() and clone(). copy() just copies it and doesnt allow the animation to run. All clone() does is makes the animation appear wherever it is in its loop(meaning that there is a original animation that is running during this program, when it clones itself it picks up from whever that image is in its loop). Im trying to make it bloom seperately. Sorry if this is confusing. Your forum just doesn't like .wrl files.

Code:
import viz
import viztask
import vizact
viz.go()

viz.MainView.setPosition([0,10,-35]) #sets camera position
viz.MainView.setEuler([0,2,0]) #sets camera pitch

PORT_PPT = 6
PORT_INTERSENSE = 8

#creates a stage
viz.add('tut_ground.wrl')

#Create sensor
ppt1 = viz.add('vizppt.dls')
ppt2 = viz.add('vizppt.dls')

#Creates visual of dancer 1 location (make viz.OFF)
ball1 = viz.add('white_ball.wrl')
ball1.scale(1,1,1)
ballLink1 = viz.link(ppt1, ball1)

int1 = viz.add('intersense.dls')
interLink1 = viz.link(int1, ball1)

#Creates visual of dancer 2 location (make viz.OFF)
ball2 = viz.add('white_ball.wrl')
ball2.scale(1,1,1)
ballLink2 = viz.link(ppt2, ball2)

int2 = viz.add('intersense.dls')
interLink2 = viz.link(int2, ball2)

#controls distance in virtual world
ballLink1.postScale([8,1,13],target = viz.LINK_FULL_OP)
ballLink2.postScale([8,1,13],target = viz.LINK_FULL_OP)

def CalculateSpeed(obj):
	
	#Get current and last position
	current_pos = obj.getPosition()
	last_pos = getattr(obj, 'last_pos', None)

	if last_pos is None:
		#This is first call, so save position and set speed to 0
		obj.last_pos = current_pos
		obj.speed = 0.0
		
	else:
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
		#Makes new animation and removes it (and sets euler position "eventually")
		if obj.speed > 1 and obj.speed < 2.5:
			def showFlower():
				flower1 = viz.add('flowers_grow_01.wrl')
				flower1.scale(.06,.06,.06)
				flower1.color(viz.RED)
				
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower1.setPosition([x,0,-10])
				if z >= 0:
					flower1.setPosition([x,0,10])
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower() )

		if obj.speed >= 2.5 and obj.speed < 3:
			def showFlower1():
				flower1 = viz.add('flowers_grow_01.wrl')
				flower1.scale(.2,.2,.2)
				flower1.color(viz.PURPLE)
				
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower1.setPosition([x,0,-10])
				if z >= 0:
					flower1.setPosition([x,0,10])
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower1() )
		if obj.speed >= 3 and obj.speed < 5:
			def showFlower1():
				x,y,z = ball1.getPosition()
				if z >= 0:
					flower1 = viz.add('flowers_grow_01.wrl')
					flower1.setPosition([x,0,10])
					flower1.scale(1,1,1)
					flower1.color(viz.BLUE)

				if z < 0:
					flower1 = viz.add('flowers_grow_01.wrl')
					flower1.setPosition([x,0,-10])
					flower1.scale(.2,.2,.2)
					flower1.color(viz.BLUE)
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower1() )
vizact.ontimer(0,CalculateSpeed,ppt1)

def CalculateSpeed(obj):
	
	#Get current and last position
	current_pos = obj.getPosition()
	last_pos = getattr(obj, 'last_pos', None)
	
	if last_pos is None:
		#This is first call, so save position and set speed to 0
		obj.last_pos = current_pos
		obj.speed = 0.0
		
	else:
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
		#Checks speed between 3 and 5
		if obj.speed > 1 and obj.speed < 2.5:
			def showFlower2():
				flower2 = viz.add('flowers_grow_01.wrl')
				flower2.scale(.06,.06,.06)
				flower2.color(viz.PURPLE)
				x,y,z = ball2.getPosition()
				
				if z < 0:
					flower2.setPosition([x,0,-10])
				if z >= 0:
					flower2.setPosition([x,0,10])
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )

		if obj.speed >= 2.5 and obj.speed < 3:
			def showFlower2():
				flower2 = viz.add('flowers_grow_01.wrl')
				flower2.scale(.2,.2,.2)
				flower2.color(viz.BLUE)
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower2.setPosition([x,0,-10])
				if z >= 0:
					flower2.setPosition([x,0,10])
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )
			
		if obj.speed >= 3 and obj.speed < 5:
			def showFlower2():
				x,y,z = ball2.getPosition()
				if z >= 0:
					flower2 = viz.add('flowers_grow_01.wrl')
					flower2.setPosition([x,0,10])
					flower2.scale(1,1,1)
					flower2.color(viz.RED)

				if z < 0:
					flower2 = viz.add('flowers_grow_01.wrl')
					flower2.setPosition([x,0,-10])
					flower2.scale(.2,.2,.2)
					flower2.color(viz.RED)
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )
vizact.ontimer(0,CalculateSpeed,ppt2)
Reply With Quote
  #6  
Old 03-27-2009, 04:22 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
attachments.zip

Ok, I put the files in a zip file so you should be able to get them now for the above program. Thanks.
Reply With Quote
  #7  
Old 03-31-2009, 11:35 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
I'm not sure why you have to keep adding the object. Instead of removing it can't you just turn its visibility off and on?
Reply With Quote
  #8  
Old 03-31-2009, 11:59 AM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
The reason I did not turn the visiblilty on and off is because its a looping animation. I dont want it to be visible half way through the loop. I want it to start the loop at its starting point(when loaded) and end after 3.5 seconds.
Maybe there is no way around this.
Reply With Quote
  #9  
Old 04-01-2009, 09:45 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Have faith honorable durf. There is a way.

node.hint(viz.RESET_ANIMATION_HINT)
__________________
Paul Elliott
WorldViz LLC
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 11:19 PM.


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