Alpha in Sketcup::Color
-
One of the things that messed up our ruby script in SketchUp 8.0 was the addition alpha to the class Sketchup::Color.
Try this line in the ruby console:
printf("%#x\n", Sketchup::Color.new('white'))
in SU 7 it displays: 0xffffff
in SU 8 it displays: 0xffffffff
We fixed our applications, but does anyone know anything good that the new alpha channel is used for?
-
I see the documentation says:
@unknownuser said:
NOTE: Assigning an alpha does not actually work.
color = Sketchup::Color.new "AliceBlue"
alpha = color.alpha = 255 -
This, or not?
-
My guess was that it is transparency, like you can control the transparency of a material inside of SketchUp in the materials browser. Maybe they finally made it work via Ruby?
-
It's a mysterious property - as you have to use material.alpha to set a material's transparency. I never got any explanation to the alpha property of Color - I did request it could be made use of for when you draw on to the viewport with the GL methods, but still not seen anything of it.
It is odd that they made some changes in SU8 in regard to this property - would be interesting to know why. Because the release notes doesn't say nothing.
-
The 'draw' colors are OpenGL standard colors only and seem unconnected to the model.materials - so transparency is not available to them anyway. I think that making the color 'red' say [0,0,0] in the model doesn't affect the color 'red' used in the 'draw' methods.
A 'color' has always has an 'alpha' value [but it was never used!].
I think that the 'A' transparency in color [R,G,B,A] is a hangover from a much earlier SUp version where it was planned that you applied a 'color' to a face - so you would then need aplha 'A' for its transparency... BUT when 'materials' [allowing texture-images etc] were introduced they contained the transparency property and thereafter the 'color' only needed to be in RGB. So if you add a value for alpha 'A' to a color it is just ignored in its rendering but remembered in its values: but if you add no value it defaults to 255.
The API notes say, "color.alpha=i - NOTE: Though documented historically in the Ruby API, this method has never been implemented."Here's the rub...
v7.
Sketchup::Color.new('white')
Color(255, 255, 255, 255)
printf("%#x\n", Sketchup::Color.new('white'))
0xffffff
Sketchup::Color.new('white').to_a
[255, 255, 255, 255]
Sketchup::Color.new('white')**.to_i**
16777215 <<<<<<<<<<<<<<<<<<<<< NOTE
Sketchup::Color.new(255, 255, 255)
Color(255, 255, 255, 255)
Sketchup::Color.new(255, 255, 255, 255)
Color(255, 255, 255, 255)
Sketchup::Color.new(255, 255, 255, 123)
Color(255, 255, 255, 123)
printf("%#x\n", **16777215**)
<<<<<<<<<<<<<<<<<<<<< NOTE
0xffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255))
<<<<<<<<<<< NOTE
0xffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255, 255))
0xffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255, **123**))
0xffffff
Sketchup::Color.new(255, 255, 255, 123).to_i
16777215 <<<<<<<<<<<<<<<<<<<<< NOTE[the unused alpha is ignored in the i/hex value]
v8.
Sketchup::Color.new('white')
Color(255, 255, 255, 255)
printf("%#x\n", Sketchup::Color.new('white'))
0xffffffff
Sketchup::Color.new('white').to_a
[255, 255, 255, 255]
Sketchup::Color.new('white')**.to_i**
4294967295 <<<<<<<<<<<<<<<<<<<<< NOTE
Sketchup::Color.new(255, 255, 255)
Color(255, 255, 255, 255)
Sketchup::Color.new(255, 255, 255, 123)
Color(255, 255, 255, 123)
printf("%#x\n", **4294967295**)
<<<<<<<<<<<<<<<<<<<<< NOTE
0xffffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255))
<<<<<<<<<< NOTE
0xffffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255, 255))
0xffffffff
printf("%#x\n", Sketchup::Color.new(255, 255, 255, **123**))
0xffffffff
Sketchup::Color.new(255, 255, 255, 123).to_i
4294967295 <<<<<<<<<<<<<<<<<<<<< NOTE[AGAIN the unused alpha is ignored in the i/hex value]
The 'integer value' of the color is being returned as a different value between v7 and v8 BUT the alpha is actually ignored in BOTH versions - so the alpha issue is therefore a red-herring.
In v8 it is now a
Bignum
soface.material=0xffffffff
fails - whereas in v7 it's a [ruby:3hoxppyu]Fixnum[/ruby:3hoxppyu] so [ruby:3hoxppyu]face.material=0xffffff[/ruby:3hoxppyu] works !Somebody broke 'Color'...
I'll lodge a v8 bug-report...
Advertisement