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

threejs 3D Rendering of (planar) Polygons #70

Open
rocky opened this issue Jun 10, 2021 · 5 comments
Open

threejs 3D Rendering of (planar) Polygons #70

rocky opened this issue Jun 10, 2021 · 5 comments

Comments

@rocky
Copy link
Member

rocky commented Jun 10, 2021

Graphics3D[
  Polygon[{
	{0, 0, Sqrt[3]},
	{0, 2 Sqrt[2/3], 1 / Sqrt[3]},
	{Sqrt[2], Sqrt[2/3], -1 / Sqrt[3]},
	{Sqrt[2], -Sqrt[2/3], 1 /  Sqrt[3]},
	{0, -2 Sqrt[2/3], -1 / Sqrt[3]},
	{-Sqrt[2], -Sqrt[2/3], 1/Sqrt[3]},
	{-Sqrt[2], Sqrt[2/3], -1/Sqrt[3]}
    }]]

should be a hexagon and slanted.

Graphics3D[Polygon[{{150,0, 0},{121,90, 0},{198,35, 0},{102,35, 0},{179,90, 0}}]]

should be a 5-pointed start with a hole for interior pentagon.

@TiagoCavalcante
Copy link
Collaborator

TiagoCavalcante commented Jun 10, 2021

Graphics3D[
  Polygon[{
	{0, 0, Sqrt[3]},
	{0, 2 Sqrt[2/3], 1 / Sqrt[3]},
	{Sqrt[2], Sqrt[2/3], -1 / Sqrt[3]},
	{Sqrt[2], -Sqrt[2/3], 1 /  Sqrt[3]},
	{0, -2 Sqrt[2/3], -1 / Sqrt[3]},
	{-Sqrt[2], -Sqrt[2/3], 1/Sqrt[3]},
	{-Sqrt[2], Sqrt[2/3], -1/Sqrt[3]}
    }]]

should be a hexagon and slanted.

@rocky I already tried to draw non coplanar polygons and I could only do it with 500 lines of code, I guess that maybe we should keep the behavior of WL.

Graphics3D[Polygon[{{150,0, 0},{121,90, 0},{198,35, 0},{102,35, 0},{179,90, 0}}]]

should be a 5-pointed start with a hole for interior pentagon.

This [I guess] is possible to be done in WL, but also polygons with holes is very hard in three.js.

@rocky maybe we should focus in draw coplanar polygons first?

@rocky
Copy link
Member Author

rocky commented Jun 10, 2021

Would using the js earcut library help?

@TiagoCavalcante
Copy link
Collaborator

TiagoCavalcante commented Jun 10, 2021

@rocky I used this library, for this works completely for non triangular polygons it's just necessary to convert Cuboid to draw cubes (this library doesn't draw triangular polygons correctly).

But for polygons with holes not specied it doesn't works.

But this fix the coplanar polygons problem.

Also, as we could add an if to toggle the library use, performance bottleneck won't be a problem.

I just said what I did because of I was wondering if we should add more one dependency. But after the Cuboid be converted to draw cube I can do it.

@rocky
Copy link
Member Author

rocky commented Jun 10, 2021

@TiagoCavalcanteTrindade Ok - thanks for the information.

I am for adding the dependency, especially since it seems to be pure JavaScript. And we just removed the dependency on scriptaculous.

We can wait for coplanar to work and get help on the Mathics-core side of things for holes.

If you think it helps for performance or want to try it, my opinion is go ahead. If on the other hand you don't want to go this route, that's fine too. You are probably in the best position to decide this.

@TiagoCavalcante
Copy link
Collaborator

TiagoCavalcante commented Jun 10, 2021

I am for adding the dependency, especially since it seems to be pure JavaScript. And we just removed the dependency on scriptaculous.

@rocky it's still there, I just deleted some files, the main file was split into multiple ones because of a bug in Opera.

Also @rocky I'll go ahead, I just want to reformat the code and remove the dependency on prototype before.

But the performance will fall for the coplanar polygons (at least for the ones with the z axis always 0).

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

2 participants