LAB REPORT WEEK 3: Blender’s Python Console’s Functionality

Objective: My goal was to identify how Blender presents itself within the python console it provides.

Materials:

Blender (software)

Methods:

  1. Open Blender
  2. Set the rendering to “Blender Game”
  3. Go to Materials (the icon looks like a globe with a four-square checker pattern on it) on the right
  4. Make sure that your cube (Blender should provide you one upon starting up) has a material. If not, add a new material by clicking “New”
  5. Click the button on the lower left and select “Logic Editor”
  6. Add some sensors, controllers, and actuators to the object
  7. Do not connect the sensors, controllers, or actuators
  8. Click the button on the lower left and select “Python Console”
  9. Click into the Python console window
  10. Type into the console import bpy and then hit enter
  11. Type into the console cube = bpy.data.objects[“Cube”]
  12. Type print(cube.location)
  13. Type print(cube.game.sensors[:])
  14. Type print(cube.game.controllers[:])
  15. Type print(cube.game.actuators[:])
  16. Type cube.game.actuators[0].link(cube.game.controllers[0])
  17. Type cube.game.controllers[0].link(cube.game.sensors[0])
  18. Type print(cube.active_material.diffuse_color)
  19. Type cube.active_material.diffuse_color.r = 0.0
  20. Type print(cube.active_material.diffuse_color.hsv)
  21. Type cube.active_material.diffuse_color.h = 0.8
  22. Go to the Logic Editor

Results: By performing the above, I first made the python console amenable to Blender and its properties. Then I assigned the premade cube object to the variable cube. After that, I identified the location of the cube. Then I identified the sensors, controllers, and actuators I’ve made for the cube. Proceeding this, I linked the first actuator to the first controller, and then the first controller to the first sensor. I identified the RGB value of the active material on the cube. I changed the red value, r, to 0.0, as the values of RGB and HSV are both floats ranging from 0.0 to 1.0. Once I changed it, the cube became cyan in color. Before changing the hue, h, to 0.8, I identified the HSV values of the active material on the cube. Once I changed it, it became magenta in color. Lastly, I looked to the Logic Editor and observed that I had successfully linked the sensor, controller, and actuator I targeted in the python console.

Discussion: This took a lot of figuring out to do, as the resources online for the Python Console with Blender were shoddy at best, confusing at worst, and for much older versions at “what.” However, that I’ve managed to do this much made me quite happy. I relied on extensive use of dir(command) along the way to understand what I was poking around at, but I managed to do more than I expected on my own. Connecting the different logic pieces may be easier through clicking, but if you have a large amount of logic pieces a looping script may make things easier. I wasn’t expecting the RGB and HSV values to be on a 0.0 to 1.0 scale, rather a 0 to 255 scale, but I recognized the possibility. Additionally, I found the requirement for parentheses on the print statement to be frustrating. Either way, this was a blast!

This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.