-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from Doprez/particle-example
feat: Particle example
- Loading branch information
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
examples/code-only/Example12_Particles/Example12_Particles/Example12_Particles.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\src\Stride.CommunityToolkit.ImGui\Stride.CommunityToolkit.ImGui.csproj" /> | ||
<ProjectReference Include="..\..\..\..\src\Stride.CommunityToolkit.Skyboxes\Stride.CommunityToolkit.Skyboxes.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
112 changes: 112 additions & 0 deletions
112
examples/code-only/Example12_Particles/Example12_Particles/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using Stride.CommunityToolkit.Engine; | ||
using Stride.CommunityToolkit.Games; | ||
using Stride.CommunityToolkit.Skyboxes; | ||
using Stride.Core.Mathematics; | ||
using Stride.Engine; | ||
using Stride.Particles; | ||
using Stride.Particles.Components; | ||
using Stride.Particles.Initializers; | ||
using Stride.Particles.Materials; | ||
using Stride.Particles.Modules; | ||
using Stride.Particles.ShapeBuilders; | ||
using Stride.Particles.Spawners; | ||
using Stride.Rendering.Materials.ComputeColors; | ||
|
||
using var game = new Game(); | ||
|
||
game.Run(start: Start); | ||
|
||
void Start(Scene scene) | ||
{ | ||
SetupBaseScene(); | ||
|
||
game.AddSkybox(); | ||
game.AddProfiler(); | ||
|
||
game.SetMaxFPS(60); | ||
|
||
CreateParticleEffect(); | ||
} | ||
|
||
void SetupBaseScene() | ||
{ | ||
game.AddGraphicsCompositor(); | ||
game.Add3DCamera().Add3DCameraController(); | ||
game.AddDirectionalLight(); | ||
game.AddSkybox(); | ||
game.Add3DGround(); | ||
game.AddParticleRenderer(); | ||
} | ||
|
||
void CreateParticleEffect() | ||
{ | ||
|
||
var emitter = new ParticleEmitter | ||
{ | ||
ParticleLifetime = new Vector2(0.5f, 0.5f), | ||
SimulationSpace = EmitterSimulationSpace.World, | ||
RandomSeedMethod = EmitterRandomSeedMethod.Time, | ||
ShapeBuilder = new ShapeBuilderBillboard(), | ||
|
||
Material = new ParticleMaterialComputeColor() | ||
{ | ||
ComputeColor = new ComputeColor() | ||
{ | ||
Value = new Color4(0, 0, 1, 1) | ||
} | ||
}, | ||
}; | ||
|
||
emitter.Spawners.Add(new SpawnerPerSecond() | ||
{ | ||
LoopCondition = SpawnerLoopCondition.Looping, | ||
Delay = new Vector2(), | ||
Duration = new Vector2(1, 1), | ||
SpawnCount = 50, | ||
}); | ||
|
||
var sizeInitializer = new InitialSizeSeed() | ||
{ | ||
ScaleUniform = 0.3f, | ||
RandomSize = new Vector2(0.1f, 0.5f), | ||
}; | ||
|
||
var positionInitializer = new InitialPositionSeed() | ||
{ | ||
PositionMin = new Vector3(-0.03f, -0.03f, -0.03f), | ||
PositionMax = new Vector3(0.03f, 0.03f, 0.03f), | ||
}; | ||
|
||
var velocityInitialzer = new InitialVelocitySeed() | ||
{ | ||
VelocityMin = new Vector3(0, 3, 0), | ||
VelocityMax = new Vector3(3, 4, 3), | ||
}; | ||
|
||
emitter.Initializers.Add(sizeInitializer); | ||
emitter.Initializers.Add(positionInitializer); | ||
emitter.Initializers.Add(velocityInitialzer); | ||
|
||
emitter.Updaters.Add(new UpdaterGravity() { GravitationalAcceleration = new Vector3(0, -9.8f, 0) }); | ||
|
||
var particleSettings = new ParticleSystemSettings | ||
{ | ||
WarmupTime = 0, | ||
}; | ||
|
||
ParticleSystemComponent particles = new() | ||
{ | ||
Color = Color.White, | ||
RenderGroup = Stride.Rendering.RenderGroup.Group0, | ||
Speed = 1, | ||
}; | ||
particles.ParticleSystem.Emitters.Add(emitter); | ||
particles.ParticleSystem.Settings = particleSettings; | ||
|
||
var entity = new Entity | ||
{ | ||
particles | ||
}; | ||
entity.Name = "Particles"; | ||
entity.Scene = game.SceneSystem.SceneInstance.RootScene; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters