Help with globe extrusion

Hopefully the last PG I posted is working for you. However I am not completely happy with it, for one thing it produces many long very thin triangles and secondly I am pretty sure that mathematically line 32 should be

let d = p0.add(p.scale(i * lambda).add(q.scale(i * lambda * j * mu)));

however correcting it produces holes. ???

Anyway if you are happy with things how they are then you need not use this alternative (whose coding is simpler) - Whenever there are holes use the increaseVertices property on the polygon until the holes disappear. An extra parameter on drawCountry function is the number of extra points per triangle side, just work out the smallest number that gives no holes.

https://www.babylonjs-playground.com/#5I9JSA#18

The drawback ( and why I didn’t do it in the first place) is that all triangles no matter how small are split into smaller triangles and for n points per side the increase in triangles is of the order (n + 1 ) * (n + 1). Russia goes from 455 vertices to 2722 vertices

I did try to split just the larger triangles but then you have to split adjacent triangles and those adjacent to them and so on and it got too complicated.

So at the end we shall get something like that?

image

It’s funny. The last update you posted before this only really works well because you bumped the radius by 0.1. however, despite that being such a small distance, it’s visually noticeable! boo. (country doesn’t rest on surface of sphere). I raised depth by 0.1 instead and that returned to a better result. although Argentina still has a tiny slit. I am not a fan of ā€œjust make it taller and its fixed.ā€

the issue with a pure increaseVertices solution, is we are extruding to a spherical look, and that will end up with some countries taller than others, which wont be sexy.

Feature Request! One major issue really, is I have no concept right now if a hole exists or not programmatically. I’ve tried to use Mesh IntersectMeshes to help determine that, and unfortunately there’s no way to make it work with the bounding box / bounding sphere. It would be cool if Babylon created a bounding arc, so intersections could be analyzed more accurately than a bounding box on an item. I feel the logic would mimic the sphere, but I could be wrong haha.

Yesterday i ventured into the world of PDFs of algorithms, looking at CSG subtract type stuff. I was thinking I could draw a sphere at the depth height (radius+depth), with 128 segments (produces good sized triangles), and then subtract the border ribbon out of the sphere. this would return me the vertices from the sphere inside the borders, and then I’d just render those.This would solve holes and give me sweet curvature.

that … did not work in Babylon haha (cpu whimpered and died). (course, the outer shell sphere is like, 32k vertices or 64k, something crazy big). I am thinking of trying this with a csg.js library i found, but I feel it might die too. I tried to use the CreateSphere routine with an arc, to reduce vertices, but I couldn’t find a way to box in the border.

Found a paper on doing it for meshes, but sadly could not find any code, and the paper was juust vague enough i couldn’t pull it out.

As it stands right now, I have 3 functional approaches that I’ve used with varying success.

  1. Return Center and Incenter of triangle. just add those 2 as holes. works great for Canada and Brazil.
  2. Return midpoints of triangle legs, basically I’m attempting to create 4 triangles. got the idea from a Delauney triangulation article, section 1 Although on re-reading it, apparently I read it wrong. so may have to revisit (I was trying to do 4T-LE). My current code works great when i have a narrow triangle such as Argentina. in fact, i think this is the only one that solves it well and simply.
  3. JohnK’s addedPoint logic based on area. this works really well for super large triangles like Russia. but less well for Canada and Australia, and that’s not a tiny triangle! kinda interesting.

Interesting notes: i tried to make (1) and (2) subdivide, thinking if the area is big enough, multiples will be needed. did not work! although that may be programmer error. especially (2)

so I am considering looking at the area of a triangle (i have a function that gets me the true triangle area, using the vertices not a bounding box), and some logic to figure out if the triangle approaches equilateral (canada), narrow (argentina), or superlarge (Russia), and uses one of the above algorithms for it.

I am considering also looking at the longest leg length of the triangle in relation to the sphere. the issue is the curve of the sphere surface. so if my leg is 0.5 length on a radius 2 sphere, that needs to be reduced. I feel like I should be able to mathematically calculate the distance at which the curve intersects a fixed line, and use that as a guide.

This is fairly interesting project haha.

similar. no grid system for me on my render.

If you look at some of the earlier Playground examples, you can set the material to wireframe and see the mesh triangles.

example: mat1.wireframe = true;

Ok, so I cannot find any sort of mathematical formula to help me. I was trying to do some horizon calculation to see if one end of a line can see the opposite end, and I was unable to find one that worked right for me.

in the end, i simply created an array of objects for the hole countries. these are just Canada, Russia, Brazil, Argentina, and Australia.

i think the line length is the key, but given the location of the country on the globe, different values apply. so I just use my mid points for most of them, argentina is only solvable with the 4T LE approach.

a PG with the code:

https://www.babylonjs-playground.com/#5I9JSA#19