Serega Pokuy

Serega Pokuy 

ТРЕЭДАШНИК3000

11subscribers

21posts

goals1
0 of 70 paid subscribers
Я смогу уделять все свое время контенту и его станет в разы больше
import bpy
import random
from mathutils import Vector
class RandomizeDuplicates(bpy.types.Operator):
bl_idname = "object.randomize_duplicates"
bl_label = "Randomize Duplicates"
def execute(self, context):
# Get the currently selected object
selected_object = context.selected_objects[0]
# Duplicate the selected object
duplicate_object = selected_object.copy()
context.scene.collection.objects.link(duplicate_object)
# Generate a random number of copies of the selected object, between 8 and 12
num_copies = random.randint(8, 12)
# Generate a random scale for each copy, with a variance of no more than 50% from the original
original_scale = selected_object.scale
for i in range(num_copies):
scale_factor = random.uniform(0.5, 1.5)
scale_vector = Vector((scale_factor, scale_factor, scale_factor))
duplicate_object.scale = original_scale.lerp(scale_vector, 0.5) # limit the difference to 50%
duplicate_object = duplicate_object.copy()
context.scene.collection.objects.link(duplicate_object)
# Generate a random rotation for each copy, up to a maximum of 360 degrees around the Z axis
for i in range(num_copies):
rotation_angle = random.uniform(0, 360)
duplicate_object.rotation_euler = (0, 0, rotation_angle)
duplicate_object = duplicate_object.copy()
context.scene.collection.objects.link(duplicate_object)
# Generate a random position for each copy, close to the selected object, but offset along the x and y axes
for i in range(num_copies):
location_offset = Vector((random.uniform(-1, 1), random.uniform(-1, 1), 0))
location_offset.x *= random.uniform(0, 0.1) # Randomly offset along X axis by up to 0.1 units
location_offset.y *= random.uniform(0, 0.1) # Randomly offset along Y axis by up to 0.1 units
duplicate_object.location = selected_object.location + location_offset
duplicate_object = duplicate_object.copy()
context.scene.collection.objects.link(duplicate_object)
return {'FINISHED'}
class RandomizeDuplicatesPanel(bpy.types.Panel):
bl_idname = "OBJECT_PT_randomize_duplicates_panel"
bl_label = "Randomize Duplicates Panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Randomize'
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("object.randomize_duplicates")
def register():
bpy.utils.register_class(RandomizeDuplicates)
bpy.utils.register_class(RandomizeDuplicatesPanel)
def unregister():
bpy.utils.unregister_class(RandomizeDuplicates)
bpy.utils.unregister_class(RandomizeDuplicatesPanel)
if __name__ == "__main__":
register()
Subscription levels1

Особенный

$2.54 per month
Только тебе доступны:
Все-все материалы из видео
+ chat
Go up