Is there a "scale along normals" method?

Hi,

I need to scale a model accoring to it’s normals instead of normal scale.
In blender you go in editmode, select all and click alt+s. This works, but that would meen that I have to have duplicated models of everything in my game. So instead I need to scale it in jme.
Is there a method?
If not then how do I find the normals from a mesh?

2 Likes

What is the overall effect you are trying to achieve? It sounds like this would make the model look puffy. Concave sections might even close up and/or flip inside out.

Or do you mean a regular scale? (I’m not familiar with blender enough to know what alt+s means)

1 Like
@pspeed said: Or do you mean a regular scale? (I'm not familiar with blender enough to know what alt+s means)
Actually doing this in blender indeed does the "puffy" effect :p

@Addez, nothing built in to do this.
check this https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes
I guess you have to get the normals for each vertex and move the vertex along this normal axis.

@nehon said:
@pspeed said: Or do you mean a regular scale? (I'm not familiar with blender enough to know what alt+s means)
Actually doing this in blender indeed does the "puffy" effect :p

@Addez, nothing built in to do this.
check this https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes
I guess you have to get the normals for each vertex and move the vertex along this normal axis.

Note: this would be trivial with Lemur’s DMesh class but you will potentially run into problems with concave sections that invert. If all you want is a vertex+normal solution then using DMesh would only be a few lines of code to do this.

For fun since I’m about to go to bed…

[java]
Mesh m = someMesh
Deformation normalScale = new Deformation() {
public void deform( Vector3f vert, Vector3f normal ) {
float scale = 1.2f; // or whatever
vert.addLocal( normal.mult(scale) );
}
}
DMesh newMesh = new DMesh(m, normalScale);
[/java]

Tadah. Off the top of my head right before bed… so forgive any typos.

3 Likes

Definitely that’s a better solution
@addez lemur deformation and DMesh code’s is here http://code.google.com/p/jmonkeyplatform-contributions/source/browse/#svn%2Ftrunk%2FLemur%2Fsrc%2Fcom%2Fsimsilica%2Flemur%2Fgeom

Thanks everyone :smiley:
DMesh seems to be the way to go :slight_smile:

Only problem is that I need the mesh from a spatial, so I do like this:
Geometry model = (Geometry) MainGame.getAsset().loadModel(“models/”+name+".j3o");
This has worked before, maybe it doesn’t work in android?
Because when I do (Geometry) then it hogs up.
No error message or anything. Am I suppose to do this some other way?

hmm strange. Does that happen with all imported models?

If you can’t get the mesh, and don’t need the vertices afterwards for anything, and its just for an effect, then you could do that in a vertex shader

It’s used to make a black cartoon outline of all models.
But because post-processors wont work in android then I’ll do it this way.

@Addez said: Thanks everyone :D DMesh seems to be the way to go :)

Only problem is that I need the mesh from a spatial, so I do like this:
Geometry model = (Geometry) MainGame.getAsset().loadModel(“models/”+name+“.j3o”);
This has worked before, maybe it doesn’t work in android?
Because when I do (Geometry) then it hogs up.
No error message or anything. Am I suppose to do this some other way?

Your model is probably a Node with multiple nodes and geometries underneath it. You will have to traverse and find the geometries. There are classes to help do this already but the recursive way is not hard to write.

1 Like

Thanks :slight_smile:
I did that and now it works great :slight_smile:

Did you know you can do this with a vertex shader if you want to move this computation into the GPU? For a cartoon effect, you rerender the objects you want to have the cartoon effect and tell the vertex shader to expand each vertex along its normal by a small amount. Then you cull the front facing polys and draw the back facing polys with the color you want the outline.

1 Like