/// <summary> /// Create a mesh from a .x File /// </summary> /// <param name="filePath">The path of the file</param> /// <param name="fileName">The name of the file</param> public MeshClass(string filePath, string fileName) { objectMesh = Mesh.FromFile(DeviceManager.LocalDevice, filePath, MeshFlags.Managed); ExtendedMaterial[] externMaterial = objectMesh.GetMaterials(); material = new Material[externMaterial.Length]; CurrentTexture = new Texture[externMaterial.Length]; for (int i = 0; i < externMaterial.Length; i++) { material[i] = externMaterial[i].MaterialD3D; material[i].Ambient = material[i].Diffuse; string s = filePath; int index = s.IndexOf(fileName); s = s.Remove(s.IndexOf(fileName)); s = s.Insert(index, externMaterial[i].TextureFileName); CurrentTexture[i] = Texture.FromFile(DeviceManager.LocalDevice, s); } //objectMesh.Optimize(MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort); ObjectPosition = Vector3.Zero; ObjectRotate = Vector3.Zero; ObjectScale = new Vector3(1, 1, 1); world = Matrix.Identity; Name = fileName; IsShapeObject = false; }
public Texture Load(Device device, String filename) { String rawFilename = Content.Content.ContentPath + filename; String cachedFilename = Content.Content.ContentCachePath + filename + ".dds"; if (File.Exists(cachedFilename) && (File.GetLastWriteTime(cachedFilename) - File.GetLastWriteTime(rawFilename)).Ticks > 0) { return(Texture.FromFile(device, cachedFilename)); } else { Texture heightmap = Texture.FromFile(device, rawFilename, 0, 0, 0, Usage.None, Format.A32B32G32R32F, Pool.Managed, Filter.Default, Filter.Default, 0); FixupHeightmap(heightmap, heightmap.GetLevelDescription(0).Width); Texture.ToFile(heightmap, cachedFilename, ImageFileFormat.Dds); return(heightmap); } }