discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Strange coloring behavior

MV
Maurice van Peursem
Sun, Apr 9, 2023 2:36 AM

I try to color one half of an object (in this case a cube) in one color,
and the other half in a different color, like this:

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I cut off one half of the object and color it red, and then in the same
way the other half green. If you execute only the first part you get a
red half cube, however, if you execute both parts you get a green full
cube, the red is gone, apparently overruled by the green.

My provisional solution is to slightly reduce the size of the second
part, and this works. But it seems this is an error in OpenSCAD, if you
cut off a part of an object, it should cut off the color too....

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
scale([1,.99,.99])
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I use OpenSCAD 2021.01 on an M2 Mac.

Maurice

I try to color one half of an object (in this case a cube) in one color, and the other half in a different color, like this: color("red") difference(){ cube(30,center=true); translate([15,0,0]) cube([30,31,31],center=true); } color("green") difference(){ cube(30,center=true); translate([-15,0,0]) cube([30,31,31],center=true); } I cut off one half of the object and color it red, and then in the same way the other half green. If you execute only the first part you get a red half cube, however, if you execute both parts you get a green full cube, the red is gone, apparently overruled by the green. My provisional solution is to slightly reduce the size of the second part, and this works. But it seems this is an error in OpenSCAD, if you cut off a part of an object, it should cut off the color too.... color("red") difference(){ cube(30,center=true); translate([15,0,0]) cube([30,31,31],center=true); } color("green") difference(){ scale([1,.99,.99]) cube(30,center=true); translate([-15,0,0]) cube([30,31,31],center=true); } I use OpenSCAD 2021.01 on an M2 Mac. Maurice
MM
Michael Möller
Sun, Apr 9, 2023 1:25 PM

color("red") *render() *
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}

color("green") *render() *
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

works after I added the render() for each half in the original
first example. Others can explain why, I just had a hunch after having tried
color("red") sphere(d=50);
color("green") cube(40) ;
and confirmed that colors do not "override" on a join

Msquare

On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem openscad@vanpeursem.net
wrote:

I try to color one half of an object (in this case a cube) in one color,
and the other half in a different color, like this:

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I cut off one half of the object and color it red, and then in the same
way the other half green. If you execute only the first part you get a
red half cube, however, if you execute both parts you get a green full
cube, the red is gone, apparently overruled by the green.

My provisional solution is to slightly reduce the size of the second
part, and this works. But it seems this is an error in OpenSCAD, if you
cut off a part of an object, it should cut off the color too....

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
scale([1,.99,.99])
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I use OpenSCAD 2021.01 on an M2 Mac.

Maurice


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

color("red") *render() * difference(){ cube(30,center=true); translate([15,0,0]) cube([30,31,31],center=true); } color("green") *render() * difference(){ cube(30,center=true); translate([-15,0,0]) cube([30,31,31],center=true); } works after I added the render() for each half in the original first example. Others can explain why, I just had a hunch after having tried color("red") sphere(d=50); color("green") cube(40) ; and confirmed that colors do not "override" on a join Msquare On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem <openscad@vanpeursem.net> wrote: > I try to color one half of an object (in this case a cube) in one color, > and the other half in a different color, like this: > > color("red") > difference(){ > cube(30,center=true); > translate([15,0,0]) > cube([30,31,31],center=true); > } > color("green") > difference(){ > cube(30,center=true); > translate([-15,0,0]) > cube([30,31,31],center=true); > } > > I cut off one half of the object and color it red, and then in the same > way the other half green. If you execute only the first part you get a > red half cube, however, if you execute both parts you get a green full > cube, the red is gone, apparently overruled by the green. > > My provisional solution is to slightly reduce the size of the second > part, and this works. But it seems this is an error in OpenSCAD, if you > cut off a part of an object, it should cut off the color too.... > > color("red") > difference(){ > cube(30,center=true); > translate([15,0,0]) > cube([30,31,31],center=true); > } > color("green") > difference(){ > scale([1,.99,.99]) > cube(30,center=true); > translate([-15,0,0]) > cube([30,31,31],center=true); > } > > I use OpenSCAD 2021.01 on an M2 Mac. > > Maurice > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
MK
Marius Kintel
Sun, Apr 9, 2023 1:52 PM

I’m pretty sure this is a weakness in the CSG rendering library we use (OpenCSG). If two overlapping CSG objects produce exactly the same coordinates, but different color values, the last color will win.

-Marius

On Apr 8, 2023, at 22:36, Maurice van Peursem openscad@vanpeursem.net wrote:

I try to color one half of an object (in this case a cube) in one color, and the other half in a different color, like this:

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I cut off one half of the object and color it red, and then in the same way the other half green. If you execute only the first part you get a red half cube, however, if you execute both parts you get a green full cube, the red is gone, apparently overruled by the green.

My provisional solution is to slightly reduce the size of the second part, and this works. But it seems this is an error in OpenSCAD, if you cut off a part of an object, it should cut off the color too....

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
difference(){
scale([1,.99,.99])
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

I use OpenSCAD 2021.01 on an M2 Mac.

Maurice


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I’m pretty sure this is a weakness in the CSG rendering library we use (OpenCSG). If two overlapping CSG objects produce exactly the same coordinates, but different color values, the last color will win. -Marius > On Apr 8, 2023, at 22:36, Maurice van Peursem <openscad@vanpeursem.net> wrote: > > I try to color one half of an object (in this case a cube) in one color, and the other half in a different color, like this: > > color("red") > difference(){ > cube(30,center=true); > translate([15,0,0]) > cube([30,31,31],center=true); > } > color("green") > difference(){ > cube(30,center=true); > translate([-15,0,0]) > cube([30,31,31],center=true); > } > > I cut off one half of the object and color it red, and then in the same way the other half green. If you execute only the first part you get a red half cube, however, if you execute both parts you get a green full cube, the red is gone, apparently overruled by the green. > > My provisional solution is to slightly reduce the size of the second part, and this works. But it seems this is an error in OpenSCAD, if you cut off a part of an object, it should cut off the color too.... > > color("red") > difference(){ > cube(30,center=true); > translate([15,0,0]) > cube([30,31,31],center=true); > } > color("green") > difference(){ > scale([1,.99,.99]) > cube(30,center=true); > translate([-15,0,0]) > cube([30,31,31],center=true); > } > > I use OpenSCAD 2021.01 on an M2 Mac. > > Maurice > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
MV
Maurice van Peursem
Sun, Apr 9, 2023 9:58 PM

Thanks for that! There is no need to use render() on the first part, and
when I did use it I got a strange, transparent looking result (my object
is more complicated than a simple cube). But if you only use render() on
the second part, everything works out perfectly.

Maurice

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
render()
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

On 09/04/2023 15:25, Michael Möller wrote:

color("red") /render() /
        difference(){
                cube(30,center=true);
                translate([15,0,0])
                        cube([30,31,31],center=true);
        }

color("green") /render() /
        difference(){
                cube(30,center=true);
                translate([-15,0,0])
                        cube([30,31,31],center=true);
        }

works after I added the render() for each half in the original
first example. Others can explain why, I just had a hunch after having tried
color("red") sphere(d=50);
color("green") cube(40) ;
and confirmed that colors do not "override" on a join

Msquare

On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem
<openscad@vanpeursem.net mailto:openscad@vanpeursem.net> wrote:

 I try to color one half of an object (in this case a cube) in one
 color,
 and the other half in a different color, like this:

 color("red")
          difference(){
                  cube(30,center=true);
                  translate([15,0,0])
                          cube([30,31,31],center=true);
          }
 color("green")
          difference(){
                  cube(30,center=true);
                  translate([-15,0,0])
                          cube([30,31,31],center=true);
          }

 I cut off one half of the object and color it red, and then in the same
 way the other half green. If you execute only the first part you get a
 red half cube, however, if you execute both parts you get a green full
 cube, the red is gone, apparently overruled by the green.

 My provisional solution is to slightly reduce the size of the second
 part, and this works. But it seems this is an error in OpenSCAD, if you
 cut off a part of an object, it should cut off the color too....

 color("red")
          difference(){
                  cube(30,center=true);
                  translate([15,0,0])
                          cube([30,31,31],center=true);
          }
 color("green")
          difference(){
                  scale([1,.99,.99])
                          cube(30,center=true);
                          translate([-15,0,0])
                                  cube([30,31,31],center=true);
          }

 I use OpenSCAD 2021.01 on an M2 Mac.

 Maurice
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org
 <mailto:discuss-leave@lists.openscad.org>

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks for that! There is no need to use render() on the first part, and when I did use it I got a strange, transparent looking result (my object is more complicated than a simple cube). But if you only use render() on the second part, everything works out perfectly. Maurice color("red") difference(){ cube(30,center=true); translate([15,0,0]) cube([30,31,31],center=true); } color("green") render() difference(){ cube(30,center=true); translate([-15,0,0]) cube([30,31,31],center=true); } On 09/04/2023 15:25, Michael Möller wrote: > color("red") /render() / >         difference(){ >                 cube(30,center=true); >                 translate([15,0,0]) >                         cube([30,31,31],center=true); >         } > > color("green") /render() / >         difference(){ >                 cube(30,center=true); >                 translate([-15,0,0]) >                         cube([30,31,31],center=true); >         } > > works after I added the render() for each half in the original > first example. Others can explain why, I just had a hunch after having tried > color("red") sphere(d=50); > color("green") cube(40) ; > and confirmed that colors do not "override" on a join > > Msquare > > On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem > <openscad@vanpeursem.net <mailto:openscad@vanpeursem.net>> wrote: > > I try to color one half of an object (in this case a cube) in one > color, > and the other half in a different color, like this: > > color("red") >         difference(){ >                 cube(30,center=true); >                 translate([15,0,0]) >                         cube([30,31,31],center=true); >         } > color("green") >         difference(){ >                 cube(30,center=true); >                 translate([-15,0,0]) >                         cube([30,31,31],center=true); >         } > > I cut off one half of the object and color it red, and then in the same > way the other half green. If you execute only the first part you get a > red half cube, however, if you execute both parts you get a green full > cube, the red is gone, apparently overruled by the green. > > My provisional solution is to slightly reduce the size of the second > part, and this works. But it seems this is an error in OpenSCAD, if you > cut off a part of an object, it should cut off the color too.... > > color("red") >         difference(){ >                 cube(30,center=true); >                 translate([15,0,0]) >                         cube([30,31,31],center=true); >         } > color("green") >         difference(){ >                 scale([1,.99,.99]) >                         cube(30,center=true); >                         translate([-15,0,0]) >                                 cube([30,31,31],center=true); >         } > > I use OpenSCAD 2021.01 on an M2 Mac. > > Maurice > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > <mailto:discuss-leave@lists.openscad.org> > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
MM
Michael Möller
Mon, Apr 10, 2023 1:29 PM

The "strange transparency" may be resolved by using render(convexity=10) or
a slightly higer number

Michael, fra mobilen

søn. 9. apr. 2023 23.59 skrev Maurice van Peursem openscad@vanpeursem.net:

Thanks for that! There is no need to use render() on the first part, and
when I did use it I got a strange, transparent looking result (my object
is more complicated than a simple cube). But if you only use render() on
the second part, everything works out perfectly.

Maurice

color("red")
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}
color("green")
render()
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

On 09/04/2023 15:25, Michael Möller wrote:

color("red") /render() /
difference(){
cube(30,center=true);
translate([15,0,0])
cube([30,31,31],center=true);
}

color("green") /render() /
difference(){
cube(30,center=true);
translate([-15,0,0])
cube([30,31,31],center=true);
}

works after I added the render() for each half in the original
first example. Others can explain why, I just had a hunch after having

tried

color("red") sphere(d=50);
color("green") cube(40) ;
and confirmed that colors do not "override" on a join

Msquare

On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem
<openscad@vanpeursem.net mailto:openscad@vanpeursem.net> wrote:

 I try to color one half of an object (in this case a cube) in one
 color,
 and the other half in a different color, like this:

 color("red")
          difference(){
                  cube(30,center=true);
                  translate([15,0,0])
                          cube([30,31,31],center=true);
          }
 color("green")
          difference(){
                  cube(30,center=true);
                  translate([-15,0,0])
                          cube([30,31,31],center=true);
          }

 I cut off one half of the object and color it red, and then in the

same

 way the other half green. If you execute only the first part you get

a

 red half cube, however, if you execute both parts you get a green

full

 cube, the red is gone, apparently overruled by the green.

 My provisional solution is to slightly reduce the size of the second
 part, and this works. But it seems this is an error in OpenSCAD, if

you

 cut off a part of an object, it should cut off the color too....

 color("red")
          difference(){
                  cube(30,center=true);
                  translate([15,0,0])
                          cube([30,31,31],center=true);
          }
 color("green")
          difference(){
                  scale([1,.99,.99])
                          cube(30,center=true);
                          translate([-15,0,0])
                                  cube([30,31,31],center=true);
          }

 I use OpenSCAD 2021.01 on an M2 Mac.

 Maurice
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org
 <mailto:discuss-leave@lists.openscad.org>

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The "strange transparency" may be resolved by using render(convexity=10) or a slightly higer number Michael, fra mobilen søn. 9. apr. 2023 23.59 skrev Maurice van Peursem <openscad@vanpeursem.net>: > Thanks for that! There is no need to use render() on the first part, and > when I did use it I got a strange, transparent looking result (my object > is more complicated than a simple cube). But if you only use render() on > the second part, everything works out perfectly. > > Maurice > > color("red") > difference(){ > cube(30,center=true); > translate([15,0,0]) > cube([30,31,31],center=true); > } > color("green") > render() > difference(){ > cube(30,center=true); > translate([-15,0,0]) > cube([30,31,31],center=true); > } > > On 09/04/2023 15:25, Michael Möller wrote: > > color("red") /render() / > > difference(){ > > cube(30,center=true); > > translate([15,0,0]) > > cube([30,31,31],center=true); > > } > > > > color("green") /render() / > > difference(){ > > cube(30,center=true); > > translate([-15,0,0]) > > cube([30,31,31],center=true); > > } > > > > works after I added the render() for each half in the original > > first example. Others can explain why, I just had a hunch after having > tried > > color("red") sphere(d=50); > > color("green") cube(40) ; > > and confirmed that colors do not "override" on a join > > > > Msquare > > > > On Sun, 9 Apr 2023 at 04:37, Maurice van Peursem > > <openscad@vanpeursem.net <mailto:openscad@vanpeursem.net>> wrote: > > > > I try to color one half of an object (in this case a cube) in one > > color, > > and the other half in a different color, like this: > > > > color("red") > > difference(){ > > cube(30,center=true); > > translate([15,0,0]) > > cube([30,31,31],center=true); > > } > > color("green") > > difference(){ > > cube(30,center=true); > > translate([-15,0,0]) > > cube([30,31,31],center=true); > > } > > > > I cut off one half of the object and color it red, and then in the > same > > way the other half green. If you execute only the first part you get > a > > red half cube, however, if you execute both parts you get a green > full > > cube, the red is gone, apparently overruled by the green. > > > > My provisional solution is to slightly reduce the size of the second > > part, and this works. But it seems this is an error in OpenSCAD, if > you > > cut off a part of an object, it should cut off the color too.... > > > > color("red") > > difference(){ > > cube(30,center=true); > > translate([15,0,0]) > > cube([30,31,31],center=true); > > } > > color("green") > > difference(){ > > scale([1,.99,.99]) > > cube(30,center=true); > > translate([-15,0,0]) > > cube([30,31,31],center=true); > > } > > > > I use OpenSCAD 2021.01 on an M2 Mac. > > > > Maurice > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > <mailto:discuss-leave@lists.openscad.org> > > > > > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
MV
Maurice van Peursem
Wed, Apr 12, 2023 9:28 PM

Thanks Michael, that did help indeed!

Maurice

On 10/04/2023 15:29, Michael Möller wrote:

The "strange transparency" may be resolved by using render(convexity=10)
or a slightly higher number

Michael, fra mobilen

søn. 9. apr. 2023 23.59 skrev Maurice van Peursem
<openscad@vanpeursem.net mailto:openscad@vanpeursem.net>:

 Thanks for that! There is no need to use render() on the first part,
 and
 when I did use it I got a strange, transparent looking result (my
 object
 is more complicated than a simple cube). But if you only use
 render() on
 the second part, everything works out perfectly.

 Maurice

 color("red")
       difference(){
           cube(30,center=true);
           translate([15,0,0])
               cube([30,31,31],center=true);
       }
 color("green")
       render()
           difference(){
               cube(30,center=true);
               translate([-15,0,0])
                   cube([30,31,31],center=true);
       }
Thanks Michael, that did help indeed! Maurice On 10/04/2023 15:29, Michael Möller wrote: > The "strange transparency" may be resolved by using render(convexity=10) > or a slightly higher number > > Michael, fra mobilen > > søn. 9. apr. 2023 23.59 skrev Maurice van Peursem > <openscad@vanpeursem.net <mailto:openscad@vanpeursem.net>>: > > Thanks for that! There is no need to use render() on the first part, > and > when I did use it I got a strange, transparent looking result (my > object > is more complicated than a simple cube). But if you only use > render() on > the second part, everything works out perfectly. > > Maurice > > color("red") >      difference(){ >          cube(30,center=true); >          translate([15,0,0]) >              cube([30,31,31],center=true); >      } > color("green") >      render() >          difference(){ >              cube(30,center=true); >              translate([-15,0,0]) >                  cube([30,31,31],center=true); >      } >