private string AddFileToProject(string filename) { string openFile = Program.Instance.OpenFile; if (openFile != null) { string projectFolder = string.Concat(new FileInfo(openFile).DirectoryName, "\\"); string newFileName = new FileInfo(filename).Name; string copiedName = string.Concat(projectFolder, newFileName); if (!File.Exists(copiedName)) { File.Copy(filename, copiedName); if (filename.EndsWith(".x")) { XMesh mesh = new XMesh(filename); for (int i = 0; i < mesh.NumberTextures; i++) { TextureBase texture = mesh.GetTexture(i); if ((texture != null) && (!string.IsNullOrEmpty(texture.FileName))) { AddFileToProject(texture.FileName); } } mesh.Dispose(); } } return(copiedName); } else { return(null); } }
public Flag(Vector3 position) { count++; pole = new GameObject(); flag = new GameObject(); if (meshPole == null) { meshPole = new XMesh("data/flagpole.x"); } if (meshFlag == null) { meshFlag = new XMesh("data/flag.x"); flagShader = new ShaderBase("FlagShader", "data/flag.fx"); flagShader.SetVariable("matWorldViewProj", ShaderBase.ShaderParameters.WorldProjection); flagShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); flagShader.SetVariable("vecLightDir", new Vector3(-0.3529871f, 0.8714578f, -0.3405313f)); flagShader.SetTechnique("TFlag"); } //this.Position = new Microsoft.DirectX.Vector3((count % 2 == 0)?5f:-5f, 0, (count % 2 == 0)?50f:20f); this.Position = position; pole.Mesh = meshPole; pole.Scale = new Vector3(2, 2, 2); flag.Mesh = meshFlag; flag.Position = new Vector3(0, 2.3f, 0); flag.Shader = flagShader; this.AddChild(pole); this.AddChild(flag); this.Scale = new Microsoft.DirectX.Vector3(2f, 2f, 2f); if (!string.IsNullOrEmpty(oldTexture) && !string.IsNullOrEmpty(newTexture)) { meshFlag.ReplaceTexture(oldTexture, newTexture, true); flagShader.SetVariable("Texture", meshFlag.GetTexture(0)); } }