Spaces:
Sleeping
Sleeping
| import bpy | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def setup_3d_scene(img_path, depth_path, out_path, strength=1.5): | |
| # Nettoyage | |
| bpy.ops.wm.read_factory_settings(use_empty=True) | |
| # 1. Plane | |
| bpy.ops.mesh.primitive_plane_add(size=10) | |
| plane = bpy.context.object | |
| plane.rotation_euler[0] = 1.5708 # 90 degrees on X (Vertical) | |
| # 2. Subdivision | |
| subdiv = plane.modifiers.new(name="Subdiv", type='SUBSURF') | |
| subdiv.subdivision_type = 'SIMPLE' | |
| subdiv.levels = 4 | |
| subdiv.render_levels = 6 | |
| # 3. Displace | |
| tex = bpy.data.textures.new('DepthTex', type='IMAGE') | |
| tex.image = bpy.data.images.load(depth_path) | |
| disp = plane.modifiers.new("Displace", type='DISPLACE') | |
| disp.texture = tex | |
| disp.strength = strength | |
| # 4. Material | |
| mat = bpy.data.materials.new(name="DarkMediaMat") | |
| mat.use_nodes = True | |
| nodes = mat.node_tree.nodes | |
| links = mat.node_tree.links | |
| nodes.clear() | |
| node_tex = nodes.new('ShaderNodeTexImage') | |
| node_tex.image = bpy.data.images.load(img_path) | |
| node_bsdf = nodes.new('ShaderNodeBsdfPrincipled') | |
| node_out = nodes.new('ShaderNodeOutputMaterial') | |
| links.new(node_tex.outputs['Color'], node_bsdf.inputs['Base Color']) | |
| links.new(node_bsdf.outputs['BSDF'], node_out.inputs['Surface']) | |
| plane.data.materials.append(mat) | |
| # 5. Camera & Light | |
| bpy.ops.object.camera_add(location=(0, -20, 0), rotation=(1.5708, 0, 0)) | |
| bpy.context.scene.camera = bpy.context.object | |
| bpy.ops.object.light_add(type='SUN', location=(5, -15, 10)) | |
| # 6. Render Settings | |
| scene = bpy.context.scene | |
| scene.render.resolution_x = 1080 | |
| scene.render.resolution_y = 1920 | |
| scene.render.filepath = out_path | |
| bpy.ops.render.render(write_still=True) | |
| if __name__ == "__main__": | |
| argv = sys.argv | |
| if "--" in argv: | |
| argv = argv[argv.index("--") + 1:] | |
| setup_3d_scene(argv[0], argv[1], argv[2]) | |