public static ICollisionData GetCollisionNode(XmlTextReader reader, out CollisionDataType type) { type = CollisionDataType.None; ICollisionData data = null; string result = reader.GetAttribute("type"); if (result == null) throw new FileFormatException("Nieprawid³owy opis collision data w pliku "); switch (result) { case "BS": type = CollisionDataType.CollisionSphere; result = reader.GetAttribute("radius"); if (result == null) throw new FileFormatException("Nieprawid³owy opis collision data w pliku "); data = new CollisionSphere(float.Parse(result, _nfi)); break; case "Mesh": type = CollisionDataType.CollisionMesh; result = reader.GetAttribute("file"); if (result == null) throw new FileFormatException("Nieprawid³owy opis collision data w pliku "); data = CollisionMesh.FromFile(AppConfig.MeshPath + result, false); break; case "Tree": type = CollisionDataType.CollisionOctree; result = reader.GetAttribute("file"); if (result == null) throw new FileFormatException("Nieprawid³owy opis collision data w pliku "); CollisionMesh m = CollisionMesh.FromFile(AppConfig.MeshPath + result, false); data = CollisionOctree.FromMesh(m, 0, 0, 0, 20, 5, 100); break; } return data; }
public StaticMesh(ICollisionData cdata, CollisionDataType cdataType, RenderingData rdata, MyVector position, MyVector rotation) { collisionDataType = cdataType; collisionData = cdata; renderingData = rdata; this.Position = position; this.Orientation = MyQuaternion.FromEulerAngles(rotation.X, rotation.Y, rotation.Z); }
//StaticBodyData bodyData; public StaticMesh(ICollisionData cdata, CollisionDataType cdataType, RenderingData rdata, MyVector position) { collisionDataType = cdataType; collisionData = cdata; renderingData = rdata; this.Position = position; //bodyData.Orientation = MyQuaternion.FromEulerAngles(0, 0, 0); this.Orientation = MyQuaternion.FromEulerAngles(0, 0, 0); }
public CookData(PropertiesProxy proxy, string resultUrl, CollisionDataType type, Model model, int modelLodIndex, ConvexMeshGenerationFlags convexFlags, int convexVertexLimit) : base("Collision Data", resultUrl) { Proxy = proxy; Type = type; Model = model; ModelLodIndex = modelLodIndex; ConvexFlags = convexFlags; ConvexVertexLimit = convexVertexLimit; }
public bool CookCollision(CollisionDataType type, Vector3[] vertices, int[] triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { if (vertices == null) { throw new ArgumentNullException(); } var tmp = new Float3[vertices.Length]; for (int i = 0; i < tmp.Length; i++) { tmp[i] = vertices[i]; } return(CookCollision(type, tmp, triangles, convexFlags, convexVertexLimit)); }
public void OnLoad(CollisionDataWindow window) { // Link Window = window; Asset = window.Asset; // Setup cooking parameters Type = Asset.Type; if (Type == CollisionDataType.None) { Type = CollisionDataType.ConvexMesh; } Model = Asset.Model; Asset.GetCookOptions(out ModelLodIndex, out ConvexFlags, out ConvexVertexLimit); }
/// <summary> /// Cooks the mesh collision data and saves it to the asset using <see cref="CollisionData"/> format. action cannot be performed on a main thread. /// </summary> /// <param name="path">The output asset path.</param> /// <param name="type">The collision data type.</param> /// <param name="model">The source model.</param> /// <param name="modelLodIndex">The source model LOD index.</param> /// <param name="convexFlags">The convex mesh generation flags.</param> /// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param> /// <returns>True if failed, otherwise false.</returns> public static bool CookMeshCollision(string path, CollisionDataType type, Model model, int modelLodIndex = 0, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } if (type == CollisionDataType.None) { throw new ArgumentException(nameof(type)); } return(Internal_CookMeshCollision(path, type, model.unmanagedPtr, modelLodIndex, convexFlags, convexVertexLimit)); }
public void OnLoad(CollisionDataWindow window) { // Link Window = window; Asset = window.Asset; // Setup cooking parameters var options = Asset.Options; Type = options.Type; if (Type == CollisionDataType.None) { Type = CollisionDataType.ConvexMesh; } Model = FlaxEngine.Content.LoadAsync <ModelBase>(options.Model); ModelLodIndex = options.ModelLodIndex; ConvexFlags = options.ConvexFlags; ConvexVertexLimit = options.ConvexVertexLimit; }
/// <summary> /// Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread. /// </summary> /// <remarks> /// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>). /// </remarks> /// <param name="type">The collision data type.</param> /// <param name="model">The source model.</param> /// <param name="modelLodIndex">The source model LOD index.</param> /// <param name="convexFlags">The convex mesh generation flags.</param> /// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param> public void CookCollision(CollisionDataType type, Model model, int modelLodIndex = 0, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { // Validate state and input if (!IsVirtual) { throw new InvalidOperationException("Only virtual assets can be updated at runtime."); } if (model == null) { throw new ArgumentNullException(nameof(model)); } if (type == CollisionDataType.None) { throw new ArgumentException(nameof(type)); } if (Internal_CookCollision(unmanagedPtr, type, model.unmanagedPtr, modelLodIndex, convexFlags, convexVertexLimit)) { throw new FlaxException("Mesh cooking failed. See log to learn more."); } }
/// <summary> /// Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread. /// </summary> /// <remarks> /// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>). /// </remarks> /// <param name="type">The collision data type.</param> /// <param name="model">The source geometry vertex buffer with vertices positions. Cannot be null.</param> /// <param name="triangles">The source data index buffer (triangles). Uses 32-bit stride buffer. Cannot be null.</param> /// <param name="convexFlags">The convex mesh generation flags.</param> /// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param> public void CookCollision(CollisionDataType type, List <Vector3> vertices, List <int> triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { // Validate state and input if (!IsVirtual) { throw new InvalidOperationException("Only virtual assets can be updated at runtime."); } if (vertices == null) { throw new ArgumentNullException(nameof(vertices)); } if (triangles == null) { throw new ArgumentNullException(nameof(triangles)); } if (triangles.Count == 0 || triangles.Count % 3 != 0) { throw new ArgumentOutOfRangeException(nameof(triangles)); } if (type == CollisionDataType.None) { throw new ArgumentException(nameof(type)); } if (Internal_CookCollisionDataInt( unmanagedPtr, type, vertices.Count, triangles.Count / 3, Utils.ExtractArrayFromList(vertices), Utils.ExtractArrayFromList(triangles), convexFlags, convexVertexLimit )) { throw new FlaxException("Mesh cooking failed. See log to learn more."); } }
internal static extern bool Internal_CookCollision(IntPtr obj, CollisionDataType type, IntPtr model, int modelLodIndex, ConvexMeshGenerationFlags convexFlags, int convexVertexLimit);
internal static extern bool Internal_CookCollisionDataInt(IntPtr obj, CollisionDataType type, int vertexCount, int triangleCount, Vector3[] vertices, int[] triangles, ConvexMeshGenerationFlags convexFlags, int convexVertexLimit);
/// <summary> /// Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread. /// </summary> /// <remarks> /// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>). /// </remarks> /// <param name="type">The collision data type.</param> /// <param name="vertices">The source geometry vertex buffer with vertices positions. Cannot be empty.</param> /// <param name="triangles">The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle).</param> /// <param name="convexFlags">The convex mesh generation flags.</param> /// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param> public bool CookCollision(CollisionDataType type, Vector3[] vertices, uint[] triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { return(Internal_CookCollision1(unmanagedPtr, type, vertices, triangles, convexFlags, convexVertexLimit)); }
/// <summary> /// Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread. /// </summary> /// <remarks> /// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>). /// </remarks> /// <param name="type">The collision data type.</param> /// <param name="model">The source model.</param> /// <param name="modelLodIndex">The source model LOD index.</param> /// <param name="convexFlags">The convex mesh generation flags.</param> /// <param name="convexVertexLimit">The convex mesh vertex limit. Use values in range [8;255]</param> public bool CookCollision(CollisionDataType type, Model model, int modelLodIndex = 0, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { return(Internal_CookCollision(unmanagedPtr, type, FlaxEngine.Object.GetUnmanagedPtr(model), modelLodIndex, convexFlags, convexVertexLimit)); }