-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blender script for overlaying aligned mesh on input images #100
Comments
Using @gkioxari It would be immensely helpful if you could comment on a simple and correct way of adding a background image to blender scene and ensuring correct coordinates. I could not figure out how to resolve problems with environment texture and ended up using snippet that creates nodes. Another useful feature may be partial opacity of the rendered mesh in order to better check object boundaries alignment. def render(background_path, output_path):
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
links = tree.links
for node in tree.nodes:
tree.nodes.remove(node)
image_node = tree.nodes.new('CompositorNodeImage')
scale_node = tree.nodes.new('CompositorNodeScale')
alpha_over_node = tree.nodes.new('CompositorNodeAlphaOver')
render_layer_node = tree.nodes.new('CompositorNodeRLayers')
file_output_node = tree.nodes.new('CompositorNodeOutputFile')
#enum in [‘RELATIVE’, ‘ABSOLUTE’, ‘SCENE_SIZE’, ‘RENDER_SIZE’], default ‘RELATIVE’
scale_node.space = 'RENDER_SIZE'
image_node.image = bpy.data.images.load(background_path)
file_output_node.base_path = os.path.dirname(output_path)
file_output_node.file_slots[0].path = os.path.basename(output_path)
links.new(image_node.outputs[0], scale_node.inputs[0])
links.new(scale_node.outputs[0], alpha_over_node.inputs[1])
links.new(render_layer_node.outputs[0], alpha_over_node.inputs[2])
links.new(alpha_over_node.outputs[0], file_output_node.inputs[0])
bpy.ops.render.render(write_still = False)
ef unused_build_environment_texture_background(world, background_path, rotation = 0.0):
world.use_nodes = True
node_tree = world.node_tree
environment_texture_node = node_tree.nodes.new(type="ShaderNodeTexEnvironment")
environment_texture_node.image = bpy.data.images.load(background_path)
mapping_node = node_tree.nodes.new(type="ShaderNodeMapping")
mapping_node.inputs["Rotation"].default_value = (0.0, 0.0, rotation)
tex_coord_node = node_tree.nodes.new(type="ShaderNodeTexCoord")
node_tree.links.new(tex_coord_node.outputs["Generated"], mapping_node.inputs["Vector"])
node_tree.links.new(mapping_node.outputs["Vector"], environment_texture_node.inputs["Vector"])
node_tree.links.new(environment_texture_node.outputs["Color"], node_tree.nodes["Background"].inputs["Color"])
return environment_texture_node.image.size |
My current attempt (along with estimated rotation of 2D bounding box, the lower plane is considered fixed to XZ (?)): Still not sure if I got the depth / coordinates correctly My code is at https://gist.github.com/vadimkantorov/eb53ce740cb80c12444079875facff85 Would be glad to have any feedback on the code / rendering, this is my first use of blender. Thank you :) |
For the demo image My script is at https://gist.github.com/vadimkantorov/eb53ce740cb80c12444079875facff85 |
Hi @gkioxari!
Following #22, I tried to create a rendering Blender script myself: https://gist.github.com/vadimkantorov/eb53ce740cb80c12444079875facff85
From image
It renders
Since it's my first Blender use, it's mostly a combination of other code found online, so I don't understand everything perfectly. And the rendered image is quite noisy.
I would be very grateful if you could comment or provide feedback:
scene.render.resolution_x
to input image resolution?The text was updated successfully, but these errors were encountered: