Teaching UV unwrapping

Thursday, March 18th, 2010

Getting to grips with 2D to 3D

This is a simple little exercise I came up with for showing students how to convert 2D to 3D and vise versa. The idea is to not go straight to 3D, but in stead give them a hands-on task that gets the idea into their heads. It’s not a completely new thing for most students, but the relation to UV unwrapping is. And of course it is fun to try to make it challenging as well.


The example

To give my students some idea of what I expected them to do I showed them an example I made the night before class. It’s a basic svg I made in Inkscape that I printed on A4 paper.

I could have just made a single T shape to make a single cube, but since I was teaching university level students that was a bit too simple. In stead I made this, which turns into 2 cubes that are connected at a corner. The real world result that I glued together the night before class, and showed my students in the morning is below here.


The task

After showing the students my example, I provided them all with paper, rulers, pencils, glue or tape, and scissors. Then put them right to work. The task I gave them was was rather simple…

Make something more complicated than a single cube!


The results

As usual my students surprised me with their inventiveness. The range of designs they came up with was really nice. Especially the surprises and “misinterpretations” that I really didn’t see coming. All I did during the class was walk around and give some pointers.


Round up

That’s basicly all this class was. After finishing the exercise we got stuck in in Blender 3D to UV unwrap the models they had made the day before. It was a lot easier for me to teach them that technique after they had done exactly the opposite with paper (which is what this exercise is). All in all this was a fun hour to break up the week of staring at computer screens, and I’ll definitely repeat it in future.

I hope this helps you, and if you have similar fun ways of teaching your students, please let me know. I’m always looking for novel ways of getting these complex ideas into students heads.

Dolf

Normal smooth method

Wednesday, March 17th, 2010

On this post I’ll try to explain how the method for the Normal Smooth script works.


Concept

The idea is to reposition verticles so your mesh ends up nice and smooth. Of course there is already a function in Blender that does it, but that doesn’t take the actual “surface” of the mesh into account. So say you have a part of a perfect sphere selected, and you run the current internal function, it would flatten that selection, or even make it concave (hollow). That’s what we don’t want. In stead if you try to smooth a perfect sphere, it should not change anything. You can’t get smoother than a sphere!

See below here… that’s not nicely smoothed!


Smoothing the normal way

I’ll explain the concept in 2D. Lets say we want to smooth the position of vertex A and it’s connected to vertex B and C. Then we get the vertex normals for B and C. We then rotate those normal vectors 90 degrees towards A and make them half the length of the distance between that specific vert (B or C) and A. Once we have those, we find the points at the ends of those two vectors and place vert A at the midpoint between them.

But let me explain with a picture, which should help.


That’s just the basics

Of course there is a lot more that you can do with a script. Like looking further along the surface and using more normals. Also in 3d at times you have quads and you need to figure out what you want to do with the vert at the far end of the quad. Having non manifold meshes can be tricky too.

At least I hope this explains the idea a bit, and as ideas go…. it’s not too bad

Dolf

Finding mesh angles

Wednesday, March 17th, 2010

Here I’ll try to explain a method for finding out the angle of a mesh at a specific point/edge in python.

This method can for instance be used to create effects like with the ma baker or ma self scripts;


Finding the angle between two faces in Blender

Now this isn’t really complicated.

Lets say you retrieve two faces from Blender’s python API that are connected by an edge.

Lets call them face1 and face2 and face1.no retrieves the face normal of face1.

Then we can simply do the following to find the angle:

  1. myAngle = Mathutils.AngleBetweenVecs(face1.no, face2.no)

Display clean python code for copying

myAngle = Mathutils.AngleBetweenVecs(face1.no, face2.no)

The result though is only an angle between 0 and 90 degrees, to find out if that is positive or negative continue reading below.


Finding out whether the angle between two faces is convex or concave

A lot of the time you also want to know whether the angle is concave or convex (positive or negative).

To get that we get the vector from the midpoint of face1 to the midpoint of face2.

The midpoint of a face is retrieved by getting face1.cent.

Then we get the dot product of the face normal of face1 and the vector we just retrieved.

In python that could be:

  1. dotProduct = Mathutils.DotVecs(face1.no, (face2.cent - face1.cent))

Display clean python code for copying

dotProduct = Mathutils.DotVecs(face1.no, (face2.cent - face1.cent))

The resulting dot product will be either positive or negative depending on whether the angle is concave or convex.

Using python scripts

Wednesday, March 17th, 2010

This page is here to help you understand how to use basic python scripts in blender 2.4x.

It’s not about writing scripts, just using them.

I assume you know enough about blender to open windows, find menus, and open files in it.

I will only cover Windows on this page. I don’t have the other Operating systems handy. Also using scripts in the Game engine can be a bit different than how I explain here.


What is python?

If you really want to know everything about python you should go to python.org but I’ll give a simple description here.

Python is a programming language released originally by yet another Dutchman. I know they’re everywhere! You can read more about it’s history on this page if you want.

The thing that makes python unlike C or C++ for instance is that you don’t have to actually compile your programs. Basicly all programming languages are written in basic text. Programs written in C you would ’compile’, which would turn your code into a program that you can use and give to people. So for example with python you don’t generate a blender.exe file.

In stead the programming code stays in it’s basic text format, in what is really just a textfile, nothing more. This textfile can be read by a ‘real’ program which is called python as well (just like the language). This program then does all the things that it’s told to do in the textfile.

These textfiles are called python scripts. And scripts are files that tell programs what to do, they are not programs themselves. There are lots of other languages that work in the same way… like asp, php, and javascript.


The infamous blender startup message!

You may have seen this screen before and it scares a lot of people at first. I mean… it’s an actual bonafide error message…. or is it?

Do not close this screen!

This screen is used by blender to show you messages, if you close it you will close blender as well.

Let me try to explain where the message comes from.

We can use python scripts in blender. Now we can only do so because inside blender is a small version of the python program that can read these scripts, and do what they say. That’s where the first line comes from. Apparently the copy of blender that I took this screenshot from had python 2.5 put in it. The actual line of text is created by the python program in blender when it’s started. Now as the python program in blender is started (when you start blender) it has a look at itself and your computer to see what it can do, where it is, and basicly everything I do every morning when I wake up.

So it wakes up and finds out it’s the small version. Then it has a look to see if there’s a big version of itself on your computer that would allow it to do everything the big version can do. In this case it can’t find it, and all the other messages you see basicly mean: ’Hey I am only the small version inside blender, and I can’t do everything I could do if my big brother was here’. This is no reason for anyone to worry! Really it isn’t. The small version inside blender can do pretty much everything you want. Only for the really advanced stuff like communicating with big databases and such, would you need the complete version of python.

So we have blender, and we can use pretty much all python scripts released for blender in it. You can install a full version of python if you really need it, or if you want to get rid of those messages, but normally there really is no need. I use python all the time and don’t need a full version at all.


I downloaded a script… now what?

Ok so you have a script. Lets call it myScript.py, and remember that really all it is is a textfile. You can use the script inside blender in two basic ways.


One: Put the file in the blender scripts folder

If you put the script you downloaded in the same folder as all the scripts you get with blender you can use it as if its one of those official scripts. If you are on windows find the folder that has the blender.exe program file in it and there should be a folder called ‘.blender’. In that folder should be another folder called ‘scripts’. This is where all the official scripts are.

Once you put the file in there you can find it in the blender scripts menu. Don’t forget to use the ‘Update menus’ function at the top of the menu if you had blender already running when you put the script in the folder. As soon as you select the script in this menu it will ‘run/be executed’

If you are not sure where to find the script in this menu you can open it in a text editor (notepad for instance) and near the top it should say what group it’s in. That is where you’ll find it in the menu. If you can’t find the group, you’ll have to use the second way.


Two: Open the script as a textfile.

Save the script anywhere on your computer. Then in blender open a text window, and in there open the file like a textfile.

Now if you have your mouse pointer over the text window and you click ALT + P the script will run.


Having the right blender version.

Every script should tell you for what blender version it was written at the top of the script itself. There is no guarantee that a script will work if you have a newer or older version of blender than the one for which the script was written.


That’s it.

You should now know enough to use most python scripts in blender.

Have fun!
Dolf

Angle math

Wednesday, March 17th, 2010

This is just here so I don’t forget ;)

(small characters here refer to angles, capitals to lengths of sides)


An oblique triangle

A triangle without a 90 degree angle

Python equivalents of the above math are for instance (untested):

A = math.sin(a) / (math.sin(b)/B)

B = math.sin(b) / (math.sin(c)/C)

C = math.sin(c) / (math.sin(a)/A)


A right angle triangle

A triangle with a single 90 degree angle (a in this case)

Python equivalents of the above math are for instance:

c = math.asin(C/A)

c = math.acos(A/C)

c = math.atan(C/B)

A = math.sqrt(B*B+C*C)

Remember soscastoa!

Creating a Rubiks Cube as a computer game

Wednesday, November 14th, 2007

Downloadable Files

As a small side project Brian Hynds and I worked on creating a rubics cube in Blender 3D. Almost all the interactivity was programmed by me in Python. In basis the game works as a proof of concept.

You can download both a zipped runtime (windows) version and the latest .blend

Use the arrow keys on your keyboard to rotate the cube, and click/drag your mouse to manipulate it.

click here to close

Help keep these files free,
and support further development!