Problem exporting normals

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

griff
Posts: 4
Joined: Mon Aug 02, 2004 6:15 pm

Problem exporting normals

Postby griff » Mon Aug 02, 2004 6:35 pm

don't flame me for asking stupid questions cause i'm totaly new to blender :) The only thing i need is to export a blender object (designed by a fellow) as an *.obj (alias) file. There are lots of example scripts for doing that. But the normal information isn't correct. The simplest example. A standard cube (not smoothed) and triangulated. So there have to be normals like
(+/- 1, 0, 0), (0, +/-1, 0) and (0, 0, +/-1). But the information caught by

Code: Select all

for f in Object.Get().getData().faces:
 for v in f.v
  # only pseudocode to demonstrate my problem
  #print v.no[0]
  #print v.no[1]
  #print v.no[2]


is erroneous.

there are values like:
+/-0.577349 +/-0.577349 +/-0.577349

Is anybody familiar to this problem?

z3r0_d
Posts: 1522
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Postby z3r0_d » Mon Aug 02, 2004 7:03 pm

ah, but vertex normals don't care about wether or not the face is smoothed

those values are ones I would expect, a vertex normal considers all faces the vertex is used in [regardless of smoothing attributes, at least in the python api]

so, either get the face normal, or if it isn't there it is easy enough to calculate with a cross product

griff
Posts: 4
Joined: Mon Aug 02, 2004 6:15 pm

Postby griff » Mon Aug 02, 2004 7:34 pm

the point is... i need the *.obj files as sources for a game (with LWJGL therefor: OpenGL) and it depends on the normals how an material responds to light... i not always need normals that are realy 'normal' to the surface...
as i know, it depends on the normals if an object consisting of triangles looks sharp edged or smooth?
and it's simply so, that BLENDER returns wrong normal information. Is that a bug?

griff
Posts: 4
Joined: Mon Aug 02, 2004 6:15 pm

Postby griff » Mon Aug 02, 2004 9:09 pm

sorry, naturally it was my fault... i totally mixed up vertex normals with face normals :)
thnx anyway for your respond, without that i wouldnt have the solution til now

EladarGL
Posts: 10
Joined: Sun May 15, 2005 4:58 pm

Postby EladarGL » Sun May 15, 2005 5:04 pm

I have that problem too. I need per vertex per face normal. I am trying to do a game exporter, but i need a per vertex normal.. per face normal not allow high quality graphics in an engine. Do you make this feature early in python scripting? Thanks for read this.

PD:My english is bad :P, sorry.

EDITED: I think per face normal isnt enough, because i can use a 3d model with some "smoothing groups". An example is a cube, each vertex have three normals, it havent one smoothing (this is my problem that i want resolve). The solution can be use per face normal, but, what happen if a face of the cube are a lot of triangles in sphere form?

Thanks for read this. PDPD: I think my english is very very bad, hehe :oops:

Brandano
Posts: 22
Joined: Mon Apr 19, 2004 6:03 pm

Postby Brandano » Sun May 15, 2005 6:22 pm

I met this problem as well, and have seen how it has been handled in a couple of commercial games. Blender doesn't support vertices with more than one normal set, it wouldn't make sense. How would you decide what face the normal belongs to? the way to work around this problem is to 'split' the mesh along the sharp edges. By this I mean that whenever you have a sharp edge you should duplicate the vertex, so that the faces are no longer 'connected' by an edge, but you actually have two coincident edges. This should also make it easier for your 3D engine to render the model. I am also working on a little script to individually edit vertex normals, but I am still in the concept phase, so don't expect it any time soon.

EladarGL
Posts: 10
Joined: Sun May 15, 2005 4:58 pm

Postby EladarGL » Mon May 16, 2005 12:09 pm

I think that smoothing group is needed in this case (or a some in this way), or simply make a per vertex normal.

One question, if i want smooth a part of a figure, must i make that figure in two figures? this solution is not enough i think. I hope this was resolve early, i like blender very much, but this problem stop me for follow develop over Blender. Ideal way was that when i export face.v[i].no[0] ..no[1] ..no[2], this write in the file the normals transformed (with smoothed if it have and solid if havent it).

Thx for replay.

PD: My English is bad.. (maybe i said something wrong)

Brandano
Posts: 22
Joined: Mon Apr 19, 2004 6:03 pm

Postby Brandano » Mon May 16, 2005 12:50 pm

Hm, no, the current Blender mesh supports face normals and vertex normals, but no 'per face' vertex normals.
What I meant was this: you don't need to create new meshes, but whenever two faces belong to two different 'smoothing groups' they should not share vertices. they can be attached to coincident vertices, but not to the same vertex. So if you have 4 vertices v1,v2,v3,v4, and two faces f1.v=[v1,v2,v3], f2.v=[v2,v3,v4] in order for them to have a sharp edge you must add to the mesh two new vertices, v2' and v3', so that the first face is still f1.v=[v1,v2,v3], and the second face becomes f2.v=[v2',v3',v4] instead. as long as v2.co = v2'.co and v3.co = v3'.co the mesh won't have a visible seam, but if v2.no != v2'.no and v3.no != v3'.no the edge will show as an hard edge.

ideasman
Posts: 1000
Joined: Tue Feb 25, 2003 2:37 pm

Postby ideasman » Mon May 16, 2005 2:07 pm

The bottom line is that if you want realy nice smoothing for game models your going to needto code your own smoothing code that generates normals etc.

Useualy the problem is that normals in openGL require one vertex per normal. so a single blender vert needs to be split into many. each with there own normal.

There is a script that does some autosmoothing like this for you- its called autosmooth... look on elysuin.

z3r0_d
Posts: 1522
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Postby z3r0_d » Mon May 16, 2005 5:31 pm

ideasman wrote:There is a script that does some autosmoothing like this for you- its called autosmooth... look on elysuin.

http://www.elysiun.com/forum/viewtopic. ... 467#235467

[yes, I wrote it]

EladarGL
Posts: 10
Joined: Sun May 15, 2005 4:58 pm

Postby EladarGL » Wed May 18, 2005 5:20 pm

Thank you to all. I try for a cube normals, and it did it!, normals are solids and not smoothed. I have only tried whit a cube but i think that this script is very usefull for 3D engine GNU developers. Thx z3r0_d for the script ;)

Hyakutake
Posts: 1
Joined: Thu Jan 01, 1970 1:00 am

Postby Hyakutake » Thu Oct 27, 2005 3:04 pm

Hi, ive got a newbie question... I've got the same problem whit normals in obj exporting, so downloaded the script autosmooth. To use the script I must select the "meshes, press alt+p with the cursor in the text window". Where is the text window? How do i know the script has worked?

Thanks.

PS:sorry about the stupid question


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest