Page MenuHome

Collada: add tangents and multiple UV maps to mesh export (supercedes #30112)
Closed, ArchivedPublicPATCH


This is basically #30112 but includes support for exporting tangents, as needed for tangent space normal mapping.

- supports multiple UV maps per vertex
- tangents will be exported automatically if the object references a tangent-space normal map
- if the material is set to shadeless, normals will be omitted

tangents will be exported in blender-format (a xyzw vector, w-component is used as sign to reconstruct the binormal).

vec3 normal
vec4 tangent
vec3 binormal = cross( normal , ) * tangent.w

This way it works very well for me and my projects (meshes and matching normal maps created with blender), but it's maybe a better approach to export both tangent and binormal as separate streams, since COLLADA does not know about this .w trick. Also I do not like normals if shadeless (I haven't found a nice way to express this in COLLADA).

Tested with my engine, PVR tools and OSX Preview app.

Event Timeline

Please ignore the first patch, it was uploaded from the wrong folder. The one with "-fixed" in the name is the correct one.
I'm sorry!

Hi, Daniel. Does this patch supersede ? Then i would close the other patch.

Yes, please close #30112.

Please can you help me to verify that your patch works correct by supplying a test blend file and describe in detail what will be exported ?
i created a cube, added 3 different uv maps to it with different layouts. The difference between with your patch and without your patch
only shows up in the Material polylist, where the 3 texture coordinate maps are assigned differently to UV vertices.

However in the reimported .dae file the cube and the UV maps look identical regardless whether your patch is applied or not.
So i must have missed something.

Hi Gaia,

to be honest: I never cared about importing anything into blender - for us it's a content creation tool. So a full round-trip is (very likely) not possible.If it's required I'll have to spent some time here.

If you export xyz + normal + vertex color + uv map, you'll get a position,normal,color and texcoord component in COLLADA, as expected. Unfortunately, blender is currently only exporting for COLLADA 1.4.x and writes just profile_COMMON.

profile_COMMON does not offer very much, and this is a problem. You can only have one diffuse texture (with one UV layer), and even bump mapping is a hack. So if you export ie three different UV maps (like in attached test.blend / test.dae), you'll get something like this at the node:

<node id="Cube" name="Cube" type="NODE">
<instance_geometry url="#Cube-mesh">
<instance_material symbol="Material" target="#Material-material">
<bind_vertex_input semantic="uv-checker" input_semantic="TEXCOORD" input_set="0"/>
<bind_vertex_input semantic="uv-gradient" input_semantic="TEXCOORD" input_set="1"/>
<bind_vertex_input semantic="uv-puzzle" input_semantic="TEXCOORD" input_set="2"/>

And if you search further for "uv" inside of test.dae, you'll find only this:

<technique sid="common">
<texture texture="puzzle_png-sampler" texcoord="uv-puzzle"/>

So this is actually a limitation of using just profile_COMMON (and especially OpenCOLLADA) in blender: the correct format does only offer one UV channel.

However, if you look at the actual geometry definition, all UV maps will be written correctly:

<polylist material="Material" count="6">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-0" offset="1" set="0"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-1" offset="2" set="1"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-2" offset="3" set="2"/>

My decision was: if you know what you're doing with blender and the resulting COLLADA, you'll get your UV maps. Normally you're writing a fragment/vertexshader that is hardcoded to a specific vertex format anyway.

If you just use a single diffuse uv-map and a secondary normal/bump uv-map it will fit perfectly into profile_COMMON. I admit that it does not make much sense to have a diffuse+normalmap combination with different UV maps.

Since this is a major limitation, I have started to work on experimental profiles, see test_GLSL.dae. So the next version of this patch will write multiple profiles: profile_COMMON, profile_GLSL, profile_GLES, ...

Please instruct me how to change/modify/document, if required.

I have created an alternative patch for this feature. My version is based on Daniel's, but changes always exports tangents (as opposed to just on objects with UV maps). My version also includes bitangents.

I have not tested this extensively, but it works for my purposes and should be useful as a starting point for someone to verify accuracy and perhaps add options to the UI.

My version is attached as collada-export-tangents-bitangents.diff.


Thanks for the patch. However would you mind to test again with the current development version from trunk ? I have added the gsoc improvements for Collada a few days ago. I have not yet checked it but possibly the new code conflicts with your patch


Bump for request to update patch against current master. I'm trying to get an overview of the currently open tasks and patches in our tracker for COLLADA.

Campbell Barton (campbellbarton) changed the task status from Duplicate to Unknown Status.Sep 8 2015, 5:32 AM
Campbell Barton (campbellbarton) edited projects, added Collada; removed BF Blender.
Dalai Felinto (dfelinto) closed this task as Archived.Dec 23 2019, 6:49 PM

Hi, thanks for your patch.

We are undergoing a Tracker Curfew where we are automatically closing old patches.

If you think the patch is still relevant please update and re-submit it. For new features make sure there is a clear design from the user level perspective.