I have a building model too detailed for my purposes. I basically have been taking screenshots of the model and using the screenshot as a texture for each side of the building. Is there a less hacky way to accomplish something like this? Is there a way to set up 4 cameras around the building and grab all my screenshot/textures at once?
-
1$\begingroup$ if you mean projecting various aspects of a high-resolution model to textures on a low-resolution model, is this not baking, one way or another? $\endgroup$– Robin Betts ♦Commented Jan 13, 2023 at 8:29
-
$\begingroup$ Kind of but I've never heard anyone use baking to describe what I'm trying to do $\endgroup$– Austin CapobiancoCommented Jan 13, 2023 at 9:55
-
$\begingroup$ The Hi-res model exists as geometry in your scene? You just want, say, its color, as a texture on a Lo-res model? $\endgroup$– Robin Betts ♦Commented Jan 13, 2023 at 10:32
-
$\begingroup$ Not quite. I also want a projection of some of the geometry $\endgroup$– Austin CapobiancoCommented Jan 13, 2023 at 13:33
-
1$\begingroup$ Like imagine there is a complex object with a bunch of overlapping pipes on the outside of a wall, then you take a picture of that object with a head-on direct angle. Then you turn that picture into a texture for a flat wall. $\endgroup$– Austin CapobiancoCommented Jan 16, 2023 at 18:12
1 Answer
You can use the following Python script. Copy and paste the script into the Text Editor
within the Scripting Tab. Make sure to change this line within the script:
scene.render.filepath = f'/path/to/your/file/{image_name}.png'
to the path where you want to save the generated image files. Select the object from which you want to obtain screenshots from each side and click Run Script.
import bpy
from math import radians
c = bpy.context
scene = c.scene
scene.frame_current = 1
scene.frame_set(1)
scene.render.image_settings.file_format = 'PNG'
def render_camera_at(x,y,z,image_name):
scene.camera.rotation_euler = radians(x), radians(y), radians(z)
bpy.ops.view3d.camera_to_view_selected()
scene.render.filepath = f'/path/to/your/file/{image_name}.png' # change this line, example f'C:/Users/somebody/Desktop/{image_name}.png'
bpy.ops.render.render(animation=False, write_still=True)
render_camera_at(90,0,0,"front")
render_camera_at(-90,180,0,"back")
render_camera_at(90,0,-90,"left")
render_camera_at(90,0,90,"right")
render_camera_at(0,0,0,"top")
This will automatically position your active camera to each side and render it. It will generate images with names front.png, back.png, left.png, right.png, top.png. Make sure there is a camera in the scene. It doesn't matter where or how it is positioned, the script will take care of that. And also make sure you have selected the house object before running the script.
-
2$\begingroup$ That works perfectly! Only thing I can't figure out is how to change the quality of the resulting images. I've looked here docs.blender.org/api/current/… and changed the
compression
andquality
properties ofscene.render.image_settings
, but there was no change to the resulting output images (although the script took longer to complete). Not a huge deal as I mainly needed this script for prototyping anyway, but it'd be nice to know how to improve the output quality just in case. $\endgroup$ Commented Jan 16, 2023 at 18:09 -
2$\begingroup$ +1 Very nice... just wondering, strictly, does the camera need to be orthographic? $\endgroup$– Robin Betts ♦Commented Jan 16, 2023 at 18:21
-
$\begingroup$ I just used the exact code except for the filepath, so whatever the default camera is I guess $\endgroup$ Commented Jan 16, 2023 at 20:45
-
$\begingroup$ nice thank you! double check if
type(scene.render.image_settings)
really outputsbpy.types.ImageFormatSettings
then100
should be maximum lossless compression` else it is a bug. can you share the PNG file output you got and explain what exactly in that file you think makes it not lossless? $\endgroup$– Harry McKenzie ♦Commented Jan 17, 2023 at 0:06