Question about transparency

Hello,

I am trying to make objects appeared transparent when selected. The issue is that I have different objects, some textured, other not, with different kind of format for the textures.
Objects with textures having an alpha canal(png) work perfectly, but other having jpg texture or having the colors set on the vertice directly in the .egg dont became transparent.

I was wondering if there was any solution to make these object transparent.
I just want to make for example the full object half transparent.

For now, I use that:

self.drawing_alpha=self.drawing_object.concrete.getColorScale() self.drawing_object.concrete.setColorScale(self.drawing_alpha[0],self.drawing_alpha[1],self.drawing_alpha[2],0.3)
self.drawing_object.concrete.setTransparency(TransparencyAttrib.MDual )

with self.drawing_object.concrete being a nodePath

That doesn’t work.

I tryed changing the color rather than using scaleColor:
self.drawing_object.concrete.setColor(0.3,0.3,0.3,0.3)
wich didn’t work better.

So is there a way to have transparency on a nodePath that wouldn’t depend on the texture?

no it does work for me:

import direct.directbase.DirectStart
t = loader.loadModel('teapot')
t.reparentTo(render)
t.setTransparency(True)
t.setColor(1,1,1,0.3)
#t.setColorScale(1,1,1,0.3)
run() 

Both color and color scale give the same result with no texture. And if you use ‘panda’ instead of the teapot you see that vertex colors also work.

That seems like it should work. I’ll look into it soon.

Thank you for your answer.
I tried with pandda, and it works. I also tied with panda-model, it still works.
But when I try with my object, it doesn’t.
I searched for differences but didn’t find anything.

I saw that panda_model use a texture in jpg;

<Texture> Tex1 {

  "maps/panda-model.jpg"

  <Scalar> format { rgb }

  <Scalar> wrapu { repeat }

  <Scalar> wrapv { repeat }

  <Scalar> minfilter { linear_mipmap_linear }

  <Scalar> magfilter { linear }

}

wich doesn’t prevent it from becaming transparent.

Where my object using also a jpg

<Texture> Wood_Bamboo_Medium {
  "rocking_chair/Wood_Bamboo_Medium.jpg"
  <Scalar> format { rgb }

  <Scalar> wrapu { repeat }

  <Scalar> wrapv { repeat }

  <Scalar> minfilter { linear_mipmap_linear }

  <Scalar> magfilter { linear }
}

still refuse to became transparent.

Here are some part of my .egg:

<CoordinateSystem> { Z-up }

<Comment> { "Egg laid by Chicken for Blender v1.0" }

<Material> Wood_Bamboo_Medium {
  <Scalar> diffr {0.694118022919}
  <Scalar> diffg {0.411765009165}
  <Scalar> diffb {0.168626993895}
  <Scalar> specr {0.0825000032783}
  <Scalar> specg {0.0825000032783}
  <Scalar> specb {0.0825000032783}
  <Scalar> shininess {12.5}
}

    . . . .

<Texture> Wood_Bamboo_Medium {
  "rocking_chair/Wood_Bamboo_Medium.jpg"
  <Scalar> format { rgb }

  <Scalar> wrapu { repeat }

  <Scalar> wrapv { repeat }

  <Scalar> minfilter { linear_mipmap_linear }

  <Scalar> magfilter { linear }
}
<Group> rocking_chair {
  <Transform> {
    <Matrix4> {
      0.100000 0.000000 0.000000 0.000000
      0.000000 0.100000 0.000000 0.000000
      0.000000 0.000000 0.100000 0.000000
      -1.204936 -1.186393 0.000000 1.000000
    }
  }
  <VertexPool> rocking_chair {
    <Vertex> 0 {
      -0.358918 1.218167 2.316150
      <UV> { 0.000000 0.000000 }
    }
    <Vertex> 1 {
      -0.337268 1.180957 2.320780
      <UV> { 0.018042 0.000000 }
    }

    . . . . .



    <Vertex> 1719 {
      -1.004179 1.128097 2.375700
      <UV> { -0.234944 0.455841 }
    }
  }
  <Group> rocking_chair2 {
    <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { Wood_Bamboo_Medium }
      <MRef> { Wood_Bamboo_Medium }
      <Normal> { -0.866044 -0.496145 0.061714 }
      <VertexRef> { 0 1 2 3 <Ref> { rocking_chair } }
    }
    <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { Wood_Bamboo_Medium }
      <MRef> { Wood_Bamboo_Medium }
      <Normal> { 0.866032 -0.496165 0.061716 }
      <VertexRef> { 4 5 6 7 <Ref> { rocking_chair } }
    }
     . . . .

I don’t see where we made something that can prevent the object from becoming half transparent, if someone have an idea, it would be really useful.

It’s your material. Your material is specifying a diffuse color, which hides the color specified by setColor() (including its alpha channel).

An object has multiple places in which color may be defined. Most objects just use the vertex color, and don’t have a lighting material (or if they do have a lighting material, the material doesn’t have an explicit diffuse color specified, which means it shows the vertex color).

Since your object has a material with a diffuse color, whenever lighting is enabled that diffuse color is used instead of the vertex color. That’s what a material means: use this color instead of whatever color you find on the object.

You have three choices.

(1) Instead of using setColor(), use setMaterial() to change the color, and use a material with a different color.

(2) Edit the egg file to remove the diffuse color from your material, and instead specify the color you want via entries on your vertices or polygons.

(3) At runtime, use setMaterial() to apply a material with no diffuse color specified, and then use setColor().

If your egg file was created via a model converter, it may be difficult to employ option (2).

David