WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-30-2018, 08:00 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Transparency gradient for cylinder

I would like to create simple cylinder with a transparency gradient that lets the object 'fade out' in y-direction.

A Vizard cylinder consists of a configurable number of slices, iirc. Is there any way to access those slices individually?
Reply With Quote
  #2  
Old 08-31-2018, 11:56 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The cylinder object does not have any commands to access individual slices. It's building up the object using on-the-fly triangle fans. If you look into the vizshape code, it maybe possible to modify the cylinder object and apply different alpha values as the triangle fans are created. If you have access to 3ds Max, you could export a cylinder with alpha map.
Reply With Quote
  #3  
Old 09-04-2018, 04:45 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Jeff, thank you for your reply and the advice.

In the meantime I have created my own slice-based cylinder (100 slices, simply looped code with increasing height offset) with a decreasing alpha. Looks ok-ish for the purpose. I only have one issue with this:

The floor of the experimental space should resemble something like grass. I can't remember how but we ended up with an osgb object imported into the scene. At certain points of the experiment the floor gets rotated to prevent the participants to develop any orientation strategies apart from their actual instructions. And ever time after this rotation of the osgb model my cylinder gets opaque and strangely darkish if viewed from one half of the experimental space. From the other half it maintains its transparency. It does not matter whether the cylinder was present all the time, was set to invisible in the meantime, or got re-created from scratch.

Do you have any idea why this might be and how I could prevent it?


EDIT: And now I understand your above comment: the cylinder does not actually consist of slices, but more like cake pieces (makes sense, determines its roundness). This is why you were talking about fan-like elements.

Last edited by peterparker; 09-04-2018 at 04:51 AM.
Reply With Quote
  #4  
Old 09-05-2018, 05:53 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Maybe some visuals to illustrate what I mean. the left side shows transparency working. If I rotate the view only a little bit further, it does not work anymore. Basically the question is: do I look in the direction of 180° (left side, working) or 0° (right side, not working).

Reply With Quote
  #5  
Old 09-05-2018, 08:23 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Turns out I was wrong. Around the ground rotation event there is a fade-out/fade-in sequence, which manipulates the alpha value of the ground model. This fading process actually is the culprit.

Now I only need to find out, how to fade out the ground without manipulating its alpha. And it would be interesting to understand, why the fading breaks my tube transparency, in the first place.

(sorry for the confusion, this code isn't originally by me)
Reply With Quote
  #6  
Old 09-05-2018, 08:50 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Can you post example code that reproduces the issue?
Reply With Quote
  #7  
Old 09-06-2018, 04:23 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Code:
import viz, vizshape, vizact
import random


# run script
viz.go()
viz.setMultiSample(4)


# create world
#world = viz.add('spot_rotation_resources/circle_grass_lukas2.osgb')

world = vizshape.addCylinder(.01,50)
#tex = viz.addTexture('GRASS.JPG')
#world.texture(tex)
world.color(viz.GREEN)

light = viz.addLight()
light.setEuler(0,45,0)


# create spot
spot_elevation = .05
spot_height = 2.5
spot_nslices = 1	#originally 100
spot_slice_height = spot_height / spot_nslices
alpha_start = 0.5
alpha_end = 0.0
alpha_step = (alpha_end - alpha_start)/spot_nslices

spot = []

for a in range(spot_nslices):
	cyl = vizshape.addCylinder(height=spot_slice_height, radius=0.30, color=viz.YELLOW, top=None)
	cyl.alpha( alpha_start + a*alpha_step )
	spot_yPos = spot_slice_height/2 + spot_elevation + a*spot_slice_height
	cyl.setPosition([0,spot_yPos,10])
	spot.append(cyl)


# rotate ground
def random_rotate(object_to_rotate, duration):

        rotate_val = random.randint(1, 360)

        spinto = vizact.spinTo(euler=(rotate_val, 0, 0), time=0, mode=viz.REL_GLOBAL)
        fadeout = vizact.fadeTo(0, time=duration)
        fadein = vizact.fadeTo(1, time=duration)

        rotate_action = vizact.sequence(fadeout, spinto, fadein)
        object_to_rotate.addAction(rotate_action)

vizact.onkeydown('r', random_rotate, world, 1)

Also works with
Code:
vizact.onkeydown('s', world.alpha, .9)
instead of the fading action.

Last edited by peterparker; 09-06-2018 at 04:29 AM.
Reply With Quote
  #8  
Old 09-06-2018, 04:42 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
EDIT: I can even use 's' first (see above) and _then_ create the spot. Same result.
Reply With Quote
  #9  
Old 09-10-2018, 09:52 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
It seems to be an issue with alpha and blending multiple objects. See the limitations and workarounds page here. Try enabling alpha to coverage and disabling blending on each of the cylinder parts and scene model.
Reply With Quote
  #10  
Old 09-11-2018, 01:47 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Ok, so I do this for my ground model and for each cylinder slice:

Code:
cyl.enable(viz.SAMPLE_ALPHA_TO_COVERAGE)
cyl.disable(viz.BLEND)
Do I do this before or after setting the alpha value? I have tried both and it seems to not help.
Reply With Quote
  #11  
Old 09-17-2018, 06:41 AM
peterparker peterparker is offline
Member
 
Join Date: Aug 2018
Posts: 12
Jeff, any idea why this does not work for me?
Reply With Quote
  #12  
Old 09-18-2018, 03:22 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
I'll check with a developer for suggestions.
Reply With Quote
  #13  
Old 09-19-2018, 03:10 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The following code works for me. The appearance of the cylinder parts do not change when the ground is faded. I had an issue with the alpha that was fixed after updating my nvidia graphics drivers.

Code:
import viz, vizshape, vizact
import random

viz.setMultiSample(4)
viz.go()

world = viz.addChild('ground.osgb')

light = viz.addLight()
light.setEuler(0,45,0)

# create spot
spot_elevation = .05
spot_height = 2.5
spot_nslices = 4	#originally 100
spot_slice_height = spot_height / spot_nslices
alpha_start = 0.5
alpha_end = 0.0
alpha_step = (alpha_end - alpha_start)/spot_nslices
print alpha_step
spot = []

for a in range(spot_nslices):
	cyl = vizshape.addCylinder(height=spot_slice_height, radius=0.30, color=viz.YELLOW, top=None)	
	print a*alpha_step
	cyl.alpha( alpha_start + a*alpha_step )
	cyl.enable(viz.SAMPLE_ALPHA_TO_COVERAGE)
	cyl.disable(viz.BLEND)
	spot_yPos = spot_slice_height/2 + spot_elevation + a*spot_slice_height
	cyl.setPosition([0,spot_yPos,10])
	spot.append(cyl)

# rotate ground
def random_rotate(object_to_rotate, duration):

        rotate_val = random.randint(1, 360)

        spinto = vizact.spinTo(euler=(rotate_val, 0, 0), time=0, mode=viz.REL_GLOBAL)
        fadeout = vizact.fadeTo(0, time=duration)
        fadein = vizact.fadeTo(1, time=duration)

        rotate_action = vizact.sequence(fadeout, spinto, fadein)
        object_to_rotate.addAction(rotate_action)

vizact.onkeydown('r', random_rotate, world, 1)


import vizcam
cam = vizcam.PivotNavigate(center=[0,0,10],distance = 7)
cam.rotateUp(30)
Reply With Quote
Reply

Tags
cylinder, gradient, transparency

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
maintaining transparency in a model while fading in krimble Vizard 3 08-17-2017 06:10 AM
transparency control hankiwan Vizard 1 02-14-2012 07:02 AM
How to vary the transparency of the scene whj Vizard 2 04-04-2010 08:16 PM
How to vary the transparency of part of the scene whj Vizard 0 04-02-2010 02:32 PM
Quicktime movie with transparency channel aaThomas Vizard 7 11-12-2007 09:54 AM


All times are GMT -7. The time now is 10:34 AM.


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