Remote object management in Blender
- Tutorial
Debugging different control algorithms for our robot , we felt how pleasant it would be to have a modeling environment and debug programs first in it, and then test on a real robot. Since we actively used Blender to create models for 3D printing and for the user interface, we decided to try the Blender Game Engine as a medium for modeling the robot. The first results were very good:
The video shows the control panel for the driver, which shows the view from the on-board cameras and data from the sensors.
After that, the question arose - how to integrate BGE with our communication and management system? Those. How to make the same program able to control a real or virtual robot in BGE without changes? To control the robot over the network, we use the Ice library, which, among many others, supports Python. Blender also knows how to execute Python scripts and provides an interface to all its objects and functions. Thus, a plan was born - to write a program in python that would implement exactly the same (remote) interfaces as a program that runs on a robot. But instead of real motors, it would change the properties of objects in BGE in accordance with the commands coming through the network.
As a first step, we decided to make the simplest example possible, which shows:
To do this, I needed to make two Python files. The first is with the server code that will be launched inside Blender and the second is a client program that sends requests for changing the position to the server over the network. These two programs can be found on Github . Testblender.py is a server. It should be noted that it was necessary to start the server in a separate thread, as otherwise, while waiting for a message over the network, it blocked the Blender user interface and the change in the position of the object was not visually displayed. Client.py is a simple program sending 100 requests to change the position of the current (selected) object by moving it in a circle in the XZ plane. The following video shows how to start the server and client program and the result of work is an object moving in a circle.
After we learned how to manage objects inside Blender remotely (over the network), we plan to implement interfaces for controlling the robot inside BGE to control the model.
In fact, the described remote object management technique in Blender can be used for completely different applications. For example, to visualize data collected on another computer. Therefore, we hope that the simple example described above and this article will be interesting and useful for readers :-).
The video shows the control panel for the driver, which shows the view from the on-board cameras and data from the sensors.
After that, the question arose - how to integrate BGE with our communication and management system? Those. How to make the same program able to control a real or virtual robot in BGE without changes? To control the robot over the network, we use the Ice library, which, among many others, supports Python. Blender also knows how to execute Python scripts and provides an interface to all its objects and functions. Thus, a plan was born - to write a program in python that would implement exactly the same (remote) interfaces as a program that runs on a robot. But instead of real motors, it would change the properties of objects in BGE in accordance with the commands coming through the network.
As a first step, we decided to make the simplest example possible, which shows:
- how to write and run an ice server written in python inside Blender?
- How to change the attributes of an object (for example, a position) when receiving information over a network?
To do this, I needed to make two Python files. The first is with the server code that will be launched inside Blender and the second is a client program that sends requests for changing the position to the server over the network. These two programs can be found on Github . Testblender.py is a server. It should be noted that it was necessary to start the server in a separate thread, as otherwise, while waiting for a message over the network, it blocked the Blender user interface and the change in the position of the object was not visually displayed. Client.py is a simple program sending 100 requests to change the position of the current (selected) object by moving it in a circle in the XZ plane. The following video shows how to start the server and client program and the result of work is an object moving in a circle.
After we learned how to manage objects inside Blender remotely (over the network), we plan to implement interfaces for controlling the robot inside BGE to control the model.
In fact, the described remote object management technique in Blender can be used for completely different applications. For example, to visualize data collected on another computer. Therefore, we hope that the simple example described above and this article will be interesting and useful for readers :-).