# Generating normals

Does jme3 have normal generator for meshes?

No. There is no generally accurate way to generate the normals for a mesh… though it can be approximated in a few different ways as a wild guess. It’s better to do this in a 3D editor where you have control over the outcome when it doesn’t do the right thing.

Or it’s better to generate them as part of the source data.

Where does your mesh come from where it doesn’t already have normals?

It’s generated procedurally, marching tetrahedrons.

Is it possibile to generate it having only density value? Couldn’t find any articles about it.

@Neomex said: It's generated procedurally, marching tetrahedrons.

Is it possibile to generate it having only density value? Couldn’t find any articles about it.

Hmm… that’s interesting because nearly every marching “anything” article I’ve read covers normals.

Yes, you will definitely want to generate them from the density field. Otherwise they will be incorrect using just about any ‘automatic’ solution.

Essentially you need to find the direction of the density field at the point. There are several ways to do this depending on how the density field was generated. Sampling is the easiest. This was covered in the GPU Gems article, actually… and I implemented it in my marching cubes library (IsoSurface).

I was rewriting someones code to fit my needs and implement multimaterial support and he was aswell generating density through noise functions.
In my case I set density values by hand or write functions to calculate them.

I have tried doing this:

[java]double nx = getDensity(x + d, y, z)
- getDensity(x - d, y, z);
double ny = getDensity(x, y + d, z)
- getDensity(x, y - d, z);
double nz = getDensity(x, y, z + d)
- getDensity(x, y, z - d);
[/java]

but either I have messed something up, or it doesn’t work when you directly get density value from an array

[java]getDensity(vec at) { return data[at.x][at.y][at.z]; }[/java]

You would have to interpolate them or you will have really strange results. You can’t just grab grid values.

If you are generating density by hand then you may also have the information to store field direction. Hard to say.

Other code in my library can interpolate array density fields.