@dimforge/rapier3d
Version:
3-dimensional physics engine in Rust - official JS bindings.
49 lines • 2.07 kB
JavaScript
import { RawSerializationPipeline } from "../raw";
import { VectorOps } from "../math";
import { World } from "./world";
/**
* A pipeline for serializing the physics scene.
*
* To avoid leaking WASM resources, this MUST be freed manually with `serializationPipeline.free()`
* once you are done using it (and all the rigid-bodies it created).
*/
export class SerializationPipeline {
/**
* Release the WASM memory occupied by this serialization pipeline.
*/
free() {
if (!!this.raw) {
this.raw.free();
}
this.raw = undefined;
}
constructor(raw) {
this.raw = raw || new RawSerializationPipeline();
}
/**
* Serialize a complete physics state into a single byte array.
* @param gravity - The current gravity affecting the simulation.
* @param integrationParameters - The integration parameters of the simulation.
* @param broadPhase - The broad-phase of the simulation.
* @param narrowPhase - The narrow-phase of the simulation.
* @param bodies - The rigid-bodies taking part into the simulation.
* @param colliders - The colliders taking part into the simulation.
* @param impulseJoints - The impulse joints taking part into the simulation.
* @param multibodyJoints - The multibody joints taking part into the simulation.
*/
serializeAll(gravity, integrationParameters, islands, broadPhase, narrowPhase, bodies, colliders, impulseJoints, multibodyJoints) {
let rawGra = VectorOps.intoRaw(gravity);
const res = this.raw.serializeAll(rawGra, integrationParameters.raw, islands.raw, broadPhase.raw, narrowPhase.raw, bodies.raw, colliders.raw, impulseJoints.raw, multibodyJoints.raw);
rawGra.free();
return res;
}
/**
* Deserialize the complete physics state from a single byte array.
*
* @param data - The byte array to deserialize.
*/
deserializeAll(data) {
return World.fromRaw(this.raw.deserializeAll(data));
}
}
//# sourceMappingURL=serialization_pipeline.js.map