Page 1 of 1
Geometry
Posted: Tue Sep 30, 2008 2:47 pm
by Kjell
A collection of useful ( and not so useful ) procedurally generated meshes. All generated with a Grid2DOnly MeshBox using U and V coordinates ranging from -Pi to Pi ( unless notified ).
First up, a diamond cluster.
Code: Select all
this.V.X = (2+sin(U)*sin(V*4))*sin(V)*-1;
this.V.Y = (2+sin(U)*sin(V*4))*cos(V);
this.V.Z = cos(U)*sin(V*4);
Posted: Tue Sep 30, 2008 2:56 pm
by Kjell
Next, a teardrop.
Code: Select all
this.V.X = 0.5*(1-cos(U))*sin(U)*cos(V);
this.V.Y = 0.5*(1-cos(U))*sin(U)*sin(V);
this.V.Z = cos(U);
Posted: Tue Sep 30, 2008 2:56 pm
by Kjell
Followed by, a pillow.
Code: Select all
this.V.X = cos(U);
this.V.Y = cos(V);
this.V.Z = (sin(U)*sin(V))/Pi*2;
Posted: Tue Sep 30, 2008 2:57 pm
by Kjell
Let's try a spring.
Code: Select all
this.V.X = (Pi+Radius*cos(V))*cos(U*Length);
this.V.Y = (Pi+Radius*cos(V))*sin(U*Length);
this.V.Z = Radius*(sin(V)+Period*U*Length/Pi);
Posted: Thu Oct 02, 2008 3:38 pm
by jph_wacheski
Cool! thanks for posting these,. more fun stuff to play around with!
The more I work with these generative type geometries the better understanding I am developing of the math that defines them,. it is just great to have some starting places for gaining that.
I am wondering if we had a torus prim. if we could get rid of that seam on that very usefull torus bit you post elsewere? You know so the primitve, to begin with, was a solid torus geometry,. and we could use the equations to warp it from there? peace.
Posted: Thu Oct 02, 2008 4:56 pm
by Kjell
By request, a torus with calculated normals ( unusual subdivisions to illustrate normals ).
Code: Select all
this.V.X = cos(U)*cos(V)*Size+cos(U)*Radius;
this.V.Y = sin(U)*cos(V)*Size+sin(U)*Radius;
this.V.Z = sin(V)*Size;
this.N.X = cos(U)*cos(V)*Size;
this.N.Y = sin(U)*cos(V)*Size;
this.N.Z = this.V.Z;
Posted: Sat Jan 10, 2009 12:01 pm
by kattle87
I'm posting here also the Sphere and the cylinder with subdivided upper and lower faces. A cylinder is to come if someone ask for it
Note: for the cylinder, you can change the variable "VarQ" that indicates how many "circles" you are going to have on upper and lower surface.
For Ville: try using "int" instead of "float" for VarP and tell me if it's working for you. I get different results. Is this because of truncate on integer divisions? If yes, it's fine
Posted: Sat Jan 10, 2009 3:17 pm
by jph_wacheski
Excellent! These are both great and usefull!! I apretiate the normal correctness, for perfect smoothing.
Keep 'em coming,. can you design a routine for a Icosphere?!?!
Hay,. I was just wundering about using renderMesh components to buils animated object,. would they be faster to animate? can closed shapes be made using these techneques??
I'm still looking for a way to do nice poly-trails,. you know 3d ribbons,. that fade in width,. and alpha preferably,. . I can get the points and build a list in arrays but havent figured how to draw them,.
Posted: Wed Nov 11, 2009 1:23 pm
by Kjell
Using this one myself all the time ( for collision representation ).
Code: Select all
ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="CapsuleMesh">
<Producers>
<MeshBox Scale="0.5 0.5 1" XCount="15" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX;
RX = this.V.X*PI*2;
SX = sin(RX); CX = cos(RX);
this.V.X = SX/2;
this.V.Z = CX/2;
this.N.X = this.V.X;
this.N.Y = 0;
this.N.Z = this.V.Z;]]>
</Expression>
</MeshExpression>
<MeshBox Scale="0.5 0.5 1" XCount="15" YCount="3" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX,
RY, SY, CY;
RX = this.V.X*PI*2;
RY = this.V.Y*PI/2-PI/4;
SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);
this.V.X = SX*CY/2;
this.V.Y = SY/2;
this.V.Z = CX*CY/2;
this.N.X = this.V.X;
this.N.Y = this.V.Y;
this.N.Z = this.V.Z;
this.V.Y -= 0.5;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
<MeshBox Scale="0.5 0.5 1" XCount="15" YCount="3" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX,
RY, SY, CY;
RX = this.V.X*PI*2;
RY = this.V.Y*PI/2+PI/4;
SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);
this.V.X = SX*CY/2;
this.V.Y = SY/2;
this.V.Z = CX*CY/2;
this.N.X = this.V.X;
this.N.Y = this.V.Y;
this.N.Z = this.V.Z;
this.V.Y += 0.5;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
</Producers>
</Mesh>
I'm aware you can generate a capsule out of a single plane as well, but this mesh is easier to modify
Posted: Wed Nov 11, 2009 1:39 pm
by jph_wacheski
Very cool,. this reminded me that the mesh component now has the nifty Graph feature! Curious, how have you have implemented Capsule Collision? Can it be added to the standard ZGE collision tests or is it dependent on a bunch of your own code?
Posted: Wed Nov 11, 2009 1:48 pm
by Kjell
Using my own collision libraries .. couldn't wait for that
Raycast ( and the rest ) forever
K
Posted: Tue Dec 15, 2009 12:23 am
by diki
Kjell wrote:my own collision libraries
ach, the envy!
Posted: Thu May 24, 2012 5:04 pm
by jph_wacheski
I still suck with mesh math,. anyone able to generate this more correctly??
Code: Select all
ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="g_Z">
<Producers>
<MeshBox Grid2DOnly="255"/>
<MeshExpression>
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
v.y*=0.035;
v.x*=0.5;
v.x+=0.019;
v.y+=.385;]]>
</Expression>
</MeshExpression>
<MeshBox Grid2DOnly="255"/>
<MeshExpression>
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
v.x*=0.07;
if (v.y<-.5) v.y+=.65;
if (v.y<-.25) v.x-=.45;
if (v.y>.5) v.y-=.65;
if (v.y>.25) v.x+=.45;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
<MeshBox Grid2DOnly="255"/>
<MeshExpression>
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
v.y*=0.035;
v.x*=0.5;
v.x-=0.019;
v.y-=.385;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
<MeshTransform Scale="1 1.3 1"/>
</Producers>
</Mesh>
Posted: Thu May 24, 2012 6:16 pm
by Kjell
Hi jph,
jph_wacheski wrote:I still suck with mesh math, anyone able to generate this more correctly??
The letter "Z" isn't really a geometric primitive .. however, you could do something like this.
Code: Select all
ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="Mesh">
<Producers>
<MeshBox Scale="2 0.5 1" XCount="3" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[//
float Y = this.V.Y;
switch(this.V.X+2+(0.5-Y)*5)
{
case 0:
case 9:
this.V.Y *= 4;
break;
case 1:
case 8:
this.V.X *= -2;
this.V.Y *= 4;
break;
case 2:
case 7:
this.V.X = Y*4;
this.V.Y *= 3;
break;
case 3:
case 6:
this.V.X *= -1.2;
this.V.Y *= -3;
break;
case 4:
case 5:
this.V.Y *= -3;
break;
}]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
K
Posted: Thu May 24, 2012 10:31 pm
by jph_wacheski
it is a primitive 'Z' I guess, as opposed to a modern one, lol.
anyway, thanks,. that is much better than my lame hack. I always learn stuff from your examples, this one is no different in that. cheers.