Color problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Color problem

Gordon Wrigley
With regard to this block of code:

module bob(){
    union(){
        for(i=[0:$children-1]){
            for(j=[0:$children-1]){
                if(i != j){
                    color([1,0,0,1]){
                        intersection(){
                            child(i);
                            child(j);
                        }
                    }
                }
            }
        }                         // XXX
        for(i=[0:$children-1]){   // XXX
            color([1,1,0,0.5]){
                child(i);
            }
        }
    }
}

bob(){
    cylinder(r=10,h=20,center=true);
    translate([-15,0,0]) cylinder(r=10,h=10,center=true);
    translate([15,0,0]) cylinder(r=10,h=10,center=true);
}

It seems that the two lines marked with // XXX should be redundant, but if you comment them out the coloration of the object changes. I don't understand why that happens. What am I doing wrong?

Version stuff:

OpenSCAD 2011.09.30 (www.openscad.org)

Visitor refactored version

openscad deb: 2011.09~git20110929-1natty1

libopencsg1 deb: 1.2.1-4

Linux koi 2.6.38-13-generic-pae #55-Ubuntu SMP Tue Jan 24 15:54:51 UTC 2012 i686 athlon i386 GNU/Linux


Regards G


Reply | Threaded
Open this post in threaded view
|

Re: Color problem

Gordon Wrigley
I found a much simpler example of color confusion.

union(){
    intersection(){
        cube(size=10, center=true);
        translate([5,5,5]) sphere(r=10);
    }
    color([1,1,0,0.5]) cube(size=10, center=true);
}

if you move the color line above the intersection like this:

union(){
    color([1,1,0,0.5]) cube(size=10, center=true);
    intersection(){
        cube(size=10, center=true);
        translate([5,5,5]) sphere(r=10);
    }
}

Then the behavior changes.

On Sun, Feb 5, 2012 at 12:31 PM, Gordon Wrigley <[hidden email]> wrote:
With regard to this block of code:

module bob(){
    union(){
        for(i=[0:$children-1]){
            for(j=[0:$children-1]){
                if(i != j){
                    color([1,0,0,1]){
                        intersection(){
                            child(i);
                            child(j);
                        }
                    }
                }
            }
        }                         // XXX
        for(i=[0:$children-1]){   // XXX
            color([1,1,0,0.5]){
                child(i);
            }
        }
    }
}

bob(){
    cylinder(r=10,h=20,center=true);
    translate([-15,0,0]) cylinder(r=10,h=10,center=true);
    translate([15,0,0]) cylinder(r=10,h=10,center=true);
}

It seems that the two lines marked with // XXX should be redundant, but if you comment them out the coloration of the object changes. I don't understand why that happens. What am I doing wrong?

Version stuff:

OpenSCAD 2011.09.30 (www.openscad.org)

Visitor refactored version

openscad deb: 2011.09~git20110929-1natty1

libopencsg1 deb: 1.2.1-4

Linux koi 2.6.38-13-generic-pae #55-Ubuntu SMP Tue Jan 24 15:54:51 UTC 2012 i686 athlon i386 GNU/Linux


Regards G



Reply | Threaded
Open this post in threaded view
|

Re: Color problem

kintel
Administrator
In reply to this post by Gordon Wrigley
On Feb 5, 2012, at 02:31 AM, Gordon Wrigley wrote:
>
> It seems that the two lines marked with // XXX should be redundant, but if you comment them out the coloration of the object changes. I don't understand why that happens. What am I doing wrong?
>
Thanks for you minimal example!

I can reproduce it here - it looks like something weird is going on when rendering intersected objects if the z-buffer is already filled with the contents of one of the intersected objects.
This might be an artifact of how OpenCSG handles intersections, but I would need to look into that in more detail.
Otoh, even if this would work, you'd run into a transparency weakness causing your intersections to be shadowed by the primary objects.

One workaround to your problem would be to ensure to always render the primary objects last. You can do this by changing your second for loop to  "for(j=[1:$children-1]){"

 -Marius