I should start off by saying I'm new to WebGL and the THREE library. I'm trying to achieve:
- Add 2D shapes to a scene (squares, triangles, circles etc)
- Shapes can have any size and position
- Shapes should have no fill and an outline that scales depending on the shape size
I tried using wireframe:
const geometry = new THREE.BoxGeometry(40, 40, 0);
const material = new THREE.MeshBasicMaterial({
color: 0xff0000,
wireframe: true,
});
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
The above renders the following:
- A 3D box with no depth
- A non-scalable outline with a set width of 1
- A cross through the box
I also tried the same but plotting the points for a 2D shape:
const shapeSize = 100;
const x = -shapeSize / 2;
const y = -shapeSize / 2;
const square = new THREE.Shape();
square.moveTo(x, y);
square.lineTo(x + shapeSize, y);
square.lineTo(x + shapeSize, y + shapeSize);
square.lineTo(x, y + shapeSize);
square.lineTo(x, y);
const geometry = new THREE.ShapeGeometry(square);
const material = new THREE.MeshBasicMaterial({
color: 0xff0000,
wireframe: true,
});
const mesh = new THREE.Mesh(geometry, material);
this.scene.add(mesh);
The above renders:
- A 2D box
- A non-scalable outline with a set width of 1
- A single diagonal line through the box
Can anyone demonstrate how to achieve the scalable outline of just the 2D shape? Do I need to use a shader?