Blurred LatheGeometry output

geometry

#1

I’ve adapted a LatheGeometry pen (Pot Maker, by Don Pinkus, which fills the frame) to load in a div, here: https://www.intmath.com/math-art-code/solid-revolution-maker.php

The result is blurry, as follows:

image

The relevant function is as follows:

function addLathe(points = []) {
  let normalizedPoints = [];
  for (let i = 0; i < points.length; i++) {
	let scale = globals.cameraDimensions.frustrumSize;
	let absDistanceFromCenter =  Math.abs(-canvasFromLeft + points[i].x - canvasWidth / 2);
	let nWidth = absDistanceFromCenter / (canvasWidth / 2);
	let nHeight =  (-canvasFromTop + points[i].y) * -1 / canvasHeight;
	normalizedPoints.push(
	  new THREE.Vector2(
		nWidth * globals.cameraDimensions.right,
		nHeight * scale + globals.cameraDimensions.top
	  )
	);
  }
  var geometry = new THREE.LatheGeometry(normalizedPoints, 60 );
  geometry.mergeVertices();
  var material = new THREE.MeshNormalMaterial({
	side: THREE.DoubleSide
  });
  //material.magFilter = THREE.NearestFilter;
  //material.minFilter = THREE.LinearMipMapLinearFilter;
  
  var lathe = new THREE.Mesh(geometry, material);
  if (globals.objects.lathe) {
	scene.remove(globals.objects.lathe);
  }
  globals.objects.lathe = lathe;
  scene.add(globals.objects.lathe);
}

I experimented with magFilter and minFilter on the material, but it didn’t make a difference.

I suspect it’s a problem with the normalizing and/or scaling, but couldn’t fix it.

Also, on updating to r97, I"m now seeing “Faceless geometries are not supported.” I couldn’t figure out how to fix that.


#2

The renderer’s size (300x150 pixels) isn’t set to the correct size for your canvas (450x450 pixels) as shown by the attached image. (red box in image)
You can fix this by setting the renderer’s size to match the canvas renderer.setSize(450,450); (blue box in image)


#3

Perfect - thank you. It’s fixed now.

Any ideas on how to fix “Faceless geometries are not supported”?


#4

I think this happens since you call LatheGeometry() with just a single point. I suggest you use LatheBufferGeometry and remove the call of mergeVertices(). Alternatively, you only create an instance of LatheGeometry if normalizedPoints has at least two points.

BTW: minFilter and magFilter are properties of Texture and not of Material. So setting them on a material has no effect.


#5

Creating LatheGeometry only when there are 2 or more points fixed it. Thanks a lot!