/// <summary> /// Loads the data into the mesh buffers, overwriting existing content. /// </summary> /// <param name="data">The data to load.</param> /// <returns>True if the load was successful.</returns> public bool Load(PolyMeshDetailData data) { if (IsDisposed || data == null || data.meshes == null || data.tris == null || data.verts == null || data.meshCount < 0 || data.meshCount > mMaxMeshes || data.triCount < 0 || data.triCount > mMaxTris || data.vertCount < 0 || data.vertCount > mMaxVerts || data.meshes.Length < data.meshCount * 4 || data.tris.Length < data.triCount * 4 || data.verts.Length < data.vertCount) { return(false); } mMeshCount = data.meshCount; mTriCount = data.triCount; mVertCount = data.vertCount; UtilEx.Copy(data.meshes, 0, mMeshes, mMeshCount * 4); Marshal.Copy(data.tris, 0, mTris, mTriCount * 4); float[] fverts = Vector3Util.Flatten(data.verts, mVertCount); Marshal.Copy(fverts, 0, mVerts, mVertCount * 3); return(true); }
internal ChunkyTriMesh(Vector3[] verts , int vertCount , int[] tris , byte[] areas , int triCount , ChunkyTriMeshNode[] nodes , int nodeCount) { int size = sizeof(float) * vertCount * 3; this.verts = UtilEx.GetBuffer(size, false); float[] fverts = Vector3Util.Flatten(verts, vertCount); // Bleh. Marshal.Copy(fverts, 0, this.verts, vertCount * 3); size = sizeof(int) * tris.Length; this.tris = UtilEx.GetBuffer(size, false); Marshal.Copy(tris, 0, this.tris, tris.Length); size = sizeof(byte) * areas.Length; this.areas = UtilEx.GetBuffer(size, false); Marshal.Copy(areas, 0, this.areas, areas.Length); mTriCount = triCount; mVertCount = vertCount; mNodes = nodes; mNodeCount = nodeCount; }
/// <summary> /// Load the off-mesh connection data. /// </summary> /// <param name="connVerts">The connection vertices</param> /// <param name="connRadii">Connection radii.</param> /// <param name="connDirs">Connection direction data.</param> /// <param name="connAreas">Connection areas.</param> /// <param name="connFlags">Connection flags.</param> /// <param name="connUserIds">Connection user ids.</param> /// <param name="connCount">The number of connections.</param> /// <returns>True if the load succeeded.</returns> public bool LoadConns(Vector3[] connVerts , float[] connRadii , byte[] connDirs , byte[] connAreas , ushort[] connFlags , uint[] connUserIds , int connCount) { if (mIsDisposed) { return(false); } if (connCount == 0) { mConnCount = 0; return(true); } if (mConnVerts == IntPtr.Zero || connCount < 0 || connCount > mMaxConns || connVerts == null || connVerts.Length < connCount * 2 || connRadii == null || connRadii.Length < connCount || connDirs == null || connDirs.Length < connCount || connAreas == null || connAreas.Length < connCount || connFlags == null || connFlags.Length < connCount || connUserIds == null || connUserIds.Length < connCount) { return(false); } mConnCount = connCount; float[] fverts = Vector3Util.Flatten(connVerts, connCount * 2); Marshal.Copy(fverts, 0, mConnVerts, connCount * 2 * 3); Marshal.Copy(connRadii, 0, mConnRadii, connCount); Marshal.Copy(connDirs, 0, mConnDirs, connCount); Marshal.Copy(connAreas, 0, mConnAreas, connCount); UtilEx.Copy(connFlags, 0, mConnFlags, connCount); UtilEx.Copy(connUserIds, 0, mConnUserIds, connCount); return(true); }
/// <summary> /// Load the detail mesh data. /// </summary> /// <param name="verts">Detail vertices.</param> /// <param name="vertCount">The number of detail vertices.</param> /// <param name="tris">Detail triangles.</param> /// <param name="triCount">The number of detail triagles.</param> /// <param name="meshes">Detail meshes.</param> /// <param name="meshCount">The number of detail meshes.</param> /// <returns>True if the load succeeded.</returns> public bool LoadDetail(Vector3[] verts , int vertCount , byte[] tris , int triCount , uint[] meshes , int meshCount) { if (mIsDisposed || mDetailMeshes == IntPtr.Zero || vertCount < 3 || triCount < 1 || verts == null || verts.Length < vertCount || vertCount > mMaxDetailVerts || tris == null || tris.Length < triCount * 4 || triCount > mMaxDetailTris || meshes == null || meshes.Length < meshCount * 4 || meshCount > mMaxPolys) { return(false); } mDetailVertCount = vertCount; mDetailTriCount = triCount; // Necessary since polys may not be loaded yet. // The poly load will override this. if (mPolyCount == 0) { mPolyCount = meshCount; } float[] fverts = Vector3Util.Flatten(verts, vertCount); Marshal.Copy(fverts, 0, mDetailVerts, vertCount * 3); Marshal.Copy(tris, 0, mDetailTris, triCount * 4); UtilEx.Copy(meshes, 0, mDetailMeshes, meshCount * 4); return(true); }