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

Closed
opened 2012-05-18 22:25:05 +02:00 by Daniel Balster · 16 comments

%%%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.xyz ) * 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.%%%

%%%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.xyz ) * 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.%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

%%%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!%%%

%%%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!%%%
Member

%%%Hi, Daniel. Does this patch supersede http://projects.blender.org/tracker/index.php?func=detail&aid=30112 ? Then i would close the other patch.%%%

%%%Hi, Daniel. Does this patch supersede http://projects.blender.org/tracker/index.php?func=detail&aid=30112 ? Then i would close the other patch.%%%
Author

%%%Yes, please close #30112.%%%

%%%Yes, please close #30112.%%%
Member

%%%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.%%%

%%%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.%%%
Author

%%%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">
        <bind_material>
          <technique_common>
            <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"/>
            </instance_material>
          </technique_common>
        </bind_material>
      </instance_geometry>
    </node>

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

<profile_COMMON>

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

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. %%%

%%%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"> <bind_material> <technique_common> <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"/> </instance_material> </technique_common> </bind_material> </instance_geometry> </node> ``` And if you search further for "uv" inside of test.dae, you'll find only this: <profile_COMMON> ``` ... <technique sid="common"> ... <diffuse> <texture texture="puzzle_png-sampler" texcoord="uv-puzzle"/> </diffuse> ... ``` 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.%%%

%%%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.%%%

%%%Oh, the patch was made against Blender 2.65a.%%%

%%%Oh, the patch was made against Blender 2.65a.%%%
Member

%%%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

  • gaia-%%%
%%%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 - gaia-%%%
Member

Added subscriber: @jesterking

Added subscriber: @jesterking
Member

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.

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.
Member

Closed as duplicate of #43298

Closed as duplicate of #43298

Changed status from 'Duplicate' to: 'Open'

Changed status from 'Duplicate' to: 'Open'

Added subscriber: @dfelinto

Added subscriber: @dfelinto

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'

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.

Hi, thanks for your patch. We are undergoing a [Tracker Curfew ](https://code.blender.org/?p=3861) 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.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#31523
No description provided.