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)); } }
public void ApplyAds(string oldTexture, string newTexture) { try { foreach (SceneryObject o in sceneryObjects) { try { if (o.Mesh is XMesh) { XMesh xMesh = o.Mesh as XMesh; if (xMesh != null) { xMesh.ReplaceTexture(oldTexture, newTexture, true); } } } catch { } } Flag.ApplyAds(oldTexture, newTexture); #if EDITOR foreach (Gate o in gates) { if (o.Mesh is XMesh) { XMesh xMesh = o.Mesh as XMesh; if (xMesh != null) { xMesh.ReplaceTexture(oldTexture, newTexture, true); } } } #endif } catch { } }
private void LoadMesh(string filename) { this.fileName = filename; if (_Meshes.ContainsKey(fileName)) { GlobalMesh globalMesh = _Meshes[fileName]; this.Mesh = globalMesh.Mesh; globalMesh.ReferenceCount = globalMesh.ReferenceCount + 1; _Meshes[fileName] = globalMesh; } else { XMesh xMesh = new XMesh(fileName); if (Utility.MediaExists("ads/ad2.jpg")) { xMesh.ReplaceTexture("ad2.jpg", "ads/ad2.jpg", true); } this.Mesh = xMesh; GlobalMesh globalMesh = new GlobalMesh(); globalMesh.Mesh = this.Mesh as XMesh; globalMesh.ReferenceCount = 1; _Meshes.Add(fileName, globalMesh); } }