The Wayback Machine - https://web.archive.org/web/20220312103416/https://github.com/mrdoob/three.js/pull/20430
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

Converted TessellateModifier to recursive and made similar to SubdivisionModifier #20430

Merged
merged 4 commits into from Nov 10, 2020

Conversation

arodic
Copy link
Contributor

@arodic arodic commented Sep 28, 2020

Currently TessellateModifier is not recursive and requires manual invocation of the modify( geometry ) multiple times like in the example here.

The problem with this is that you can't know when the maxEdgeLength parameter is satisfied and the tessellation is complete. So you have to guess how many iterations you need. In the example 6 seems to do the job, in some other cases any number of iterations between 0 .. n is needed.

This change contains the following:

  • Adds internal while ( ! finalized ) tessellation loop that runs until no edge with length > maxEdgeLength exists.
  • Instead of mutating geometry from modify( geometry ) argument, it returns new geometry (same as SubdivideModifier).

It also contains a minor change affecting both TessellateModifier and SubdivideModifier:

  • Output geometry is same type as input geometry (Geometry vs BufferGeometry)
  • Geometry.mergeVertices( precisionPoints ) now accepts optional precisionPoints argument.
  • Increased vertex merging precision to geometry.mergeVertices( 6 ); to avoid collapsing small triangles.

Questions:

  • Should precisionPoints for vertex merging also be a property of TessellateModifier and `SubdivideModifier?

@arodic arodic force-pushed the recursive-tesselation branch 2 times, most recently from 7399066 to a24c9f6 Sep 28, 2020
src/core/Geometry.js Outdated Show resolved Hide resolved
@mrdoob mrdoob added this to the r122 milestone Sep 29, 2020
@arodic arodic force-pushed the recursive-tesselation branch 3 times, most recently from 28ba9c5 to bfa8409 Sep 29, 2020
@arodic
Copy link
Contributor Author

@arodic arodic commented Sep 29, 2020

@mrdoob I also added maxFaces parameter as another way to limit number of faces more explicitly.

So constructor look like this now: new TessellateModifier( maxEdgeLength, maxIterations, maxFaces ) with all arguments being optional. It makes me wonder if these should be an object instead or perhaps arguments to modify() function?

Also, linting rules did not allow me to define constructor arguments as optional with default values in d.ts file. I tried this:

constructor( maxEdgeLength?: number = 0.1, maxIterations?: number = 6, maxFaces?: number = 100000 );

And I got error:

Error: src/core/Geometry.d.ts(248,17): error TS1015: Parameter cannot have question mark and initializer.
Error: src/core/Geometry.d.ts(248,17): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.

Is this TS linting rule intended?

@gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Sep 30, 2020

Is this TS linting rule intended?

As far as I know you can't set default function parameters in d.ts files :(

@arodic arodic force-pushed the recursive-tesselation branch from c65c865 to d8324c0 Sep 30, 2020
@arodic
Copy link
Contributor Author

@arodic arodic commented Oct 4, 2020

As far as I know you can't set default function parameters in d.ts files :(

Yeah, I'm still learning about TS. It turns out you can set default values in the constructor but cannot make arguments optional and initialized at the same time. That kinda makes sense since it would be redundant.

Anyway, the lint error is fixed. TessellateModifier is recursive so you dont have to manually repeat the modify() function. And last but not least, you can increase maxIterations and maxFaces if you dont care about computation time.

@arodic arodic force-pushed the recursive-tesselation branch from d8324c0 to b954edd Oct 4, 2020
@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Oct 27, 2020

@arodic any chance you could resolve the conflicts?

@mrdoob mrdoob removed this from the r122 milestone Oct 28, 2020
@mrdoob mrdoob added this to the r123 milestone Oct 28, 2020
@arodic
Copy link
Contributor Author

@arodic arodic commented Nov 9, 2020

I'll update this PR asap.

@arodic arodic force-pushed the recursive-tesselation branch from b954edd to 2af7f46 Nov 10, 2020
@arodic
Copy link
Contributor Author

@arodic arodic commented Nov 10, 2020

Conflicts resolved. Ready to merge.

@arodic arodic force-pushed the recursive-tesselation branch from 2af7f46 to 6381db3 Nov 10, 2020
*/

THREE.TessellateModifier = function ( maxEdgeLength ) {
THREE.TessellateModifier = function ( maxEdgeLength = 0.1, maxIterations = 6, maxFaces = 1000000 ) {
Copy link
Owner

@mrdoob mrdoob Nov 10, 2020

Choose a reason for hiding this comment

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

How about maxFaces = Infinity?

Copy link
Contributor Author

@arodic arodic Nov 10, 2020

Choose a reason for hiding this comment

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

Done.

@mrdoob mrdoob merged commit f4b504f into mrdoob:dev Nov 10, 2020
8 checks passed
@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Nov 10, 2020

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.