/// <summary> /// Spawns a given number of particles /// </summary> public unsafe void SpawnParticles( IParticleSystem particles, int count ) { float s, t; SphericalCoordinates.FromNormalizedVector( Direction, out s, out t ); float angleRad = Constants.DegreesToRadians * Angle; float sAngle = ( float )( m_Rnd.NextDouble( ) * angleRad ) - angleRad / 2; float tAngle = ( float )( m_Rnd.NextDouble( ) * angleRad ) - angleRad / 2; s = Utils.Wrap( s + sAngle, 0, Constants.TwoPi ); t = Utils.Wrap( t + tAngle, 0, Constants.Pi ); Vector3 direction = SphericalCoordinates.ToVector( s, t ); ISerialParticleBuffer sBuffer = ( ISerialParticleBuffer )particles.Buffer; for ( int i = 0; i < count; ++i ) { int particleIndex = sBuffer.AddParticle( ); float* pos = ( float* )sBuffer.GetField( ParticleBase.Position, particleIndex ); pos[ 0 ] = particles.Frame.Translation.X; pos[ 1 ] = particles.Frame.Translation.Y; pos[ 2 ] = particles.Frame.Translation.Z; float speed = m_MinSpeed + ( float )( m_Rnd.NextDouble( ) * ( m_MaxSpeed - m_MinSpeed ) ); Vector3 vec = direction * speed; float* vel = ( float* )sBuffer.GetField( ParticleBase.Velocity, particleIndex ); vel[ 0 ] = vec.X; vel[ 1 ] = vec.Y; vel[ 2 ] = vec.Z; } }
/// <summary> /// Emits the particle. /// </summary> /// <param name="particleSystem">The particleSystem that manages the emitted particles.</param> /// <param name="particle">Particle to emit.</param> /// <param name="frameTime">The factor that indicates at which time during the frame, the /// particle gets emitted. (For interpolation purposes)</param> protected void Emit(IParticleSystem particleSystem, IParticle particle, float frameTime) { if (OnEmit != null) { OnEmit(particle, frameTime); } particleSystem.Emit(particle); }
public async ValueTask createEffectForParticles(IParticleSystem particleSystem, ActionCallback <Effect> onCompiled = null, ActionCallback <Effect, string> onError = null) { await EventHorizonBlazorInterop.Func <CachedEntity>( new object[] { new string[] { this.___guid, "createEffectForParticles" }, particleSystem, onCompiled, onError } ); }
public Beams(IEffectApi effectApi, int width, int height) : base(width, height) { _api = effectApi; _render = _api.CreateRender(); _particleSystem = _api.CreateParticleSystem(); _color = new SKColor(0, 128, 128); _particleSpeed = 5; _particleSize = 4; }
/// <summary> /// Renders a collection of particles /// </summary> public void RenderParticles( IRenderContext context, IParticleSystem particleSystem ) { ISerialParticleBuffer sBuffer = ( ISerialParticleBuffer )particleSystem.Buffer; SerialParticleFieldIterator posIter = new SerialParticleFieldIterator( sBuffer, ParticleBase.Position ); for ( int particleIndex = 0; particleIndex < sBuffer.NumActiveParticles; ++particleIndex ) { posIter.MoveNext( ); Graphics.Draw.Billboard( s_ParticleBrush, posIter.Point3Value, ParticleSize, ParticleSize ); } }
/// <summary> /// Spawns a particle system of the given type at the specified position and rotation. /// </summary> /// <param name="type"></param> /// <param name="position"></param> /// <param name="rotation"></param> public void SpawnParticleSystem(ParticleType type, Vector3 position, Quaternion rotation) { IParticleSystem system = this._pools[type].Get(position, rotation); system.Play(); if (this.gameObject.activeSelf) { StartCoroutine(this.ReturnParticleSystem(type, system)); } }
private void EmitFrameParticles(IParticleSystem particleSystem, float deltaTime) { float framesPerParticle = 1.0f / particleCount; while (framesPerParticle + time <= 1.0f) { time += framesPerParticle; IParticle particle = CreateParticle(time); Emit(particleSystem, particle, time); } time -= 1.0f; }
private void EmitTimeParticles(IParticleSystem particleSystem, float deltaTime) { float timePerParticle = 1.0f / particleCount; while (timePerParticle + time <= deltaTime) { time += timePerParticle; IParticle particle = CreateParticle(time / deltaTime); particle.Age = deltaTime - time; Emit(particleSystem, particle, time / deltaTime); } time -= deltaTime; }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle emitter object. /// </summary> /// <param name="particleSystem">The particleSystem that manages the emitted particles.</param> /// <param name="deltaTime">The time since the last frame.</param> public virtual void Update(IParticleSystem particleSystem, float deltaTime) { if (enabled) { if (timeBased) { EmitTimeParticles(particleSystem, deltaTime); } else { EmitFrameParticles(particleSystem, deltaTime); } } }
public Sparkles(IEffectApi effectApi, int width, int height) : base(width, height) { _api = effectApi; // Create a render for this effect instance once. _render = _api.CreateRender(); // Create a particle system _particleSystem = _api.CreateParticleSystem(); _color = new SKColor(0, 128, 128); _numParticles = 3 * Width / 4; _particleSize = 1; }
/// <summary> /// Kills particles /// </summary> public void KillParticles( IParticleSystem particles ) { SerialParticleFieldIterator iter = new SerialParticleFieldIterator( ( ISerialParticleBuffer )particles.Buffer, ParticleBase.Age ); for ( int i = 0; i < particles.Buffer.NumActiveParticles; ++i ) { iter.MoveNext( ); ++iter.IntValue; if ( iter.IntValue > m_DeathAge ) { particles.Buffer.MarkParticleForRemoval( i ); } } particles.Buffer.RemoveMarkedParticles( ); }
/// <summary> /// Adds a particle system with custom blend state settings /// </summary> public void AddParticleSystem(IParticleSystem particleSystem, BlendState blendState) { if (particleSystems.ContainsKey(blendState)) { particleSystems[blendState].Add(particleSystem); } else { List <IParticleSystem> particleSystemBatch = new List <IParticleSystem>(); particleSystemBatch.Add(particleSystem); particleSystems.Add(blendState, particleSystemBatch); } }
public SparkleExplosion(IEffectApi api, int width, int height) : base(width, height) { _api = api; // Create a render for this effect instance once. _render = _api.CreateRender(); // Create a particle system _particleSystem = _api.CreateParticleSystem(); _random = new Random(); _color = new SKColor(0, 255, 128); _numParticles = Width * Height * 0.25f; _particleSize = 2; }
internal static void SetObjects(Dictionary <string, object> objects) { EngineApplicationInterface._objects = objects; EngineApplicationInterface.IPath = EngineApplicationInterface.GetObject <IPath>(); EngineApplicationInterface.IShader = EngineApplicationInterface.GetObject <IShader>(); EngineApplicationInterface.ITexture = EngineApplicationInterface.GetObject <ITexture>(); EngineApplicationInterface.IMaterial = EngineApplicationInterface.GetObject <IMaterial>(); EngineApplicationInterface.IMetaMesh = EngineApplicationInterface.GetObject <IMetaMesh>(); EngineApplicationInterface.IDecal = EngineApplicationInterface.GetObject <IDecal>(); EngineApplicationInterface.IClothSimulatorComponent = EngineApplicationInterface.GetObject <IClothSimulatorComponent>(); EngineApplicationInterface.ICompositeComponent = EngineApplicationInterface.GetObject <ICompositeComponent>(); EngineApplicationInterface.IPhysicsShape = EngineApplicationInterface.GetObject <IPhysicsShape>(); EngineApplicationInterface.IBodyPart = EngineApplicationInterface.GetObject <IBodyPart>(); EngineApplicationInterface.IMesh = EngineApplicationInterface.GetObject <IMesh>(); EngineApplicationInterface.IMeshBuilder = EngineApplicationInterface.GetObject <IMeshBuilder>(); EngineApplicationInterface.ICamera = EngineApplicationInterface.GetObject <ICamera>(); EngineApplicationInterface.ISkeleton = EngineApplicationInterface.GetObject <ISkeleton>(); EngineApplicationInterface.IGameEntity = EngineApplicationInterface.GetObject <IGameEntity>(); EngineApplicationInterface.IGameEntityComponent = EngineApplicationInterface.GetObject <IGameEntityComponent>(); EngineApplicationInterface.IScene = EngineApplicationInterface.GetObject <IScene>(); EngineApplicationInterface.IScriptComponent = EngineApplicationInterface.GetObject <IScriptComponent>(); EngineApplicationInterface.ILight = EngineApplicationInterface.GetObject <ILight>(); EngineApplicationInterface.IParticleSystem = EngineApplicationInterface.GetObject <IParticleSystem>(); EngineApplicationInterface.IPhysicsMaterial = EngineApplicationInterface.GetObject <IPhysicsMaterial>(); EngineApplicationInterface.ISceneView = EngineApplicationInterface.GetObject <ISceneView>(); EngineApplicationInterface.IView = EngineApplicationInterface.GetObject <IView>(); EngineApplicationInterface.ITableauView = EngineApplicationInterface.GetObject <ITableauView>(); EngineApplicationInterface.ITextureView = EngineApplicationInterface.GetObject <ITextureView>(); EngineApplicationInterface.IVideoPlayerView = EngineApplicationInterface.GetObject <IVideoPlayerView>(); EngineApplicationInterface.IThumbnailCreatorView = EngineApplicationInterface.GetObject <IThumbnailCreatorView>(); EngineApplicationInterface.IDebug = EngineApplicationInterface.GetObject <IDebug>(); EngineApplicationInterface.ITwoDimensionView = EngineApplicationInterface.GetObject <ITwoDimensionView>(); EngineApplicationInterface.IUtil = EngineApplicationInterface.GetObject <IUtil>(); EngineApplicationInterface.IEngineSizeChecker = EngineApplicationInterface.GetObject <IEngineSizeChecker>(); EngineApplicationInterface.IInput = EngineApplicationInterface.GetObject <IInput>(); EngineApplicationInterface.ITime = EngineApplicationInterface.GetObject <ITime>(); EngineApplicationInterface.IScreen = EngineApplicationInterface.GetObject <IScreen>(); EngineApplicationInterface.IMusic = EngineApplicationInterface.GetObject <IMusic>(); EngineApplicationInterface.IImgui = EngineApplicationInterface.GetObject <IImgui>(); EngineApplicationInterface.IMouseManager = EngineApplicationInterface.GetObject <IMouseManager>(); EngineApplicationInterface.IHighlights = EngineApplicationInterface.GetObject <IHighlights>(); EngineApplicationInterface.ISoundEvent = EngineApplicationInterface.GetObject <ISoundEvent>(); EngineApplicationInterface.ISoundManager = EngineApplicationInterface.GetObject <ISoundManager>(); EngineApplicationInterface.IConfig = EngineApplicationInterface.GetObject <IConfig>(); EngineApplicationInterface.IManagedMeshEditOperations = EngineApplicationInterface.GetObject <IManagedMeshEditOperations>(); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle systems. /// </summary> /// <param name="deltaTime">The time since the last frame.</param> public void Update(float deltaTime) { ArrayList clone = (ArrayList)particleSystems.Clone(); for (int i = 0; i < particleSystems.Count; i++) { IParticleSystem particleSystem = (clone[i] as IParticleSystem); if (particleSystem.IsAlive) { (clone[i] as IParticleSystem).Update(deltaTime); } else { Remove(particleSystem); } } }
/// <summary> /// Updates all particles /// </summary> public void Update( IParticleSystem ps, float updateTime ) { ISerialParticleBuffer sBuffer = ( ISerialParticleBuffer )ps.Buffer; SerialParticleFieldIterator posIter = new SerialParticleFieldIterator( sBuffer, ParticleBase.Position ); SerialParticleFieldIterator velIter = new SerialParticleFieldIterator( sBuffer, ParticleBase.Velocity ); Vector3 g = Vector3.YAxis * -Gravity * updateTime; float fr = 1.0f - Friction; for ( int particleIndex = 0; particleIndex < sBuffer.NumActiveParticles; ++particleIndex ) { posIter.MoveNext( ); velIter.MoveNext( ); posIter.Point3Value += velIter.Vector3Value; posIter.Point3Value += g; velIter.Vector3Value *= fr; } }
public Fire(IEffectApi effectApi, int width, int height) : base(width, height) { _api = effectApi; _render = _api.CreateRender(); _particleSystem = _api.CreateParticleSystem(); _beginColor = new SKColor(128, 64, 16); var endColor = new SKColor(64, 64, 64); _particleEmitters = new List <IParticleEmitter>(); int numEmbers = Math.Max((int)(Width / EmberDistance), 1); for (int i = 0; i < numEmbers; i++) { var xPos = Width / (numEmbers - 1f) * i; var yPos = Height; var emitterConfig = new ParticleEmitterConfig { Position = new Vector2(xPos, yPos), AxisPosition = new Vector2(xPos, yPos), EmissionRate = 8, Angle = new Range <float>(45, 135), Life = 4, Speed = 4, RadialAcceleration = 0, TangentialAcceleration = 0, BeginColor = _beginColor, EndColor = endColor, BeginSize = 4, EndSize = 4, EnableSizeTransition = true, EnableColorTransition = true, }; var emitter = _particleSystem.AddEmitter(emitterConfig); _particleEmitters.Add(emitter); } }
/// <summary> /// Adds a new particle system to the collection /// </summary> /// <param name="name">Particle system name</param> /// <param name="type">Particle system type</param> /// <param name="description">Particle system description</param> /// <param name="emitter">Particle emitter</param> /// <returns>Returns the new particle system</returns> public IParticleSystem AddParticleSystem(string name, ParticleSystemTypes type, ParticleSystemDescription description, ParticleEmitter emitter) { IParticleSystem pSystem = null; if (type == ParticleSystemTypes.CPU) { pSystem = new ParticleSystemCpu(this.Game, name, description, emitter); } else if (type == ParticleSystemTypes.GPU) { pSystem = new ParticleSystemGpu(this.Game, name, description, emitter); } else { throw new EngineException("Bad particle system type"); } this.AllocatedParticleCount += pSystem.MaxConcurrentParticles; this.ParticleSystems.Add(pSystem); return(pSystem); }
/// <summary> /// Adds an <see cref="IParticleSystem"/> to the manager. /// </summary> /// <param name="particleSystem">The particle System to add.</param> public void Add(IParticleSystem particleSystem) { particleSystems.Add(particleSystem); }
/// <summary> /// Returns the given particle system to the pool from where it came from. /// </summary> /// <param name="type"></param> /// <param name="system"></param> /// <returns></returns> private IEnumerator ReturnParticleSystem(ParticleType type, IParticleSystem system) { yield return(new WaitForSeconds(system.duration)); this._pools[type].Return(system); }
public void LoadWorld(GraphicFactory factory, GraphicInfo ginfo, IWorld world, ModelLoaderData worldData) { objinfos.Clear(); foreach (var item in worldData.ModelMeshesInfo) { if (objinfos.ContainsKey(item.modelName + item.meshIndex)) { objinfos[item.modelName + item.meshIndex].Add(item); } else { objinfos[item.modelName + item.meshIndex] = new List <ObjectInformation>(); objinfos[item.modelName + item.meshIndex].Add(item); } } foreach (var item in objinfos.Keys) { if (OnCreateIObject != null) { IObject[] obj = OnCreateIObject(world, factory, ginfo, objinfos[item].ToArray()); if (obj != null) { foreach (var ob in obj) { world.AddObject(ob); } } } else { foreach (var obj in WorldLoader.CreateOBJ(world, factory, ginfo, objinfos[item].ToArray())) { world.AddObject(obj); } } } foreach (var item in worldData.ConstraintInfo) { List <IObject> obb = world.Objects.ToList(); IObject o1 = obb.First(delegate(IObject o) { return(o.Name == item.bodyA); }); IObject o2 = obb.First(delegate(IObject o) { return(o.Name == item.bodyB); }); if (o1.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT && o2.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT) { if (OnCreateIConstraint != null) { IPhysicConstraint constr = OnCreateIConstraint(world, factory, ginfo, item, o1, o2); if (constr != null) { world.PhysicWorld.AddConstraint(constr); } } else { IPhysicConstraint constr = WorldLoader.CreateConstraint(world, factory, ginfo, item, o1, o2); world.PhysicWorld.AddConstraint(constr); } } } foreach (var item in worldData.LightsInfo) { if (OnCreateILight != null) { ILight l = OnCreateILight(world, factory, ginfo, item); if (l != null) { world.AddLight(l); } } else { world.AddLight(item); } } foreach (var item in worldData.CameraInfo) { if (OnCreateICamera != null) { ICamera cam = OnCreateICamera(world, factory, ginfo, item); if (cam != null) { world.CameraManager.AddCamera(cam); } } else { world.CameraManager.AddCamera(WorldLoader.CreateCamera(world, factory, ginfo, item)); } } foreach (var item in worldData.DummyInfo) { if (OnProcessDummies != null) { OnProcessDummies(world, item); } } foreach (var item in worldData.ParticleInfo) { if (OnCreateIParticle != null) { IParticleSystem part = OnCreateIParticle(world, item); if (part != null) { world.ParticleManager.AddAndInitializeParticleSystem(part); (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.PositionData.Position = item.Position; (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.OrientationData.Orientation = item.Orientation; } } } }
/// <summary> /// Sets the wrapped particle system /// </summary> public ParticleSystemEmitter( IParticleSystem ps ) { m_Ps = ps; }
/// <summary> /// Renders a particle system /// </summary> public unsafe void RenderParticles( IRenderContext context, IParticleSystem particleSystem ) { ISerialParticleBuffer sBuffer = ( ISerialParticleBuffer )particleSystem.Buffer; if ( m_MaxParticles != sBuffer.MaximumNumberOfParticles ) { BuildBuffers( sBuffer.MaximumNumberOfParticles ); } using ( IVertexBufferLock vbLock = m_Vb.Lock( 0, sBuffer.NumActiveParticles * 4, false, true ) ) { Vertex* curVertex = ( Vertex* )vbLock.Bytes; SerialParticleFieldIterator posIter = new SerialParticleFieldIterator( sBuffer, ParticleBase.Position ); ICamera3 camera = ( ICamera3 )Graphics.Renderer.Camera; Vector3 xAxis = camera.Frame.XAxis * ParticleSize / 2; Vector3 yAxis = camera.Frame.YAxis * ParticleSize / 2; const float maxU = 1.0f; const float maxV = 1.0f; for ( int particleIndex = 0; particleIndex < sBuffer.NumActiveParticles; ++particleIndex ) { posIter.MoveNext( ); curVertex++->Setup( posIter.Point3Value - xAxis - yAxis, 0, 0 ); curVertex++->Setup( posIter.Point3Value + xAxis - yAxis, maxU, 0 ); curVertex++->Setup( posIter.Point3Value + xAxis + yAxis, maxU, maxV ); curVertex++->Setup( posIter.Point3Value - xAxis + yAxis, 0, maxV ); } } m_RenderState.Begin( ); if ( m_Texture.Texture != null ) { Graphics.Renderer.PushTextures( ); m_Texture.Begin( ); } m_Vb.Begin( ); m_Ib.Draw( PrimitiveType.TriList, 0, sBuffer.NumActiveParticles * 2 ); m_Vb.End( ); if ( m_Texture.Texture != null ) { m_Texture.End( ); Graphics.Renderer.PopTextures( ); } m_RenderState.End( ); }
/// <summary> /// Called when this component is attached to a particle system /// </summary> public void Attach( IParticleSystem particles ) { particles.Buffer.AddField( ParticleBase.Position, ParticleFieldType.Float32, 3, 0.0f ); }
public void LoadContent(MainGame game) { ParticleSystem = game.ContentManager.Load <IParticleSystem>(ParticleSystemAssetName); ParticleSystem.Pool = game.Pool; }
/// <summary> /// Adds a particle system with default blend state settings /// </summary> public void AddParticleSystem(IParticleSystem particleSystem) { AddParticleSystem(particleSystem, DefaultBlendState); }
/// <summary> /// Removes an <see cref="IParticleSystem"/> from the list. /// </summary> /// <param name="particleSystem"></param> public void Remove(IParticleSystem particleSystem) { particleSystems.Remove(particleSystem); }
internal void Bind(IParticleSystem particleSystem) { particleSystem.ApplicateModule(basicModule); particleSystem.ApplicateModule(scriptModule); }
/// <summary> /// Called when this component is attached to a particle system /// </summary> public void Attach( IParticleSystem particles ) { particles.Buffer.AddField( ParticleBase.Age, ParticleFieldType.Int32, 1, 0 ); }