Dev:Py/Scripts/Guidelines/BGE Scripts Migration

提供: wiki
移動先: 案内検索

Some helper for scripts migration

The API changes from Blender 2.48 to 2.49 have nothing to do with the changes we have from 2.49 to 2.5. The first one was a big direction change in the way internal variables were handled (now we have direct access to the variables instead of having to use get/set statements). The second one is part due to python changes (thanks God we have only one Python version now), big fixes (eg Mathutils) and of course the opportunity that 2.50 brings to make things right.

So I'm not sure it brings some peace to your heart, but all the changes you did from 2.48 to 2.49 would still be necessary from 2.48 to 2.5. Therefore there is no wasted work.

Unfortunately there are other changes (most due to python 2.6->3.1 transition but some due to bge itself) that will require you some extra work. Extra work is different from work from scratch. I hope you get that.

Some of the changes Py2.xx to Py3.1 brought:

  • print should always have parenthesis (eg print())
  • has_key() doesn't work any longer. So if you want to check for a property in your object you do: object.key(key, default=None). If it has the property named key it returns it value. Otherwise it returns None (or the value of the optional default value). object.getPropertyNames() can work well too.
  • no more need for int to float conversion (eg float(2) / 3)
  • sockets now send/receive a byte array instead of a string

Some of the changes BGE 2.49 to 2.5 presents so far:

  • all the instance variables use Mathutils modules whenever possible. That means object.orientation is a Mathutils.Matrix, object.position is a Mathutils.Vector . . .
  • a lot of the Mathutils module operation was fixed. (e.g. Vector multiplication and some Matrix were using the wrong order of the arguments).
  • No more OB in front of your object name (eg my_obj = scene.objects["Cube"] is the correct now.
  • Stereo eye separation defined in the UI, focal length using the camera focal length as default (this may be used by a few, but it serves to illustrate features that have been broken so we can have them working better).
  • Mathutils.AngleBetweenVecs(vec1,vec2) was replaced by vec1.angle(vec2)
  • Mathutils.Rand(low,high) was abandoned. Can be replaced by random.uniform(low,high)
  • Mathutils.RotationMatrix now uses XYZ instead of xyz for the axis parameter
  • BGL module renamed to bgl

GENERAL BOTTOMLINE: It's not recommended for any serious project to migrate to Blender 2.5 any time soon. Maybe not even after the first Release Candidates. Therefore I don't see what's wrong with sticking to 2.49 and already getting familiar with the new API, and later to learn a few more tricks. This is smooth enough in my opinion. Better than simply having a lot of changes only when 2.5 comes out.

No one is happy with the fact that we couldn't make a smoother transition from 2.49 to 2.50, but so many things changed internally in Blender, that I bet no one predicted beforehand the extension of the changes to come. Things like the Mathutils fixes or removing OB should be done sooner or later. I'm glad 2.5 was the time for that.

It's not so hard to migrate existent files to Blender 2.5. I've been doing that to some of my projects and so far nothing extraordinary came out (despite a bunch of bugs I've been spotting and reporting). Download a recent build from Graphicall and give it a shot. It's really not hard to do the transition.

Last and probably least: I'm loving all the changes. No exception. I've been doing mainly BGE related works to live (as a freelancer and fulltime employ) and I'm very glad BGE is become better to work with. It may take time for newcomers (or people not so confident with python?) to get used to the changes. But in my opinion it pays off.