...
 
Commits (79)
This diff is collapsed.
# gpl: author Rebellion
import bpy
from bpy.types import Operator
from bpy.props import BoolProperty
def add_lights(self, context):
if self.bKeyLight:
keyLight = bpy.data.lights.new(name="Key_Light", type="SPOT")
ob = bpy.data.objects.new("Key_Light", keyLight)
constraint = ob.constraints.new(type='COPY_LOCATION')
constraint.use_offset = True
constraint.owner_space = 'LOCAL'
constraint.target = self.camera
constraint = ob.constraints.new(type='TRACK_TO')
constraint.target = self.target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_X'
constraint.owner_space = 'LOCAL'
bpy.context.collection.objects.link(ob)
ob.rotation_euler[2] = -0.785398
if self.bFillLight:
fillLight = bpy.data.lights.new(name="Fill_Light", type="SPOT")
ob = bpy.data.objects.new("Fill_Light", fillLight)
constraint = ob.constraints.new(type='COPY_LOCATION')
constraint.use_offset = True
constraint.owner_space = 'LOCAL'
constraint.target = self.camera
constraint = ob.constraints.new(type='TRACK_TO')
constraint.target = self.target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_X'
constraint.owner_space = 'LOCAL'
bpy.context.collection.objects.link(ob)
ob.rotation_euler[2] = 0.785398
ob.data.energy = 0.3
if self.bBackLight:
backLight = bpy.data.lights.new(name="Back_Light", type="SPOT")
ob = bpy.data.objects.new("Back_Light", backLight)
constraint = ob.constraints.new(type='COPY_LOCATION')
constraint.use_offset = True
constraint.owner_space = 'LOCAL'
constraint.target = self.camera
constraint = ob.constraints.new(type='TRACK_TO')
constraint.target = self.target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_X'
constraint.owner_space = 'LOCAL'
bpy.context.collection.objects.link(ob)
ob.rotation_euler[2] = 3.14159
ob.data.energy = 0.2
if self.camera_constraint and self.camera is not None and \
self.camera.type == "CAMERA":
constraint = self.camera.constraints.new(type='TRACK_TO')
constraint.target = self.target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_Y'
class OBJECT_OT_add_light_template(Operator):
bl_idname = "object.add_light_template"
bl_label = "Add Light Template"
bl_description = ("Add Key, Fill and Back Lights to the Scene\n"
"Needs an existing Active Object")
bl_options = {'REGISTER', 'UNDO'}
camera = None
target = None
bKeyLight: BoolProperty(
name="Key Light",
description="Enable Key Light in the Scene",
default=True
)
bFillLight: BoolProperty(
name="Fill Light",
description="Enable Fill Light in the Scene",
default=True
)
bBackLight: BoolProperty(
name="Back Light",
description="Enable Back Light in the Scene",
default=True
)
camera_constraint: BoolProperty(
name="Camera Constraint",
description="Add a Constraint to the Camera Object",
default=False
)
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
try:
objects = context.selected_objects
if len(objects) == 2:
for ob in objects:
if ob.type == 'CAMERA':
self.camera = ob
else:
self.target = ob
elif len(objects) == 1:
if objects[0].type == 'CAMERA':
self.camera = objects[0]
bpy.ops.object.empty_add()
self.target = context.active_object
else:
self.camera = context.scene.camera
self.target = context.active_object
elif len(objects) == 0:
bpy.ops.object.empty_add()
self.target = context.active_object
self.camera = context.scene.camera
add_lights(self, context)
except Exception as e:
self.report({'WARNING'},
"Some operations could not be performed (See Console for more info)")
print("\n[Add Advanced Objects]\nOperator: "
"object.add_light_template\nError: {}".format(e))
return {'FINISHED'}
def register():
bpy.utils.register_class(OBJECT_OT_add_light_template)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_add_light_template)
if __name__ == "__main__":
register()
This diff is collapsed.
This diff is collapsed.
# gpl author: Antonis Karvelas
# -*- coding: utf-8 -*-
bl_info = {
"name": "Circle Array",
"author": "Antonis Karvelas",
"version": (1, 0, 1),
"blender": (2, 67, 0),
"location": "View3D > Object > Circle_Array",
"description": "Uses an existing array and creates an empty, "
"rotates it properly and makes a Circle Array",
"warning": "",
"wiki_url": "",
"category": "Mesh"
}
import bpy
from bpy.types import Operator
from math import radians
class Circle_Array(Operator):
bl_label = "Circle Array"
bl_idname = "objects.circle_array_operator"
bl_description = ("Creates an Array Modifier with offset empty object\n"
"Works with Mesh, Curve, Text and Surface\n"
"Use an object with an existing Array modifier\n"
"or rotate the newly created Empty with the name pattern\n"
"EMPTY_C_Array_ if the Array doesn't exist (angle: 360/Count)")
@classmethod
def poll(cls, context):
return context.active_object is not None
def check_empty_name(self, context):
new_name, def_name = "", "EMPTY_C_Array"
suffix = 1
try:
# first slap a simple linear count + 1 for numeric suffix, if it fails
# harvest for the rightmost numbers and append the max value
list_obj = []
obj_all = context.scene.objects
list_obj = [obj.name for obj in obj_all if obj.name.startswith(def_name)]
new_name = "{}_{}".format(def_name, len(list_obj) + 1)
if new_name in list_obj:
from re import findall
test_num = [findall("\d+", words) for words in list_obj]
suffix += max([int(l[-1]) for l in test_num])
new_name = "{}_{}".format(def_name, suffix)
return new_name
except:
return None
def execute(self, context):
is_allowed = True
try:
allowed_obj = ['MESH', 'CURVE', 'SURFACE', 'FONT']
for obj in context.selected_objects:
if obj.type not in allowed_obj:
is_allowed = False
break
if not is_allowed:
self.report(
{"WARNING"},
"The Active/Selected objects are not of "
"Mesh, Curve, Surface or Font type. Operation Cancelled"
)
return {'CANCELLED'}
default_name = self.check_empty_name(context) or "EMPTY_C_Array"
bpy.ops.object.modifier_add(type='ARRAY')
if len(context.selected_objects) == 2:
selected = context.selected_objects
lists = [obj for obj in selected if obj != context.active_object]
active = lists[0]
# check if the list object has a modifier
check_mod = None
for mod in active.modifiers[:]:
if mod.type == "ARRAY":
check_mod = mod
break
if check_mod:
check_mod.use_object_offset = True
check_mod.use_relative_offset = False
else:
# fallback
bpy.context.view_layer.objects.active = active
bpy.ops.object.modifier_add(type='ARRAY')
active.modifiers[0].use_object_offset = True
active.modifiers[0].use_relative_offset = False
active.modifiers[0].use_object_offset = True
active.modifiers[0].use_relative_offset = False
active.select_set(False)
bpy.context.view_layer.objects.active = context.active_object
bpy.ops.view3d.snap_cursor_to_selected()
if active.modifiers[0].offset_object is None:
bpy.ops.object.add(type='EMPTY')
empty_name = bpy.context.active_object
empty_name.name = default_name
active.modifiers[0].offset_object = empty_name
else:
empty_name = active.modifiers[0].offset_object
bpy.context.view_layer.objects.active = active
num = active.modifiers["Array"].count
rotate_num = 360 / num
active.select_set(True)
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
empty_name.rotation_euler = (0, 0, radians(rotate_num))
empty_name.select_set(False)
active.select_set(True)
bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
return {'FINISHED'}
else:
active = context.active_object
active.modifiers[0].use_object_offset = True
active.modifiers[0].use_relative_offset = False
bpy.ops.view3d.snap_cursor_to_selected()
if active.modifiers[0].offset_object is None:
bpy.ops.object.add(type='EMPTY')
empty_name = bpy.context.active_object
empty_name.name = default_name
active.modifiers[0].offset_object = empty_name
else:
empty_name = active.modifiers[0].offset_object
bpy.context.view_layer.objects.active = active
num = active.modifiers["Array"].count
rotate_num = 360 / num
active.select_set(True)
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
empty_name.rotation_euler = (0, 0, radians(rotate_num))
empty_name.select_set(False)
active.select_set(True)
return {'FINISHED'}
except Exception as e:
self.report({'WARNING'},
"Circle Array operator could not be executed (See the console for more info)")
print("\n[objects.circle_array_operator]\nError: {}\n".format(e))
return {'CANCELLED'}
# Register
def register():
bpy.utils.register_class(Circle_Array)
def unregister():
bpy.utils.unregister_class(Circle_Array)
if __name__ == "__main__":
register()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Add Chain",
"author": "Brian Hinton (Nichod)",
"version": (0, 1, 2),
"blender": (2, 71, 0),
"location": "Toolshelf > Create Tab",
"description": "Adds Chain with curve guide for easy creation",
"warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Object/Add_Chain",
"category": "Object",
}
import bpy
from bpy.types import Operator
def Add_Chain():
# Adds Empty to scene
bpy.ops.object.add(
type='EMPTY',
view_align=False,
enter_editmode=False,
location=(0, 0, 0),
rotation=(0, 0, 0),
)
# Changes name of Empty to rot_link adds variable emp
emp = bpy.context.object
emp.name = "rot_link"
# Rotate emp ~ 90 degrees
emp.rotation_euler = [1.570796, 0, 0]
# Adds Curve Path to scene
bpy.ops.curve.primitive_nurbs_path_add(
view_align=False,
enter_editmode=False,
location=(0, 0, 0),
rotation=(0, 0, 0),
)
# Change Curve name to deform adds variable curv
curv = bpy.context.object
curv.name = "deform"
# Inserts Torus primitive
bpy.ops.mesh.primitive_torus_add(
major_radius=1,
minor_radius=0.25,
major_segments=12,
minor_segments=4,
abso_major_rad=1,
abso_minor_rad=0.5,
)
# Positions Torus primitive to center of scene
bpy.context.active_object.location = 0.0, 0.0, 0.0
# Resetting Torus rotation in case of 'Align to view' option enabled
bpy.context.active_object.rotation_euler = 0.0, 0.0, 0.0
# Changes Torus name to chain adds variable tor
tor = bpy.context.object
tor.name = "chain"
# Adds Array Modifier to tor
bpy.ops.object.modifier_add(type='ARRAY')
# Adds subsurf modifier tor
bpy.ops.object.modifier_add(type='SUBSURF')
# Smooths tor
bpy.ops.object.shade_smooth()
# Select curv
sce = bpy.context.scene
sce.objects.active = curv
# Toggle into editmode
bpy.ops.object.editmode_toggle()
# TODO, may be better to move objects directly
# Translate curve object
bpy.ops.transform.translate(
value=(2, 0, 0),
constraint_axis=(True, False, False),
orient_type='GLOBAL',
mirror=False,
proportional='DISABLED',
proportional_edit_falloff='SMOOTH',
proportional_size=1,
snap=False,
snap_target='CLOSEST',
snap_point=(0, 0, 0),
snap_align=False,
snap_normal=(0, 0, 0),
release_confirm=False,
)
# Toggle into objectmode
bpy.ops.object.editmode_toggle()
# Select tor or chain
sce.objects.active = tor
# Selects Array Modifier for editing
array = tor.modifiers['Array']
# Change Array Modifier Parameters
array.fit_type = 'FIT_CURVE'
array.curve = curv
array.offset_object = emp
array.use_object_offset = True
array.relative_offset_displace = 0.549, 0.0, 0.0
# Add curve modifier
bpy.ops.object.modifier_add(type='CURVE')
# Selects Curve Modifier for editing
cur = tor.modifiers['Curve']
# Change Curve Modifier Parameters
cur.object = curv
class AddChain(Operator):
bl_idname = "mesh.primitive_chain_add"
bl_label = "Add Chain"
bl_description = ("Create a Chain segment with helper objects controlling modifiers:\n"
"1) A Curve Modifier Object (deform) for the length and shape,\n"
"Edit the Path to extend Chain Length\n"
"2) An Empty (rot_link) as an Array Offset for rotation")
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
try:
Add_Chain()
except Exception as e:
self.report({'WARNING'},
"Some operations could not be performed (See Console for more info)")
print("\n[Add Advanced Objects]\nOperator: "
"mesh.primitive_chain_add\nError: {}".format(e))
return {'CANCELLED'}
return {'FINISHED'}
def register():
bpy.utils.register_class(AddChain)
def unregister():
bpy.utils.unregister_class(AddChain)
if __name__ == "__main__":
register()
This diff is collapsed.
# gpl author: liero
# very simple 'pixelization' or 'voxelization' engine #
bl_info = {
"name": "3D Pixelate",
"author": "liero",
"version": (0, 5, 3),
"blender": (2, 74, 0),
"location": "View3D > Tool Shelf",
"description": "Creates a 3d pixelated version of the object",
"category": "Object"}
# Note: winmgr properties are moved to the operator
import bpy
from bpy.types import Operator
from bpy.props import (
FloatProperty,
IntProperty,
)
def pix(self, obj):
sce = bpy.context.scene
obj.hide = obj.hide_render = True
mes = obj.to_mesh(sce, True, 'RENDER')
mes.transform(obj.matrix_world)
dup = bpy.data.objects.new('dup', mes)
sce.objects.link(dup)
dup.instance_type = 'VERTS'
sce.objects.active = dup
bpy.ops.object.mode_set()
ver = mes.vertices
for i in range(250):
fin = True
for i in dup.data.edges:
d = ver[i.vertices[0]].co - ver[i.vertices[1]].co
if d.length > self.size:
ver[i.vertices[0]].select = True
ver[i.vertices[1]].select = True
fin = False
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.subdivide(number_cuts=1, smoothness=self.smooth)
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.editmode_toggle()
if fin:
break
for i in ver:
for n in range(3):
i.co[n] -= (.001 + i.co[n]) % self.size
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles(threshold=0.0001)
bpy.ops.mesh.delete(type='EDGE_FACE')
bpy.ops.object.mode_set()
sca = self.size * (100 - self.gap) * .005
bpy.ops.mesh.primitive_cube_add(layers=[True] + [False] * 19)
bpy.ops.transform.resize(value=[sca] * 3)
bpy.context.view_layer.objects.active = dup
bpy.ops.object.parent_set(type='OBJECT')
class Pixelate(Operator):
bl_idname = "object.pixelate"
bl_label = "Pixelate Object"
bl_description = ("Create a 3d pixelated version of the object\n"
"using a Duplivert Box around each copied vertex\n"
"With high poly objects, it can take some time\n"
"Needs an existing Active Mesh Object")
bl_options = {'REGISTER', 'UNDO'}
size: FloatProperty(
name="Size",
min=.05, max=5,
default=.25,
description="Size of the cube / grid \n"
"Small values (below 0.1) can create a high polygon count"
)
gap: IntProperty(
name="Gap",
min=0, max=90,
default=10,
subtype='PERCENTAGE',
description="Separation - percent of size"
)
smooth: FloatProperty(
name="Smooth",
min=0, max=1,
default=.0,
description="Smooth factor when subdividing mesh"
)
@classmethod
def poll(cls, context):
return (context.active_object and
context.active_object.type == 'MESH' and
context.mode == 'OBJECT')
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.prop(self, "size")
col.prop(self, "gap")
layout.prop(self, "smooth")
def execute(self, context):
objeto = bpy.context.object
try:
pix(self, objeto)
except Exception as e:
self.report({'WARNING'},
"Some operations could not be performed (See Console for more info)")
print("\n[Add Advanced Objects]\nOperator: "
"object.pixelate\nError: {}".format(e))
return {'CANCELLED'}
return {'FINISHED'}
def register():
bpy.utils.register_class(Pixelate)
def unregister():
bpy.utils.unregister_class(Pixelate)
if __name__ == '__main__':
register()
# gpl: author Dannyboy
bl_info = {
"name": "Add Random Box Structure",
"author": "Dannyboy",
"version": (1, 0, 1),
"location": "View3D > Add > Make Box Structure",
"description": "Fill selected box shaped meshes with randomly sized cubes",
"warning": "",
"wiki_url": "",
"tracker_url": "dannyboypython.blogspot.com",
"category": "Object"}
import bpy
import random
from bpy.types import Operator
from bpy.props import (
BoolProperty,
FloatProperty,
FloatVectorProperty,
IntProperty,
)
class makestructure(Operator):
bl_idname = "object.make_structure"
bl_label = "Add Random Box Structure"
bl_description = ("Create a randomized structure made of boxes\n"
"with various control parameters\n"
"Needs an existing Active Mesh Object")
bl_options = {'REGISTER', 'UNDO'}
dc: BoolProperty(
name="Delete Base Mesh(es)",
default=True
)
wh: BoolProperty(
name="Stay Within Bounds",
description="Keeps cubes from exceeding base mesh bounds",
default=True
)
uf: BoolProperty(
name="Uniform Cube Quantity",
default=False
)
qn: IntProperty(
name="Cube Quantity",
default=10,
min=1, max=1500
)
mn: FloatVectorProperty(
name="Min Scales",
default=(0.1, 0.1, 0.1),
subtype='XYZ'
)
mx: FloatVectorProperty(
name="Max Scales",
default=(2.0, 2.0, 2.0),
subtype='XYZ'
)
lo: FloatVectorProperty(
name="XYZ Offset",
default=(0.0, 0.0, 0.0),
subtype='XYZ'
)
rsd: FloatProperty(
name="Random Seed",
default=1
)
@classmethod
def poll(cls, context):
obj = context.active_object
return obj is not None and obj.type == "MESH" and obj.mode == "OBJECT"
def draw(self, context):
layout = self.layout
box = layout.box()
box.label(text="Options:")
box.prop(self, "dc")
box.prop(self, "wh")
box.prop(self, "uf")
box = layout.box()
box.label(text="Parameters:")
box.prop(self, "qn")
box.prop(self, "mn")
box.prop(self, "mx")
box.prop(self, "lo")
box.prop(self, "rsd")
def execute(self, context):
rsdchange = self.rsd
oblst = []
uvyes = 0
bpy.ops.collection.create(name='Cubagrouper')
bpy.ops.collection.objects_remove()
for ob in bpy.context.selected_objects:
oblst.append(ob)
for obj in oblst:
bpy.ops.object.select_pattern(pattern=obj.name) # Select base mesh
bpy.context.view_layer.objects.active = obj
if obj.data.uv_layers[:] != []:
uvyes = 1
else:
uvyes = 0
bpy.ops.object.collection_link(group='Cubagrouper')
dim = obj.dimensions
rot = obj.rotation_euler
if self.uf is True:
area = dim.x * dim.y * dim.z
else:
area = 75
for cube in range(round((area / 75) * self.qn)):
random.seed(rsdchange)
pmn = self.mn # Proxy values
pmx = self.mx
if self.wh is True:
if dim.x < pmx.x: # Keeping things from exceeding proper size
pmx.x = dim.x
if dim.y < pmx.y:
pmx.y = dim.y
if dim.z < pmx.z:
pmx.z = dim.z
if 0.0 > pmn.x: # Keeping things from going under zero
pmn.x = 0.0
if 0.0 > pmn.y:
pmn.y = 0.0
if 0.0 > pmn.z:
pmn.z = 0.0
sx = (random.random() * (pmx.x - pmn.x)) + pmn.x # Just changed self.mx and .mn to pmx.
sy = (random.random() * (pmx.y - pmn.y)) + pmn.y
sz = (random.random() * (pmx.z - pmn.z)) + pmn.z
if self.wh is True: # This keeps the cubes within the base mesh
ex = (random.random() * (dim.x - sx)) - ((dim.x - sx) / 2) + obj.location.x
wy = (random.random() * (dim.y - sy)) - ((dim.y - sy) / 2) + obj.location.y
ze = (random.random() * (dim.z - sz)) - ((dim.z - sz) / 2) + obj.location.z
elif self.wh is False:
ex = (random.random() * dim.x) - (dim.x / 2) + obj.location.x
wy = (random.random() * dim.y) - (dim.y / 2) + obj.location.y
ze = (random.random() * dim.z) - (dim.z / 2) + obj.location.z
bpy.ops.mesh.primitive_cube_add(
radius=0.5, location=(ex + self.lo.x, wy + self.lo.y, ze + self.lo.z)
)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(
value=(sx, sy, sz), constraint_axis=(True, True, True),
orient_type='GLOBAL', mirror=False, proportional='DISABLED',
proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True
)
bpy.ops.object.mode_set(mode='OBJECT')
select = bpy.context.object # This is used to keep something selected for poll()
bpy.ops.object.collection_link(group='Cubagrouper')
rsdchange += 3
bpy.ops.object.select_grouped(type='GROUP')
bpy.ops.transform.rotate(
value=rot[0], axis=(1, 0, 0), constraint_axis=(False, False, False),
orient_type='GLOBAL', mirror=False, proportional='DISABLED',
proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True
)
bpy.ops.transform.rotate(
value=rot[1], axis=(0, 1, 0), constraint_axis=(False, False, False),
orient_type='GLOBAL', mirror=False, proportional='DISABLED',
proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True
)
bpy.ops.transform.rotate(
value=rot[2], axis=(0, 0, 1), constraint_axis=(False, False, False),
orient_type='GLOBAL', mirror=False, proportional='DISABLED',
proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True
)
bpy.context.view_layer.objects.active = obj # Again needed to avoid poll() taking me down
bpy.ops.object.make_links_data(type='MODIFIERS')
bpy.ops.object.make_links_data(type='MATERIAL')
if uvyes == 1:
bpy.ops.object.join_uvs()
bpy.ops.collection.objects_remove()
bpy.context.view_layer.objects.active = select
if self.dc is True:
bpy.context.collection.objects.unlink(obj)
return {'FINISHED'}
def register():
bpy.utils.register_class(makestructure)
def unregister():
bpy.utils.unregister_class(makestructure)
if __name__ == "__main__":
register()
This diff is collapsed.
# gpl: author meta-androcto
import bpy
from bpy.types import Operator
class add_BI_scene(Operator):
bl_idname = "bi.add_scene"
bl_label = "Create test scene"
bl_description = "Blender Internal renderer Scene with Objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
try:
blend_data = context.blend_data
# ob = bpy.context.active_object
# add new scene
bpy.ops.scene.new(type="NEW")
scene = bpy.context.scene
scene.name = "scene_materials"
# render settings
render = scene.render
render.resolution_x = 1920
render.resolution_y = 1080
render.resolution_percentage = 50
# add new world
world = bpy.data.worlds.new("Materials_World")
scene.world = world
world.use_sky_blend = True
world.use_sky_paper = True
world.horizon_color = (0.004393, 0.02121, 0.050)
world.zenith_color = (0.03335, 0.227, 0.359)
world.light_settings.use_ambient_occlusion = True
world.light_settings.ao_factor = 0.25
# add camera
bpy.ops.object.camera_add(
location=(7.48113, -6.50764, 5.34367),
rotation=(1.109319, 0.010817, 0.814928)
)
cam = bpy.context.active_object.data
cam.lens = 35
cam.display_size = 0.1
bpy.ops.view3d.viewnumpad(type='CAMERA')
# add point lamp
bpy.ops.object.light_add(
type="POINT", location=(4.07625, 1.00545, 5.90386),
rotation=(0.650328, 0.055217, 1.866391)
)
lamp1 = bpy.context.active_object.data
lamp1.name = "Point_Right"
lamp1.energy = 1.0
lamp1.distance = 30.0
lamp1.shadow_method = "RAY_SHADOW"
lamp1.use_sphere = True
# add point lamp2
bpy.ops.object.light_add(
type="POINT", location=(-0.57101, -4.24586, 5.53674),
rotation=(1.571, 0, 0.785)
)
lamp2 = bpy.context.active_object.data
lamp2.name = "Point_Left"
lamp2.energy = 1.0
lamp2.distance = 30.0
# Add cube
bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.subdivide(number_cuts=2)
bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
bpy.ops.object.editmode_toggle()
cube = bpy.context.active_object
# add new material
cubeMaterial = blend_data.materials.new("Cube_Material")
bpy.ops.object.material_slot_add()
cube.material_slots[0].material = cubeMaterial
# Diffuse
cubeMaterial.preview_render_type = "CUBE"
cubeMaterial.diffuse_color = (1.000, 0.373, 0.00)
cubeMaterial.diffuse_shader = 'OREN_NAYAR'
cubeMaterial.diffuse_intensity = 1.0
cubeMaterial.roughness = 0.09002
# Specular
cubeMaterial.specular_color = (1.000, 0.800, 0.136)
cubeMaterial.specular_shader = "PHONG"
cubeMaterial.specular_intensity = 1.0
cubeMaterial.specular_hardness = 511.0
# Shading
cubeMaterial.ambient = 1.00
cubeMaterial.use_cubic = False
# Transparency
cubeMaterial.use_transparency = False
cubeMaterial.alpha = 0
# Mirror
cubeMaterial.raytrace_mirror.use = True
cubeMaterial.mirror_color = (1.000, 0.793, 0.0)
cubeMaterial.raytrace_mirror.reflect_factor = 0.394
cubeMaterial.raytrace_mirror.fresnel = 2.0
cubeMaterial.raytrace_mirror.fresnel_factor = 1.641
cubeMaterial.raytrace_mirror.fade_to = "FADE_TO_SKY"
cubeMaterial.raytrace_mirror.gloss_anisotropic = 1.0
# Shadow
cubeMaterial.use_transparent_shadows = True
# Add a texture
cubetex = blend_data.textures.new("CloudTex", type='CLOUDS')
cubetex.noise_type = 'SOFT_NOISE'
cubetex.noise_scale = 0.25
mtex = cubeMaterial.texture_slots.add()
mtex.texture = cubetex
mtex.texture_coords = 'ORCO'
mtex.scale = (0.800, 0.800, 0.800)
mtex.use_map_mirror = True
mtex.mirror_factor = 0.156
mtex.use_map_color_diffuse = True
mtex.diffuse_color_factor = 0.156
mtex.use_map_normal = True
mtex.normal_factor = 0.010
mtex.blend_type = "ADD"
mtex.use_rgb_to_intensity = True
mtex.color = (1.000, 0.207, 0.000)
# Add monkey
bpy.ops.mesh.primitive_monkey_add(location=(-0.1, 0.08901, 1.505))
bpy.ops.transform.rotate(value=(1.15019), axis=(0, 0, 1))
bpy.ops.transform.rotate(value=(-0.673882), axis=(0, 1, 0))
bpy.ops.transform.rotate(value=-0.055, axis=(1, 0, 0))
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.shade_smooth()
monkey = bpy.context.active_object
# add new material
monkeyMaterial = blend_data.materials.new("Monkey_Material")
bpy.ops.object.material_slot_add()
monkey.material_slots[0].material = monkeyMaterial
# Material settings
monkeyMaterial.preview_render_type = "MONKEY"
monkeyMaterial.diffuse_color = (0.239, 0.288, 0.288)
monkeyMaterial.specular_color = (0.604, 0.465, 0.136)
monkeyMaterial.diffuse_shader = 'LAMBERT'
monkeyMaterial.diffuse_intensity = 1.0
monkeyMaterial.specular_intensity = 0.3
monkeyMaterial.ambient = 0
monkeyMaterial.type = 'SURFACE'
monkeyMaterial.use_cubic = True
monkeyMaterial.use_transparency = False
monkeyMaterial.alpha = 0
monkeyMaterial.use_transparent_shadows = True
monkeyMaterial.raytrace_mirror.use = True
monkeyMaterial.raytrace_mirror.reflect_factor = 0.65
monkeyMaterial.raytrace_mirror.fade_to = "FADE_TO_MATERIAL"
# Add plane
bpy.ops.mesh.primitive_plane_add(
radius=50, view_align=False, enter_editmode=False, location=(0, 0, -1)
)
bpy.ops.object.editmode_toggle()
bpy.ops.transform.rotate(
value=-0.8, axis=(0, 0, 1), constraint_axis=(False, False, True),
orient_type='GLOBAL', mirror=False, proportional='DISABLED',
proportional_edit_falloff='SMOOTH', proportional_size=1
)
bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
bpy.ops.object.editmode_toggle()
plane = bpy.context.active_object
# add new material
planeMaterial = blend_data.materials.new("Plane_Material")
bpy.ops.object.material_slot_add()
plane.material_slots[0].material = planeMaterial
# Material settings
planeMaterial.preview_render_type = "CUBE"
planeMaterial.diffuse_color = (0.2, 0.2, 0.2)
planeMaterial.specular_color = (0.604, 0.465, 0.136)
planeMaterial.specular_intensity = 0.3
planeMaterial.ambient = 0
planeMaterial.use_cubic = True
planeMaterial.use_transparency = False
planeMaterial.alpha = 0
planeMaterial.use_transparent_shadows = True
except Exception as e:
self.report({'WARNING'},
"Some operations could not be performed (See Console for more info)")
print("\n[Add Advanced Objects]\nOperator: "
"bi.add_scene\nError: {}".format(e))
return {'CANCELLED'}
return {"FINISHED"}
# gpl: author meta-androcto
import bpy
from bpy.types import Operator
class add_texture_scene(Operator):
bl_idname = "objects_texture.add_scene"
bl_label = "Create test scene"
bl_description = "Cycles renderer Scene: Camera aligned to a plane"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
try:
blend_data = context.blend_data
# add new scene
bpy.ops.scene.new(type="NEW")
scene = bpy.context.scene
bpy.context.scene.render.engine = 'CYCLES'
scene.name = "scene_texture_cycles"
# render settings
render = scene.render
render.resolution_x = 1080
render.resolution_y = 1080
render.resolution_percentage = 100
# add new world
world = bpy.data.worlds.new("Cycles_Textures_World")
scene.world = world
world.use_sky_blend = True
world.use_sky_paper = True
world.horizon_color = (0.004393, 0.02121, 0.050)
world.zenith_color = (0.03335, 0.227, 0.359)
world.light_settings.use_ambient_occlusion = True
world.light_settings.ao_factor = 0.5
# add camera
bpy.ops.view3d.viewnumpad(type='TOP')
bpy.ops.object.camera_add(
location=(0, 0, 2.1850), rotation=(0, 0, 0), view_align=True
)
cam = bpy.context.active_object.data
cam.lens = 35
cam.display_size = 0.1
# add plane
bpy.ops.mesh.primitive_plane_add(enter_editmode=True, location=(0, 0, 0))
bpy.ops.mesh.subdivide(number_cuts=10, smoothness=0)
bpy.ops.uv.unwrap(method='CONFORMAL', margin=0.001)
bpy.ops.object.editmode_toggle()
plane = bpy.context.active_object
# add plane material
planeMaterial = blend_data.materials.new("Cycles_Plane_Material")
bpy.ops.object.material_slot_add()
plane.material_slots[0].material = planeMaterial
# Diffuse
planeMaterial.preview_render_type = "FLAT"
planeMaterial.diffuse_color = (0.2, 0.2, 0.2)
# Cycles
planeMaterial.use_nodes = True
# Back to Scene
sc = bpy.context.scene
bpy.ops.view3d.viewnumpad(type='CAMERA')
except Exception as e:
self.report({'WARNING'},
"Some operations could not be performed (See Console for more info)")
print("\n[Add Advanced Objects]\nOperator: "
"objects_texture.add_scene\nError: {}".format(e))
return {'CANCELLED'}
return {'FINISHED'}
This diff is collapsed.
This diff is collapsed.