texturing subparts of a model

I’ve tried the following code to texture part of a model, but the area appears all black (used to be some water sparkling texture from sketch up):

tex = loader.loadTexture('models/tex_.jpg')
model.find("**/ID63").setTexture(tex, 1)

Any idea :question: Thanks in advance :slight_smile:

Update:

I wanted to use a picture to “paint” one side of my model… when I used a 20 x 20 .png with only red color, the area actually appears to be red, but with a larger picture , it’s always gray :cry:

Maybe the UV mapping is wrong on the model? It might be trying to apply a single pixel to the whole part…

Hi Dolkar

I think you are right… I used sketchUp to create the model and converted from dae to egg… Does Panda let you specify the UV mapping? Or do I need to change the .egg file?

I’m texturing the area “ID23” and below is the part that has to do with “ID23” in the .egg file just in case.

The region is rectangular, and looks like it has 30 vertices. The part immediately following uses and tags which I don’t know the meaning of…

Thank you very much!


<Group> ID23 {
    <VertexPool> ID23 {
      <Vertex> 0 {
        77.8279 -19.4555 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 1 {
        -69.1721 -17.2055 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 2 {
        -69.1721 -19.4555 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 3 {
        -69.1721 -17.2055 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 4 {
        77.8279 -19.4555 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 5 {
        77.8279 -17.2055 6.48287
        <Normal> { 0 0 1 }
      }
      <Vertex> 6 {
        77.8279 -17.2055 84.6079
        <Normal> { -1 0 0 }
      }
      <Vertex> 7 {
        77.8279 -19.4555 6.48287
        <Normal> { -1 0 0 }
      }
      <Vertex> 8 {
        77.8279 -19.4555 84.6079
        <Normal> { -1 0 0 }
      }
      <Vertex> 9 {
        77.8279 -19.4555 6.48287
        <Normal> { -1 0 0 }
      }
      <Vertex> 10 {
        77.8279 -17.2055 84.6079
        <Normal> { -1 0 0 }
      }
      <Vertex> 11 {
        77.8279 -17.2055 6.48287
        <Normal> { -1 0 0 }
      }
      <Vertex> 12 {
        77.8279 -17.2055 84.6079
        <Normal> { 0 -1 0 }
      }
      <Vertex> 13 {
        -69.1721 -17.2055 6.48287
        <Normal> { 0 -1 0 }
      }
      <Vertex> 14 {
        77.8279 -17.2055 6.48287
        <Normal> { 0 -1 0 }
      }
      <Vertex> 15 {
        -69.1721 -17.2055 6.48287
        <Normal> { 0 -1 0 }
      }
      <Vertex> 16 {
        77.8279 -17.2055 84.6079
        <Normal> { 0 -1 0 }
      }
      <Vertex> 17 {
        -69.1721 -17.2055 84.6079
        <Normal> { 0 -1 0 }
      }
      <Vertex> 18 {
        -69.1721 -17.2055 6.48287
        <Normal> { 1 0 0 }
      }
      <Vertex> 19 {
        -69.1721 -19.4555 84.6079
        <Normal> { 1 0 0 }
      }
      <Vertex> 20 {
        -69.1721 -19.4555 6.48287
        <Normal> { 1 0 0 }
      }
      <Vertex> 21 {
        -69.1721 -19.4555 84.6079
        <Normal> { 1 0 0 }
      }
      <Vertex> 22 {
        -69.1721 -17.2055 6.48287
        <Normal> { 1 0 0 }
      }
      <Vertex> 23 {
        -69.1721 -17.2055 84.6079
        <Normal> { 1 0 0 }
      }
      <Vertex> 24 {
        -69.1721 -17.2055 84.6079
        <Normal> { 0 0 -1 }
      }
      <Vertex> 25 {
        77.8279 -19.4555 84.6079
        <Normal> { 0 0 -1 }
      }
      <Vertex> 26 {
        -69.1721 -19.4555 84.6079
        <Normal> { 0 0 -1 }
      }
      <Vertex> 27 {
        77.8279 -19.4555 84.6079
        <Normal> { 0 0 -1 }
      }
      <Vertex> 28 {
        -69.1721 -17.2055 84.6079
        <Normal> { 0 0 -1 }
      }
      <Vertex> 29 {
        77.8279 -17.2055 84.6079
        <Normal> { 0 0 -1 }
      }
    }

followed by:

    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 0 1 2 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 3 4 5 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 6 7 8 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 9 10 11 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 12 13 14 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 15 16 17 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 18 19 20 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 21 22 23 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 24 25 26 <Ref> { ID23 } }
    }
    <Polygon> {
      <MRef> { Material2 }
      <BFace> { 1 }
      <VertexRef> { 27 28 29 <Ref> { ID23 } }
    }
  }

I believe that you can have Panda generate UV coordinates for you; I don’t know whether it will work as you desire – I don’t think that I’ve tried the functionality myself, and don’t know much about its use and limitations – but this page should provide more informatio.

It almost worked except that the texture pic is squeezed and repeated many times… while I just want it to appear one time to cover the specified area (can be stretched)…I tried the texture transform techniques but it’ll take many trials… well at least it shows colors other than gray now, thank you for that! :slight_smile:

Have you tried using “TexGenAttrib.MPointSprite” as the “texGenMode” parameter in “setTexGen”? Based on a quick look at the page to which I linked you, it looks as though that should do what you want.

I tried this one but it didn’t work. I guess for now I will just use OnscreenImage to display the texture, until a better alternative comes up along the way. I’m also learning how to use blender…which supposedly will make this easier with a UV-mapping? There is still a lot to figure out… thank you for helping! :slight_smile: