简体   繁体   English

Three.js-闪烁的纹理

[英]Three.js - Flickering Texture

I am trying to load a JSON file that I exported from blender. 我正在尝试加载从Blender导出的JSON文件。 There are two meshes and two materials in the file. 文件中有两个网格和两种材料。 This is the code that I use to load the JSON. 这是我用来加载JSON的代码。

var self = this;
var mushroomLoader = new THREE.JSONLoader();
    mushroomLoader.load('/js/Mushroom.js', function(mushroomGeometry, mushroomMaterial) {
    var shrooms = new THREE.Object3D();
    var mushroomCount = 10;
    var radius = 30;
        for(var i = 0; i < mushroomCount; i++) {
        var m = new THREE.Object3D();
    m.add(new THREE.Mesh(mushroomGeometry, mushroomMaterial[0]));
    m.add(new THREE.Mesh(mushroomGeometry, mushroomMaterial[1]));
        m.position.x = radius * Math.cos(Math.PI * 2 * i / mushroomCount);
        m.position.z = radius * Math.sin(Math.PI * 2 * i / mushroomCount);
    shrooms.add(m);
    }
    self.scene.add(shrooms);
}, 'images/textures');

The mushroom is separated into two meshes, the top and the trunk. 蘑菇被分成两个网格,顶部和树干。 I am using MeshPhongMaterial. 我正在使用MeshPhongMaterial。 The texture that is flashing/disappearing is on the top. 闪烁/消失的纹理在顶部。 The weird thing is that some of them display correctly. 奇怪的是,其中一些显示正确。

You were right @WestLangley! 你是对的@WestLangley! I changed my code from this 我从这里改变了我的代码

var m = new THREE.Object3D();
m.add(new THREE.Mesh(mushroomGeometry, mushroomMaterial[0]));
m.add(new THREE.Mesh(mushroomGeometry, mushroomMaterial[1]));

to

var m = new THREE.Mesh(mushroomGeometry, new THREE.MeshFaceMaterial(mushroomMaterial));

and I am not having anymore issues. 而且我再也没有问题了。 It seems so simple in retrospect. 回想起来似乎很简单。 I thought it was weird that THREE.SceneUtils.createMultiMaterialObject uses the same geometry for both meshes. 我认为THREE.SceneUtils.createMultiMaterialObject对两个网格使用相同的几何形状很奇怪。

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

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