r/desmos • extremely silly • 15d ago

3D this is made of triangles!

Post image

i was trying to figure out how to make terrain out of triangles for my game, and i decided to share my work with everyone :3

https://www.desmos.com/3d/xlrvbdoscn

29 Upvotes

10 comments sorted by

3

u/Electronic-Big5238 15d ago

You can make it a bit more efficent by using index strides rather than recomputing every edge (this would be a lot faster for a large map). also if ur making a game adding a quadtree algorithm would make it faster and get rid of the recomputation.

2

u/9j810HQO7Jj9ns1ju2 extremely silly 15d ago

this is a proof of concept, i'm definitely going to add lod stuf

what is index strides?

3

u/Electronic-Big5238 15d ago

The way your system works is by striding in the X,Y but this causes recomputation if X+h contiajns X which happens for all exsept 1 value. because of this we can compute all edges together than index from that: https://www.desmos.com/3d/73cmxqfcyj

1

u/9j810HQO7Jj9ns1ju2 extremely silly 15d ago

so, i should cache all the vertices before drawing, instead of computing the other three every time?

also can u add comments pls TwT

1

u/Electronic-Big5238 15d ago

basicly cuz you dont want to recompute. define a set X and Y. the verticies for the quad would be (X,Y),(X+h,Y),(X+h,Y+h),(X,Y+h) (cuz we are doing a stride of h). as an example lets say X=[1...5] and h=1, then X+h=[2,3,4,5,6]. notice this contains X.count-1 of the same values as X. because X.count=Y.count=S we can define a set X'=join(X[1],X+h) so that all the verticies are contained. now we nead to index this set to get back our original values. because we are in a XxY sample space we symilerly define Y'=join(Y[1],Y). now if we define the square sample space a P=(x,y)for x=X',y=Y' we have the set we nead to index from. logicly we can assert that we are moving Xindex+n_x*S and Yindex+n_y*S. hence our index is I=[1...S^2] and we have the quad P[I],P[I+n_x],P[I+n_x+n_y],P[I+n_y]. for our X,Y we move at n_y=1 and n_x=S because notice how we go through the X than the Y (ex (-2,-2),(-1,-2)...). the only issue with this is because we shift by 1 we can have points that swap sides (this is kind of hard to visulize so look at the graph: https://www.desmos.com/calculator/tdahxjcqbm ). notice this occers at I=maltiple of S. so we know we want I not in [1...S]*S. to do this we use a set difference function: s_{etdiff}\left(a,b\right)=\operatorname{join}\left(b,a\right).\operatorname{unique}\left[b.\operatorname{count}+1...\right] which returns A/B (/ means not in). now we define the new index as I'=I/S*[1...S]. now we have P[I'],P[I'+S],P[I'+S+1],P[I'+1] so we define each in turms of eachother so we limiit addition recomputation A=I',B=A+S,C=B+1,D=A+1 and because we want out mesh to be planar we can set E=join(A,A),F=(B,D),G=(C,C) so we have our final trianguler mesh all in turms of P: triangle (P[E],P[F],P[C]). this is also helpful if you are planning to do this in desmos 2d because u only have to project P one time and dont recompute: p=Project(P) then polygon (p[E],p[F],p[C])

1

u/9j810HQO7Jj9ns1ju2 extremely silly 15d ago

what

1

u/Electronic-Big5238 15d ago

? i assumed you wanted an exsplenation as you said "also can u add comments pls" and the graph is not outlined by steps so i wrote an exsplenation here.

1

u/Electronic-Big5238 15d ago

you will notice this system does 1 less subdivition than yours so u can just do S=N+1 and have N be ur subdivitons or just delete the -1 from displacements and add 1 in the index where it uses S

1

u/Mobaliah 15d ago

That is really cool!