0

I'm generating 3 plane that around about 400x300 in dimensions, and now I need to subdivide them to do some vertex shader manipulation.

My planes generate almost instantaneously (thanks to buffered geometry), now the issue is that with the subdivision, it drops my frame rate really low. I'm guessing that this has to do my my raycaster, which is called in the render loop and raycasts along the mouse position.

My question is, are there some optimizations I can do to fix the performance drop?

Here is how I'm generating my meshs:

function GeneratePlaneLayer(y) {
  var floorTexture = new THREE.ImageUtils.loadTexture('path/to/image'); 
  floorTexture.magFilter = THREE.NearestFilter;
  floorTexture.minFilter = THREE.NearestFilter;


  floorTexture.wrapS = floorTexture.wrapT = THREE.ClampToEdgeWrapping; 
  floorTexture.repeat.set(1, 1);

  var floorMaterial = new THREE.MeshBasicMaterial({
    map: floorTexture,
    side: THREE.DoubleSide,
    transparent: true
  });

  var geometry = new THREE.PlaneBufferGeometry(400, 300, 400, 300);
  var floor = new THREE.Mesh(geometry, floorMaterial);

  floor.rotation.x = -(Math.PI / 2);

  floor.position.x = maxs['ROW'] / 2;
  floor.position.z = maxs['COL'] / 2;

  floor.position.y = y;

  return floor;
}

EDIT:

I'm trying to use an octree, but it says THREE.Octree doesn't exist. I also can't find it in the docs, is it only in a dev release?

Keith M
  • 1,199
  • 2
  • 18
  • 38
  • look at http://threejs.org/examples/webgl_octree_raycasting.html – gaitat Sep 10 '15 at 18:37
  • @Gaitat Would you care to explain what an Octree is? Or at least give me some links to a bit more info on it? :) – Keith M Sep 10 '15 at 18:43
  • https://www.google.com/search?q=octree+raycasting&oq=octree+raycasting&aqs=chrome..69i57j0l5.5111j0j7&sourceid=chrome&es_sm=122&ie=UTF-8 – gaitat Sep 10 '15 at 18:46
  • Why not `PlaneBufferGeometry( 400, 300, 1, 1 )`? – WestLangley Sep 10 '15 at 20:25
  • @WestLangley because later on I'm going to be adding a heightmap to the mesh – Keith M Sep 10 '15 at 20:35
  • @gaitat Please see the edit to my question – Keith M Sep 10 '15 at 20:37
  • Are you displacing the vertices on the CPU or GPU? – WestLangley Sep 10 '15 at 20:47
  • @WestLangley I'm assuming I'm using the CPU, since I didn't know that you could push them to the GPU. – Keith M Sep 10 '15 at 20:49
  • Then what do you mean by "I need to subdivide them to do some vertex shader manipulation"? – WestLangley Sep 10 '15 at 20:50
  • @WestLangley I thought my comment was pretty straightforward? This is more of a follow up to my other question http://stackoverflow.com/questions/32447897/threejs-make-a-displaced-mesh-terrain-model then anything else. I'm trying to optimized my raycast and mesh now so that it will actually run at a smooth frame-rate before I start applying the vertex shader – Keith M Sep 10 '15 at 21:32

0 Answers0