Commit dd55fd14 authored by Rafael Peretti Pezzi's avatar Rafael Peretti Pezzi

First prototype animation: Create N particles and animate path.

parent bcd13cdc
Pipeline #38 failed with stages
in 1 minute and 19 seconds
......@@ -2,48 +2,65 @@
# particulas.py - Protótipo de animação de partículas
# Para utilizar este script chame o blender com a opção -P e o nome do arquivo
#
# $ blender -P ./particulas.py
# $ blender -P ./animate_particles.py
import bpy
bpy.context.user_preferences.view.show_splash = False
import math
import os
bpy.context.user_preferences.view.show_splash = False
# Import Particle class
filename = os.path.join(os.path.basename(bpy.data.filepath), "particle.py")
exec(compile(open(filename).read(), filename, 'exec'))
t_video=10 # duração da animação em segundos
t_video=20 # duração da animação em segundos
t_simulado=86400*365*5 # tempo próprio da simulação em segundos
fps = 24 # quadros por segundo
N_quadros=t_video*fps # calculando numero de quadros totais
delta_t=t_simulado/N_quadros # tempo passado por quadro
r_part = 0.1
particulas=[] #lista que armazena as partículas da cena
r_part = 0.05 # Particle radius
def criaNparticulas_origem(N_particulas): # Cria partículas na origem e adiciona em uma lista
#Inicia limpando a cena - ATENÇÃO - apaga todos os objetos!!
for objeto in bpy.data.objects:
bpy.data.objects.remove(objeto)
#loop sobre as partículas
for i in range(0, N_particulas):
bpy.ops.mesh.primitive_uv_sphere_add()
part = bpy.context.object
part.name = "part"+str(i)
part.location=((0,0,0))
part.delta_scale=(r_part,r_part,r_part)
particulas.append(part)
def run():
def create(particles):
bpy.context.scene.render.fps=fps
bpy.context.scene.frame_start = 0
bpy.context.scene.frame_end = N_quadros
blender_particles=[]
# Create blender spheres (particles)
for particle in particles:
bpy.ops.mesh.primitive_uv_sphere_add()
this_particle = bpy.context.object
this_particle.name = "part"+str(particle.iDx)
this_particle.location=((particle.x,particle.y,particle.z))
this_particle.delta_scale=(r_part,r_part,r_part)
blender_particles.append(this_particle)
return blender_particles
def animate(objects):
#Animate particles
for f in range(1, N_quadros):
t=delta_t*f
bpy.context.scene.frame_current = f
for i in range(0, len(particulas)):
bpy.context.scene.objects.active=particulas[i]
particulas[i].location=(0.01*f,0.05*i,0.0000005*i*i*f*f) # Dummy positions
particulas[i].keyframe_insert(data_path='location')
for i in range(0, len(objects)):
bpy.context.scene.objects.active=objects[i]
objects[i].location=(0.01*f,0.05*i,0.0000005*i*i*f*f) # Dummy positions
objects[i].keyframe_insert(data_path='location')
#Remove cube
bpy.data.objects.remove(bpy.data.objects['Cube'])
# Create particles
particles = createNparticles(30)
# Todo: Add lamp and camera in suitable positions
# Create blender objects
blender_particles = create(particles)
criaNparticulas_origem(30)
run()
#Animate Scene
animate(blender_particles)
# -*- coding: utf-8 -*-
# Exemplo de classe de partícula e criação de N elementos em uma lista
class Particula:
def __init__(self, x = 0, y = 0, z = 0):
self.x=x
self.y=y
self.z=z
def criaNparticulas_origem(N_particulas): # Cria partículas na origem
particulas=[]
for i in range(1, N_particulas):
part = Particula() # Cria todas na origem
particulas.append(part)
return particulas;
def criaNparticulas(N_particulas, x, y, z): # Cria partículas na posição fornecida
particulas=[]
for i in range(1, N_particulas):
part = Particula(x, y, z)
particulas.append(part)
return particulas;
particulas1 = criaNparticulas_origem(10)
particulas2 = criaNparticulas(10, 1, 2, 3)
indice = 0
print("particulas1:")
for particula in particulas1:
print(str(indice) + "; " + str(particula.x) +" ; "+ str(particula.y) + " ; " +str(particula.z))
indice+=1
print("particulas2:")
indice = 0
for particula in particulas2:
print(str(indice) + "; " + str(particula.x) +" ; "+ str(particula.y) + " ; " +str(particula.z))
indice+=1
File added
# -*- coding: utf-8 -*-
# Sample Particle class and function that creates N particles, returning a list of particles
class Particle:
def __init__(self, index, x = 0, y = 0, z = 0):
self.iDx=index
self.x=x
self.y=y
self.z=z
def createNparticles(N_particles, x=0, y=0, z=0): # Create particles at given position and return them in a list
particles=[]
#loop sobre as partículas
for i in range(0, N_particles):
part = Particle(i,x,y,z)
particles.append(part)
return particles;
File added
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment