-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added TriangleGeometry Class #29882
base: dev
Are you sure you want to change the base?
Added TriangleGeometry Class #29882
Conversation
New class to create triangular planes.
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
The height is now a literal value.
After giving it some thought, I can see how normalizing the height could be confusing. Height is now a literal unit and the UV maps to the base and apex of the geometry. |
Do you mind moving This kind of geometry generator has not been requested so far so I do not see it as a core module. |
Moved, as requested. For what it's worth, because a triangle is the most fundamental geometry, I (personally) would expect a triangle to be a primitive. Coupled with it being the only geometry that easily creates the Three JS logo, it seems like src/geometry/ is a better fit, but not a big deal either way. |
related: #29690 (comment) |
How about do this.
--- a/examples/jsm/geometries/TriangleGeometry.js
+++ b/examples/jsm/geometries/TriangleGeometry.js
@@ -3,17 +3,19 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
class TriangleGeometry extends BufferGeometry {
- constructor( width = 1, height = Math.sqrt( 3 ) / 2, skew = 0, detail = 0 ) {
+ constructor( width = 1, height = Math.sqrt( 3 ) / 2, skew = 0, segments = 1 ) {
super();
this.type = 'TriangleGeometry';
+ segments = Math.max( Math.floor( segments ), 1 );
+
this.parameters = {
width: width,
height: height,
skew: skew,
- detail: detail
+ segments: segments
};
// buffers
@@ -25,7 +27,6 @@ class TriangleGeometry extends BufferGeometry {
// vertex helper variables
- const segments = Math.max( Math.floor( detail + 1 ), 1 );
const offsetX = width / 2;
const offsetY = height / 3; |
|
Description
I noticed Three JS primitives do not include a triangular plane. This PR adds that primitive with the following parameters: width, height, skew, and detail.
While the default parameters create an equilateral triangle, adjusting the width / height / skew will produce any type (isosceles, scalene, right, obtuse). Increasing the detail uniformly subdivides the plane, where "detail" is the number of edge divisions, and the number of facets per division is ( detail + 1 ) ^ 2.
Example of uniform subdivision (aka. what to expect):