The MadMan is back.

 

More Madness

 

When I read my last post I must say I really must have had a boost of optimism and god-like energy over me back then, eh?

Books to be written, 3D art to be made, Allegorithmic products to review, Python programming, Blenders Game Engine, Modo stuff.. Phew!

Well. I have actually done something. I won’t present anything here today, but some things stayed and some things did not.

I’m still into writing the book series, that’s one. (But it will be a bit postponed)

What I’m still into is off course Blender! It has gotten a LOT of updates the last seven months.
I’m still willing to create a tutorial series on the BGE (Blender Game Engine) which we all know is programmed with Python. Actually A LOT of Blender is programmed with Python now. It’s just the low level bits and pieces left in hard core C / C++ (?asm?).

I was planning on starting on this in a couple of weeks and off course post it on this blog, if it is any interest for it.

As some of you know, I’m a software developer, mainly using C# and C++, but I’ve also been using some Python through the years.

Lately I’ve been keen on learning to program GAMES. What kind of games? No idea. Just games. Fun programs that can include gaming elements, like “gamification” or something.

So I’ve downloaded the latest Unreal 4 Engine, but that was totally overkill for me. I need to know the basics first.

Even Unity seems a bit cryptic to me sometimes. But that’s mostly because of the horrific implementation of C# / .Net they’ve chosen. Goes against all good usage patterns.

So now I’m going to test out Blenders Game Engine, to see if I can make any sense of that.

Along the way will be some tutorials and some Python code for those interested.

 

Also I’ll look into some rendering with Cycles, Thea Render and LuxRender…

 

Until next time…

Blender Logo

 

 

 

 

 

Follow-Up: Reasons to NOT only learn .Net / C#

A modern developer should master at least 3 languages!

A while ago I was all exited about finally “getting it” in sense of the more advanced parts of C#, like Generics, Events, Delegates, and Lambdas. So I wrote a post about 18 reasons you should use C# / .Net / Mono.  it kinda sounded like I’d found a salvation in it or something.

Well, I did not. I was just “on a roll”!

I’m often on these rolls. This is what gets me ahead of the competition and it’s what get’s developers with master degrees in Computer Science and programming  asking ME for help while at work from time to time. That’s wicked cool, but it has its downsides.   logoLispSpillerGlossy

I seldom sleep more than 4 hours per night, because I just HAVE to finish up a stupid project so I can understand a concept in a programming language I probably never going to use, like Cobol or something. But who knows right?

This brings me to the main theme of this blog post:

I’ve been interested in programming for a long time. Long before I started to work as a developer, I snuck in some developer tasks when working as a network and security administrator, and when working as a server and system administrator.
I managed to convince my boss that I really needed this and that book  or course so we could do this and that so much better. It worked all the time.

My job back then was basically sitting in my office with a self-made monitoring system that alerted me if some fiber link was down or a router to a branch office went bananas, something that didn’t happen very frequently. So, my responsibility was to make sure the systems ran 24/7, and that was that.
I make it sound a bit easier than it was from time to time, but the point is that I had a lot of time to study programming!

I started learning the C Language from the ubiquitous K&R book that I still keep in sight for the kicks emacs6-256of it. This was the first standardized version of C, so it had some quirks to put it mildly, but when you understood it, nothing could beat it! At least not in terms of efficiency and performance… Time to market is a nother story.
I was doing a good deal of scripting as part of my job, for automating mass installations, upgrades log-on scripts and those things, but that was in VBScript! Can you believe it? VBScript! I hated it.

So I started to replace many of the scripts with Perl and Python using the Win32 libraries, something that was way cooler.

Then I got interested in cross-platform programming in Java, because I missed a real GUI from the stripped out Tk I managed to get out of Perl and Python, and it had to run on both Windows, Linux and FreeBSD servers. While I probably would get a compile-time error writing “Hello World” in Java today I thought it was fun while it lasted.

Then the real shit hit the fan. I decided to change jobs and work as a full-time developer. My responsibilities where diverse and involved working with Legacy Borland C++ code and some C# 2.0 written in C++ style. So I had to get really serious about learning C++ and C#. The first months I went to work, did what I could, then I wrote down everything I didn’t know how to do.
When I got home I thought it to myself through books, tutorials and Googling so I could fix it the next day.

This went on for almost a year, and I was totally up to my neck in deadlines and trouble.
It wasn’t really my vision of having a job doing what I liked most.
But somehow I managed to get by and new projects came along that demanded the same level of commitment.
That’s the price to pay for adding a bit extra on the resume…the-ruby-mine-logo

Today I feel a lot safer about my skills in the “major languages” C, C++ and C#, but I’ve realized that I’ve only been doing one kind of paradigm type programming and that is the Object Oriented type of programming.

So I’ve now started to learn two new languages (or three actually), namely Common Lisp, Erlang and TCL/Tk.
What I discover each day is that the new things I learn about the more functional approach to programming could have saved my ass plenty of times if I’d known some of the same techniques when working with the projects I barely got through earlier,
I could have done many things so much simpler and more elegantly.

So my advice to all aspiring or maybe even more to all the mounted old dogs that refuses to learn new tricks is to actually do just that. Learn at least one purely functional language, one strictly OOP and one that blends it all together, like C++ or Objective-C if that’s your cup of tea. Plus I’d invest in learning one strictly interpreted language like Python or Ruby, as it makes prototyping and easier tasks, well, so much easier!.

erlang

Put a NoSQL database like MongoDB on top of this and you have an incredible toolbox for handling almost any programming task thrown at you. Word.

PS! Don’t forget those that  work hard for free to bring us some fantastic tools to develop cool things with! 

Get a  Member Sponsorship at the Free Software Foundation Today! 

fsfButton     <– LINK!

These guys are Funding the GNU Project.

Until next time, The MadMan.

First post about Python scripting in Maya

This is the first post in a planned series of posts about Python scripting in
Autodesk Maya. Don’t expect this to turn you into a pro or something, this is
something I do to learn the material better myself.
I don’t know about your experience with Python, but this is not meant to be
a tutorial in the python language. I’ve used Python for some time now, and
I hope you are familiar with the language to get something out of the content.
You can probably do basic stuff without knowing the ins and outs of Python,
but to do something creative you must have some knowledge about the
different datatypes and constructs that defines Python.
One thing that also is important is that you understand the basics of how MEL
works, as most of the same applies to Python for Maya.
Well, let’s get started!

Getting access to Python in Maya

You can use Python either as a single command launcher from the command line,
or as a full scripting environment in the script editor, I’ll mention both in
sequence.
To start using Python in Maya you have to click the command line where it says
“MEL”. This will change into “Python”, and for one-shot commands this is all
you need.

To access Python through the script editor, click the script editor button
also on the command line, next to the output field.
There you’ll see to tabs, MEL and Python. Off course you should choose Python,
but you already knew that!
In the script editor I also choose “Command” -> “Command Completion” and
“Command” -> “Object Path Completion”.
This makes experimenting with Python a lot easier, as you can try out
different functions without knowing the names.

One thing you should be able to do is to transform MEL commands into Python,
so that you can download existing scripts, modify them to your needs and run
them in Python. Most of the scripts out there are still MEL, but py scripts
start to show up here and there.
I’ve always wanted to learn MEL, but it didn’t really make sense to me, so I
find the Python logic easier to grasp. Besides I use it for other tasks, so
I don’t have to learn a whole new language and tools.

Let’s make a polygon cube!
Let’s see, if I watch my script editor output while creating a cube I see that
the MEL needed for this is:

polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;

Well, it’s actually not that complicated but this is all the default arguments
used by MEL in the output. The same cube will appear by just typing:

polyCube

Try that in the command line by changing back to MEL and press enter. Whee!
But hey! This is not Python… True. Lets try to switch back to Python
and run:

polyCube()

as all function calls ends with parentheses.
This does not work, because we have to import the namespace that the Maya
commands live in. We can do that by:

from maya.cmds import *

This makes a bunch of frequently used commands accessible to Python.
Now we can try again with:

polyCube()

or, for a change, let’s say that we wanted to change the defaults. Look back
to the MEL command used to create the polyCube. -w 1 -h 1 -d 1 etc.
All these define width, height, depth, sizeX, sizeY, sizeZ and so on.
To access these preferences in python, we have to write it as arguments
with a value in the construction call:

polyCube(w=2,h=3,d=4)

This creates a different cube with changed parameters.

Well, this wasn’t much but I’ll post more soon!
Try creating different shapes with different attributes to get a feel for how
it works.

Have a nice one!

Scripting Maya with Python

This is the introduction to a series of small tutorials I’m going to make while learning to use Python in Maya.

I always learn stuff better if I try to teach what I learn to others while doing it. Maybe someone out there will find use for my experiences!
To start with I want to explain why I want to learn to use Python with Maya.
For some years now, I’ve used both Python and Maya occasionally, just as a hobby.
I am by no means an advanced user of Maya, but I find the software incredibly fascinating.
You can do so much cool stuff with its modules, like the nCloth module, the dynamics and fluids modules, hair and fur, Maya Muscle,
I could go on and on. Incredibly complex software. It’s also very demanding and difficult to learn properly.

People spend years of working with it without learning everything. You just can’t expect to master all aspects of the software, but
that’s not my goal either.
I like to model objects, set up the shaders and render settings and watch the results. Animation is also something that Maya does maybe best in the industry, so a bit of that is also something I like to spend time doing.
When it comes to Python, I learned some of it while working as a network administrator, using it for system scripting mostly.
I’ve never felt the need for extending Maya with anything, because I have plenty to learn before ever needing to customize anything myself.

So basically this project with learning how to use Python to script Maya is purely for entertainment.
But, who knows? Maybe I find it so interesting that I can start writing plugins. Or maybe I come across a situation where I miss a certain modeling tool or want to change how the defaults are working, then it would be nice to
roll my own little script instead of relying on others work on places like creativecrash.com.

Anyway, if you’re new to the world of scripting Maya with Python, the upcoming posts to this blog might get you in the right direction of learning it!

So, until next time, sharpen your senses.

Easy way to get Apache and MOD_WSGI working on OS X

I’ve fooled around with some Python Web-frameworks lately, and maybe someone would care to know that you don’t have to install MAMP or XXAMP or whatever they are called, because as you probably already know, OS X does have Apache 2 Server already installed, just waiting to be configured to your needs.
Off course, it is very easy and convenient in many cases to just push a button and have it all working, but I always like to have total control over the environment when I do stuff like this, so…
I don’t know if these packages support mod_wsgi anyway, so I’ll explain how to get things going the hard way! Similarly you could enable PHP, but that is a nother story.

This is about getting Python web hosting locally, so you can set up frameworks like Django, py2web and the likes.

I’m using OS X 10.7 (Lion), but I think this will work just as fine with older versions, but then you’ll get the module linked to an older release of Python by default.

Here is some information on mod_wsgi:

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.
The mod_wsgi module is written in C code directly against the internal Apache and Python application programming interfaces. As such, for hosting WSGI applications in conjunction with Apache it has a lower memory overhead and performs better than existing WSGI adapters for mod_python or alternative FASTCGI/SCGI/CGI or proxy based solutions.

As mod_wsgi supports the WSGI interface specification, any Python web framework or application which is compatible with the WSGI interface specification should be able to be hosted on top of mod_wsgi.

Major Python web frameworks and toolkits which are known to work include CherryPy, Django, Pylons, TurboGears, Pyramid, web.py, Werkzeug, Web2Py and Zope. Major Python web applications which are known to work include MoinMoin, PyBlosxom and Trac.

How to set it up using the internal Apache web server on OS X:

Download the latest version of mod_wsgi from:
http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2

Unpack the sources, and do the usual:

./configure
make
sudo make install

(if you have an older version of OS X, and would like to link to a newer Python version you have installed, use the

–with-python=/path/to/your_python with ./configure command)

Then, you have to edit the Apache configuration to load the newly installed module:

sudo vi /private/etc/apache2/httpd.conf

After the list of default modules to load type in:

#Load mod_wsgi module:
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
WSGIScriptAlias / /Library/WebServer/Documents/

Now you should be ready to serve Python content on the local Apache server that comes with OS X.

To try out your new configuration, create the following .py file, and save it to your document root folder /Library/WebServer/Documents/testpy.py:

def application(environ, start_response):
status = ‘200 OK’
output = ‘Hello World!’

response_headers = [(‘Content-type’, ‘text/plain’),
(‘Content-Length’, str(len(output)))]
start_response(status, response_headers)

return [output]

Start the web server via System Preferences -> Sharing -> Web Sharing
or via the
sudo /usr/sbin/apachectl start
Terminal command

Visit http://localhost/testpy.py
You should be greeted with the notorious “Hello World!” message, indicating that you now serve Python locally via Apache and mod_wsgi!

Pyrex

This is a promising project for those who need both speed (not the drug) and Python (not the .. no).

Very easy to combine C and Python with Pyrex, for those who didn’t know.

Check it out!

Pyrex.