gpt4 book ai didi

javascript - Three.js - 在 JSON 对象上显示图像

转载 作者:行者123 更新时间:2023-11-28 00:02:30 24 4
gpt4 key购买 nike

我正在使用该库的版本 71。我试图在 3D 对象的每个面上显示图像(通过 Blender 制作)。无论是通过不同的图像还是重复一张图像并不重要。该对象在实例化为 JSONLoader 后通过加载函数加载。以下是加载json文件的示例。在本例中,形状是一个立方体,有六个面。有没有办法修改以下代码来实现这一点?

    var loaderSix = new THREE.JSONLoader();
loaderSix.load("./resources/json/six.json", function (model) {
var materialSix = new THREE.MeshNormalMaterial();

six = new THREE.Mesh(model, materialSix);
six.translateY(1);
six.scale = new THREE.Vector3(3, 3, 3);
meshSix = THREE.SceneUtils.createMultiMaterialObject(six, materialSix);
});

最佳答案

1) 如果您正在加载 Material ,并且已经有了几何图形,那么您是否尝试过“MeshFaceMaterial”(docs)?

var loaderSix = new THREE.JSONLoader();
loaderSix.load("./resources/json/six.json", function (model) {
var materialSix = new THREE.MeshFaceMaterial("your materials array: model");

six = new THREE.Mesh("your cube geometry", materialSix);
six.translateY(1);
six.scale = new THREE.Vector3(3, 3, 3);
});

2) 如果您正在加载对象,那么添加不同的图像“MeshFaceMaterial”也是一个选项,类似的示例 here 。我修改了该代码以适应情况:

    var image;        
var materials = [];
for (var i=0; i<6; i++) {
image = "./resources/images/"+fileName+".png"
materials.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture(image)}));
}
var loaderSix = new THREE.JSONLoader();
loaderSix.load("./resources/json/six.json", function (model) {
var materialSix = new THREE.MeshFaceMaterial(materials);

six = new THREE.Mesh(model, materialSix);
six.translateY(1);
six.scale = new THREE.Vector3(3, 3, 3);
});

关于javascript - Three.js - 在 JSON 对象上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31657104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com