Jan 21, 2010

Blender to OGRE Perl Script

Complex scenes hold lots of meshes (in xml format after you export to ogre meshes from blender). You need to convert it one by one. But I have written a script that converts all mesh.xml files into ogre meshes and save them to desired directories.



print "Looking for: $directoryName\n";

chdir($directoryName) or die "Cant chdir to $directoryName !";

opendir(DIR, ".");
@xmlFiles = grep(/\.xml$/,readdir(DIR));

foreach $file (@xmlFiles) {
print "$file\n";
system("OgreXMLConverter $file");

opendir(DIR, ".");
@meshFiles = grep(/\.mesh$/,readdir(DIR));

printf "Meshes: $outputMesh\n";
printf "Materials: $outputMat\n";

foreach $file (@meshFiles) {
system("cp $file $outputMesh");

opendir(DIR, ".");
@material = grep(/\.material$/,readdir(DIR));

foreach $file (@material) {
print "$file\n";
system("cp $file $outputMat");

[Remark] Save the script as ogreXML.perl

[Terminal] perl ogreXML.perl /path to your xml files/ /output directory for meshes/ /output directory for material/

[Remark] Don't forget to remember that you need to put your mesh files and materials in special directories in OGRE.

Jan 15, 2010

Blender To Ogre

This is a small tutorial on how to use the Blender Exporter script to use your textured models created with Blender in Ogre. This document works with Ogre 1.06 and newer and Blender 2.49b.

The procedure will be same on any Operating System because all programs used are cross-platform.

  1. In Blender
    1. In Blender scale up your cube. Make wall, fort or anything. Select the cube, and press TAB to enter EDIT mode.
    2. Move your cursor to the upper boundary till you see a two sided arrow. Right click, left klick on Split Area and afterwards determine the size of the second window by another left click.
    3. Now select UV/ImageEditor mode in the second window. Image → Open and Load(MMB) any texture from your ogrenew/samples/media/material/texture directory.
    4. Within the 3d view Edit window, press UKEY and Select Cube Projection or anything that suits you. Unwrap (smart projections) is often the best option.
      1. Change the Select mode in the 3D view Edit window to FACE
      2. Select a single face in the EDIT window
      3. Move to the UV window and press G to move that face away from the rest
      4. Select each face one at a time from the 3D view and move it in the UV image editor so that they do not overlap, but are reasonably connected, ie a t for the cube. (It doesn't need to be a t, you can make any shape you want, even overlapping or separate. The faces take the texture of the image beneath them.) You can also rotate etc the faces.
      5. Once you have them basically where you need to be, goto the 3D view and select all the faces with AKEY. You might see the faces are overlapping correctly or not touching etc. Move to the UV window and press AKEY again; they will deselect but still be there. Select one vertex of an incorrect face, then press Select -> Linked Uvs (or press CTRL-L). Now use GKEY to move the face precisely where it needs to be. Repeat with each face to place precisely.
      6. Now goto the UV/image editor window and press AKEY twice. It should select all your faces.
      7. Press S to scale your faces up or down until they fit within the grid (or your image).
      8. To verify you have done this correctly, you should see 6 separate squares in your UV window. Each time you click on a face in the 3D view Edit window, one of the squares in the UV window should highlight and the rest disappear.
    5. Move to the 3d View window and press Alt + Z and you will now see the textured object.
    6. If the texture is not facing the correct direction, go back to UV/Image Editor and move the appropriate faces so the texture looks correct on your object.
    7. If your model look jolted in Ogre press Ctrl + A in the Object Mode. The point is that Blender does not have all the mesh data transformed/rotated/scaled as you would presume by having a look at the screen. Therefore, before exporting you have to tell it to actually apply all the mesh changes (that you can already see in Blender) to the actual data that will get exported.

  1. Blender Quick Tips
    1. If you would like to render the object in Blender, be sure to press F5 and then click on the "TexFace" option in the "Material" panel at the bottom of the screen first.
      1. Make sure this option is not set before exporting the file as explained below.
    2. If you are unsure how faces in the 3D View correspond to those in the UV/Image Editor, use a test pattern image as a texture (such as the one in this tutorial).

If you have had trouble in the steps above, please post your problem to the BlenderArtists Modeling or Texturing forum accordingly.

  1. In Blender: Exporting the file
    1. File → Export → OgreXML and select Game Engine Material.
    2. Export
    3. Quit Blender. Just now you exported Cube.mesh.xml and Scene.material. Cube.mesh.xml is the Mesh itself and Scene.material contains the name of the texture applied and how it is applied. Where textures are stored is set in the resources.cfg file (/material/texture). Models are stored in /models, .material scripts in /material/scripts.

  1. Out of Blender
    1. Open up the Terminal (on Windows it's called Command prompt) and type "OgreXMLConverter Cube.mesh.xml". Press Enter. Your xml file has been converted to Ogre's .mesh format.
    2. Now you have Cube.mesh (which is the Mesh itself) and a Scene.material (which contains the name of the texture applied to Cube.mesh)
    3. Specify in the "resources.cfg" file where to find everything (or leave it as is and do the following two steps).
    4. Now copy Cube.mesh into the /models folder (somewhere under your "ogrenew" folder). Copy Scene.material to /material/scripts/ folder.
    5. Copy "your texture" to /material/texture/ folder, if you applied some other texture other than those supplied with Ogre.
    6. Open your working Ogre program and replace robot.mesh with Cube.mesh in your createEntity() function. When you change the line, the following happens during loading:
      1. Cube.mesh is found using "resources.cfg"
      2. Cube.mesh has a refernece to Scene.material (name of associated .material file is written inside Cube.mesh) and will be loaded using "resources.cfg"
      3. Scene.material applies our texture which is also loaded using "resources.cfg" (as you can see: "resources.cfg" is essential).
    7. Run your application.
Reference: http://www.ogre3d.org/wiki/index.php/Blender_to_Ogre

Jan 6, 2010

Simple& Quick mysql commands

  • $ mysql --user=your-user-name --password=your-password
  • mysql> show databases;
  • mysql> use thedatabaseyouwantoselect;
  • mysql> show tables;

How to get event numbers

$ ls /dev/input/by-id

$ ls /dev/input/by-id -l

$ file /dev/input/by-id/usb-045e_Microsoft_Natural_Keyboard_Pro-event-kbd

/dev/input/by-id/usb-045e_Microsoft_Natural_Keyboard_Pro-event-kbd: symbolic
link to `../event1'