/// <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; }
/// <summary> /// Sets the texture at a given instance /// </summary> /// <param name="instance"></param> /// <param name="value"></param> public static void SetTexture(DependencyObject instance, Texture value) { instance.SetValue(TextureProperty, value); }