This script must have a cube object to start with. This object is duplicated and assigned random material.
-------------------------------------------------------------------------------------------------------------------------------------------------------
import bpy
from random import randint
import random
number=100
#TO DELETE ALL EXISTING OBJECTS
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete(use_global=False)
#TO ADD CAMERA
bpy.ops.object.camera_add(view_align=True, location=(0,-45,0), rotation=(1.5708,0,0))
bpy.ops.transform.resize(value=(9.42627, 9.42627, 9.42627))
#TO ADD BG PLANE
bpy.ops.mesh.primitive_plane_add( location=(0,10,0))
bpy.ops.transform.resize(value=(10, 10, 10))
bpy.ops.transform.rotate(value=-1.55203, axis=(-1, 0,0))
bpy.ops.transform.resize(value=(2,2,2))
#TO ADD MATERIAL TO PLANE
obj_matl=bpy.data.materials.new("obj_clr")
obj_matl.diffuse_color=(0,0.9,0.8)
mesh=bpy.context.object.data
mesh.materials.clear()
mesh.materials.append(obj_matl)
#TO CREATE MULTIPLE TORUS AND ASSIGN MATERIAL
for i in range(0,number):
x=randint(-10,10)
y=randint(-5,5)
z=randint(-10,10)
p=randint(1,10)
bpy.ops.mesh.primitive_cube_add(location=(x,y,z))
bpy.ops.transform.resize(value=(p*0.1,p*0.1,p*0.1))
bpy.ops.transform.rotate(value=1.5708, axis=(1, 1, 0))
p=randint(0,9)
#print(p)
obj_matl=bpy.data.materials.new("obj_clr")
obj_matl.diffuse_color=(0.8,p*0.3,0)
mesh=bpy.context.object.data
mesh.materials.clear()
mesh.materials.append(obj_matl)
--------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment