visible to invisible

How fast can i turn a cube invisible and then to invisible and back again?A example would be great.

  • select object
  • go to frame n
  • Properties Editor > Object (icon with a cube) > Cycles settings: Ray Visibility >> set: check (visible) / uncheck (invisible) Camera
  • Insert keyframe (I)

cubeOnOff.blend

…or what?

Or toggle visible/invisible in viewport or rendering by recording/keyframing visibility… or?

Would the animation play in the bge?

Noooo… (cycles) animation only :eek:… uuuf, sorry missed the topic of Game Engine. Sloppy me :rolleyes:

I use visibility actuators triggered with a message. Just set the object to invisible in the properties panel. Add 2 visibility actuator logic bricks. one set to visible and one set to invisible. Then trigger with what ever sensor you choose.

You can do it multiple times per frame in python.
If you’re using render-to-texture, you can make some objects visible to some cameras and invisible to others!

What are you trying to achieve?

Here’s a quick one… press ‘p’.
invisiblebox.blend (84.7 KB)

I would feed the cube world position and global time to a sine function.
No for loops, no counters, just always-python logic brick.


import bge
from time import time
from math import sin


def posToPhase(pos):
    SPEED = -2.5
    return abs(sin(pos.length/3+time()*SPEED))


def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    phase = posToPhase(own.worldPosition)
    
    #no fade 
    phase = 0 if phase < 0.97 else 1
    
    own.color = (0.5,0.5,0.5,phase)


main()

http://i.imgur.com/566MNul.gif

Attachments

untitled.blend (5.26 MB)

waaa it looks nice

But i really wanted it to have good framerate.A framerate of 60.But this has a framerate of 2.8.But this does not use the visibility actuator in python.Maybe the framerate would be better if it were done that way.

You put the script on every cube.That may have caused the framerate to be so low.

Well they had physics on and etc… and it ran fine on my 6y old now 30$ gpu :confused:.

Mostly its not the fault of the visibility or code,its the fault of to many objects ( draw calls).
If you need better frames and the cubes don’t have to be that dynamic, merge the cubes into a single mesh and map the faces to “cubes” in python.

But anyway, fixed the logic brick overhead(logic ms).
I just register them, and then a single actor loops over an array for them.


import bge
from time import time
from math import sin


def posToPhase(pos):
    SPEED = -2.5
    return abs(sin(pos.length/3+time()*SPEED))


def register():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    try:
        bge.logic.wavers.append(own)
    except:
        wavers = [own]
        bge.logic.wavers = wavers


def waveUpdate():
    try:
        wavers = bge.logic.wavers
    except:
        return
    
    for obj in wavers:


        phase = posToPhase(obj.worldPosition)
        
        #no fade 
        phase = 0 if phase < 0.97 else 1
        
        obj.color = (0.5,0.5,0.5,phase)

Attachments

untitled (2).blend (5.34 MB)

How would i make it one line of cubes that become visible till it gets to the end of the square of cubes then it repeats?

straight lines passing through the grid?

change the pos.length to pos.x for example.

Also do you need a pulse, or waves?

EDIT: why i made it unidirectional was because t thought this would be amazing :slight_smile:
http://i.imgur.com/JCoBG5S.gif

it’s amazing VeggieJuice :smiley:

Lets see pulse.

http://i.imgur.com/6LtRqOF.gif

Waves and a pulse.

Basically rewrite posToPhase function.
Consider if a block at given position and time should be visible, and return 0 or 1 accordingly.


def posToPhase(pos):
    
    #return abs(sin(pos.x/3/100+time()*2.5)) # sine lines


    #return float( (40+pos.x) == int(time()*10)% 80 ) # a pulse