Rendering¶
Need to introduce blender here
Building your environment¶
How to generate a database using blender¶
Regular sampling¶
Blender comes with its own python installation. Thus, we need to tell blender to use our virtualenv where the navigation toolbox is installed. To do we need to import the os module
import os
import tempfile
then activate the environment:
def activate_virtualenv(name):
"""Activate given virtualenv.
Virtualenv home folder is given by environment variable
``WORKON_HOME`` or ``~/Envs`.
"""
if 'WORKON_HOME' in os.environ:
home = os.environ['WORKON_HOME']
else:
home = os.path.expanduser(os.path.join('~', 'Envs'))
filepath = os.path.join(home, name, 'bin', 'activate_this.py')
with open(filepath, 'r') as f:
exec(f.read(), dict(__file__=filepath))
activate_virtualenv(environment_name)
Now, blender can import all modules used by the navigation toolbox.
import numpy as np # noqa: E402
from navipy.rendering.bee_sampling import BeeSampling # noqa: E402
With the toolbox at disposition we just need to configure the BeeSampling to render images on a regular 3D grid.
bee_samp = BeeSampling()
x = np.linspace(-25, 25, 201)
y = np.linspace(-25, 25, 201)
z = np.linspace(1.8, 1.8, 1)
alpha_1 = np.array([0]) + np.pi / 2
alpha_2 = np.array([0])
alpha_3 = np.array([0])
bee_samp.create_sampling_grid(
x, y, z, alpha1=alpha_1, alpha2=alpha_2, alpha3=alpha_3)
If we want to use the distance to objects, we need to tell the BeeSampling what is the maximum distance to objects in the environment. Otherwise the distance can go until infinity, and since the image are compressed in the database, all distance to object will be equal to zero:
world_dim = 50 * np.sqrt(2)
bee_samp.world_dim = world_dim
Finally we can generate the database.
with tempfile.TemporaryDirectory() as folder:
bee_samp.render(folder + '/database.db')
How to test the script:¶
>>> blender test.blend --background --python demo_test.py