Camera Cargo Lock
Since the beginning I’ve wanted an effect that would follow an item as it moved along the belts. This week I made that happen! 🥳
It’s actually quite simple how it works. When you tap an item on a belt the camera will “attach” to that item and follow it until it goes into a building and is removed from the game. That “attach” behavior is just a function called every frame that re-positions the camera to where the item is.
Improving Asset Automation
This week I also made a couple of improvements to the asset automation scripts in my last post. Even with the very few models currently in game it was painfully obvious that running the scripts on every model each time wasn’t ideal. When working on a single model I wanted to export and convert only that one.
To support this I modified the script to support optional input arguments. So by passing the path(s) of assets to the script it will only convert those. If no arguments are passed in it will convert all assets like before, e.g. $ scripts/convert-game-assets.py assets/models/copper_ore.blend
if len(sys.argv) > 1:
for path in sys.argv[1:]:
convert(path)
else:
convert_all_models()
Thumbnail Creation
While continuing work on the scripts I added the ability to render thumbnails of each model so they can be used in the UI.
It wasn’t easy to find anything online that did exactly what I wanted so had to figure this out by reading the API. Earlier examples from pre-2.8 didn’t always work since the API changed a bit. In case any readers are Blender Python API experts here’s what I did to get a simple render of the model. Please let me know if there is a better way :)
def add_light(location):
data = bpy.data.lights.new(name='light', type='POINT')
data.energy = 2000
light = bpy.data.objects.new('light', data)
light.location = location
bpy.context.collection.objects.link(light)
def add_camera(location, rotation):
data = bpy.data.cameras.new('Camera')
camera = bpy.data.objects.new('Camera', data)
camera.location = location
camera.rotation_euler = rotation
bpy.context.collection.objects.link(camera)
return camera
add_light(location=(4, 1, 6))
add_light(location=(-2.5, -7, 6))
camera = add_camera(location=(7, -6.7, 5.7), rotation=(1.117, 0, 0.785))
scene = bpy.context.scene
scene.camera = camera
# reselect only exported objects and position the camera to fit
for obj in bpy.context.selected_objects:
obj.select_set(False)
for obj in exported_objects:
obj.select_set(True)
bpy.ops.view3d.camera_to_view_selected()
# Enable ambient occlusion
scene.eevee.use_gtao = True
scene.render.resolution_x = 512
scene.render.resolution_y = 512
scene.render.filepath = '${}/{}.png'.format(output_path, model_name)
scene.render.film_transparent = True
bpy.ops.render.render(write_still=True)
As you can see some of them aren’t perfect, but for now that’ll do just fine.
Follow and Subscribe 👍
This journey is just beginning. If you like what you read I’ll be posting more of it, hopefully weekly. Currently on twitter and instagram sharing images and videos from development. Reach out via email or come join discord!
Twitter @builderment
Instagram @builderment
Discord https://discord.gg/VkH4Nq3
Email contact@builderment.com