Here's a demonstration showcasing how to create an extruded shape, specifically a triangle along a straight line. This process aligns with the primary function of the Shape class. Check it out here
// Defining a 2D triangular shape
// The Shape() class facilitates the drawing of 2D shapes
var triangleShape = new THREE.Shape();
triangleShape.moveTo(-2, -2);
triangleShape.lineTo(0, 2);
triangleShape.lineTo(2, -2);
triangleShape.lineTo(-2, -2);
// Generating a new geometry by extruding the triangleShape
// 'amount' denotes the extrusion distance, 'bevelEnabled: false' disables beveling
var extrudedGeometry = new THREE.ExtrudeGeometry(triangleShape, { amount: 5, bevelEnabled: false });
// Utilizing a Mesh to give context to the geometry
var extrudedMesh = new THREE.Mesh(extrudedGeometry, new THREE.MeshPhongMaterial({ color: 0xff0000 }));
scene.add(extrudedMesh);
The essential points to grasp:
- A 2D shape can encompass any form drawable via the Shape class.
- ExtrudeGeometry() easily projects along a linear path using the amount parameter while deactivating bevelEnabled. For intricate extrusion paths, consider exploring SplineCurve3.
- ExtrudeGeometry() produces raw geometry, constituting an array of Vector3 points. Its potential is realized upon integration with Mesh and Material components.
Dive deeper into THREE.js documentation for further insights:
Learn about Shape on THREE.js documentation
Explore ExtrudeGeometry in THREE.js documentation