简体   繁体   English

Three.js –将纹理应用于Collada网格会产生意外结果

[英]Three.js – Applying texture to Collada mesh yields unexpected result

Following the Three.js ColladaLoader example , I've exported a Cinema4D soda can model ( consisting of 4 meshes ) to a .dae file. Three.js ColladaLoader示例之后 ,我将Cinema4D苏打罐模型( 由4个网格组成 )导出到了.dae文件中。 One of the meshes, the body of the can, I want to add a texture to. 我想向其中一个网格物体(罐体)添加纹理。

In Cinema4D I've already made a texture based on a UV map of the mesh (spherical). 在Cinema4D中,我已经基于网格(球形)的UV贴图制作了纹理 However, when I try to apply the texture to the mesh, it simply shows a solid white fill. 但是,当我尝试将纹理应用于网格时,它只会显示纯白色填充。 I've added the entire code in this Codepen . 我已经在Codepen中添加了整个代码。 Relevant code below, edited for brevity: 以下相关代码,为简洁起见进行了编辑:

loader = new THREE.ColladaLoader();
loader.load('can.dae', function (collada) {
    can = collada.scene;

    can.traverse(function (node) {
        var textureLoader

        if (node.name == 'wrapper') {
            textureLoader = new THREE.TextureLoader();

            textureLoader.load('wrapper.png', function (texture) {
                node.material = new THREE.MeshBasicMaterial({
                    map: texture
                });

                node.material.needsUpdate = true;
            });
        }
    });

    scene.add(can); 
});

Illustration of the result. 结果说明。 As you can see, the wrapper of the can isn't the red wrapper.png provided, but a solid white fill. 如您所见,罐的包装不是提供的红色wrapper.png ,而是纯白色填充。 I've tried experimenting with mapping and wrapping modes, but to no avail. 我尝试过尝试映射和包装模式,但无济于事。 Any help very much appreciated! 任何帮助非常感谢!

在此处输入图片说明

FYI: I've already ruled out CORS issues. 仅供参考:我已经排除了CORS问题。

I added a cube in your loader and gave it that material and it worked.. so the implication is that your can mesh does not have proper UV coordinates assigned to it.. Perhaps it is using an automatic cylindrical mapping in your authoring software which is not exporting it's UVs? 我在您的加载器中添加了一个多维数据集,并给它提供了该材料,它就可以正常工作..因此,这意味着您的罐头网格没有为其分配适当的UV坐标。.也许它是在创作软件中使用自动圆柱映射的,不出口紫外线? What software are you authoring in? 您在编写什么软件?

            scene.add(new THREE.Mesh(new THREE.BoxGeometry(1,1,1),node.material));

https://codepen.io/manthrax/pen/ePBZbZ?editors=1001 https://codepen.io/manthrax/pen/ePBZbZ?editors=1001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM