Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SmokeParticleEmitterComponent.cs
Go to the documentation of this file.
1 using System;
2 
3 using SiliconStudio.Paradox.Effects;
4 using SiliconStudio.Paradox.Engine;
5 using SiliconStudio.Paradox.EntityModel;
6 using SiliconStudio.Paradox.Games;
7 using SiliconStudio.Paradox.Games.Mathematics;
8 using SiliconStudio.Paradox.Games.Serialization.Contents;
9 using Paradox.Framework.Shaders;
10 
11 namespace ScriptTest
12 {
13  [ContentSerializer(typeof(EntityComponentContentSerializer<SmokeParticleEmitterComponent>))]
14  [Display]
16  {
18  {
19  Type = ParticleEmitterType.GpuStatic;
20  Shader = new ShaderClassSource("ParticleUpdaterSmoke");
21  UpdateData += UpdateParticlesData;
23  Parameters.Set(ScriptParticleSmoke.SmokeEmitterKey, new SmokeEmitterDescription());
24  }
25 
26  private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
27  {
28  bool isUptoDate = true;
29  if (ParticleData == null || ParticleData.Length != Count)
30  {
32  isUptoDate = false;
33  }
34 
35  if (isUptoDate)
36  return;
37 
38  var description = Description;
39  var random = new Random();
40  var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;
41 
42  for (int i = 0; i < particlesBuffer.Length; i++)
43  {
44  particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
45  {
46  Position = description.Position,
47  Velocity = (Half3)(description.Velocity + Vector3.Modulate(new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble())), description.Scatter)),
48  Size = (Half)description.InitialSize,
49  Time = (float)random.NextDouble() * description.MaxTime,
50  Opacity = (Half)description.Opacity,
51  Factors = new Half4((Half)random.NextDouble(), (Half)0, (Half)description.Opacity, (Half)0),
52  TimeStep = (Half)10.0f,
53  };
54  particlesBuffer[i].Position += ((Vector3)particlesBuffer[i].Velocity) * particlesBuffer[i].Time * 100.0f / 1000.0f;
55  }
56  }
57 
58  [DataMemberConvert]
59  [Display]
60  public SmokeEmitterDescription Description
61  {
62  get
63  {
64  return Parameters.TryGet(ScriptParticleSmoke.SmokeEmitterKey);
65  }
66  set
67  {
68  Parameters.Set(ScriptParticleSmoke.SmokeEmitterKey, value);
69  }
70  }
71  }
72 }
SiliconStudio.Paradox.Games.Mathematics.Half4 Half4
int ParticleElementSize
Gets or sets the size of the particle element.
ShaderClassSource Shader
Gets or sets the shader.
SiliconStudio.Paradox.Games.Mathematics.Half Half
ParticleEmitterType Type
Gets or sets the type of this emitter..
SiliconStudio.Core.Mathematics.Vector3 Vector3