Advertisement
tsurubaso

NEW Planetarium Script

Aug 17th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. import bpy
  2. import random
  3.  
  4. #Toutes les variables
  5. #le calcul des points des lamps
  6. xl=10
  7. yl=10
  8. zl=10
  9. x=0
  10. y=0
  11. z=0
  12.  
  13.  
  14. meshgr=[]
  15. g=0.1
  16.  
  17. #tripatouillage avec le world
  18. #je fais ca apres
  19.  
  20. #efface quelques elements
  21. #bpy.data.objects['Cube'].select_set(True)
  22. #bpy.data.objects['Light'].select_set(True)
  23.  
  24. #bpy.ops.object.delete()
  25.  
  26.  
  27. #l'ensemble des def
  28.  
  29. def addLamp(loc):
  30.     bpy.ops.object.add(radius=1.0, type='LIGHT', enter_editmode=False, align='WORLD', location=loc, rotation=(0.0, 0.0, 0.0))
  31.     bpy.context.object.data.type = 'SUN'
  32.     bpy.context.object.data.energy = 50
  33.  
  34.  
  35. def makeplanet(loc, si):
  36.     bpy.ops.mesh.primitive_uv_sphere_add(segments=64, ring_count=32, radius=si, calc_uvs=True, enter_editmode=False, align='WORLD', location=loc, rotation=(0.0, 0.0, 0.0))
  37.     bpy.ops.object.shade_smooth()
  38.     obj=bpy.ops.object
  39.     ma = random.randint(0,5)
  40.     mat =  bpy.data.materials[ma]
  41.     bpy.context.object.data.materials.append(mat)
  42.  
  43.  
  44.    
  45.  
  46. #nombre de repetition de la boucle
  47. def bouclePlanet(loc2):
  48.     (x,y,z)=loc2
  49.     i=0
  50.     g=0.1
  51.     r = random.randint(1,10)
  52.     while i < r:
  53.         t=random.uniform(-1.0,1.0)
  54.         t2=random.uniform(-1.0,1.0)
  55.         t3=random.uniform(-1.0,1.0)
  56.         makeplanet((x,y,z), (g))
  57.         meshgr.append(bpy.context.object)
  58.         x=t3+x
  59.         y=t+y
  60.         z=t2+z
  61.         g=g+0.1
  62.         i=i+1
  63.     return x,y,z,g
  64.  
  65.  
  66.  
  67.  
  68.    
  69.    
  70. addLamp((xl,yl,zl))
  71. addLamp((-xl,-yl,zl))
  72. addLamp((-xl,yl,-zl))
  73. addLamp((xl,-yl,-zl))
  74.  
  75.  
  76. bouclePlanet((x,y,z))
  77. print(x,y,z,g)
  78. bouclePlanet((x,y,z))
  79. print(x,y,z,g)
  80. bouclePlanet((x,y,z))
  81. print(x,y,z,g)
  82. bouclePlanet((x,y,z))
  83. print(x,y,z,g)
  84.  
  85. obj=bpy.data.objects
  86. for i in range (12, len(obj)-1):
  87.  bpy.ops.object.select_all(action='DESELECT')
  88.  obj[i].select_set(True)
  89.  obj[i+1].select_set(True)
  90.  bpy.context.view_layer.objects.active = obj[i]
  91.  bpy.ops.object.parent_set()
  92.      
  93. for iframe in range (1, 600,100):
  94.    
  95.     for gritika in meshgr:
  96.         bpy.ops.object.select_all(action='SELECT')
  97.         bpy.ops.anim.keyframe_insert_menu(type='Rotation')
  98.         bpy.ops.object.select_all(action='DESELECT')
  99.         rer=random.uniform(-15.0,15.0)
  100.         rer2=random.uniform(-15.0,15.0)
  101.         rer3=random.uniform(-15.0,15.0)
  102.         gritika.rotation_euler=((rer2, rer3, rer))
  103.         bpy.data.scenes['Scene'].frame_set(iframe+100, subframe=0)
  104.         bpy.ops.object.select_all(action='SELECT')
  105.         bpy.ops.anim.keyframe_insert_menu(type='Rotation')
  106.         bpy.ops.object.select_all(action='DESELECT')
  107.    
  108.  
  109.        
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement