dyn_vertex_check.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """
  2. This is free and unencumbered software released into the public domain.
  3. Anyone is free to copy, modify, publish, use, compile, sell, or
  4. distribute this software, either in source code form or as a compiled
  5. binary, for any purpose, commercial or non-commercial, and by any
  6. means.
  7. In jurisdictions that recognize copyright laws, the author or authors
  8. of this software dedicate any and all copyright interest in the
  9. software to the public domain. We make this dedication for the benefit
  10. of the public at large and to the detriment of our heirs and
  11. successors. We intend this dedication to be an overt act of
  12. relinquishment in perpetuity of all present and future rights to this
  13. software under copyright law.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. For more information, please refer to [http://unlicense.org]
  22. """
  23. # Bring in Blender's Python API
  24. import bpy
  25. def add_mesh(verts, faces, name):
  26. mesh = bpy.data.meshes.new(name)
  27. mesh.from_pydata(verts, [], faces)
  28. mesh.update()
  29. obj = bpy.data.objects.new("Obj_" + name, mesh)
  30. scene = bpy.context.scene
  31. scene.objects.link(obj)
  32. return obj
  33. def add_point(pos, name):
  34. point_to_triangle = [
  35. # insert position of the molecule here
  36. pos,
  37. ( pos[0], pos[1] + 0.01, pos[2] + 10),
  38. ( pos[0], pos[1] + 0.01, pos[2] - 0.01),
  39. ]
  40. point_faces = [
  41. (0, 1, 2)
  42. ]
  43. pt = bpy.data.meshes.new("molecule")
  44. pt.from_pydata(point_to_triangle, [], point_faces)
  45. pt.update()
  46. obj = bpy.data.objects.new("Obj_" + name, pt)
  47. scene = bpy.context.scene
  48. scene.objects.link(obj)
  49. return obj
  50. # add generated code below
  51. mesh_verts = [
  52. (0, 0, 2), #0
  53. (-1, -2, -1), #1
  54. (2, 0, -1), #2
  55. (0, 0, 1), #3
  56. (-1, -2, -1), #4
  57. (2, 0, -1), #5
  58. ]
  59. mesh_faces = [
  60. (0, 1, 2, ),
  61. (3, 4, 5, ),
  62. (0, 1, 3, ),
  63. (3, 1, 4, ),
  64. (1, 2, 4, ),
  65. (4, 2, 5, ),
  66. (2, 0, 5, ),
  67. (5, 0, 3, ),
  68. ]
  69. add_mesh(mesh_verts, mesh_faces, "my_mesh")
  70. mol0 = (0.583606, 0.255219, 0.63674)
  71. add_point(mol0, "molecule0")
  72. mol1 = (0.413867, 0.175317, -0.334765)
  73. add_point(mol1, "molecule1")
  74. mol2 = (0.195182, -0.446152, 0.66672)
  75. add_point(mol2, "molecule2")
  76. mol3 = (-0.47739, 0.532683, -0.000138335)
  77. add_point(mol3, "molecule3")