10
$\begingroup$

I've been having trouble exporting collada objects from blender, so I stripped everything back and textured a single cube, and exported it.

This is a completely trivial model, one cube, with one material assigned to it, the material has a single 'g.png' texture assigned to it.

The exported collada data looks like this:

  <library_materials>
    <material id="Material-material" name="Material">
      <instance_effect url="#Material-effect"/>
    </material>
  </library_materials>

Where:

  <library_effects>
    <effect id="Material-effect">
      <profile_COMMON>
        <technique sid="common">
          <phong>
            <emission>
              <color sid="emission">0.2879998 0.2879998 0.2879998 1</color>
            </emission>
            <ambient>
              <color sid="ambient">0 0 0 1</color>
            </ambient>
            <diffuse>
              <color sid="diffuse">0.2163267 0.1845119 0.2121569 1</color>
            </diffuse>
            <specular>
              <color sid="specular">0.5 0.5 0.5 1</color>
            </specular>
            <shininess>
              <float sid="shininess">50</float>
            </shininess>
            <index_of_refraction>
              <float sid="index_of_refraction">1</float>
            </index_of_refraction>
          </phong>
        </technique>
        <extra>
          <technique profile="GOOGLEEARTH">
            <double_sided>1</double_sided>
          </technique>
        </extra>
      </profile_COMMON>
      <extra><technique profile="MAX3D"><double_sided>1</double_sided></technique></extra>
    </effect>
  </library_effects>

This seems to be missing the texture data associated with the object.

By comparsion, exporting a wavefront object generates this .mtl file:

# Blender MTL File: 'basic.blend'
# Material Count: 1

newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.790000 0.790000 0.790000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 0
map_Kd g.png   <----- ie. Blender is aware of this texture

So... is the collada exporter for blender just broken, or does it require some kind of special config in order to function correctly?

If the latter, how/what is required to make this work?

(NB for what it's worth, the UV coordinates are exported in the .dae, abit they obviously are completely useless without a texture assigned to them; I've also tried adding two different textures to see if the exporter needs that because it naively assumes 'one texture = don't bother, it's one texture for the whole model'. That didn't work either)

$\endgroup$
6
$\begingroup$

Start with the default cube. Ensure you've created a material or use the default material already created. Assign a texture to it as a diffuse image, say "lava.png". The important point here is to assign your object texture via a material. There is another way to directly texture mesh faces without a material but you still need a default material to get the Collada export to recognise textures, so I suggest going with this approach. If you export as Collada format now, ensure you select "Include material textures" checkbox in the export options. This will produce something along the lines of following XML element in the export file:

<library_images>
    <image id="lava_png" name="lava_png">
        <init_from>lava.png</init_from>
    </image>
</library_images>

But the library effect element will look something like:

<library_effects>
    <effect id="Material-effect">
        <profile_COMMON>
            <technique sid="common">
                <phong>
                    <emission>
                        <color sid="emission">0 0 0 1</color>
                    </emission>
                    <ambient>
                        <color sid="ambient">0 0 0 1</color>
                        </ambient>
                    <diffuse>
                        <color sid="diffuse">0.64 0.64 0.64 1</color>
                    </diffuse>
                    <specular>
                        <color sid="specular">0.5 0.5 0.5 1</color>
                    </specular>
                    <shininess>
                        <float sid="shininess">50</float>
                    </shininess>
                    <index_of_refraction>
                        <float sid="index_of_refraction">1</float>
                    </index_of_refraction>
                </phong>
            </technique>
        <extra>
            <technique profile="GOOGLEEARTH">
                <double_sided>1</double_sided>
            </technique>
        </extra>
        </profile_COMMON>
        <extra>
            <technique profile="MAX3D"><double_sided>1</double_sided>
            </technique>
        </extra>
    </effect>
</library_effects>

Note that the diffuse element defines a colour rather than an image reference. This means there's no 'link' in the Collada file between the lava.png and the diffuse component of the material associated with the mesh.

The missing step relates to the coordinate mapping technique used. Go to the texture panel for the lava.png and find the "Mapping" section. The coordinates entry is likely set to "generated". Change this to UV and export again with "Include material textures" and the diffuse entry will now reference "lava_png-sampler". Something like:

<library_effects>
    <effect id="Material-effect">
        <profile_COMMON>
            <newparam sid="lava_png-surface">
                <surface type="2D">
                    <init_from>lava_png</init_from>
                </surface>
            </newparam>
            <newparam sid="lava_png-sampler">
                <sampler2D>
                    <source>lava_png-surface</source>
                </sampler2D>
            </newparam>
            <technique sid="common">
                <phong>
                    <emission>
                        <color sid="emission">0 0 0 1</color>
                    </emission>
                    <ambient>
                         <color sid="ambient">0 0 0 1</color>
                    </ambient>
                    <diffuse>
                        <texture texture="lava_png-sampler"/>
                    </diffuse>
                    <specular>
                        <color sid="specular">0.5 0.5 0.5 1</color>
                    </specular>
                    <shininess>
                        <float sid="shininess">50</float>
                    </shininess>
                    <index_of_refraction>
                        <float sid="index_of_refraction">1</float>
                    </index_of_refraction>
                </phong>
            </technique>
            <extra>
                <technique profile="GOOGLEEARTH">
                    <double_sided>1</double_sided>
                </technique>
            </extra>
        </profile_COMMON>
        <extra>
            <technique profile="MAX3D"><double_sided>1</double_sided>
            </technique> 
        </extra>
    </effect>
</library_effects>

This should then import, with the texture intact, into whatever you're using, e.g. Assimp or a modelling package/viewer.

Hope this helps.

$\endgroup$
  • $\begingroup$ Just for anyone else who finds this, the key here was: Go to the texture panel for the lava.png and find the "Mapping" section. The coordinates entry is likely set to "generated". Change this to UV and export again. (btw: I'm pretty sure this means the collada exporter is actually broken. Changing the UV coordinate type shouldn't have any impact on this) $\endgroup$ – Doug Nov 16 '13 at 0:04
5
$\begingroup$

I was having an issue when exporting DAE's to use in Aurasma. After hours of messing around and re-exporting I realised that the problem was that I'd set Blender to default to the 'Cycles' renderer (and therefore associated materials) and exporting DAE's with textures only works with materials created in 'Blender Render' mode. I'm not sure that this solves the exact issue above but it's worth checking out and/or it may help someone else who is trawling the internet looking for a solution to the same issue as me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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