Results 1 to 8 of 8

Thread: about texture coordinate in collada

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    8

    about texture coordinate in collada

    Hi,

    I'm very puzzled by texture coordinate in collada. I draw a cube in sketchup and with material mapped to one plane just for test. I find it is very strange that there are UV values out of range of [0,1], and these value seems the same with the vertex of the cube but not exactly. So how can extract useful datas from these UV datas to describe the texture coordinate in [0,1]? i think the UV texture coordinate should be in [0,1] not others. Could anyone help me? Any reference will be OK.

    Thank you.

    Mia

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Texture units have wrapping modes to handle coordinates outside the range [0,1]. Values outside that range can cause the image to repeat, clap, use a specified border color, etc..

    For OpenGL wrapping modes you can read about GL_TEXTURE_WRAP_S here http://opengl.org/sdk/docs/man/xhtml/glTexParameter.xml .

    I hope that helps.

  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    8
    Hi,

    i still don't know how to extract these UV datas to texture coordinate that could be used.
    Code :
    <source id="mesh1-geometry-uv">
      <float_array id="mesh1-geometry-uv-array" count="48">-178.350505 121.322840 -48.100505 84.572840 -48.100505 121.322840 -178.350505 84.572840 121.322840 0.000000 84.572840 12.000000 84.572840 0.000000 121.322840 12.000000 -178.350505 0.000000 -48.100505 12.000000 -178.350505 12.000000 -48.100505 0.000000 -84.572840 0.000000 -121.322840 12.000000 -121.322840 0.000000 -84.572840 12.000000 48.100505 0.000000 178.350505 12.000000 48.100505 12.000000 178.350505 0.000000 178.350505 84.572840 48.100505 121.322840 48.100505 84.572840 178.350505 121.322840</float_array> 
    - <technique_common>
    - <accessor source="#mesh1-geometry-uv-array" count="24" stride="2">
      <param name="S" type="float" /> 
      <param name="T" type="float" /> 
      </accessor>
      </technique_common>
      </source>
    Code :
    <source id="mesh1-geometry-position">
      <float_array id="mesh1-geometry-position-array" count="24">178.350505 121.322840 0.000000 48.100505 84.572840 0.000000 48.100505 121.322840 0.000000 178.350505 84.572840 0.000000 178.350505 84.572840 12.000000 178.350505 121.322840 12.000000 48.100505 121.322840 12.000000 48.100505 84.572840 12.000000</float_array> 
    - <technique_common>
    - <accessor source="#mesh1-geometry-position-array" count="8" stride="3">
      <param name="X" type="float" /> 
      <param name="Y" type="float" /> 
      <param name="Z" type="float" /> 
      </accessor>
      </technique_common>
      </source>
    Code :
     
    <source id="mesh1-geometry-normal">
      <float_array id="mesh1-geometry-normal-array" count="18">0.000000 0.000000 -1.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 -1.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 0.000000 0.000000 1.000000</float_array> 
    - <technique_common>
    - <accessor source="#mesh1-geometry-normal-array" count="6" stride="3">
      <param name="X" type="float" /> 
      <param name="Y" type="float" /> 
      <param name="Z" type="float" /> 
      </accessor>
      </technique_common>
      </source>
    Code :
    <triangles material="FrontColorNoCulling" count="12">
      <input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0" /> 
      <input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1" /> 
      <input semantic="TEXCOORD" source="#mesh1-geometry-uv" offset="2" set="0" /> 
     
     
    0 0 0 1 0 1 2 0 2 1 0 1 0 0 0 3 0 3 0 1 4 4 1 5 3 1 6 4 1 5 0 1 4 5 1 7 0 2 8 6 2 9 5 2 10 6 2 9 0 2 8 2 2 11 1 3 12 6 3 13 2 3 14 6 3 13 1 3 12 7 3 15 1 4 16 4 4 17 7 4 18 4 4 17 1 4 16 3 4 19 4 5 20 6 5 21 7 5 22 6 5 21 4 5 20 5 5 23</p> 
      </triangles>

    I know how to extract the vertex and it's normal vector , but i dosen't know how to get texture coordinate that could be used in glTexPointer.
    Could you give me more detail?
    Thank you

    Mia

  4. #4
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    All <input> parsing is done the same way, so if you know how to do one semantic you should be able to write functiions that do the others.

    The TEXCOORD input semantic samples texture coordinates in the order S, T, P, Q for 1D to 4D coordinates. In your case the <source> supplies 2D (S,T) coordinates. The first value sampled for (S,T) is [-178.350505,121.322840].

    The first index vectors of the

    element that are used to sample successive values from the inputs are:

    1. [0,0,0]
    2. [1,0,1]
    3. [2,0,2]

    etc... Your TEXCOORD input has on offset of 2 (values of [0,1,2]) resulting in sampled TEXCOORD values of:

    ST1: [-178.350505,121.322840]
    ST2: [-48.100505,84.572840]
    ST3: [-48.100505,121.322840]

    etc.

    The "set" attribute distinguishes vertex attributes that belong in different logical groupings (e.g. multi-texture use cases). In other words each vertex is built from base VERTEX attributes plus zero or more sets of other attributes (e.g NORMAL, TEXCOORD, etc.). In your case you only have one logical grouping (TEXCOORD).

    Note: COLLADA distinguishes between TEXCOORD (texture coordinates) and UV (generic parameters).

    I hope that helps.

  5. #5
    Junior Member
    Join Date
    Sep 2008
    Posts
    8
    Quote Originally Posted by marcus


    The "set" attribute distinguishes vertex attributes that belong in different logical groupings (e.g. multi-texture use cases). In other words each vertex is built from base VERTEX attributes plus zero or more sets of other attributes (e.g NORMAL, TEXCOORD, etc.). In your case you only have one logical grouping (TEXCOORD).

    Note: COLLADA distinguishes between TEXCOORD (texture coordinates) and UV (generic parameters).
    Hi,

    i still doesn't know why these texture coordinates are out of [0,1]. When i want to map the same texture in OpenGL, i read the picture and generate texture, how can set the correct texture coordinate for every vertex?
    if i set the first vertex's texture coordinate ST1: [-178.350505,121.322840] , i think it cann't work.

    i got this file from sketchup , may some problems in sketchup ?

  6. #6
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Just use the values for each vertex as supplied in the .dae document.

    The material should say how the texture wraps on the geometry, whether it repeats or clamps. Can you post the <material> and <effect> that Sketchup exported? That will show the answer.

    If it doesn't have the texture wrapping mode explicitly within a <profile_GLSL> or as an extra or parameter in <profile_COMMON> then Sketchup must assume one setting all the time for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T. You can try using either GL_CLAMP or GL_REPEAT to see which one works.

    I hope that helps.

  7. #7
    Junior Member
    Join Date
    Sep 2008
    Posts
    8

    Re:

    Hi,

    i post the material and effect in .dae file as follow:

    Code :
    <library_images>
          <image id="material0-image" name="material0-image">
             <init_from>../images/texture0.jpg</init_from>
          </image>
       </library_images>

    Code :
    <library_materials>
          <material id="FrontColorNoCullingID" name="FrontColorNoCulling">
             <instance_effect url="#FrontColorNoCulling-effect"/>
          </material>
          <material id="material0ID" name="material0">
             <instance_effect url="#material0-effect"/>
          </material>
          <material id="ForegroundColorID" name="ForegroundColor">
             <instance_effect url="#ForegroundColor-effect"/>
          </material>
       </library_materials>

    Code :
    <library_effects>
          <effect id="FrontColorNoCulling-effect" name="FrontColorNoCulling-effect">
             <profile_COMMON>
                <technique sid="COMMON">
                   <phong>
                      <emission>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </emission>
                      <ambient>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </ambient>
                      <diffuse>
                         <color>1.000000 1.000000 1.000000 1</color>
                      </diffuse>
                      <specular>
                         <color>0.330000 0.330000 0.330000 1</color>
                      </specular>
                      <shininess>
                         <float>20.000000</float>
                      </shininess>
                      <reflectivity>
                         <float>0.100000</float>
                      </reflectivity>
                      <transparent>
                         <color>1 1 1 1</color>
                      </transparent>
                      <transparency>
                         <float>0.000000</float>
                      </transparency>
                   </phong>
                </technique>
                <extra>
                   <technique profile="GOOGLEEARTH">
                      <double_sided>1</double_sided>
                   </technique>
                </extra>
             </profile_COMMON>
          </effect>
          <effect id="material0-effect" name="material0-effect">
             <profile_COMMON>
                <newparam sid="material0-image-surface">
                   <surface type="2D">
                      <init_from>material0-image</init_from>
                   </surface>
                </newparam>
                <newparam sid="material0-image-sampler">
                   <sampler2D>
                      <source>material0-image-surface</source>
                   </sampler2D>
                </newparam>
                <technique sid="COMMON">
                   <phong>
                      <emission>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </emission>
                      <ambient>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </ambient>
                      <diffuse>
                         <texture texture="material0-image-sampler" texcoord="UVSET0"/>
                      </diffuse>
                      <specular>
                         <color>0.330000 0.330000 0.330000 1</color>
                      </specular>
                      <shininess>
                         <float>20.000000</float>
                      </shininess>
                      <reflectivity>
                         <float>0.100000</float>
                      </reflectivity>
                      <transparent>
                         <color>1 1 1 1</color>
                      </transparent>
                      <transparency>
                         <float>0.000000</float>
                      </transparency>
                   </phong>
                </technique>
                <extra>
                   <technique profile="GOOGLEEARTH">
                      <double_sided>1</double_sided>
                   </technique>
                </extra>
             </profile_COMMON>
          </effect>
          <effect id="ForegroundColor-effect" name="ForegroundColor-effect">
             <profile_COMMON>
                <technique sid="COMMON">
                   <phong>
                      <emission>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </emission>
                      <ambient>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </ambient>
                      <diffuse>
                         <color>0.000000 0.000000 0.000000 1</color>
                      </diffuse>
                      <specular>
                         <color>0.330000 0.330000 0.330000 1</color>
                      </specular>
                      <shininess>
                         <float>20.000000</float>
                      </shininess>
                      <reflectivity>
                         <float>0.100000</float>
                      </reflectivity>
                      <transparent>
                         <color>1 1 1 1</color>
                      </transparent>
                      <transparency>
                         <float>0.000000</float>
                      </transparency>
                   </phong>
                </technique>
                <extra>
                   <technique profile="GOOGLEEARTH">
                      <double_sided>1</double_sided>
                   </technique>
                </extra>
             </profile_COMMON>
          </effect>
       </library_effects>

    Code :
    <library_visual_scenes>
          <visual_scene id="SketchUpScene" name="SketchUpScene">
             <node id="Model" name="Model">
                <node id="mesh1" name="mesh1">
                   <instance_geometry url="#mesh1-geometry">
                      <bind_material>
                         <technique_common>
                            <instance_material symbol="FrontColorNoCulling" target="#FrontColorNoCullingID"/>
                            <instance_material symbol="material0" target="#material0ID">
                               <bind_vertex_input semantic="UVSET0" input_semantic="TEXCOORD" input_set="0"/>
                            </instance_material>
                         </technique_common>
                      </bind_material>
                   </instance_geometry>
                </node>
                <node id="mesh2" name="mesh2">
                   <instance_geometry url="#mesh2-geometry">
                      <bind_material>
                         <technique_common>
                            <instance_material symbol="ForegroundColor" target="#ForegroundColorID"/>
                         </technique_common>
                      </bind_material>
                   </instance_geometry>
                </node>
             </node>
             <node id="Camera" name="Camera">
                <matrix>
                   1.000000 0.000000 0.000000 117.500445
                   0.000000 1.000000 0.000000 92.644007
                   0.000000 0.000000 1.000000 840.167135
                   0.000000 0.000000 0.000000 1.000000
                </matrix>
                <instance_camera url="#Camera-camera"/>
             </node>
          </visual_scene>
       </library_visual_scenes>

    Just like you say, i could use these texture coordinates directly. I will try but i don't think it will work. In fact, i just map one face of the cube with texture, why are there 24 pairs of texture coordinates? I still cann't understand.

  8. #8
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    In your Sketchup example, the <triangles> element assembles 12 triangle primitives from a pool of: 8 positions, 6 normals, and 24 texcoords.

    The position input [index 0] sample ranges from 0 to 7.
    The normal input [index 1] sample ranges from 0 to 5.
    The texcoord input [index 2] sample ranges from 0 to 23.

    I've formatted the triangle primitives into rows of three vertexes so that you can see them better:
    Code :
     
     
     
        0 0 0     1 0 1     2 0 2
        1 0 1     0 0 0     3 0 3
        0 1 4     4 1 5     3 1 6
        4 1 5     0 1 4     5 1 7
        0 2 8     6 2 9     5 2 10
        6 2 9     0 2 8     2 2 11
        1 3 12    6 3 13    2 3 14
        6 3 13    1 3 12    7 3 15
        1 4 16    4 4 17    7 4 18
        4 4 17    1 4 16    3 4 19
        4 5 20    6 5 21    7 5 22
        6 5 21    4 5 20    5 5 23
    </p>

    I hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •