Hello Cesium Community.
I am beginner of CesiumJS and I have trouble with this.
I tried to add particle into the cesium viewer but it’s not working properly.
Here I added my current code.
async _addParticleCloud() {
const position = Cesium.Cartesian3.fromDegrees(this.longitude, this.latitude, this._height);
const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
position,
new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0))
);
const ParticleImageURL = "/assets/smoke.png";
const particleSystemParameters = {
emissionRate: 10.0,
gravity: 1,
minimumParticleLife: 1.2,
maximumParticleLife: 1.2,
minimumSpeed: 1.0,
maximumSpeed: 4.0,
startScale: 1.0,
endScale: 5.0,
particleSize: 10.0,
speed: 0.0,
particleLife: 5.0,
length: 30
};
const applyGravityAndWind = (particles: any, windSpeed: number, windDirection: number, dt: number) => {
const length = particleSystemParameters.length * dt;
// Calculate the displacement based on wind speed and direction
const ellipsoid = Cesium.Ellipsoid.WGS84;
const ENU = new Cesium.Matrix4();
Cesium.Transforms.eastNorthUpToFixedFrame(particles.position, ellipsoid, ENU);
const windDirectionRad = Cesium.Math.toRadians(windDirection);
const displacement = new Cesium.Cartesian3();
const phi = Math.atan(windSpeed / length);
displacement.x = length * Math.sin(phi) * Math.sin(windDirectionRad); // Adjust x-axis based on wind direction
displacement.y = length * Math.sin(phi) * Math.cos(windDirectionRad); // Adjust y-axis based on wind direction
displacement.z = length * Math.cos(phi);
// Update position2 of the polyline
particles.position = Cesium.Matrix4.multiplyByPoint(ENU, displacement, new Cesium.Cartesian3());
};
this._particlePrimitive = this._viewer.scene.primitives.add(
new Cesium.ParticleSystem({
modelMatrix: modelMatrix,
image: ParticleImageURL,
startColor: Cesium.Color.WHITE.withAlpha(0.7),
endColor: Cesium.Color.WHITE.withAlpha(0.1),
startScale: 1.0,
endScale: 5.0,
particleLife: particleSystemParameters.particleLife,
speed: particleSystemParameters.speed,
lifetime: particleSystemParameters.particleLife,
sizeInMeters: true,
imageSize: new Cesium.Cartesian2(particleSystemParameters.particleSize, particleSystemParameters.particleSize),
updateCallback: (particles, dt) => {
const { windSpeed, windDirection } = this._particleCloudSimulationProps;
applyGravityAndWind(particles, windSpeed, windDirection, dt);
}
})
);
if (this._particlePrimitive) {
this._particlePrimitive.show = true;
}
}
I can confirm that this._particlePrimitive have the correct particle type but updateCallback didn’t call applyGravityAndWind function.
I am not sure why this is happening.
And the console prints so many these types of errors.
[Violation] ‘requestAnimationFrame’ handler took ms
Please help me if you have experience to solve such problem before.
Best regards
James