Rendering superellipsoids

Hi. I want to render superellipsoids with jme3.

I use the following code for calculating one vertex:

[java]public Vector3f EvalSuperEllipse(float t1,float t2,float p1,float p2)


float tmp;

float ct1,ct2,st1,st2;

ct1 = (float) Math.cos(t1);

ct2 = (float) Math.cos(t2);

st1 = (float) Math.sin(t1);

st2 = (float) Math.sin(t2);

tmp = (float) Math.pow(fabs(ct1),p1)sign(ct1);

Vector3f pp = new Vector3f(sign(ct2)15(float) (tmp

sign(st1)15(float) Math.pow(fabs(st1),p1),

sign(st2)15(float) (tmp * Math.pow(fabs(st2),p2))


return pp;


The following code calculates all the vertices and sets the arrays for them, the indexes array and the textures array:

[java]for (int j=0;j<n/2;j++) {

theta1 = j * TWOPI / n - PID2;

theta2 = (j + 1) * TWOPI / n - PID2;

for (int i=0;i<=n;i++) {

if (i == 0 || i == n)

theta3 = 0;


theta3 = i * TWOPI / n;

p = EvalSuperEllipse(theta2,theta3,e1,e2);

p1 = EvalSuperEllipse(theta1+delta,theta3,e1,e2);

p2 = EvalSuperEllipse(theta1,theta3+delta,e1,e2);

en = calcNormal(p1,p,p2);

tex = new Vector2f(i/(float)n,2j/(float)n);



p = EvalSuperEllipse(theta1,theta3,e1,e2);

p1 = EvalSuperEllipse(theta2+delta,theta3,e1,e2);

p2 = EvalSuperEllipse(theta2,theta3+delta,e1,e2);

en = calcNormal(p1,p,p2);

tex = new Vector2f(i/(float)n,2





vertices = new Vector3f[vertexArray.size()];

vertices = vertexArray.toArray(vertices);

texCoord = new Vector2f[textureArray.size()];

texCoord = textureArray.toArray(texCoord);

int k = 0;

while(k < vertices.length) {

int d = k;

for(int j=d; j < d+3; j++) {

if(j < vertices.length) {







indexes = new int[indexList.size()];

for(int i=0; i<indexes.length; i++) {

indexes = indexList.get(i);


setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));

setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));



I used these codes from the link given above. In the end i render the mesh a standard way:

[java]SuperEllipsoid se = new SuperEllipsoid(1.0f, 1.0f, 100);

Geometry seGeo = new Geometry(“SuperEllipsoid”, se);

Material seMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

seMat.setColor(“Color”, ColorRGBA.Blue);



Somehow i get this:

What is the problem? I’ve read the Custom Mesh tutorial. I think the problem is the indexes, but i dont really know how to solve it…

That should be a sphere, for the parameters 1.0, 1.0

When each triangle is projected onto screenspace, the vertices should be in counterclockwise order (on screen), otherwise they are culled. You may need to orient your indices to generate triangles in that order.

1 Like

The main problem is that these superellipsoids can be very complicated shapes, so its a little hard to imagine an order of the vertices.

Well, you could cheat and turn off back face culling but later when you go to have normals and stuff, you’ll wish you hadn’t.

Edit: you “might” wish you hadn’t. Could be that it works ok for you and your use-case.

1 Like

Without backface culling it looks good, but as you said: when i switch to Lightning.j3m material, its a mess again. I am atill pretty sure, that my indexes are wrong, but I just couldnt find out how to arrange them in the correct order. I am attaching a txt file containing the coordinates of the sphere, if someone could just take a look at it, maybe somebody else can figure it out, i would appriciate that :slight_smile: Currently the indexes look like this: 0,1,2, 1,2,3, 2,3,4, 3,4,5, 4,5,6, etc, you see the logic.

Btw dont open it in notepad, because you wont see sh*t, wordpad works fine.


| |

| |


Assuming you have indexed your angles this way the correct order is:



1 Like

Just to see how does it look like now (with backface culling ON, and the indexes mentioned in my previous post):

Seems he’s making a triangle strip mesh, why not do that as well? Then you dont need to specify the index order. Otherwise why not look at the indexing of the jME sphere? Maybe even start from that class and just change the equations, and maybe do some extra alternatives for degenerate shapes etc.

1 Like

I set it to TriangleStrip, and removed the indexes. Its better now thx for the tip, but still something is wrong. Maybe not the indexes are the problem? The objects are look like this now, all have these stripes:

Just got something in my mind…maybe something wrong about the normals…I’ll check it.

YES! It was the normals. Problem ALMOST solved :slight_smile: Now only one issue left, every object has a “hole” (like a butthole :D) on the top and bottom side, here how it looks like on the sphere:

Thx for the help everyone btw, I try to solve this last little problem (i hope its a little problem), but any ideas are welcomed :slight_smile:

I dunno if anyone reading this or i’m talking with myself, :smiley: but heres a hint, if someone is into solving this last problem: it looks like this isnt a hole (which is btw much bigger at objects like a cylinder for example), but it looks like the top and bottom of the object are mixed up. This black circle u see on the picture above is gray on the bottom. TLDR: the top is on the bottom, and the bottom is on the top.

PROBLEM SOLVED! It was the normals again. I wrote my own method to normalize the vectors and something was wrong in it, so i just picked the built in normalize() method and it works like a charm :slight_smile: Thanks everyone again!