Create a Sphere Geometry in VEX

   4758   3   1
User Avatar
Member
2 posts
Joined: July 2016
Offline
hello, I'm trying create geometry from a group of point,polar coordinates, from an array.

It gives a meshed sphere but with hole, and overlapping points.

I guess I shd use some condition but I'm not really sure how..

int total =40;
int prim;
float r = 200.0;

float lon = 2*($PI); //-pi,pi
float lat = 2*($PI);//-pi/2, pi/2

float step_lon = lon/total; //angle sur la longitude
float step_lat = lat/total;//angle sur la latitude

int globe = {0,0,0};
vector pos ={0,0,0};

for (int i=0 ; i<total+1; i++){
for (int j=0; j< total+2; j++){

//polar to cartesian
float x = r * sin(lon) * cos(lat);
float y = r * sin(lon) * sin(lat);
float z = r * cos(lon);

//vector pos
pos = set(x,y,z);

//feed array, create points sphere
globe=addpoint(geoself(), pos);

int v1 = globe;
int v2 = globe;
int v3 = globe;

prim = addprim(geoself(), “poly”);

addvertex(geoself(), prim, v1);
addvertex(geoself(), prim, v2);
addvertex(geoself(), prim, v3);

//setpointattrib(geoself(), “lat”, v1, j, “set”);
// setpointattrib(geoself(), “lat”, v2, j+1, “set”);
//setpointattrib(geoself(), “lat”, v3, j+2, “set”);

lat += step_lat;
}

lon +=step_lon;
}



u will find in my hip file, vex code for creating a sphere, then a mesh.

thks

Attachments:
sphere_od.hipnc (166.1 KB)

User Avatar
Member
2528 posts
Joined: June 2008
Offline
I think you need to calculate one more point. You see holes because you have 3 points forming a triangle inside of a quad area.
Here is a link [gamedev.stackexchange.com] to a possible solution for calculating the fourth point but you may want to search a bit on your own.
Using Houdini Indie 20.0
Ubuntu 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2 posts
Joined: July 2016
Offline
Im gonna look for it!!
due to my lack of english, I think I couldnt proper look on google,
thks so much for the answer,

awesome community!
Edited by ezza - July 29, 2016 17:23:50
User Avatar
Member
1736 posts
Joined: May 2006
Online
Sorry for the late reply, but I was wondering a similar thing, found your wrangle, tidied it a little to make it properly mesh. You might find it useful…

(double edit)

Heh, as soon as I posted it I can see it can create some bad geo if you set the sliders incorrectly. ‘Lon Mult’ should be 2, ‘Lat Mult’ should be 4.

-matt
Edited by mestela - Feb. 1, 2017 05:26:06

Attachments:
vex_sphere.hipnc (59.3 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links