private void Preload() { using (PhysX.Collection coll = _scene.Physics.CreateCollection()) { using (MemoryStream ms = new MemoryStream()) { coll.Deserialize(ms); } } }
private bool TryExtractSerializedShapes(MeshingStage meshingStage, ulong meshHash, ShapeType bestShape) { if (SerializedShapes == null) { return(false); } if (bestShape != ShapeType.TriMesh && bestShape != ShapeType.DecomposedConvexHulls && bestShape != ShapeType.SingleConvex) { return(false); //we only handle these types } using (PhysX.Collection coll = meshingStage._scene.Physics.CreateCollection()) { using (MemoryStream ms = new MemoryStream(SerializedShapes)) { if (!coll.Deserialize(ms)) { m_log.Warn("[InWorldz.PhysxPhysics]: Geometry deserialization failed"); return(false); } } if (coll.DeserializedObjects.Count > 0) { PhysicsShape phyShape; if (coll.DeserializedObjects[0] is PhysX.ConvexMesh) { List <PhysX.ConvexMesh> target = new List <PhysX.ConvexMesh>(coll.DeserializedObjects.Cast <PhysX.ConvexMesh>()); var geoms = new List <PhysX.ConvexMeshGeometry>(target.Select(item => new PhysX.ConvexMeshGeometry(item))); if (bestShape == ShapeType.DecomposedConvexHulls) { phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, geoms); } else if (bestShape == ShapeType.SingleConvex) { phyShape = CreatePhysicsShapeFromSingleConvexAndCache(meshingStage, meshHash, geoms[0]); } else { m_log.Warn("[InWorldz.PhysxPhysics]: Serialized geoms were convex, but best shape doesnt match"); return(false); } } else if (coll.DeserializedObjects[0] is PhysX.TriangleMesh) { List <PhysX.TriangleMesh> target = new List <PhysX.TriangleMesh>(coll.DeserializedObjects.Cast <PhysX.TriangleMesh>()); var geoms = new List <PhysX.TriangleMeshGeometry>(target.Select(item => new PhysX.TriangleMeshGeometry(item))); if (target.Count == 1) { phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, geoms[0]); } else { m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Got more than one serialized trimesh back"); return(false); } } else { m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Serialized geoms weren't convex or trimesh"); return(false); } this.CompletedDelegate(phyShape); return(true); } else { //no geom? m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Didnt find any geom even though we were supplied with a serialized collection"); return(false); } } }