Fix T52833: OBJ triangulate doesn't match viewport
[blender-addons.git] / add_advanced_objects_menu / scene_objects_cycles.py
blob85e85867b0d7b0e8ee680b2c8c4eb5068580f4df
1 # gpl: author meta-androcto
3 import bpy
4 from bpy.types import Operator
7 class add_cycles_scene(Operator):
8 bl_idname = "objects_cycles.add_scene"
9 bl_label = "Create test scene"
10 bl_description = "Cycles renderer Scene with Objects"
11 bl_options = {'REGISTER'}
13 def execute(self, context):
14 try:
15 blend_data = context.blend_data
17 # add new scene
18 bpy.ops.scene.new(type="NEW")
19 scene = bpy.context.scene
20 bpy.context.scene.render.engine = 'CYCLES'
21 scene.name = "scene_object_cycles"
23 # render settings
24 render = scene.render
25 render.resolution_x = 1920
26 render.resolution_y = 1080
27 render.resolution_percentage = 50
29 # add new world
30 world = bpy.data.worlds.new("Cycles_Object_World")
31 scene.world = world
32 world.use_sky_blend = True
33 world.use_sky_paper = True
34 world.horizon_color = (0.004393, 0.02121, 0.050)
35 world.zenith_color = (0.03335, 0.227, 0.359)
36 world.light_settings.use_ambient_occlusion = True
37 world.light_settings.ao_factor = 0.25
39 # add camera
40 bpy.ops.object.camera_add(
41 location=(7.48113, -6.50764, 5.34367),
42 rotation=(1.109319, 0.010817, 0.814928)
44 cam = bpy.context.active_object.data
45 cam.lens = 35
46 cam.draw_size = 0.1
47 bpy.ops.view3d.viewnumpad(type='CAMERA')
49 # add point lamp
50 bpy.ops.object.lamp_add(
51 type="POINT", location=(4.07625, 1.00545, 5.90386),
52 rotation=(0.650328, 0.055217, 1.866391)
54 lamp1 = bpy.context.active_object.data
55 lamp1.name = "Point_Right"
56 lamp1.energy = 1.0
57 lamp1.distance = 30.0
58 lamp1.shadow_method = "RAY_SHADOW"
59 lamp1.use_sphere = True
61 # add point lamp2
62 bpy.ops.object.lamp_add(
63 type="POINT", location=(-0.57101, -4.24586, 5.53674),
64 rotation=(1.571, 0, 0.785)
66 lamp2 = bpy.context.active_object.data
67 lamp2.name = "Point_Left"
68 lamp2.energy = 1.0
69 lamp2.distance = 30.0
71 # Add cube
72 bpy.ops.mesh.primitive_cube_add()
73 bpy.ops.object.editmode_toggle()
74 bpy.ops.mesh.subdivide(number_cuts=2)
75 bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
76 bpy.ops.object.editmode_toggle()
77 cube = bpy.context.active_object
79 # add cube material
80 cubeMaterial = blend_data.materials.new("Cycles_Cube_Material")
81 bpy.ops.object.material_slot_add()
82 cube.material_slots[0].material = cubeMaterial
83 # Diffuse
84 cubeMaterial.preview_render_type = "CUBE"
85 cubeMaterial.diffuse_color = (1.000, 0.373, 0.00)
86 # Cycles
87 cubeMaterial.use_nodes = True
89 # Add monkey
90 bpy.ops.mesh.primitive_monkey_add(location=(-0.1, 0.08901, 1.505))
91 bpy.ops.transform.rotate(value=(1.15019), axis=(0, 0, 1))
92 bpy.ops.transform.rotate(value=(-0.673882), axis=(0, 1, 0))
93 bpy.ops.transform.rotate(value=-0.055, axis=(1, 0, 0))
95 bpy.ops.object.modifier_add(type='SUBSURF')
96 bpy.ops.object.shade_smooth()
97 monkey = bpy.context.active_object
99 # add monkey material
100 monkeyMaterial = blend_data.materials.new("Cycles_Monkey_Material")
101 bpy.ops.object.material_slot_add()
102 monkey.material_slots[0].material = monkeyMaterial
103 # Diffuse
104 monkeyMaterial.preview_render_type = "MONKEY"
105 monkeyMaterial.diffuse_color = (0.239, 0.288, 0.288)
106 # Cycles
107 monkeyMaterial.use_nodes = True
109 # Add plane
110 bpy.ops.mesh.primitive_plane_add(
111 radius=50, view_align=False,
112 enter_editmode=False, location=(0, 0, -1)
114 bpy.ops.object.editmode_toggle()
115 bpy.ops.transform.rotate(
116 value=-0.8, axis=(0, 0, 1),
117 constraint_axis=(False, False, True)
119 bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
120 bpy.ops.object.editmode_toggle()
121 plane = bpy.context.active_object
123 # add plane material
124 planeMaterial = blend_data.materials.new("Cycles_Plane_Material")
125 bpy.ops.object.material_slot_add()
126 plane.material_slots[0].material = planeMaterial
127 # Diffuse
128 planeMaterial.preview_render_type = "FLAT"
129 planeMaterial.diffuse_color = (0.2, 0.2, 0.2)
130 # Cycles
131 planeMaterial.use_nodes = True
133 except Exception as e:
134 self.report({'WARNING'},
135 "Some operations could not be performed (See Console for more info)")
137 print("\n[Add Advanced Objects]\nOperator: "
138 "objects_cycles.add_scene\nError: {}".format(e))
140 return {'CANCELLED'}
142 return {'FINISHED'}