123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import * as THREE from "../../../../libs/three.js/build/three.module.js";
- import Tween from '../Tween.js'
- export default class Particle{
- constructor(prop={}){
- this.position = new THREE.Vector3();
- this.velocity = new THREE.Vector3(); // units per second
-
- this.angle = 0;
- this.angleVelocity = 0; // degrees per second
- this.angleAcceleration = 0; // degrees per second, per second
- this.size = 16.0;
-
- this.color = new THREE.Color();
- this.opacity = 1.0;
-
- this.age = 0;
- this.alive = 0; // use float instead of boolean for shader purposes
- this.lastChangeVage = 0 //add
- this.sizeTween = prop.sizeTween || new Tween( [0, 1], [32, 128] );
- this.opacityTween = prop.opacityTween || new Tween( [0.8, 2], [0.5, 0] );
- this.colorTween = prop.colorTween || new Tween( [0.4, 1], [ new THREE.Vector3(0,0,0.2), new THREE.Vector3(0, 0, 0.5) ] );
-
-
-
- }
- update(dt)
- {
- this.position.add(this.velocity.clone().multiplyScalar(dt))
- this.velocity.multiplyScalar( 1+this.acceleration*dt )
-
- // convert from degrees to radians: 0.01745329251 = Math.PI/180
- this.angle += this.angleVelocity * 0.01745329251 * dt;
- this.angleVelocity += this.angleAcceleration * 0.01745329251 * dt;
- this.age += dt;
-
- // if the tween for a given attribute is nonempty,
- // then use it to update the attribute's value
- if ( this.sizeTween.times.length > 0 )
- this.size = this.sizeTween.lerp( this.age/this.deathAge );
-
- if ( this.colorTween.times.length > 0 )
- {
- var colorHSL = this.colorTween.lerp( this.age/this.deathAge );
- this.color = new THREE.Color().setHSL( colorHSL.x, colorHSL.y, colorHSL.z );
- }
-
- if ( this.opacityTween.times.length > 0 )
- {
- this.opacity = this.opacityTween.lerp( this.age/this.deathAge);
- }
- }
- }
|