0
$\begingroup$

I have the following DAE file, handmade (pyramid with no bottom). Uncomment two triangles to make it pyramid with bottom:

It shows a pyramid and tries to put a texture on it. It is displayed both on inner and outer sides of a pyramid (if the pyramid has bottom, it displays texture both on sides and bottom).

I only want it on sides - not on bottom, and ou outer side of these sides, not inside.

Could you please help?

I guess there are multiple possible solutions: I would go for making the texture of two parts - one for inner and one for outer side of a pyramid, like 1280x640. This way a left half of an image will be stretched over inner side of a pyramid, and right part - over the outer part of a pyramid. The question is, how to map such a texture to this pyramid? A working example would be great, a working example with explanation even better.

The only thing, I am going to GENERATE this DAE, so if you suggest changes, PLEASE keep them to minimum :)

Thank you.

<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
    <asset>
        <created>2023-11-27T12:48:14</created>
        <modified>2023-11-27T12:48:14</modified>
        <unit meter="1.0" name="meter" />
        <up_axis>Y_UP</up_axis>
    </asset>

    <library_images>
        <image id="texture0" name="texture">
            <init_from>../maps/perfect_texture.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_materials>
        <material id="material0">
            <instance_effect url="#effect0" />
        </material>
    </library_materials>

    <library_geometries>
        <geometry id="shape0">
            <mesh>
                <source id="positions">
                    <float_array id="positions-array" count="15">
                        0 1 0
                        0 0 0
                        1 0 0
                        1 1 0

                        0.5 0.5 1
                    </float_array>
                    <technique_common>
                        <accessor count="5" source="#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="normals">
                <float_array id="normals-array" count="15">
                    0.0 0.0 -1.0
                    0.0 0.0 -1.0
                    0.0 0.0 -1.0
                    0.0 0.0 -1.0
                    0.0 0.0  1.0  <!-- Normals for the sides of the pyramid -->
                </float_array>
                <technique_common>
                    <accessor count="5" source="#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="uv-source">
                    <float_array id="uv-float-array" count="10">
                        0.0 0.0
                        1.0 0.0
                        0.0 1.0
                        1.0 1.0
                        0.5 0.5
                    </float_array>
                    <technique_common>
                        <accessor source="#uv-float-array" count="5" stride="2">
                        <param name="S" type="float"/>
                        <param name="T" type="float"/>
                        </accessor>
                    </technique_common>
                </source>

                <vertices id="verts-array-vertices">
                    <input semantic="POSITION" source="#positions" />
                    <input semantic="NORMAL" source="#normals" />
                    <input semantic="TEXCOORD" source="#uv-source" />
                </vertices>

                <triangles count="6" material="material0">
                    <input offset="0" semantic="VERTEX" source="#verts-array-vertices" />
                    <p>
                        <!-- 0 1 2 
                        0 2 3 -->

                        0 4 3
                        3 4 2
                        2 4 1
                        1 4 0
                    </p>
                </triangles>
            </mesh>
        </geometry>
    </library_geometries>

    <library_visual_scenes>
        <visual_scene id="scene0">
        <node 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="#scene0" />
    </scene>
</COLLADA>
$\endgroup$

1 Answer 1

0
$\begingroup$

Here is a curated pyramid. As usual, I will put complete explanations with examples at robotics.snowcron.com, within few days :)

Things to keep in mind:

  1. mesh sources (...) can be in any units, so you can use meters etc. For example, 0 1 1 is ok, but 0 2 2 is ok too. Depends on the size of your object.

  2. However, UV mapping (...) should be within 0-1, so for your image, you need to recalculate something like

    for v in mesh.vertices: uvs.append([(v[0] - x_min) / (x_max - x_min), (v1 - y_min) / (y_max - y_min)])

Here it is:

<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
    <asset>
        <created>2023-11-27T12:48:14</created>
        <modified>2023-11-27T12:48:14</modified>
        <unit meter="1.0" name="meter" />
        <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_materials>
        <material id="material0">
            <instance_effect url="#effect0" />
        </material>
    </library_materials>

    <library_geometries>
        <geometry id="shape0">
            <mesh>
                <source id="positions">
                    <float_array id="positions-array" count="15">
                        0 1 0
                        1 1 0
                        1 0 0
                        0 0 0

                        0.5 0.5 1
                    </float_array>
                    <technique_common>
                        <accessor count="5" source="#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="normals">
                    <float_array id="normals-array" count="15">
                        0.0 0.0 -1.0
                        0.0 0.0 -1.0
                        0.0 0.0 -1.0
                        0.0 0.0 -1.0
                        0.0 0.0  1.0
                    </float_array>
                    <technique_common>
                        <accessor count="5" source="#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="uv-source">
                    <float_array id="uv-float-array" count="10">
                        0.0 1.0
                        1.0 1.0
                        1.0 0.0
                        0.0 0.0
                        0.5 0.5
                    </float_array>
                    <technique_common>
                        <accessor source="#uv-float-array" count="5" stride="2">
                        <param name="S" type="float"/>
                        <param name="T" type="float"/>
                        </accessor>
                    </technique_common>
                </source>

                <vertices id="verts-array-vertices">
                    <input semantic="POSITION" source="#positions" />
                    <input semantic="NORMAL" source="#normals" />
                    <input semantic="TEXCOORD" source="#uv-source" />
                </vertices>

                <triangles count="6" material="material0">
                    <input offset="0" semantic="VERTEX" source="#verts-array-vertices" />
                    <p>
                        <!-- 0 1 2 
                        0 2 3 -->

                        0 4 3
                        3 4 2
                        2 4 1
                        1 4 0
                    </p>
                </triangles>
            </mesh>
        </geometry>
    </library_geometries>

    <library_visual_scenes>
        <visual_scene id="scene0">
        <node 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="#scene0" />
    </scene>
</COLLADA>

enter image description here

$\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.