Last active
July 6, 2019 17:37
-
-
Save SabinT/8d71954a6c49c6b405f4 to your computer and use it in GitHub Desktop.
Blender - Clone a given object at mesh vertices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following function is adapted from | |
# Nick Keeline "Cloud Generator" addNewObject | |
# from object_cloud_gen.py (an addon that comes with the Blender 2.6 package) | |
# Create a clone of object "coypobj" at all vertices in the "verticesFrom" object | |
# Usage example: cloneAtVertices(bpy.context.scene, bpy.data.objects['ball'], bpy.data.objects['positions']) | |
def cloneAtVertices(scene, copyobj, verticesFrom): | |
index = 0; | |
for v in verticesFrom.data.vertices: | |
index = index + 1 | |
name = copyobj.name + str(index) | |
mesh = bpy.data.meshes.new(name) | |
ob_new = bpy.data.objects.new(name, mesh) | |
ob_new.data = copyobj.data.copy() | |
ob_new.scale = copyobj.scale | |
ob_new.location = v.co # place object at the vertex | |
scene.objects.link(ob_new) | |
ob_new.select = True | |
# Create a clone of object "coypobj" at selected vertices in the "verticesFrom" object | |
# The vertex indices are specified in the list "vList" | |
# Usage example: cloneAtVertices(bpy.context.scene, bpy.data.objects['ball'], bpy.data.objects['positions']) | |
def cloneAtSelectedVertices(scene, copyobj, verticesFrom, vList): | |
index = 0; | |
for vi in vList: | |
v = verticesFrom.data.vertices[vi] | |
index = index + 1 | |
name = copyobj.name + str(index) | |
mesh = bpy.data.meshes.new(name) | |
ob_new = bpy.data.objects.new(name, mesh) | |
ob_new.data = copyobj.data.copy() | |
ob_new.scale = copyobj.scale | |
ob_new.location = v.co # place object at the vertex | |
scene.objects.link(ob_new) | |
ob_new.select = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment