Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import bpy
  2. from mathutils import Matrix, Vector
  3.  
  4.  
  5. def make_obj(verts, faces, name_mesh, name_object, matrix, use_matrix_local=False):
  6. mesh_data = bpy.data.meshes.new(name_mesh)
  7. mesh_data.from_pydata(verts, [], faces)
  8. mesh_data.update()
  9.  
  10. _object = bpy.data.objects.new(name_object, mesh_data)
  11.  
  12. scene = bpy.context.scene
  13. scene.objects.link(_object)
  14.  
  15. if use_matrix_local:
  16. _object.matrix_local = matrix
  17. else:
  18. for v in _object.data.vertices:
  19. v.co = matrix * v.co
  20.  
  21. _object.select = True
  22.  
  23. faces = [
  24. [4, 9, 5, 0], [3, 8, 9, 4], [1, 6, 7, 2], [0, 5, 6, 1],
  25. [14, 10, 15, 19], [13, 14, 19, 18], [11, 12, 17, 16], [10, 11, 16, 15],
  26. [2, 7, 17, 12], [8, 3, 13, 18], [5, 9, 19, 15], [9, 8, 18, 19],
  27. [7, 6, 16, 17], [6, 5, 15, 16], [4, 0, 10, 14], [3, 4, 14, 13],
  28. [1, 2, 12, 11], [0, 1, 11, 10]]
  29.  
  30. matrix = Matrix((
  31. Vector((-8.180699637705402e-07, -0.9997419118881226, 0.022718962281942368, -0.3149009048938751)),
  32. Vector((-2.0309057617851067e-06, -0.022718962281942368, -0.9997419118881226, 1.9882060289382935)),
  33. Vector((1.0, -8.639988777758845e-07, -2.011795913858805e-06, 2.0)),
  34. Vector((0.0, 0.0, 0.0, 1.0))
  35. ))
  36.  
  37. verts = [
  38. (1.2355599210422952e-08, 2.5331974029541016e-06, 0.008681532926857471),
  39. (-5.960487214906607e-09, -0.26104986667633057, 0.02579176053404808),
  40. (-5.960487214906607e-09, -0.5062174201011658, 0.07455870509147644),
  41. (5.231795441318354e-08, 0.5062174797058105, 0.07455730438232422),
  42. (2.3841835172788706e-08, 0.2610493302345276, 0.025791045278310776),
  43. (-3.441232365730684e-08, 2.5968843146984e-06, -0.09131837636232376),
  44. (-5.364415756048402e-08, -0.27410241961479187, -0.07335258275270462),
  45. (-5.364415756048402e-08, -0.5315283536911011, -0.022147277370095253),
  46. (7.548215386066204e-09, 0.5315283536911011, -0.022148676216602325),
  47. (-2.2351741790771484e-08, 0.27410173416137695, -0.07335329800844193),
  48. (0.9750000238418579, 2.475631390552735e-06, 0.00868106447160244),
  49. (0.9750000238418579, -0.26104992628097534, 0.025791293010115623),
  50. (0.9750000238418579, -0.5062174797058105, 0.07455824315547943),
  51. (0.9750000238418579, 0.5062174201011658, 0.07455683499574661),
  52. (0.9750000238418579, 0.2610492706298828, 0.02579057775437832),
  53. (0.9749999642372131, 2.5393183022970334e-06, -0.09131884574890137),
  54. (0.9749999642372131, -0.27410247921943665, -0.07335305213928223),
  55. (0.9749999642372131, -0.5315284132957458, -0.02214774489402771),
  56. (0.9750000238418579, 0.5315282940864563, -0.022149143740534782),
  57. (0.9750000238418579, 0.2741016745567322, -0.07335376739501953)
  58. ]
  59.  
  60. make_obj(verts, faces, 'name_mesh1', 'name_object1', matrix, use_matrix_local=False)
  61. make_obj(verts, faces, 'name_mesh2', 'name_object2', matrix, use_matrix_local=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement