Fix T52833: OBJ triangulate doesn't match viewport
[blender-addons.git] / add_advanced_objects_menu / scene_objects_bi.py
blobf189bb1189b9580c8807031a3e84ad9be78af24c
1 # gpl: author meta-androcto
3 import bpy
4 from bpy.types import Operator
7 class add_BI_scene(Operator):
8 bl_idname = "bi.add_scene"
9 bl_label = "Create test scene"
10 bl_description = "Blender Internal renderer Scene with Objects"
11 bl_options = {'REGISTER', 'UNDO'}
13 def execute(self, context):
14 try:
15 blend_data = context.blend_data
16 # ob = bpy.context.active_object
18 # add new scene
19 bpy.ops.scene.new(type="NEW")
20 scene = bpy.context.scene
21 scene.name = "scene_materials"
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("Materials_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()
78 cube = bpy.context.active_object
79 # add new material
80 cubeMaterial = blend_data.materials.new("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 cubeMaterial.diffuse_shader = 'OREN_NAYAR'
87 cubeMaterial.diffuse_intensity = 1.0
88 cubeMaterial.roughness = 0.09002
89 # Specular
90 cubeMaterial.specular_color = (1.000, 0.800, 0.136)
91 cubeMaterial.specular_shader = "PHONG"
92 cubeMaterial.specular_intensity = 1.0
93 cubeMaterial.specular_hardness = 511.0
94 # Shading
95 cubeMaterial.ambient = 1.00
96 cubeMaterial.use_cubic = False
97 # Transparency
98 cubeMaterial.use_transparency = False
99 cubeMaterial.alpha = 0
100 # Mirror
101 cubeMaterial.raytrace_mirror.use = True
102 cubeMaterial.mirror_color = (1.000, 0.793, 0.0)
103 cubeMaterial.raytrace_mirror.reflect_factor = 0.394
104 cubeMaterial.raytrace_mirror.fresnel = 2.0
105 cubeMaterial.raytrace_mirror.fresnel_factor = 1.641
106 cubeMaterial.raytrace_mirror.fade_to = "FADE_TO_SKY"
107 cubeMaterial.raytrace_mirror.gloss_anisotropic = 1.0
108 # Shadow
109 cubeMaterial.use_transparent_shadows = True
111 # Add a texture
112 cubetex = blend_data.textures.new("CloudTex", type='CLOUDS')
113 cubetex.noise_type = 'SOFT_NOISE'
114 cubetex.noise_scale = 0.25
115 mtex = cubeMaterial.texture_slots.add()
116 mtex.texture = cubetex
117 mtex.texture_coords = 'ORCO'
118 mtex.scale = (0.800, 0.800, 0.800)
119 mtex.use_map_mirror = True
120 mtex.mirror_factor = 0.156
121 mtex.use_map_color_diffuse = True
122 mtex.diffuse_color_factor = 0.156
123 mtex.use_map_normal = True
124 mtex.normal_factor = 0.010
125 mtex.blend_type = "ADD"
126 mtex.use_rgb_to_intensity = True
127 mtex.color = (1.000, 0.207, 0.000)
129 # Add monkey
130 bpy.ops.mesh.primitive_monkey_add(location=(-0.1, 0.08901, 1.505))
131 bpy.ops.transform.rotate(value=(1.15019), axis=(0, 0, 1))
132 bpy.ops.transform.rotate(value=(-0.673882), axis=(0, 1, 0))
133 bpy.ops.transform.rotate(value=-0.055, axis=(1, 0, 0))
134 bpy.ops.object.modifier_add(type='SUBSURF')
135 bpy.ops.object.shade_smooth()
136 monkey = bpy.context.active_object
137 # add new material
138 monkeyMaterial = blend_data.materials.new("Monkey_Material")
139 bpy.ops.object.material_slot_add()
140 monkey.material_slots[0].material = monkeyMaterial
141 # Material settings
142 monkeyMaterial.preview_render_type = "MONKEY"
143 monkeyMaterial.diffuse_color = (0.239, 0.288, 0.288)
144 monkeyMaterial.specular_color = (0.604, 0.465, 0.136)
145 monkeyMaterial.diffuse_shader = 'LAMBERT'
146 monkeyMaterial.diffuse_intensity = 1.0
147 monkeyMaterial.specular_intensity = 0.3
148 monkeyMaterial.ambient = 0
149 monkeyMaterial.type = 'SURFACE'
150 monkeyMaterial.use_cubic = True
151 monkeyMaterial.use_transparency = False
152 monkeyMaterial.alpha = 0
153 monkeyMaterial.use_transparent_shadows = True
154 monkeyMaterial.raytrace_mirror.use = True
155 monkeyMaterial.raytrace_mirror.reflect_factor = 0.65
156 monkeyMaterial.raytrace_mirror.fade_to = "FADE_TO_MATERIAL"
158 # Add plane
159 bpy.ops.mesh.primitive_plane_add(
160 radius=50, view_align=False, enter_editmode=False, location=(0, 0, -1)
162 bpy.ops.object.editmode_toggle()
163 bpy.ops.transform.rotate(
164 value=-0.8, axis=(0, 0, 1), constraint_axis=(False, False, True),
165 constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED',
166 proportional_edit_falloff='SMOOTH', proportional_size=1
168 bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
169 bpy.ops.object.editmode_toggle()
170 plane = bpy.context.active_object
171 # add new material
172 planeMaterial = blend_data.materials.new("Plane_Material")
173 bpy.ops.object.material_slot_add()
174 plane.material_slots[0].material = planeMaterial
175 # Material settings
176 planeMaterial.preview_render_type = "CUBE"
177 planeMaterial.diffuse_color = (0.2, 0.2, 0.2)
178 planeMaterial.specular_color = (0.604, 0.465, 0.136)
179 planeMaterial.specular_intensity = 0.3
180 planeMaterial.ambient = 0
181 planeMaterial.use_cubic = True
182 planeMaterial.use_transparency = False
183 planeMaterial.alpha = 0
184 planeMaterial.use_transparent_shadows = True
186 except Exception as e:
187 self.report({'WARNING'},
188 "Some operations could not be performed (See Console for more info)")
190 print("\n[Add Advanced Objects]\nOperator: "
191 "bi.add_scene\nError: {}".format(e))
193 return {'CANCELLED'}
195 return {"FINISHED"}