-
-
Notifications
You must be signed in to change notification settings - Fork 396
particle support limit velocity over lifetime #2925
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
base: dev/2.0
Are you sure you want to change the base?
Changes from 48 commits
3594b58
80803df
2193eb7
d023c18
d1b3bc2
ba3cf33
e19d3d5
fcc73e5
2024ae1
b913778
86d670f
33cc9dc
b5ab642
30141c4
e1e8bcd
efd53e1
fc66911
c2d491b
639e893
86caf6a
98fc9f6
41755f2
7bbe5a9
5795450
784f01a
c9c418f
ef83408
4cc87be
486e497
dc1f4e1
fdaf404
5c9d35f
c382b20
14e406a
554e5d8
7a207d8
993c6ce
63fd990
24d4600
0802398
dc064eb
ee67e54
429db08
cadf867
cc1ab6b
3455cd6
7d9f2df
47d64aa
0ffa4cf
1cb0c20
b9a816e
2d192a7
30af3da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /** | ||
| * @title Particle Limit Velocity Over Lifetime | ||
| * @category Particle | ||
| */ | ||
| import { | ||
| AssetType, | ||
| BlendMode, | ||
| Burst, | ||
| Camera, | ||
| Color, | ||
| Engine, | ||
| Entity, | ||
| SphereShape, | ||
| ParticleCompositeCurve, | ||
| ParticleCurveMode, | ||
| ParticleGradientMode, | ||
| ParticleMaterial, | ||
| ParticleRenderer, | ||
| ParticleSimulationSpace, | ||
| PostProcess, | ||
| BloomEffect, | ||
| TonemappingEffect, | ||
| Texture2D, | ||
| WebGLEngine | ||
| } from "@galacean/engine"; | ||
| import { initScreenshot, updateForE2E } from "./.mockForE2E"; | ||
|
|
||
| WebGLEngine.create({ | ||
| canvas: "canvas" | ||
| }).then((engine) => { | ||
| engine.canvas.resizeByClientSize(); | ||
|
|
||
| const scene = engine.sceneManager.activeScene; | ||
| const rootEntity = scene.createRootEntity(); | ||
| scene.background.solidColor = new Color(0, 0, 0, 1); | ||
|
|
||
| const cameraEntity = rootEntity.createChild("camera"); | ||
| cameraEntity.transform.setPosition(2, 1.43, 30); | ||
| const camera = cameraEntity.addComponent(Camera); | ||
| camera.fieldOfView = 60; | ||
| camera.enableHDR = true; | ||
| camera.enablePostProcess = true; | ||
|
|
||
| // Post process | ||
| const postProcess = rootEntity.addComponent(PostProcess); | ||
| const bloom = postProcess.addEffect(BloomEffect); | ||
| bloom.intensity.value = 1; | ||
| bloom.threshold.value = 0.8; | ||
| postProcess.addEffect(TonemappingEffect); | ||
|
|
||
| engine.resourceManager | ||
| .load({ | ||
| url: "https://mdn.alipayobjects.com/huamei_b4l2if/afts/img/A*JPsCSK5LtYkAAAAAAAAAAAAADil6AQ/original", | ||
| type: AssetType.Texture2D | ||
| }) | ||
| .then((texture) => { | ||
| createParticle(engine, rootEntity, <Texture2D>texture); | ||
|
|
||
| updateForE2E(engine, 30); | ||
| initScreenshot(engine, camera); | ||
| }); | ||
| }); | ||
|
|
||
| function createParticle(engine: Engine, rootEntity: Entity, texture: Texture2D): void { | ||
| const particleEntity = new Entity(engine, "LimitVelocity"); | ||
| particleEntity.transform.setPosition(2.006557, 1.43, 12.35); | ||
|
|
||
| const particleRenderer = particleEntity.addComponent(ParticleRenderer); | ||
| const generator = particleRenderer.generator; | ||
| generator.useAutoRandomSeed = false; | ||
|
|
||
| const material = new ParticleMaterial(engine); | ||
| material.baseColor = new Color(0.2, 0.6, 1.0, 1.0); | ||
| material.blendMode = BlendMode.Additive; | ||
| material.baseTexture = texture; | ||
| particleRenderer.setMaterial(material); | ||
|
|
||
| const { main, emission, limitVelocityOverLifetime, colorOverLifetime, velocityOverLifetime } = generator; | ||
|
|
||
| // Main | ||
| main.duration = 2; | ||
| main.isLoop = true; | ||
| main.startDelay.constant = 0; | ||
| main.startLifetime.constantMin = 0.6; | ||
| main.startLifetime.constantMax = 1; | ||
| main.startLifetime.mode = ParticleCurveMode.TwoConstants; | ||
| main.startSpeed.constantMin = 20; | ||
| main.startSpeed.constantMax = 40; | ||
| main.startSpeed.mode = ParticleCurveMode.TwoConstants; | ||
| main.startSize.constantMin = 0.05; | ||
| main.startSize.constantMax = 0.15; | ||
| main.startSize.mode = ParticleCurveMode.TwoConstants; | ||
| main.startColor.constantMin.set(280 / 255, 670 / 255, 2550 / 255, 1); | ||
| main.startColor.constantMax.set(1130 / 255, 740 / 255, 2550 / 255, 1); | ||
| main.startColor.mode = ParticleGradientMode.TwoConstants; | ||
| main.gravityModifier.constant = 0; | ||
| main.simulationSpace = ParticleSimulationSpace.Local; | ||
| main.maxParticles = 100; | ||
|
|
||
| // Emission | ||
| emission.rateOverTime.constant = 0; | ||
| emission.addBurst(new Burst(0, new ParticleCompositeCurve(10, 30))); | ||
| const sphereShape = new SphereShape(); | ||
| sphereShape.radius = 0.8; | ||
| emission.shape = sphereShape; | ||
|
|
||
| // Color over lifetime | ||
| colorOverLifetime.enabled = true; | ||
| colorOverLifetime.color.mode = ParticleGradientMode.Gradient; | ||
| const gradient = colorOverLifetime.color.gradient; | ||
| gradient.alphaKeys[0].alpha = 0; | ||
| gradient.alphaKeys[1].alpha = 0; | ||
| gradient.addAlphaKey(0.2, 1.0); | ||
| gradient.addAlphaKey(0.8, 1.0); | ||
|
|
||
| velocityOverLifetime.enabled = true; | ||
| velocityOverLifetime.velocityX.constant = 1; | ||
| velocityOverLifetime.velocityY.constant = 20; | ||
| velocityOverLifetime.velocityZ.constant = 1; | ||
|
|
||
| // Limit velocity over lifetime | ||
| limitVelocityOverLifetime.enabled = true; | ||
| limitVelocityOverLifetime.separateAxes = true; | ||
|
Comment on lines
+122
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Verify module behavior: enabling is gated by WebGL2.
module_file="$(fd 'LimitVelocityOverLifetimeModule.ts$' | head -n1)"
case_file="$(fd 'particleRenderer-limitVelocity.ts$' | head -n1)"
echo "Module file: ${module_file}"
echo "Case file: ${case_file}"
rg -n -C3 'override set enabled|isWebGL2|_setTransformFeedback' "$module_file"
rg -n -C3 'limitVelocityOverLifetime\.enabled|isWebGL2' "$case_file"
# Optional: inspect similar E2E patterns for capability gating.
rg -n --type=ts -C2 'isWebGL2|TransformFeedback|limitVelocityOverLifetime' e2e/caseRepository: galacean/engine Length of output: 2685 Fail fast when WebGL2 is unavailable so this test actually exercises limit-velocity. The module's 🤖 Prompt for AI Agents |
||
| limitVelocityOverLifetime.limitX = new ParticleCompositeCurve(1); | ||
| limitVelocityOverLifetime.limitY = new ParticleCompositeCurve(1); | ||
| limitVelocityOverLifetime.limitZ = new ParticleCompositeCurve(0); | ||
| limitVelocityOverLifetime.space = ParticleSimulationSpace.World; | ||
| limitVelocityOverLifetime.dampen = 0.25; | ||
| limitVelocityOverLifetime.drag = new ParticleCompositeCurve(0.0); | ||
| limitVelocityOverLifetime.multiplyDragByParticleSize = true; | ||
| limitVelocityOverLifetime.multiplyDragByParticleVelocity = true; | ||
|
|
||
| rootEntity.addChild(particleEntity); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.