Retrieving texture's scale

Hi! I’ve this cube:

<CoordinateSystem> { Z-up } 
<Material> MATCube {
  <Scalar> diffr { 0.800000 }
  <Scalar> diffg { 0.800000 }
  <Scalar> diffb { 0.800000 }
  <Scalar> specr { 0.500000 }
  <Scalar> specg { 0.500000 }
  <Scalar> specb { 0.500000 }
  <Scalar> shininess { 12.5 }
  <Scalar> ambr { 1.000000 }
  <Scalar> ambg { 1.000000 }
  <Scalar> ambb { 1.000000 }
  <Scalar> emitr { 0.000000 }
  <Scalar> emitg { 0.000000 }
  <Scalar> emitb { 0.000000 }
}

<Texture> TEXCube {
  "1.jpg"
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> wrap { REPEAT }
}

<Texture> TEXREPCube {
  "2.jpg"
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> wrap { REPEAT }
  <Transform> {
    <Translate> { -0.5 -0.5 -0.5 }
    <Scale> { 20.0 20.0 1.0 }
    <Translate> { 0.5 0.5 0.5 }
  }
}

  <Group> Cube {
    <Transform> {
      <Matrix4> {
        1.0 0.0 0.0 0.0 
        0.0 1.0 0.0 0.0 
        0.0 0.0 1.0 0.0 
        0.0 0.0 0.0 1.0 
      }
    }
    
    <VertexPool> Cube {
    
      <Vertex> 0 {-1.000000 -1.000000 -1.000000
        <UV>  {
          0.749957 0.749957 
        }
      }
      <Vertex> 1 {-1.000000 -1.000000 1.000000
        <UV>  {
          0.749957 0.999913 
        }
      }
      <Vertex> 2 {-1.000000 1.000000 1.000000
        <UV>  {
          0.500000 0.999913 
        }
      }
      <Vertex> 3 {-1.000000 1.000000 -1.000000
        <UV>  {
          0.500000 0.749957 
        }
      }
      <Vertex> 4 {-1.000000 1.000000 -1.000000
        <UV>  {
          0.500000 0.749957 
        }
      }
      <Vertex> 5 {-1.000000 1.000000 1.000000
        <UV>  {
          0.500000 0.999913 
        }
      }
      <Vertex> 6 {1.000000 1.000000 1.000000
        <UV>  {
          0.250043 0.999913 
        }
      }
      <Vertex> 7 {1.000000 1.000000 -1.000000
        <UV>  {
          0.250043 0.749957 
        }
      }
      <Vertex> 8 {1.000000 1.000000 -1.000000
        <UV>  {
          0.250043 0.749957 
        }
      }
      <Vertex> 9 {1.000000 1.000000 1.000000
        <UV>  {
          0.250043 0.999913 
        }
      }
      <Vertex> 10 {1.000000 -1.000000 1.000000
        <UV>  {
          0.000087 0.999913 
        }
      }
      <Vertex> 11 {1.000000 -1.000000 -1.000000
        <UV>  {
          0.000087 0.749957 
        }
      }
      <Vertex> 12 {1.000000 -1.000000 -1.000000
        <UV>  {
          0.250043 0.500000 
        }
      }
      <Vertex> 13 {1.000000 -1.000000 1.000000
        <UV>  {
          0.250043 0.250043 
        }
      }
      <Vertex> 14 {-1.000000 -1.000000 1.000000
        <UV>  {
          0.500000 0.250043 
        }
      }
      <Vertex> 15 {-1.000000 -1.000000 -1.000000
        <UV>  {
          0.500000 0.500000 
        }
      }
      <Vertex> 16 {-1.000000 1.000000 -1.000000
        <UV>  {
          0.500000 0.749957 
        }
      }
      <Vertex> 17 {1.000000 1.000000 -1.000000
        <UV>  {
          0.250043 0.749957 
        }
      }
      <Vertex> 18 {1.000000 -1.000000 -1.000000
        <UV>  {
          0.250043 0.500000 
        }
      }
      <Vertex> 19 {-1.000000 -1.000000 -1.000000
        <UV>  {
          0.500000 0.500000 
        }
      }
      <Vertex> 20 {1.000000 1.000000 1.000000
        <UV>  {
          0.250043 0.000087 
        }
      }
      <Vertex> 21 {-1.000000 1.000000 1.000000
        <UV>  {
          0.500000 0.000087 
        }
      }
      <Vertex> 22 {-1.000000 -1.000000 1.000000
        <UV>  {
          0.500000 0.250043 
        }
      }
      <Vertex> 23 {1.000000 -1.000000 1.000000
        <UV>  {
          0.250043 0.250043 
        }
      }}
    
    
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {-1.000000 0.000000 0.000000}
      <VertexRef> { 0 1 2 3 <Ref> { Cube }} 
    }
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {0.000000 1.000000 0.000000}
      <VertexRef> { 4 5 6 7 <Ref> { Cube }} 
    }
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {1.000000 0.000000 0.000000}
      <VertexRef> { 8 9 10 11 <Ref> { Cube }} 
    }
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {0.000000 -1.000000 0.000000}
      <VertexRef> { 12 13 14 15 <Ref> { Cube }} 
    }
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {0.000000 0.000000 -1.000000}
      <VertexRef> { 16 17 18 19 <Ref> { Cube }} 
    }
    <Polygon> {
      <TRef> { TEXCube }
      <TRef> { TEXREPCube }
      <MRef> { MATCube }
      <Normal> {0.000000 0.000000 1.000000}
      <VertexRef> { 20 21 22 23 <Ref> { Cube }} 
    }
  }

In detail, the cube has this texture:

<Texture> TEXREPCube {
  "2.jpg"
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
  <Scalar> wrap { REPEAT }
  <Transform> {
    <Translate> { -0.5 -0.5 -0.5 }
    <Scale> { 20.0 20.0 1.0 }
    <Translate> { 0.5 0.5 0.5 }
  }
}

I would like to retrieve its scale (20.0, 20.0) from code. I’ve tried with this program:

import direct.directbase.DirectStart
model = loader.loadModel('cube')
for ts in model.find_all_texture_stages():
    print model.get_tex_scale(ts)
    print model.get_tex_transform(ts)
textures = model.find_all_textures()
for tex in textures:
    print tex
    print tex.get_tex_scale()
base.run()

But I observe this output (i.e. scale (1, 1)):

LVecBase2f(1, 1)
T:(identity)

LVecBase2f(1, 1)
T:(identity)

2d_texture 1 (from /home/flavio/Desktop/texscale/1.jpg)
  2-d, 1024 x 1024 pixels, each 3 bytes, rgb
  sampler wrap(u=repeat, v=repeat, w=repeat, border=0 0 0 1) filter(min=linear_mipmap_linear, mag=linear, aniso=0) lod(min=-1000, max=1000, bias=0)  3145728 bytes in ram, compression off
  simple image: 1 x 1, 4 bytes

LVecBase2f(1, 1)
2d_texture 2 (from /home/flavio/Desktop/texscale/2.jpg)
  2-d, 512 x 512 pixels, each 3 bytes, rgb
  sampler wrap(u=repeat, v=repeat, w=repeat, border=0 0 0 1) filter(min=linear_mipmap_linear, mag=linear, aniso=0) lod(min=-1000, max=1000, bias=0)  786432 bytes in ram, compression off
  simple image: 1 x 1, 4 bytes

LVecBase2f(1, 1)

That scale is processed by Panda since if I change it in the .egg file then I can see the new scale in the rendered model.

How can I access that scale from a Panda3D program? Thank you very much!

When I call model.ls(), I get this:

ModelRoot cube.egg
  GeomNode Cube (1 geoms: S:(MaterialAttrib TexMatrixAttrib TextureAttrib TransparencyAttrib))

which tells me that the texture matrix is an attribute of the RenderState that is associated directly with the Geom, not with the GeomNode, so you can retrieve it like this:

attrib_type = TexMatrixAttrib.get_class_type()
for geom_np in model.find_all_matches("**/+GeomNode"):
    geom_node = geom_np.node()
    for i in range(geom_node.get_num_geoms()):
        state = geom_node.get_geom_state(i)
        if state.has_attrib(attrib_type):
            attrib = state.get_attrib(attrib_type)
            for j in range(attrib.get_num_stages()):
                transform = attrib.get_transform(attrib.get_stage(j))
                if transform.has_scale():
                    print "Texture scale:", transform.get_scale()

Hopefully this can help you :slight_smile: .

Thank you very much! :smiley: