Face normal + Object rotation..?

Hi all.
I am newly into python in blender and I am working on a rewrite of a section script.
It is goinf well and I can now get a section from a mesh, but I have a small problem…

I get a the normal of a polygon, but the normal is relative to the local space of the face… I need the normal in world space… So:
1: I get the local normal and rotate it by the objects rotation. Problem: how do I rotate a normal?
or…
2: I get the normal relative to world space diractly. Can that be done?

Thanks. Hope to get the script done soon so I can share it…

  • removed incorrect suggestion *

Sorry about that, normalized matrix are used for quaternion multiplication but not for normals.
I didn’t use this stuff in a while and got it confused.

Hi ejnaren,

ideasman’s code just needs a slight tweak if your object is non-uniformly scaled (as that can change normal direction also) if that’s the case for you, you can use:

matrix = obj.matrix_world
matrix_new = matrix.to_3x3().inverted().transposed()
no_world = matrix_new * no
no_world.normalize()

The last line assumes that you want to maintain unit normal length (i.e. length of 1)

Hope that helps.

Cheers,
Truman

Thanks ideasman and trumanblending!
You just cant buy support like this.

As said I am very new to blender scripting and while this helped me it is acually unclear to me why.
I am porting a 2.49 scropt so I need not know to much about scripting to get results.
In the 2.49 script one applies a matrix to a vector by just multiplying it, but in the 2.5 I need to use matrix.transposed() ??
How come. Has the matrices in 2.5+ been flipped?

Anyway Thanks again. When I post the script/addon/tool maybe someone would like to look it over. There might be much easier ways to do this now or I might have unseen bugs crawling around the code. Even though I can know cut things by a plane in blender again :slight_smile:

Ok, so this is a first for me, but I would like to share what I have done so far, but I am not sure how to proceed about this.
The script is still not ported 100% but it works and can cut an object, creating a section. The FILL option in hardcoded TRUE in the code because I havent yet figured out how to interact with the user through python.
Also I am not really into matrix calc so I was kind of fumbling in blind, but with the above help got it to work.
If anyone would like to look at it go for it as I have some other things I need to do before continuing with this :slight_smile:

Link to newly ported script (2.65): CrossSection.py

Link to original script (2.49): CrossSection

Thanks.

Ejnaren

PS: If anyone have good ideas as to what is the best way to get into blender I would be happy to hear about it.

Yes, @TrumanBlending changed this since 2.4x.
http://wiki.blender.org/index.php/User:TrumanBlending/Matrix_Indexing

Hey ejnaren, I like your port. It works fine for me except an error on line 252, changed that to

bpy.context.tool_settings.mesh_select_mode=(False,True,False)

For the next steps:
You could make an Operator out of it, so its callable by a button in the GUI.
There you could also have a Panel with a boolean Property for the fill option.
In the internal Text Editor there some samples for UI Panels and Operators.

Feel free to ask if you get stuck.

Thanks Afeitadora!
I am in the middle of launching my portfolio site and deliver my exams for this semester. After this I think I will finish the script as you mentioned.
I have also thought of improving it with an option for multiple face sections so it can be ued for more intersections.
For that I might call on help :smiley:

Roger over