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

Extrusion not working #26

Closed
sirtobi79 opened this issue Mar 31, 2020 · 3 comments
Closed

Extrusion not working #26

sirtobi79 opened this issue Mar 31, 2020 · 3 comments

Comments

@sirtobi79
Copy link

Hi everyone,

I'm doing a comparision between different X3D players for my master thesis with Dr. Brutzman at the Naval Postgraduate School. I created a scene showing the Olympic Rings using extrusions. Your player gave me the hint, that something with my extrusion was wrong. I fixed the model and there are no more errors in the console. Octaga and Instant Reality are displaying it perfectly.
Could you help me to find out, whether it is an issue with my model or with the player?

You can find the model on gitlab.nps.edu:

https://gitlab.nps.edu/Savage/mv3204x3dforwebauthors/-/blob/master/assignments/DirectedStudy/Tobias/Scenes/OlympicRings.x3d

Thank you very much for your help.

@michaliskambi
Copy link
Member

Analysis:

Testing your model with latest view3dscene reports errors that you have a self-intersecting polygon:

Triangulator: Triangulation of concave polygon failed. Polygon is probably self-intersecting (not allowed by VRML / X3D). You can use Castle Game Engine tool in castle_game_engine/examples/visualize_triangulation/ to easily observe the polygon vertexes and triangulation process.

Since in the test file, you only have one geometry node (Extrusion called RingExtrusion), and it has a simple spine (0 0 0 0 1 0), I knew the problem is most likely the extrusion crossSection shape. Looks like Castle Game Engine (engine under view3dscene) has a problem triangulating it.

I created a series of images that visualize how the triangulation process "sees" your polygon and how it fails to triangulate it: download the files from https://drive.google.com/open?id=1U-hztHZg12eEOnxfs4nK4lPC-A1DA96F (in triangulation/ subdirectory).

Here's an older video showing how the algorithm works correctly on other polygons: https://www.youtube.com/watch?v=XMh608TZRXA .

What happened:

X3D doesn't allow polygons to be self-intersecting (even when convex=false).

View3dscene uses an "ear clipping" triangulation that indeed relies on this fact. IOW, "self-intersecting" polygon may fail the triangulation. "Self-intersecting" means that an edge of the polygon crosses another edge. This happens in your polygon when you try to make a hole:

  • Vertexes 0...36 go in a clockwise direction along the outer circle.
  • Vertexes 36,37,38 (these have positions 5 -0 4.8 0 4.5 0 in crossSection) go from the outer circle into the inner circle.
  • Vertexes 38..74 go in a clockwise direction along the inner circle.
  • Finally, implicitly, first and last vertex (74 and 0) are connected.

This makes edges intersect when the polygon closes. It's unavoidable, even if there would be no precision errors. If you draw it using a pencil on a paper, you will have to cross your own line at some point too :), to close the shape.

In a summary, I'm afraid this is a problem of your model. It has "self-intersecting" polygon, which is not allowed by X3D. Some X3D browsers may work anyway, but our triangulation will not.

Solutions:

  1. One solution is to fix crossSection shape:

    • Make vertexes 38..74 go in a counter-clockwise direction along the inner circle.

    • And move the vertexes 36,37,38 an "epsilon" higher, such that user doesn't see anything bad, but internally the edges 36-37-38 and 74-0 are not "touching" each other.

    This should make our ear-clipping algorithm work.

  2. The other solution, which I would advise (unless you have some specific reason to use X3D Extrusion node) is to instead create a geometry using a 3D modeling application like Blender. And then export it to X3D.

    It will not use X3D Extrusion node and it automatically generates a convex geometry as a simple X3D IndexedFaceSet. It's a matter of a few clicks to create a "ring with hole" in Blender and you can export it to X3D :) See also information about exporting to Blender on https://castle-engine.io/creating_data_blender.php .

    For fun, I quickly created it in Blender, it's so easy :) The blend file and corresponding exported X3D file are inside the https://drive.google.com/open?id=1U-hztHZg12eEOnxfs4nK4lPC-A1DA96F in blender/ subdirectory . The X3D file works in view3dscene immediately.

@brutzman
Copy link

brutzman commented Apr 1, 2020

Great technique to visualize triangulation. I tried to use VLC to create movie, could render but had trouble saving. Switched to Camtasia 9, visualization movie available in SavageTheses archive.

Am interested in following up to add a limited form of this kind of functionality to X3DJSAIL and X3D-Edit at some point to diagnose self-intersecting polygons as part of X3D Quality Assurance (QA).

@michaliskambi
Copy link
Member

@brutzman I used ffmpeg on the command-line in the past to combine a series of images into a movie. It should look like this::

ffmpeg -f image2 -i image_%d.png -y -qscale 1 output.avi

The %d inside will be automatically substituted by consecutive numbers.

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

No branches or pull requests

3 participants