Skip to content
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

Src: add CapsuleGeometry #23586

Merged
merged 14 commits into from
Feb 26, 2022
Merged

Src: add CapsuleGeometry #23586

merged 14 commits into from
Feb 26, 2022

Conversation

gsimone
Copy link
Contributor

@gsimone gsimone commented Feb 24, 2022

Related issue: #23579

Preview

https://rawcdn.githack.com/gsimone/three.js/feature/capsule-geometry/docs/index.html?q=caps#api/en/geometries/CapsuleGeometry
image

Description

Adds a simple CapsuleGeometry class that extends LatheGeometry.

Some Notes

  • the naming for the arguments and the descriptions were inspired by other geometries, suggestions and improvements are welcome.
  • there are combinations of radii/height that don't produce a geometry, should we try to prevent them or leave it to users?

Checklist

  • Export both Geometry and BufferGeometry
  • Export from Geometries.js
  • Add docs navigation
  • Add docs page w/ working example
  • Add unit tests

Comment on lines 18 to 19
// max here prevents failing when height is 0
const a = Math.asin( R1 / Math.max( Number.EPSILON, height ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this check to avoid a void geometry.
Problems still arise when passing certain combinations of radii and height, should we add more checks/failsafes?

@gsimone
Copy link
Contributor Author

gsimone commented Feb 24, 2022

Not sure what's wrong with the unit tests, maybe I missed something but the action message doesn't help

@mrdoob mrdoob added this to the r139 milestone Feb 24, 2022
@mrdoob
Copy link
Owner

mrdoob commented Feb 24, 2022

Could you remove the builds from the PR?

@gsimone
Copy link
Contributor Author

gsimone commented Feb 25, 2022

✅ Removed them

@gsimone
Copy link
Contributor Author

gsimone commented Feb 25, 2022

@mrdoob @WestLangley

2 separate radii or 1? I agree that radius/length is less clumsy to use, and the change is not a big effort 🤷 Let me know which one you prefer

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 25, 2022

I vote for a single radius value.

@mrdoob
Copy link
Owner

mrdoob commented Feb 25, 2022

Yes, radius and length 👍

@gsimone
Copy link
Contributor Author

gsimone commented Feb 25, 2022

Removed the double radius situation, only thing missing is this suggestion #23586 (comment)

@gsimone
Copy link
Contributor Author

gsimone commented Feb 25, 2022

✅ simplified code accounting for single radius

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 25, 2022

You have to add the new unit test file to this section:

import './src/geometries/BoxGeometry.tests.js';
import './src/geometries/CircleGeometry.tests.js';
import './src/geometries/ConeGeometry.tests.js';
import './src/geometries/CylinderGeometry.tests.js';
import './src/geometries/DodecahedronGeometry.tests.js';
import './src/geometries/EdgesGeometry.tests.js';
import './src/geometries/ExtrudeGeometry.tests.js';
import './src/geometries/IcosahedronGeometry.tests.js';
import './src/geometries/LatheGeometry.tests.js';
import './src/geometries/OctahedronGeometry.tests.js';
import './src/geometries/PlaneGeometry.tests.js';
import './src/geometries/PolyhedronGeometry.tests.js';
import './src/geometries/RingGeometry.tests.js';
import './src/geometries/ShapeGeometry.tests.js';
import './src/geometries/SphereGeometry.tests.js';
import './src/geometries/TetrahedronGeometry.tests.js';
import './src/geometries/TorusGeometry.tests.js';
import './src/geometries/TorusKnotGeometry.tests.js';
import './src/geometries/TubeGeometry.tests.js';
import './src/geometries/WireframeGeometry.tests.js';


super( path.getPoints( capSegments ), radialSegments );

this.translate( 0, - length / 2, 0 );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way of doing this offset in the Path instead? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4ed3391 LGTY?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mrdoob mrdoob merged commit 3d24599 into mrdoob:dev Feb 26, 2022
@mrdoob
Copy link
Owner

mrdoob commented Feb 26, 2022

Thanks!

@gsimone gsimone deleted the feature/capsule-geometry branch February 26, 2022 09:05
@WestLangley WestLangley changed the title feat: adds CapsuleGeometry Src: add CapsuleGeometry Feb 26, 2022
@mrdoob
Copy link
Owner

mrdoob commented Feb 28, 2022

@gsimone It seems to me that SphereGeometry could be simplified by adopt the approach used here?

@joshuaellis joshuaellis mentioned this pull request Mar 1, 2022
10 tasks
@gsimone
Copy link
Contributor Author

gsimone commented Mar 1, 2022

@mrdoob This is what it would look like, I didn't check if it generates the same vertices though, is that something we'd care about 🤔

Screen.Recording.2022-03-01.at.09.55.46.mov

Try here 👉 https://codesandbox.io/s/three-js-lathe-spheregeometry-vg4bvz?file=/src/LatheSphereGeometry.js

@mrdoob
Copy link
Owner

mrdoob commented Mar 1, 2022

That's great!

I didn't check if it generates the same vertices though, is that something we'd care about 🤔

Ideally yes. Including the phiStart, phiLength, thetaStart and thetaLength properties 😬

@gsimone
Copy link
Contributor Author

gsimone commented Mar 2, 2022

I think it would be an interesting experiment, but maybe not worth it? I'll play with adding the angles and see how it differs from the sphere we have now.

It could be good as long as it's not a huge breaking change (eg. UV and normals are close enough to not cause differences if people are relying on constructing spheres with the old geo)

donmccurdy pushed a commit to donmccurdy/three.js that referenced this pull request Mar 10, 2022
* feat: adds CapsuleGeometry

* .

* Update src/geometries/CapsuleGeometry.js

* Update docs/api/en/geometries/CapsuleGeometry.html

* removes radiusBottom

* Update src/geometries/CapsuleGeometry.js

* adds test import

* fixes test file name typo

* .

* fixes imports in capsuleGeometry module

* .

* pre-translate path

* lint
abernier pushed a commit to abernier/three.js that referenced this pull request Sep 16, 2022
* feat: adds CapsuleGeometry

* .

* Update src/geometries/CapsuleGeometry.js

* Update docs/api/en/geometries/CapsuleGeometry.html

* removes radiusBottom

* Update src/geometries/CapsuleGeometry.js

* adds test import

* fixes test file name typo

* .

* fixes imports in capsuleGeometry module

* .

* pre-translate path

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants