与MeshBasicMaterial相比,ThreeJS MeshStandardMaterial在移动设备中的速度太慢

时间:2019-09-10 11:11:48

标签: javascript html three.js

我有以下代码在场景中添加多维数据集,当我在PC上的浏览器中打开页面时,它可以正常工作,但是当我在移动设备中打开时,控制速度太慢。需要3-4秒才能从触摸屏获得响应,而移动设备的响应速度也会变慢。

好像我将MeshStandardMaterial更改为MeshBasicMaterial一样,一切正常。可能是什么问题。

sideWallMaterial = [new THREE.MeshStandardMaterial({
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0055
  }),
  new THREE.MeshStandardMaterial({
    color: '#a6aea2',
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0005,
    opacity: 0.5,
    transparent: true,
    depthWrite: false
  }),
  new THREE.MeshStandardMaterial({
    color: '#a6aea2',
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0005
  }),
  new THREE.MeshStandardMaterial({
    color: '#a6aea2',
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0005
  }),
  new THREE.MeshStandardMaterial({
    color: '#a6aea2',
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0005
  }),
  new THREE.MeshStandardMaterial({
    color: '#a6aea2',
    roughness: 0.8,
    metalness: 0.2,
    bumpScale: 0.0005
  })
];

var textureLoader = new THREE.TextureLoader();
textureLoader.load("img1.jpg", function(map) {
  map.wrapS = THREE.RepeatWrapping;
  map.wrapT = THREE.RepeatWrapping;
  map.anisotropy = 4;
  map.repeat.set(10, 10);
  sideWallMaterial[0].map = map;
  sideWallMaterial[0].needsUpdate = true;

});
textureLoader.load("img2.jpg", function(map) {

  map.wrapS = THREE.RepeatWrapping;
  map.wrapT = THREE.RepeatWrapping;
  map.anisotropy = 4;
  map.repeat.set(10, 10);
  sideWallMaterial[0].bumpMap = map;
  sideWallMaterial[0].needsUpdate = true;

});
textureLoader.load("img3.jpg", function(map) {

  map.wrapS = THREE.RepeatWrapping;
  map.wrapT = THREE.RepeatWrapping;
  map.anisotropy = 4;
  map.repeat.set(10, 24);
  sideWallMaterial[0].roughnessMap = map;
  sideWallMaterial[0].needsUpdate = true;

});

var geometry = new THREE.BoxBufferGeometry(wall_t, wall_h, wall_w);
var material = new THREE.MeshLambertMaterial();
mesh = new THREE.Mesh(geometry, sideWallMaterial);
mesh.receiveShadow = true;
mesh.position.set(0, 0, 0);
scene.add(mesh);

1 个答案:

答案 0 :(得分:2)

MeshStandardMaterial是PBR材料,而MeshBasicMaterial是不发光的材料。因此,后者的渲染性能要好得多。但是,它对任何灯光都没有反应,因此其简单的视觉外观无法与更高级的MeshStandardMaterial相提并论。

还请记住,并非所有材料都具有相同的属性。您可以为MeshStandardMaterial分配凹凸和粗糙度贴图,但不能为MeshBasicMaterialMeshLambertMaterial(在代码段中使用过)分配凹凸贴图。两种材质都只会忽略这些纹理,这意味着您可以保存各自的纹理解码和GPU上传。当然,这将改善初始的“编译/显示”性能。

three.js R108