0
$\begingroup$

Edited-3 Problem solved:

enter image description here

I will put a complete description to robotics.snowcron.com in few days. It is going to take few pages :)

Brief description: There were some "features" of Collada format that prevented texture from showing (see "Edited" below). After it was fixed, the texture was displayed "generally" ok, but each triangle was displaying its texture with rotation. So I had to revisit the "triangles" part of a mesh. The problem was that vertices were listed as 0,1,2,3,4... 100, 101, 102, 103... While triangles (obvious, in retrospective) were something like 0,1,100 100,1,101 1,2,101... So mapping in "triangles" became non-obvious:

uvs = []

Find mesh vertices closest to bounding box corners

for i, v in enumerate(mesh.vertices): if(i%4 == 0): uvs.append([(v[0] - x_min) / (x_max - x_min), (v1 - y_min) / (y_max - y_min) + 1.0/nGridSizeY]) elif(i%4 == 1): uvs.append([(v[0] - x_min) / (x_max - x_min), (v1 - y_min) / (y_max - y_min)]) elif(i%4 == 2): uvs.append([(v[0] - x_min) / (x_max - x_min), (v1 - y_min) / (y_max - y_min) + 1.0/nGridSizeY]) elif(i%4 == 3 and i < len(mesh.vertices) - 2): uvs.append([(v[0] - x_min) / (x_max - x_min), (v1 - y_min) / (y_max - y_min)])

Well, it is resolved now :)

Edited-2 https://drive.google.com/file/d/1xRl-X46nhj-zsNds5hCBae18bhqR8q9W/view?usp=sharing

Here is a modified DAE. It still has problems: texture is generally ok, but turned in each triangle :(

The original problem is fixed by adding

<input offset="2" semantic="TEXCOORD" source="#uv-source"/>

to the "triangles" section, plus third element to each triplet of these triangles, that refers to a triangle.

Edited post:

Below I have a Collada (DAE) file. It is very simple: just two triangles. When I open it in Gazebo (see below on how it is called), it draws the shape, but no texture on it. However, under certain, very limited, angle this texture is visible. It is like within 5 degrees, flashing in and out when you spin the world in Gazebo. Please help me to figure out what is wrong with this DAE: I want to see the texture always, not just accidentally.

Thank you.

<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
  <asset>
    <created>2023-12-02T10:05:43.192932</created>
    <modified>2023-12-02T10:05:43.192937</modified>
    <up_axis>Y_UP</up_axis>
  </asset>
    <!-- library_images>
            <image id="texture0" name="texture">
                <init_from>../maps/perfect_texture_01.png</init_from>
        </image>
    </library_images -->
    <library_effects>
        <effect id="effect0">
            <profile_COMMON>
                <newparam sid="surface0">
                    <surface type="2D">
                        <init_from>texture0</init_from>
                    </surface>
                </newparam>
                <newparam sid="sampler0">
                    <sampler2D>
                        <source>surface0</source>
                    </sampler2D>
                </newparam>
                <technique sid="common">
                    <phong>
                        <diffuse>
                            <texture texture="sampler0" texcoord="UVSET0" />
                        </diffuse>
                    </phong>
                </technique>
            </profile_COMMON>
        </effect>
    </library_effects>
  <library_geometries>
    <geometry id="shape0">
      <mesh>
        <source id='uv-source' name='uv'>
            <float_array id='uv-float-array' count='8'>0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 </float_array>
            <technique_common>
                <accessor source='#uv-float-array' count='4' stride='2'>
                    <param name='S' type='float'/>
                    <param name='T' type='float'/>
                    <param name="NORMALIZED" type="float" />
                </accessor>
            </technique_common>
        </source>
        <vertices id='verts-array-vertices'>
            <input semantic="POSITION" source="#positions" />
            <input semantic='TEXCOORD' source='#uv-source' />
            <input semantic="NORMAL" source="#normals" />
        </vertices>
        <source id="positions">
          <float_array count="12" id="positions-array">0 0 0 2.97 0 1 0 2.97 1 2.97 2.97 0</float_array>
          <technique_common>
            <accessor count="4" source="#positions-array" stride="3">
              <param type="float" name="X"/>
              <param type="float" name="Y"/>
              <param type="float" name="Z"/>
            </accessor>
          </technique_common>
        </source>
        <source id="normals">
          <float_array count="12" id="normals-array">-0.3039963 -0.3039963 0.902869 0 0 1 7.35093e-17 7.35093e-17 1 0.3039963 0.3039963 0.902869</float_array>
          <technique_common>
            <accessor count="4" source="#normals-array" stride="3">
              <param type="float" name="X"/>
              <param type="float" name="Y"/>
              <param type="float" name="Z"/>
            </accessor>
          </technique_common>
        </source>
        <triangles count="2" material="material0">
          <input offset="0" semantic="VERTEX" source="#verts-array-vertices"/>
          <input offset="1" semantic="NORMAL" source="#normals-array"/>
          <p>0 0 1 1 2 2 2 2 1 1 3 3</p>
        </triangles>
      </mesh>
    </geometry>
  </library_geometries>
    <library_materials>
        <material id="material0">
            <instance_effect url="#effect0" />
        </material>
    </library_materials>
  <library_visual_scenes>
    <visual_scene id="scene">
      <node id="node0" name="node0">
<instance_geometry url="#shape0">
          <bind_material>
            <technique_common>
<instance_material symbol="material0" target="#material0">
<bind_vertex_input semantic="TEXCOORD" input_semantic="TEXCOORD" />
</instance_material>
            </technique_common>
          </bind_material>
        </instance_geometry>
      </node>
    </visual_scene>
  </library_visual_scenes>
  <scene>
    <instance_visual_scene url="#scene"/>
  </scene>
</COLLADA>

=== Old post ===

I have created (generated with Python script) a DAE file with some landscape for use in Gazebo. Here it is:

https://drive.google.com/file/d/1X_6Q87Cpf-JvnczDhLFUwD3BtXhbztpd/view?usp=sharing

It refers to a texture image (any png image will do).

Now, it opens just fine in Blender, showing the texture where I expect it to be. However, I can not show this texture properly in Gazebo. When I say "properly", I mean that it picks up the texture, I can see the 3d shape changing color to a base color of a texture... Of its top-right pixel. So UV mapping is ignored.

Here is what I tried:

  1. The reference to image in DAE

    <image id="texture0" name="texture">
        <init_from>../maps/perfect_texture_01.png</init_from>
    </image>
    

    ...

has a priority. If I use materials in Gazebo, it probably should be commented out (I tried both commenting and not commenting, if not commented, Gazebo uses this image, if commented, Gazebo uses image refered by material).

  1. The model in a Gazebo world (first version), uses direct link to DAE:

    <model name="landscape">
        <static>true</static>
        <pose>0 0 0 0 0 0</pose>
    
        <link name="link">
            <pose>-100 -100 0 0 0 0</pose>
            <visual name="visual">
                <pose>0 0 0 0 0 0</pose>
                <geometry>
                    <mesh>
                        <uri>../models/perfect_topo.dae</uri>
                        <scale>1 1 1</scale>
                        <texture_coords>
                            <tex_coord_semantic>uv-source</tex_coord_semantic>
                        </texture_coords>                               
                    </mesh>
                </geometry>
    
            </visual>
    
            <collision name="collision">
                <pose>0 0 0 0 0 0</pose>
                <geometry>
                    <mesh>
                        <uri>../models/perfect_topo.dae</uri>
                        <scale>1 1 1</scale>
                    </mesh>
                </geometry>
                <surface>
                    <contact>
                        <collide_bitmask>65535</collide_bitmask>
                        <ode/>
                    </contact>
                    <friction>
                        <ode>
                            <mu>100</mu>
                            <mu2>50</mu2>
                        </ode>
                        <torsional>
                            <ode/>
                        </torsional>
                    </friction>
                    <bounce/>
                </surface>
                <max_contacts>10</max_contacts>
            </collision>            
        </link>
    </model>
    
  2. The model in a Gazebo world (second version), uses script:

     <model name="landscape">
         <static>true</static>
         <pose>0 0 0 0 0 0</pose>
    
         <link name="link">
             <pose>-100 -100 0 0 0 0</pose>
             <visual name="visual">
                 <pose>0 0 0 0 0 0</pose>
                 <geometry>
                     <mesh>
                         <uri>../models/perfect_topo.dae</uri>
                         <scale>1 1 1</scale>
                     </mesh>
                 </geometry>
    
                 <material>
                     <script>
                         <uri>file://src/models/topo_maps/materials/scripts</uri>
                         <uri>file://src/models/topo_maps/textures</uri>
                         <name>perfect_material</name>
                     </script>
                     <ambient>1 1 1 1</ambient>
                     <diffuse>1 1 1 1</diffuse>
                     <specular>0.5 0.5 0.5 1</specular>
                     <emissive>0 0 0 1</emissive>
                     <shader type='pixel'>
                         <normal_map>__default__</normal_map>
                     </shader>
    
                 </material>                    
    
             </visual>
    
             <collision name="collision">
                 <pose>0 0 0 0 0 0</pose>
                 <geometry>
                     <mesh>
                         <uri>../models/perfect_topo.dae</uri>
                         <scale>1 1 1</scale>
                     </mesh>
                 </geometry>
                 <surface>
                     <contact>
                         <collide_bitmask>65535</collide_bitmask>
                         <ode/>
                     </contact>
                     <friction>
                         <ode>
                             <mu>100</mu>
                             <mu2>50</mu2>
                         </ode>
                         <torsional>
                             <ode/>
                         </torsional>
                     </friction>
                     <bounce/>
                 </surface>
                 <max_contacts>10</max_contacts>
             </collision>            
         </link>
     </model>
    

As I mentioned, in all cases I see a texture, but UV mapping is not used. And, once again, Blender opens it correctly.

Please take a look, I need to know what is wrong in this DAE. Thank you.

$\endgroup$
3
  • $\begingroup$ Just to add: I use Galactic, Ubuntu and Gazebo classic (11) $\endgroup$ Dec 1, 2023 at 19:03
  • $\begingroup$ Any ideas? Please? $\endgroup$ Dec 2, 2023 at 12:56
  • $\begingroup$ I have added a very simple - two triangles - shape. Please look at questions in main post. Looks like there are some new hints. $\endgroup$ Dec 2, 2023 at 15:26

1 Answer 1

0
$\begingroup$

[https://drive.google.com/file/d/1xRl-X46nhj-zsNds5hCBae18bhqR8q9W/view?usp=sharing][1]

Here is a modified DAE. It still has problems: texture is generally ok, but turned in each triangle :(

The original problem is fixed by adding

<input offset="2" semantic="TEXCOORD" source="#uv-source"/>

to the "triangles" section, plus third element to each triplet of these triangles, that refers to a triangle.

I will post complete report on robotics.snowcron.com as soon as I fix that last issue.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.