简体   繁体   English

如何在Three.js形状几何中添加正面和背面纹理?

[英]How to add front and Back textures in Three.js shape geometry?

I'm creating a flat shape geometry with rounded corners. 我正在创建带有圆角的平面几何形状。 Here's a part of my code. 这是我的代码的一部分。

    var geometry = new THREE.ShapeGeometry(shape);
    var front_material = new THREE.MeshPhongMaterial({ map: frontTexture, side: THREE.FrontSide });
    var back_material = new THREE.MeshPhongMaterial({ map: backTexture, side: THREE.BackSide });
    var materials = [front_material, back_material];
    mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));

This codes only load the front side and renders invisible on back side. 此代码仅加载正面,而在背面不可见。 After few hours of googling I can't find how to add materialIndex on current Three.js version r78. 经过数小时的搜寻后,我找不到如何在当前Three.js版本r78上添加materialIndex的方法。

I suspect that I just need to add material index on this problem. 我怀疑我只需要添加关于此问题的实质性索引。

If you want to create a flat shape that has a different material on the front and the back, you can use this pattern: 如果要创建在正面和背面具有不同材质的扁平形状,则可以使用以下模式:

var geometry = new THREE.ShapeGeometry( shape );

var frontMaterial = new THREE.MeshPhongMaterial( { map: frontTexture, side: THREE.FrontSide } );
var backMaterial = new THREE.MeshPhongMaterial( { map: backTexture, side: THREE.BackSide } );

var materials = [ frontMaterial, backMaterial ];

var object = THREE.SceneUtils.createMultiMaterialObject( geometry, materials );

scene.add( object );

Study the source code of SceneUtils so you understand what it is doing. 研究SceneUtils的源代码,以便您了解它在做什么。

three.js r.78 three.js r.78

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

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