WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   trouble changing subnode (child node) color, alpha, etc. (https://forum.worldviz.com/showthread.php?t=1738)

michaelrepucci 12-03-2008 10:40 AM

trouble changing subnode (child node) color, alpha, etc.
 
I'm having trouble setting various properties (e.g., color, alpha, ambient) for on-the-fly objects when they are the children (or subnodes) of other objects. For example

Code:

square = makeOTFSquare()
square.color(viz.RED)

works just fine, but

Code:

square = makeOTFSquare()
square2 = makeOTFSquare()
square2.setPosition(someOffset)
square2.parent(square)
square.color(viz.RED)

only changes the color of square, not square2. I tried changing the OpMode of the square node, either when setting the color, or globally via square.setOpMode, but none of the OpMode options changes this behavior.

Is there any easy way to do this, or will I have to loop over all the child (and grand-child, great-grand-child, etc.) nodes, changing each one individually?

michaelrepucci 12-08-2008 04:39 PM

Still having the same trouble, though I have found that some node properties do get passed onto children. For example, setting .lineWidth or .pointSize works as I would like. Any thoughts?

farshizzo 12-09-2008 09:18 AM

Does it work if you put all the OTF nodes underneath a group node, and then apply the color to the group node?

michaelrepucci 12-09-2008 10:15 AM

No, actually, that was how I first tried it. It doesn't work either way.

farshizzo 12-09-2008 10:48 AM

Can you post a working script that reproduces this specific problem? I tried the following script and it works for me. It loads 2 OTF nodes underneath a group node. When the spacebar is pressed, it will set the color of the group node to red, which gets applied to the OTF nodes.
Code:

import vizshape
viz.go()

group = viz.addGroup(pos=(0,1,10))

box = vizshape.addBox(parent=group,color=viz.BLUE,pos=(-1,0,0))
sphere = vizshape.addSphere(parent=group,color=viz.GREEN,pos=(1,0,0))

vizact.onkeydown(' ',group.color,viz.RED)


michaelrepucci 12-09-2008 11:53 AM

Interesting ... I wish I'd known about vizshape, because I've basically recreated much of its functionality, and in an apparently inferior way. I can't seem to find any documentation on vizshape, and its code comments are rather sparse as well. What you sent me does work.

Here's an example of what I did (a bit stripped down but reproduces the error):

Code:

import viz
import math

class Circle(viz.VizPrimitive):
        def __init__(self):
                #draw circle
                viz.startlayer(viz.LINE_LOOP)
                for i in range(32):
                        radians = 2*math.pi*i/32
                        viz.vertex([math.sin(radians),math.cos(radians),0])
                self.node = viz.endlayer()
               
                #initialize base class
                viz.VizPrimitive.__init__(self,self.node.id)

class Probe(viz.VizPrimitive):
        def __init__(self):
                #draw probe
                self.node = viz.addGroup()
               
                #draw circle
                circle = Circle()
                circle.parent(self.node)
               
                #draw lines
                viz.startlayer(viz.LINES)
                viz.vertex(0,0,0)
                viz.vertex(0,0,-1)
                line = viz.endlayer(self.node)
               
                #initialize base class
                viz.VizPrimitive.__init__(self,self.node.id)
       
viz.go()
viz.eyeheight(0)

probe = Probe()
probe.setPosition(0,0,5)
probe.setEuler(20,10,0)
probe.color(viz.RED)
probe.lineWidth(10)

Here you will notice the probe shows up with wide lines, but in white, not red.

michaelrepucci 12-30-2008 08:40 AM

Can anyone explain why my classes don't work correctly for setting color? I'm a bit boggled, and looking over the vizshape module didn't really clarify anything for me.

Gladsomebeast 01-14-2009 08:38 PM

I run into a similar problem when creating GUIs. Some child nodes don't take the alpha of their parent. In the following example the texture quad does inherit the parent's alpha, the text and on-the-fly objects do not.

By the by, I only got the texture quad to take the parent's alpha when I set the alpha call's op mode to viz.OP_OVERRIDE.

Code:

import viz
viz.go()
viz.clearcolor(viz.SKYBLUE)
forceIDRoot = viz.addGroup(parent=viz.SCREEN, pos=[.40, .92, 0])
forceIDRoot.alpha(.5, op=viz.OP_OVERRIDE) # viz.OP_OVERRIDE gets the quad alphaed
forceIDQuad = viz.addTexQuad(parent=forceIDRoot, scale=[4.5,1,0]) #yes alpha
#no text alpha
t = viz.addText('afdasdf asdfasdf', parent=forceIDRoot, pos=[-.165, .01, 0], scale=[.3]*3)
t.color(viz.BLACK)

viz.startlayer(viz.QUADS)
viz.vertex([0,0,0])
viz.vertex([.5,0,0])
viz.vertex([.5,.5,0])
viz.vertex([0,.5,0])
viz.endlayer(parent=forceIDRoot) #no alpha?



All times are GMT -7. The time now is 09:36 AM.

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