Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import bpy
  2. import bmesh
  3.  
  4. class SubdivisionModel:
  5. def __init__(self, vertices):
  6. self._vertices = vertices
  7. self._quads = []
  8.  
  9. def subdivide(self):
  10. # A list of the new quads we will be creating. We will replace the old quads
  11. # with these when we're done
  12. newQuads = []
  13.  
  14. # These data-structures will hold the intermediary vertices for edge midpoints
  15. # and face centers. We will need ready access to these after we generate them
  16. edgeMids = {}
  17. quadCtrList = []
  18.  
  19. oldVertexCount = len(self._vertices)
  20.  
  21. # STEP ONE: Generate face points
  22. # -----------------------------------------------------------
  23. for quadVerts in self._quads:
  24. polyCount = len(quadVerts)
  25. # create the center point
  26. ctr = vec3(0, 0, 0)
  27. for idx in quadVerts:
  28. ctr = ctr.add(self._vertices[idx])
  29. ctr = ctr.div_f(polyCount)
  30.  
  31. centerIdx = self.addVertex(ctr)
  32.  
  33. quadCtrList.append(centerIdx)
  34.  
  35.  
  36. cube = bpy.data.objects["Cube"]
  37. vertices = [v.co for v in cube.data.vertices]
  38. ss = SubdivisionModel(vertices=vertices)
  39.  
  40. bm = bmesh.new()
  41. print(type(cube))
  42. cube.mode_set(mode="EDIT")
  43. cube.mode_set(mode="OBJECT")
  44. bm.free()
  45. # for _ in range(step_count):
  46. # ss.subdivide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement