WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   .clone() or .copy() (https://forum.worldviz.com/showthread.php?t=1931)

durf 03-24-2009 01:25 PM

.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

durf 03-24-2009 07:46 PM

sorry the viztask.schedule should be tabed over one space

Jeff 03-25-2009 03:10 PM

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.

durf 03-25-2009 04:15 PM

Sure Ill post the code Friday when I am in.

durf 03-27-2009 03:02 PM

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)


durf 03-27-2009 03:22 PM

1 Attachment(s)
Attachment 296

Ok, I put the files in a zip file so you should be able to get them now for the above program. Thanks.

Jeff 03-31-2009 10:35 AM

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?

durf 03-31-2009 10:59 AM

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.

Gladsomebeast 04-01-2009 08:45 PM

Have faith honorable durf. There is a way.

node.hint(viz.RESET_ANIMATION_HINT)


All times are GMT -7. The time now is 06:11 AM.

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