# Python newbie trying to turn all normals on a curve to face outward...!

Hey folks!

I’ve completed a few professional projects in C#/Unity, have worked through 90% of Microsoft’s Beginners Guide to Python, just started Python the Hard Way and have done a bunch of beginner Blender Python tutorials. I’m kinda starting to become familiar with Blender’s api.

I’m currently trying to build a network of interchanging, overlapping roads similar to the image below, which is then wrapped into ball of twine (but roads).

I’ve got one road working, as seen in this tutorial, then wrapped it into a ball with this answer.

The following is my current effort (file link here ):

You can also see this attempt as the blue ball in centre right of the following image (the other images are examples of my ultimate goal):

Here it is in 3D! =D

My problem is I can’t seem to get the roads to all face outwards - the beziers are being bent somewhat randomly. I’ve been pointed in the direction of this control , but unfortunately I’d need to apply all my modifiers and then change the direction of the bezier control points independently - which obviously slows iteration to a crawl.

I’ve been trying to think of what kind of code I need to get all the normals oriented correctly - presumably:

• I import Math and Mathutils
• select all the curve points (`bpy.ops.curve.` `select_all` ( action=‘TOGGLE’ ))
• and get a Vector3 list of the curve points
• Going through each point, I’d get a Vector3 from the centre of the bounding box to the current point
• Then set the bounding box quaternion to face the Vector3 direction…

…But I’m not sure how I’d do that. Or where I’d get the bounding box centre of a Curve - or if I can get that box after the curve has been twisted up by the modifiers.

If I try to apply the rotation, will this happen to the modified object or the underlying data? Would it be possible to undo this change when I want to unroll the sphere and edit the underlying bezier?

I’m really confused, folks. I think I’ve talked myself into a corner here, and I’m not sure where to start with the code. I’d really appreciate any suggestions you could make.

If you want the roads to be on a sphere you could think about cube mapping, then do a cube -> sphere just with subdividing and transforming the points to a sphere.

How to get normals. Isn’t it just the normalized vector from the bounding box center? Then you just have to figure out how to apply that normal to each spline vertex.

If you want an undo thing, you would probably have to save the previous mesh to a global variable and manage that, if you don’t want to do it manually.

Thanks, @ambi…!

I’m used to the subdivided cube to sphere trick, but I’m not entirely sure what you mean by cube mapping in relation to bezier curves? I think I’m not understanding something here.

Regards your second paragraph - yeah, that’s basically what I was thinking (or tried to state in my second last bullet point). Not sure how to get the bounding box centre for the curve, though, and I’m not sure if I’m going to get it before or after the modifiers have affected it…!

Well, the ultimate thing regards undo would be to try to build this as a further modifier that can be performed after the simple deforms and shrinkwrap to sphere - that would really save me a lot of time in iteration. Otherwise, yeah, saving a list of vector normals for the control points makes sense…!

I’ll continue to experiment here, but I’m having a bit of trouble working out where to start…!