WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Adding a lot of Avatars (https://forum.worldviz.com/showthread.php?t=6325)

Roy 09-22-2020 11:26 AM

Adding a lot of Avatars
 
Hello,

How to add many avatars at once?
If we try to add 100 different avatars, do we need to use 'addAvatar()' for each avatar?

Thanks

sado_rabaudi 09-25-2020 02:22 PM

You can note it all down in a list and iterate through it. Here's a sample script for it.

import viz

viz.clearcolor(viz.SKYBLUE)

avatar_files = ['vcc_male.cfg', 'vcc_female.cfg', 'vcc_male2.cfg']
avatars = []
position = 0
for i in avatar_files:
new = viz.addAvatar(i, pos = (position*2, 0, 4), euler=(180,0,0))
avatars.append(new)
position += 1

viz.go()

Roy 09-26-2020 12:34 PM

Hi Sado,

How about animations for each avatar?
If animation is added by 'state()', do every avatars have different animations?
I tried to make 2avatars x 15 animations list, and show them in random order as program below. But the same avatar with same animation is shown.

Code:

avatar_files = ['vcc_male.cfg', 'vcc_female.cfg']#2avatars
animation = range(1,16)#default 15 animations

#make 30 stimuli list (2avatars x 15animations), and shuffule the order
stimulus = []
for i in avatar_files:
        for j in animation:
                avatarAnim = viz.addAvatar(i, pos=(0,0,0), euler=(180,0,0))
                avatarAnim.state(j)
                avatarAnim.visible(viz.OFF)
                stimulus.append(avatarAnim)
random.shuffle(stimulus)

def experiment():
        yield viztask.waitKeyDown(viz.KEY_RETURN)
        for trial in stimulus:
                yield viztask.waitTime(1)
                avatarAnim.visible(viz.ON)
                yield viztask.waitKeyDown(viz.KEY_RETURN)
                avatarAnim.visible(viz.OFF)

viztask.schedule(experiment())


kennethkarthik 09-29-2020 12:54 AM

Hi Roy,

There was just a bug in your code. You were setting "avatarAnim" to visible off and on states in your experiment function instead of using "trial" which would iterate between your shuffled states.

Code:

import viz
import random
import viztask

avatar_files = ['vcc_male.cfg', 'vcc_female.cfg']#2avatars
animation = range(0,16)  #default 15 animations

viz.go()

piazza = viz.addChild('piazza.osgb')


#make 30 stimuli list (2 avatars x 15 animations), and shuffle the order
stimulus = []
for i in avatar_files:
        for j in animation:
                avatarAnim = viz.addAvatar(i, pos=(0,0,0), euler=(180,0,0))
                avatarAnim.state(j)
                avatarAnim.visible(viz.OFF)
                stimulus.append(avatarAnim)
print(stimulus)
random.shuffle(stimulus)
print(stimulus)

def experiment():
        yield viztask.waitKeyDown(viz.KEY_RETURN)
        for trial in stimulus:
                yield viztask.waitTime(1)
                trial.visible(viz.ON)
                yield viztask.waitKeyDown(viz.KEY_RETURN)
                trial.visible(viz.OFF)

viztask.schedule(experiment())

Check this and let us know if this was your intended experiment. Thanks

Roy 10-04-2020 03:36 AM

Hi kennethkarthik,

Thank you, it works!
But I'm wondering any other way to add avatars.
In this program, 2 avatars are loaded 15 times, causing long time to run the program.
Any ideas?

Thanks

kennethkarthik 10-05-2020 04:41 PM

Hey Roy,

Vizard does it's optimisation when it reuses objects. However if you do want to improve load time, I would suggest just changing the state of your characters on the same avatar instead of adding a new one for each animation state. Check out the code below

Code:

import viz
import random
import viztask

avatar_files = ['vcc_male.cfg', 'vcc_female.cfg']#2avatars
animation = range(0,16)  #default 15 animations

viz.go()

piazza = viz.addChild('piazza.osgb')


#make 30 stimuli list (2 avatars x 15 animations), and shuffle the order
avatars = []
for i in avatar_files:
        avatarAnim = viz.addAvatar(i, pos=(0,0,0), euler=(180,0,0))
        avatarAnim.visible(viz.OFF)
        avatars.append(avatarAnim)
       
def experiment():
        yield viztask.waitKeyDown(viz.KEY_RETURN)
        for i in avatars:
                i.visible(viz.ON)
                for state in animation:
                        yield viztask.waitTime(0.5)
                        i.state(state)
                        yield viztask.waitKeyDown(viz.KEY_RETURN)
                i.visible(viz.OFF)

viztask.schedule(experiment())



All times are GMT -7. The time now is 09:41 PM.

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