Three.JS

时间:2015-05-06 17:57:23

标签: three.js

我生成一个随机平面,该平面动画顶点中的运动以产生结晶效果。当我使用常规PlaneGeometry时,着色不是问题:http://codepen.io/shshaw/pen/GJppEX

但是,我尝试切换到PlaneBufferGeometry以查看是否可以获得更好的性能,但阴影消失了。 http://codepen.io/shshaw/pen/oXjyJL?editors=001

var planeGeometry = new THREE.PlaneBufferGeometry(opts.planeSize, opts.planeSize, opts.planeDefinition, opts.planeDefinition),
    planeMaterial = new THREE.MeshLambertMaterial({
      color: 0x555555,
      emissive: 0xdddddd,
      shading: THREE.NoShading
    }),
    plane = new THREE.Mesh(planeGeometry, planeMaterial),
    defaultVertices = planeGeometry.attributes.position.clone().array;

  function randomVertices() {
    var vertices = planeGeometry.attributes.position.clone().array;
    for (var i = 0; i <= vertices.length; i += 3) {
      // x
      vertices[i] = defaultVertices[i] + (rand(-opts.variance.x, opts.variance.x));
      // y
      vertices[i + 1] = defaultVertices[i + 1] + (rand(-opts.variance.y, opts.variance.y));
      // z
      vertices[i + 2] = rand(-opts.variance.z, -opts.variance.z);
    }
    return vertices;
  }

  plane.geometry.attributes.position.array = randomVertices();

正如我看到建议的in this answer to 'Shading on a plane',我试过了:

plane.geometry.computeVertexNormals();

在渲染时,我已经尝试了几何的所有以下属性,以确保它更新法线和&amp ;;顶点,就像我在PlaneGeometry的工作示例中所做的那样:

plane.geometry.verticesNeedUpdate = true;
plane.geometry.normalsNeedUpdate = true;
plane.geometry.computeVertexNormals();
plane.geometry.computeFaceNormals();
plane.geometry.normalizeNormals();

阴影发生了什么变化?我可以将它带回PlaneBufferGeometry网格,还是需要坚持使用PlaneGeometry

谢谢!

0 个答案:

没有答案