【问题标题】:Verification of using multiple textures with three.js cubes使用 three.js 立方体使用多个纹理的验证
【发布时间】:2018-05-26 01:05:53
【问题描述】:

有人可以验证一下three.js r53的以下代码吗?

取自这个问题:How to use multiple materials in a Three.js cube?

我尝试了这段代码和一些变体,但没有看到可见的立方体。我的纹理图像按应有的名称命名。

var materials = [];

for (var i=0; i<6; i++) {
  var img = new Image();
  img.src = i + '.png';
  var tex = new THREE.Texture(img);
  img.tex = tex;

  img.onload = function() {
      this.tex.needsUpdate = true;
  };

  var mat = new THREE.MeshBasicMaterial({color: 0xffffff, map: tex});
  materials.push(mat);
}

var cubeGeo = new THREE.CubeGeometry(400, 400, 400, 1, 1, 1, materials);
var cube = new THREE.Mesh(cubeGeo, new THREE.MeshFaceMaterial());

【问题讨论】:

    标签: javascript 3d three.js


    【解决方案1】:

    改为这样做:

    var cubeGeo = new THREE.BoxGeometry( 400, 400, 400, 1, 1, 1 );
    var cube = new THREE.Mesh( cubeGeo, materials );
    

    materials 是一个包含 6 个 three.js 材料的数组,每个人脸一个。

    请参阅迁移指南:https://github.com/mrdoob/three.js/wiki/Migration-Guide

    编辑:CubeGeometry 已重命名为 BoxGeometryTHREE.MeshFaceMaterial 已被弃用。

    three.js r.92

    【讨论】:

    • 还将 CubeGeometry 重命名为 BoxGeometry (r66)
    • @imcg 谢谢。更新了答案。
    【解决方案2】:

    THREE.CubeGeometry() 不支持材质列表。我也认为是这样,但如果你检查当前的源代码......它没有

    【讨论】:

      猜你喜欢
      • 2013-10-10
      • 2012-11-19
      • 2017-01-18
      • 2016-09-26
      • 2013-12-19
      • 2021-01-08
      • 2013-02-23
      • 2019-11-23
      • 2013-06-29
      相关资源
      最近更新 更多