Collada (.dae) only 1st texture is applied on object

125 views Asked by At

I have made me an app that creates Collada .dae file for 3D objects with decorations (textures) for use in another 3th party rendering app.

Let's take for example this simple LEGO brick - it has two textures, one on each opposite site.

All works fine as it should in case an object is made out of 3 separate parts, so each has only one texture = one UV map defined (the displayed image below is the same brick where the 2nd one is just rotated 180 degrees to show the texture on the opposite site).

enter image description here

But as soon as the object is as one complete object with both uv map defined for it, then only the 1st one is applied and I do not know why.

enter image description here

I should say I am really no pro in Collada files, so maybe I just omit something or defined wrongly, so I need help with this.

Here is content of Collada file my app created for that brick:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
    <asset>
        <unit meter="1.0" name="LDU"/>
        <up_axis>Y_UP</up_axis>
    </asset>
    <library_images>
        <image id="Image-3003025" name="Image-3003025">
            <init_from>3003025.png</init_from>
        </image>
        <image id="Image-3003077" name="Image-3003077">
            <init_from>3003077.png</init_from>
        </image>
    </library_images>
    <library_effects>
        <effect id="effect_id_21_3003025">
            <profile_COMMON id="eyesight">
                <newparam sid="effect_id_21_3003025-surface">
                    <surface type="2D">
                        <init_from>Image-3003025</init_from>
                    </surface>
                </newparam>
                <newparam sid="StickerTexture">
                    <sampler2D>
                        <source>effect_id_21_3003025-surface</source>
                        <minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
                        <magfilter>LINEAR</magfilter>
                        <mipfilter>LINEAR_MIPMAP_LINEAR</mipfilter>
                        <wrap_s>NONE</wrap_s>
                        <wrap_t>NONE</wrap_t>
                    </sampler2D>
                </newparam>
                <technique sid="common">
                    <phong>
                        <emission>
                            <texture texcoord="UVMap" texture="StickerTexture"/>
                        </emission>
                    </phong>
                </technique>
            </profile_COMMON>
        </effect>
        <effect id="effect_id_21_3003077">
            <profile_COMMON id="eyesight">
                <newparam sid="effect_id_21_3003077-surface">
                    <surface type="2D">
                        <init_from>Image-3003077</init_from>
                    </surface>
                </newparam>
                <newparam sid="StickerTexture">
                    <sampler2D>
                        <source>effect_id_21_3003077-surface</source>
                        <minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
                        <magfilter>LINEAR</magfilter>
                        <mipfilter>LINEAR_MIPMAP_LINEAR</mipfilter>
                        <wrap_s>NONE</wrap_s>
                        <wrap_t>NONE</wrap_t>
                    </sampler2D>
                </newparam>
                <technique sid="common">
                    <phong>
                        <emission>
                            <texture texcoord="UVMap" texture="StickerTexture"/>
                        </emission>
                    </phong>
                </technique>
            </profile_COMMON>
        </effect>
        <effect id="effect_id_21"/>
    </library_effects>
    <library_materials>
        <material id="material_id_21_3003025" name="SOLID-RED">
            <instance_effect url="#effect_id_21_3003025"/>
        </material>
        <material id="material_id_21_3003077" name="SOLID-RED">
            <instance_effect url="#effect_id_21_3003077"/>
        </material>
        <material id="material_id_21" name="SOLID-RED">
            <instance_effect url="#effect_id_21"/>
        </material>
    </library_materials>
    <library_geometries>
        <geometry id="Part-3003_g" name="Part-3003_g">
            <mesh>
                <source id="Part-3003_g-positions">
                    <float_array count="492" id="Part-3003_g-positions-array">[very-long-numbers-sequence-here]</float_array>
                    <technique_common>
                        <accessor count="164" source="#Part-3003_g-positions-array" stride="3">
                            <param name="X" type="float"/>
                            <param name="Y" type="float"/>
                            <param name="Z" type="float"/>
                        </accessor>
                    </technique_common>
                </source>
                <source id="Part-3003_g-normals">
                    <float_array count="666" id="Part-3003_g-normals-array">[very-long-numbers-sequence-here]</float_array>
                    <technique_common>
                        <accessor count="222" source="#Part-3003_g-normals-array" stride="3">
                            <param name="X" type="float"/>
                            <param name="Y" type="float"/>
                            <param name="Z" type="float"/>
                        </accessor>
                    </technique_common>
                </source>
                <source id="Part-3003_g-uvmap-0">
                    <float_array count="1800" id="Part-3003_g-uvmap-0-array">[very-long-numbers-sequence-here]</float_array>
                    <technique_common>
                        <accessor count="900" source="#Part-3003_g-uvmap-0-array" stride="2">
                            <param name="S" type="float"/>
                            <param name="T" type="float"/>
                        </accessor>
                    </technique_common>
                </source>
                <source id="Part-3003_g-uvmap-1">
                    <float_array count="1800" id="Part-3003_g-uvmap-1-array">[very-long-numbers-sequence-here]</float_array>
                    <technique_common>
                        <accessor count="900" source="#Part-3003_g-uvmap-1-array" stride="2">
                            <param name="S" type="float"/>
                            <param name="T" type="float"/>
                        </accessor>
                    </technique_common>
                </source>
                <vertices id="Part-3003_g-vertices">
                    <input semantic="POSITION" source="#Part-3003_g-positions"/>
                </vertices>
                <triangles count="296">
                    <input offset="0" semantic="VERTEX" source="#Part-3003_g-vertices"/>
                    <input offset="1" semantic="NORMAL" source="#Part-3003_g-normals"/>
                    <input offset="2" semantic="TEXCOORD" set="0" source="#Part-3003_g-uvmap-0"/>
                    <input offset="2" semantic="TEXCOORD" set="1" source="#Part-3003_g-uvmap-1"/>
                    <p>[very-long-numbers-sequence-here]</p>
                </triangles>
                <triangles count="2">
                    <input offset="0" semantic="VERTEX" source="#Part-3003_g-vertices"/>
                    <input offset="1" semantic="NORMAL" source="#Part-3003_g-normals"/>
                    <input offset="2" semantic="TEXCOORD" set="0" source="#Part-3003_g-uvmap-0"/>
                    <input offset="2" semantic="TEXCOORD" set="1" source="#Part-3003_g-uvmap-1"/>
                    <p>1 44 378 0 44 379 2 44 380 1 44 828 5 44 829 0 44 830</p>
                </triangles>
                <triangles count="2">
                    <input offset="0" semantic="VERTEX" source="#Part-3003_g-vertices"/>
                    <input offset="1" semantic="NORMAL" source="#Part-3003_g-normals"/>
                    <input offset="2" semantic="TEXCOORD" set="0" source="#Part-3003_g-uvmap-0"/>
                    <input offset="2" semantic="TEXCOORD" set="1" source="#Part-3003_g-uvmap-1"/>
                    <p>4 40 84 162 40 85 3 40 86 4 40 567 163 40 568 162 40 569</p>
                </triangles>
            </mesh>
        </geometry>
    </library_geometries>
    <library_nodes>
        <node id="node_lddmodel">
            <node id="node_lddmodel-0">
                <node>
                    <matrix>1.0 0.0 0.0 -1.1999995 0.0 0.9999999 0.0 0.0 0.0 0.0 1.0 -0.40000013 0.0 0.0 0.0 1.0</matrix>
                    <instance_geometry url="#Part-3003_g">
                        <bind_material>
                            <technique_common>
                                <instance_material symbol="Base" target="#material_id_21_3003025">
                                    <bind_vertex_input input_semantic="TEXCOORD" input_set="0" semantic="UVMap"/>
                                </instance_material>
                                <instance_material symbol="Base" target="#material_id_21_3003077">
                                    <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="UVMap"/>
                                </instance_material>
                            </technique_common>
                        </bind_material>
                    </instance_geometry>
                </node>
            </node>
            <node id="node_lddmodel-1">
                <node>
                    <matrix>-1.0 0.0 0.0 1.9999995 0.0 1.0 0.0 0.0 0.0 0.0 -1.0 -1.1999999 0.0 0.0 0.0 1.0</matrix>
                    <instance_geometry url="#Part-3003_g">
                        <bind_material>
                            <technique_common>
                                <instance_material symbol="Base" target="#material_id_21_3003025">
                                    <bind_vertex_input input_semantic="TEXCOORD" input_set="0" semantic="UVMap"/>
                                </instance_material>
                                <instance_material symbol="Base" target="#material_id_21_3003077">
                                    <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="UVMap"/>
                                </instance_material>
                            </technique_common>
                        </bind_material>
                    </instance_geometry>
                </node>
            </node>
        </node>
    </library_nodes>
    <library_visual_scenes>
        <visual_scene id="Scene1">
            <node id="Model" name="Model">
                <matrix>1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
                <instance_node url="#node_lddmodel"/>
            </node>
        </visual_scene>
    </library_visual_scenes>
    <scene>
        <instance_visual_scene url="#Scene1"/>
    </scene>
</COLLADA>

I played with the code and found out that the section responsible for the material/texture binding for a specific instance (rendered object) will render on the 2nd uv map fine if I change the input_set value on the 1st bind_vertex_input node like this - so the problem is not with the 2nd uv map:

<technique_common>
    <instance_material symbol="Base" target="#material_id_21_3003025">
        <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="UVMap"/>
    </instance_material>
    <instance_material symbol="Base" target="#material_id_21_3003077">
        <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="UVMap"/>
    </instance_material>
</technique_common>

But still, only the 1st texture is rendered again no matter what - the other instance_material seems to be ignored, see:

enter image description here

I also replaced the 1st material for the 2nd as to test if the problem is with the 2nd texture (21_3003077) like this:

<technique_common>
    <instance_material symbol="Base" target="#material_id_21_3003077">
        <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="UVMap"/>
    </instance_material>
    <instance_material symbol="Base" target="#material_id_21_3003025">
        <bind_vertex_input input_semantic="TEXCOORD" input_set="0" semantic="UVMap"/>
    </instance_material>
</technique_common>

But it renders it fine, just still only the 1st instance material, the 2nd instance material is ignored (this means that the problem is also not with the texture):

enter image description here

So can anyone explain/show to me why only the 1st instance_material tag is rendered and any other ignored?

0

There are 0 answers