31 января 2010 в 16:54Рейтинг: 0
0
0
Morthan, ну, ключей от квартиры, где деньги лежат у меня нету, но я расскажу, как я забрался в такие дебри. Я не знаю Питона. Отправной точкой послужили два скрипта про одно и то же. Это скрипт add_mesh_torus для 2.49 и для 2.50. Я открыл их и попробовал сравнить, а дальше, я взял скрипт add_mesh_star, написанный для 2.49:
и попытался воссоздать из него для 2.50. У меня получилось вот что:
# -*- coding: utf-8 -*-
# ##### 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8-80 compliant>
import bpy
import Mathutils
def add_star(points, outr_rad, innr_rad, depth):
Vector = Mathutils.Vector
RotationMatrix = Mathutils.RotationMatrix
verts = []
faces = []
segments = points * 2
tot_verts = segments * 2 + 2
half_height = depth * .5
verts.append( Vector(0, 0, half_height) )
verts.append( Vector(0, 0, -half_height) )
i = 2
alt_idx = 0
for index in xrange(segments):
mtx = RotationMatrix( (360 * float(index)/segments)+90, 3, 'z' )
radius = alt_idx and PREF_INNR_RAD or PREF_OUTR_RAD
verts.append( Vector(radius, 0, half_height) * mtx )
it1 = i
i+=1
verts.append( Vector(radius, 0, -half_height) * mtx )
ib1 = i
i+=1
if i>4:
faces.append( (it2, it1, 0) )
faces.append( (it1, it2, ib2, ib1) )
faces.append( (ib1, ib2, 1) )
it2 = it1
ib2 = ib1
alt_idx = 1 - alt_idx
faces.append( (tot_verts-2, 2, 0) )
faces.append( (3, 2, tot_verts-2, tot_verts-1) )
faces.append( (3, tot_verts-1, 1) )
return verts, faces
class AddStar(bpy.types.Operator):
'''Add a star mesh.'''
bl_idname = "mesh.primitive_star_add"
bl_label = "Add Star"
bl_register = True
bl_undo = True
points = IntProperty(name="Points",
description="Number of points of the star",
default=1.0, min=2, max=256)
outer_radius = FloatProperty(name="Outer Radius",
description="Outer Radius of the star",
default=1, min=0.01, max=100.0)
inner_radius = IntProperty(name="Inner Radius",
description="Inner Radius of the star",
default=0.25, min=0.01, max=100.0)
depth = IntProperty(name="Depth",
description="Depth of the star",
default=1, min=0.01, max=100)
def execute(self, context):
if self.properties.use_abso == True:
extra_helper = (self.properties.abso_outer_rad - self.properties.abso_inner_rad) * 0.5
self.properties.outer_radius = self.properties.abso_inner_rad + extra_helper
self.properties.inner_radius = extra_helper
verts_loc, faces = add_torus(self.properties.points,
self.properties.outer_radius,
self.properties.inner_radius,
self.properties.depth)
mesh = bpy.data.meshes.new("Star"

mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
mesh.verts.foreach_set("co", verts_loc)
mesh.faces.foreach_set("verts_raw", faces)
scene = context.scene
# ugh
for ob in scene.objects:
ob.selected = False
mesh.update()
ob_new = bpy.data.objects.new("Star", 'MESH'

ob_new.data = mesh
scene.objects.link(ob_new)
ob_new.selected = True
ob_new.location = scene.cursor_location
obj_act = scene.objects.active
if obj_act and obj_act.mode == 'EDIT':
bpy.ops.object.mode_set(mode='OBJECT'
obj_act.selected = True
scene.update() # apply location
#scene.objects.active = ob_new
bpy.ops.object.join() # join into the active.
bpy.ops.object.mode_set(mode='EDIT'

else:
scene.objects.active = ob_new
if context.user_preferences.edit.enter_edit_mode:
bpy.ops.object.mode_set(mode='EDIT'

return {'FINISHED'}
# Register the operator
bpy.types.register(AddTorus)
# Add to the menu
menu_func = (lambda self, context: self.layout.operator(AddTorus.bl_idname,
text="Star", icon='MESH_DONUT'

)
bpy.types.INFO_MT_mesh_add.append(menu_func)
if __name__ == "__main__":
bpy.ops.mesh.primitive_star_add()