Transparency in Sketchup 6
-
I'm trying to programatically create a new transparent material and I'm having trouble getting this to work in Sketchup 6. Worked fine in 8 but backporting to 6 and its not.
All I'm doing is the following
$transparent_matl = Sketchup::Color.new
$transparent_matl.red = 255
$transparent_matl.green = 255
$transparent_matl.blue = 255
$transparent_matl.alpha = 0When I do this in 6, the entity gets colored white but completely opaque. My new material does get added to the materials list. And from there I can assign it to the entity and see the transparency.... This worked fine in 8 and I'd like to get it to work in 6 if possible.
Any ideas?
Thanks,
Josh -
EDIT: Looks like TOMOT has a working example, cool!
-
this is an example of how I used it in v6 and it still works now
glass=entities.add_face(@pt0jj, @pt1jj, @pt2jj, @pt3jj) glass.material=Sketchup;;Color.new(163,204,204) #use RGB Color numbers glass.material.alpha = 0.6 status=glaz.back_material=Sketchup;;Color.new(163,204,204) #use RGB Color numbers glaz.material.alpha = 0.6
-
Until the latest version of 8 color transparency [alpha] didn't work - now you can make a color [e.g.
color.alpha=0.5
] and give it a transparency to use in a 'view.draw' command as colored faces are fixed in 'draw' for v8.
Giving a material's color transparency still has no affect on how thatmaterial displays, you need to give the transparency [alpha] to the material itself e.g.material.alpha=0.5
...
People often confusecolor.alpha
andmaterial.alpha
-
Thanks for the help guys. I switched up my code to apply the alpha to the material vs the color but am still having problems. Here what I'm experiencing now.
If I use my tool to apply the new color (white with alpha=.1), the entity just turns white with no alpha. If I then bring up the materials editor and edit my newly created material, it properly shows up in the dialog as having an alpha of .1. If I then use the editor to modify the alpha, say from 10 to 11, the alpha is then visible in the 3D view.
So it looks like my code is setting all of the data up properly, but just not triggering the view to refresh. I see that the view class has a refresh method but that its not available in 6. Is there an equivalent way to do that in 6 that might explain this behavior?
Thanks,
Josh -
This works just fine in all versions I've tested it on...
mats=Sketchup.active_model.materials mats.add('White') if not mats['White'] mat=mats['White'] mat.color='White' mat.alpha=0.1
Note that I used the shortcut 'name' to set the color= but [255,255,255] etc will work too.
The alpha is set to 10% [0.1].
Your Style needs transparency enabled for you to see the effect - check it out: also check in the Material-Browser > Edit settings that the material is getting made/set as expected - it seems like it is.
Note that the 'if' test is to ensure it only gets defined once and we don't get 'White1' etc etc...
If the Style's settings seem OK you can try this in your code
Sketchup.active_model.active_view.invalidate
to see it that helps... -
Thanks TIG... Seems like the Style is the issue. In this particular model the "enable transparency" option on the style is not checked. When I programmatically add a material with transparency, its still not checked... only upon adjusting the alpha in the materials editor does it become checked. If I manually enable the transparency in the style, my tool then works as expected.
Looking at the documentation for the style object, it seems pretty sparse. Is there there any way to programmatically set the style to turn on transparency? Or is there a way to switch to use one of the default styles?
Thanks again,
Josh -
You can 'force' transparency in code... but changing a Style permanently is more difficult.
To set transparency in code use this
Sketchup.active_model.rendering_options['MaterialTransparency']=true
'true' is 'on'
'false' is 'off'
To set the transparency quality use
Sketchup.active_model.rendering_options['TransparencySort']=2
2=Nicer
1=Medium
0=Faster
Don't use other values here unless you want a Bugsplat! -
Thanks!
-
Hi all;
I'm new to sketchUp, using V8 and also new to the OOP-structure business...
I've found in this thread the most relevant info and therefor posting here.I've composed 2 routines which I want to perform the following:
Draw a thin transparent red cylinder and over that one a larger yellow transparent one.The cylinder4 routine alone = OK; red cylinder = check
The cylinder5 routine alone = OK; yellow cylinder = checkThe 2 together makes the inner cylinder also Yellow...
Most likely i'm sinning to the OOP-structure, but i'm just starting...
Thanks
Johnps: i've made a combined picture and the "to_be" picture in the series is a version of which i used the paintin bucket to make the inner one red again...
the code:
def draw_cylinder4 # variables. center_point = Geom;;Point3d.new(0, 0, 0) vector = Geom;;Vector3d.new(0,-1,0) radius = 10 segments = 24 height = 50 # Get handles to our model and the Entities collection it contains. group=Sketchup.active_model.active_entities.add_group() Sketchup.active_model.rendering_options['MaterialTransparency']=true Sketchup.active_model.rendering_options['TransparencySort']=2 cyl_grp_ents=group.entities edges=cyl_grp_ents.add_circle(center_point, vector, radius, segments) edges[0].find_faces face=edges[0].faces[0] mats=Sketchup.active_model.materials mats.add('White') if not mats['White'] mat=mats['White'] mat.color='red' mat.alpha=0.5 face.material = "red" face.reverse! face.pushpull(height) end def draw_cylinder5 # variables. center_point = Geom;;Point3d.new(0, 0, 0) vector = Geom;;Vector3d.new(0,-1,0) radius = 20 segments = 24 height = 50 # Get handles to our model and the Entities collection it contains. group2=Sketchup.active_model.active_entities.add_group() Sketchup.active_model.rendering_options['MaterialTransparency']=true Sketchup.active_model.rendering_options['TransparencySort']=2 cyl_grp_ents2=group2.entities edges2=cyl_grp_ents2.add_circle(center_point, vector, radius, segments) edges2[0].find_faces face2=edges2[0].faces[0] mats2=Sketchup.active_model.materials mats2.add('White') if not mats2['White'] mat2=mats2['White'] mat2.color='yellow' mat2.alpha=0.5 face2.material = "yellow" face2.reverse! face2.pushpull(height) end
remark:
I can't combine it into 1 routine because i also need them separately...
-
You are confusing yourself in your convoluted material making!
You make a material named 'white' which you then illogically color 'red', and then when you make the second cylinder you change the color the same 'white' material to 'yellow'
Why not simply make a material called 'mat4' for cylinder-4 [unless it exists] and set its color to 'red' and alpha=0.5; then similarly for cyliner-5 make 'mat5' and color that 'yellow' etc etc.
Now you'd have two separate materials that you can adjust at will, without them 'overlapping' at all... -
@unknownuser said:
'white' which you then illogically color 'red'
Nah
i was fumbling around and i didn't quite understand what is going on in the lines above.
Now i do...the code looks now like this:
For the red cylinder:mats=Sketchup.active_model.materials mats.add('red') if not mats['red'] mat=mats['red'] mat.color='red' mat.alpha=0.5
For the yellow cylinder:
mats2=Sketchup.active_model.materials mats2.add('Yellow') if not mats2['Yellow'] mat2=mats2['Yellow'] mat2.color='yellow' mat2.alpha=0.5
I will give the materials a name which makes more sense now.
Thanks TIG
Greetings
John -
@john_q said:
I'm new to sketchUp, using V8 and also new to the OOP-structure business...
Advertisement