Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Particles Effect (Test) #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions ursina/prefabs/particles_system/particle_effect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from ursina import *
from ursina import curve

class ParticleEffect( Entity ):
def __init__( self, **kwargs ):
super().__init__()

#Rendering
self.model = "quad"
self.texture = "star"
self.billboard = True

#Gravity and position
self.gravity = Vec3(0, 0, 0)
self.velocity = Vec3(0, 0, 0)

#Coloring
self.color = color.rgba(255, 255, 255, 255)
self.final_color = color.rgba(255, 255, 255, 255)
self.color_curve = curve.linear

#Scaling
self.scale = (1, 1, 1)
self.final_scale = (0, 0, 0)
self.scale_curve = curve.linear

#Lifetime
self.life_time = 1

#Kwargs
for key, value in kwargs.items():
setattr(self, key, value)

#Animation
self.animate_scale(self.final_scale, self.life_time, curve = self.scale_curve)
self.animate_color(self.final_color, self.life_time, curve = self.color_curve)

#Destroying
destroy(self, self.life_time)

def update( self ):
#Updating physics
self.position += self.velocity * time.dt
self.velocity += self.gravity * time.dt
60 changes: 60 additions & 0 deletions ursina/prefabs/particles_system/particle_effect_pack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from ursina import *
from ursina import curve
from particle_effect import *

class ParticleEffectSmokeJet( ParticleEffect ):
def __init__( self ):
super().__init__(
texture = "smoke",
velocity = Vec3(random.uniform(-0.5, 0.5), random.uniform(1, 3), random.uniform(-0.5, 0.5)),
scale = Vec3(0, 0, 0),
final_scale = Vec3(1, 1, 1) * random.uniform(1, 3),
final_color = color.rgba(255, 255, 255, 0),
life_time = random.uniform(1, 3)
)

class ParticleEffectSmokeStatic( ParticleEffect ):
def __init__( self ):
super().__init__(
texture = "smoke",
velocity = Vec3(random.uniform(-0.1, 0.1), random.uniform(-0.1, 0.1), random.uniform(-0.1, 0.1)),
scale = Vec3(0, 0, 0),
final_scale = Vec3(1, 1, 1) * random.uniform(1, 3),
final_color = color.rgba(255, 255, 255, 0),
life_time = random.uniform(1, 3)
)

class ParticleEffectFire( ParticleEffect ):
def __init__( self ):
super().__init__(
texture = f"default_textures/fire/fire_{random.randint(1, 3)}",
velocity = Vec3(random.uniform(-0.5, 0.5), random.uniform(-0.1, 3), random.uniform(-0.5, 0.5)),
scale = Vec3(0.8, 0.8, 0.8) * random.uniform(1, 3),
final_scale = Vec3(0, 0, 0),
final_color = color.rgba(255, 255, 255, 0),
life_time = random.uniform(1, 3)
)

class ParticleEffectStar( ParticleEffect ):
def __init__( self ):
super().__init__(
texture = "star_2",
velocity = Vec3(random.uniform(-3.5, 3.5), random.uniform(5, 10), random.uniform(-3.5, 3.5)),
gravity = Vec3(0, -10, 0),
scale = Vec3(1, 1, 1) * random.uniform(1, 3),
final_scale = Vec3(0, 0, 0),
final_color = color.rgba(0, 0, 0, 0),
life_time = random.uniform(1, 3)
)

class ParticleEffectSpark( ParticleEffect ):
def __init__( self ):
super().__init__(
texture = "spark",
velocity = Vec3(random.uniform(-3.5, 3.5), random.uniform(5, 10), random.uniform(-3.5, 3.5)),
gravity = Vec3(0, -10, 0),
scale = Vec3(0.3, 0.3, 0.3) * random.uniform(1, 3),
final_scale = Vec3(0, 0, 0),
final_color = color.rgba(255, 255, 255, 0),
life_time = random.uniform(1, 3)
)
34 changes: 34 additions & 0 deletions ursina/prefabs/particles_system/particle_emitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from ursina import *

from particle_effect import *

class ParticleEmitter( Entity ):
def __init__( self, particle_class, **kwargs ):
super().__init__(
model = "quad",
billboard = True,
texture = "particle_emitter_2"
)

#Debug mode
self.debug_mode = False

#Random
self.random_max = 5

#Accessing the Particle Class
self.particle_class = particle_class

#Kwargs
for key, value in kwargs.items():
setattr(self, key, value)

#Debug Mode ?
self.visible = self.debug_mode

def update( self ):

#Spawn particles
if random.randint(0, self.random_max) == 0:
new_particle = self.particle_class()
new_particle.position = self.position
20 changes: 20 additions & 0 deletions ursina/prefabs/particles_system/particles_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ursina import *

from particle_emitter import *
from particle_effect_pack import *

App = Ursina()

ParticleEmitter( ParticleEffectSmokeJet, position = (0, 0, 0), debug_mode = True)

ParticleEmitter( ParticleEffectStar, position = (3, 0, 0), debug_mode = True)

ParticleEmitter( ParticleEffectSpark, position = (6, 0, 0), debug_mode = True)

ParticleEmitter( ParticleEffectFire, position = (9, 0, 0), debug_mode = True)

Entity(model = "cube", texture = "white_cube")

EditorCamera()

App.run()