chore: 添加第三方依赖库
This commit is contained in:
84
thirdparty/rapier.js/src.ts/pipeline/serialization_pipeline.ts
vendored
Normal file
84
thirdparty/rapier.js/src.ts/pipeline/serialization_pipeline.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
import {RawSerializationPipeline} from "../raw";
|
||||
import {Vector, VectorOps} from "../math";
|
||||
import {
|
||||
IntegrationParameters,
|
||||
IslandManager,
|
||||
ImpulseJointSet,
|
||||
MultibodyJointSet,
|
||||
RigidBodySet,
|
||||
} from "../dynamics";
|
||||
import {BroadPhase, ColliderSet, NarrowPhase} from "../geometry";
|
||||
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 {
|
||||
raw: RawSerializationPipeline;
|
||||
|
||||
/**
|
||||
* Release the WASM memory occupied by this serialization pipeline.
|
||||
*/
|
||||
free() {
|
||||
if (!!this.raw) {
|
||||
this.raw.free();
|
||||
}
|
||||
this.raw = undefined;
|
||||
}
|
||||
|
||||
constructor(raw?: RawSerializationPipeline) {
|
||||
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.
|
||||
*/
|
||||
public serializeAll(
|
||||
gravity: Vector,
|
||||
integrationParameters: IntegrationParameters,
|
||||
islands: IslandManager,
|
||||
broadPhase: BroadPhase,
|
||||
narrowPhase: NarrowPhase,
|
||||
bodies: RigidBodySet,
|
||||
colliders: ColliderSet,
|
||||
impulseJoints: ImpulseJointSet,
|
||||
multibodyJoints: MultibodyJointSet,
|
||||
): Uint8Array {
|
||||
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.
|
||||
*/
|
||||
public deserializeAll(data: Uint8Array): World {
|
||||
return World.fromRaw(this.raw.deserializeAll(data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user