private void BindTexture(Device device, Effect effect) { if (Textures.ContainsKey("diffuseMap")) { device.SetTexture(0, Textures["diffuseMap"].Texture); effect.SetValue("useDiffuse", true); } else { effect.SetValue("useDiffuse", false); } if (Textures.ContainsKey("normalMap") && ApplicationSettings.Default.NormalTextureEnabled) { device.SetTexture(1, Textures["normalMap"].Texture); effect.SetValue("useNormal", true); } else { effect.SetValue("useNormal", false); } if (ApplicationSettings.Default.SpecularTextureEnabled) { if (Textures.ContainsKey("specularMap")) { device.SetTexture(2, Textures["specularMap"].Texture); effect.SetValue("useSpecular", true); effect.SetValue("useMetallicDetail", false); } else if (Textures.ContainsKey("metallicGlossMap")) { device.SetTexture(2, Textures["metallicGlossMap"].Texture); effect.SetValue("useSpecular", true); if (Textures.ContainsKey("metallicDetailMap") && DetailPower > 0.0f) { device.SetTexture(3, Textures["metallicDetailMap"].Texture); effect.SetValue("useMetallicDetail", true); effect.SetValue("detailUVTiling", this.DetailUvTiling); effect.SetValue("detailPower", DetailPower); } } } else { effect.SetValue("useSpecular", false); } effect.SetValue("alphaTestEnable", AlphaTestEnable); if (AlphaTestEnable) { effect.SetValue("alphaReference", (float)AlphaReference / 255.0f); } effect.SetValue("useNormalPackDXT1", this.UseNormalPackDxt1); effect.SetValue("useNormalBC1", this.UseNormalBc1); }
/* * public string TryAddTexture(string path) * { * string id_name = AssetManager.GenerateIDFromFilePath(path); * Texture t = AssetManager.LoadAndReturnTexture(path); * this.TryAddTexture(new Tuple<string, Texture>(id_name, t)); * return id_name; * } */ public void TryAddTexture(Tuple <string, Texture> texture_data) { if (false == Textures.ContainsKey(texture_data.Item1)) { Textures.Add(texture_data.Item1, texture_data.Item2); } }
public void UpdateValuesFromParent(ResourcePackModelBase parent) { if (parent == null) { return; } if (!GuiLight.HasValue && parent.GuiLight.HasValue) { GuiLight = parent.GuiLight; } if (Elements.Length == 0 && parent.Elements.Length > 0) { Elements = parent.Elements.Select(x => x.Clone()).ToArray();//.Clone(); } foreach (var kvp in parent.Textures) { if (!Textures.ContainsKey(kvp.Key)) { Textures.Add(kvp.Key, kvp.Value); } } foreach (var kvp in parent.Display) { if (!Display.ContainsKey(kvp.Key)) { Display.Add(kvp.Key, kvp.Value); } } }
public void LoadTexturesFromFile(string FolderName, string Prefix) { DirectoryInfo folder = new DirectoryInfo(FolderName); if (folder.Exists) { FileInfo[] ConfigFiles = folder.GetFiles(); foreach (FileInfo File in ConfigFiles) { if (File.Extension.Equals(".png")) { FileStream FileStream = new FileStream(File.FullName.ToString(), FileMode.Open); if (Textures.ContainsKey(Prefix + File.Name.Remove(File.Name.Length - 4, 4))) { Textures[Prefix + File.Name.Remove(File.Name.Length - 4, 4)] = Texture2D.FromStream(Graphics, FileStream); } else { Textures.Add(Prefix + File.Name.Remove(File.Name.Length - 4, 4), Texture2D.FromStream(Graphics, FileStream)); } FileStream.Close(); } } } }
public void Render(SpriteBatch batch, SpriteFont font) { UpdateImagery(); foreach (TextureRole role in Enum.GetValues(typeof(TextureRole))) { if (Textures.ContainsKey(role) && Textures[role] != null) { batch.Draw(Textures[role], TEXTURE_LOCATIONS[role].ToWorld(batch.GraphicsDevice.Viewport), Color.White); } } if (CurrentDialog.NextId == -1 && CurrentDialog.Message == UNKNOWN_CHOICE.Message) { // Do nothing. } else { batch.DrawString(font, CurrentDialog.GetMessage(m_luaContext), new Vector2(5, (int)(batch.GraphicsDevice.Viewport.Height * 0.75f)), Color.Black); } //if (CurrentDialog.NextId != -1 && CurrentDialog.Message != UNKNOWN_CHOICE.Message) //{ // batch.DrawString(font, CurrentDialog.GetMessage(m_luaContext), new Vector2(5, (int)(batch.GraphicsDevice.Viewport.Height * 0.75f)), Color.Black); //} }
public static Texture2D GetTexture(string texture) { if (!Textures.ContainsKey(texture)) { Textures.Add(texture, content.Load <Texture2D>(texture)); } return(Textures[texture]); }
public Texture ResolveTexture(string key) { if (!Textures.ContainsKey(key)) { throw new Exception($"Texture with name '{key}' not created in chamscontroller"); } return(Textures[key]); }
public static Texture2D LoadTexture(string texPath, string name, bool alpha = true) { if (!Textures.ContainsKey(name)) { Textures[name] = LoadTextureFromFile(texPath, alpha); } return(Textures[name]); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { SpriteObject gestureSprite; // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // Update all game objects UpdateAll(gameTime); while (TouchPanel.IsGestureAvailable) { // Read the next gesture GestureSample gesture = TouchPanel.ReadGesture(); // Get a typed reference to the first game object gestureSprite = (SpriteObject)GameObjects[0]; // Set the sprite position (except for Flick, as this has no position) if (gesture.GestureType != GestureType.Flick) { gestureSprite.Position = gesture.Position - new Vector2(50, 50); } // Scale to full size gestureSprite.Scale = Vector2.One; // Set the texture to match the gesture type if (Textures.ContainsKey(gesture.GestureType.ToString())) { gestureSprite.SpriteTexture = Textures[gesture.GestureType.ToString()]; } // Is this a pinch? if (gesture.GestureType == GestureType.Pinch) { // Yes, so set the size, texture and position of the second sprite too. // Get a typed reference to the second game object gestureSprite = (SpriteObject)GameObjects[1]; gestureSprite.Position = gesture.Position2 - new Vector2(50, 50); // Scale to full size gestureSprite.Scale = Vector2.One; // Set the texture gestureSprite.SpriteTexture = Textures["Pinch2"]; } } // Reduce the scale of all objects so that they fade away for (int i = 0; i < GameObjects.Count; i++) { // Is the object at this position a sprite (and not text)? if (GameObjects[i] is SpriteObject && !(GameObjects[i] is TextObject)) { // Yes, so scale it down a little ((SpriteObject)GameObjects[i]).Scale *= 0.95f; } } }
public Texture2D GetTexture(int variation) { if (Textures.ContainsKey(variation)) { return(Textures[variation]); } return(Textures[0]); }
public DrawableTexture this[string id] { get { if (Textures.ContainsKey(id)) { return(Textures[id]); } return(GFX.Empty); } set => Textures[id] = value;
/// <summary> /// Gets the texture with the specified name. /// </summary> /// <param name="name">Name of the texture to retrieve.</param> /// <returns>The Texture2D instance with the name specified, or null if not found.</returns> public Texture2D GetTexture(string name) { if (Textures.ContainsKey(name)) { return(Textures[name]); } return(null); }
internal bool LoadCustomTexture(string name, Texture2D t) { if (!Textures.ContainsKey(name)) { Textures.Add(name, new QTexture(this, t)); return(true); } return(false); }
internal bool LoadTexture(string name, string path) { if (!Textures.ContainsKey(name)) { QTexture t = new QTexture(this, Load <Texture2D>(path)); Textures.Add(name, t); return(true); } return(false); }
public void RefreshImage(string FileName, string TextureName) { if (Textures.ContainsKey(TextureName)) { FileStream FileStream = new FileStream(FileName, FileMode.Open); Textures[TextureName] = Texture2D.FromStream(Graphics, FileStream); FileStream.Close(); FileStream.Dispose(); } }
public void RemoveTexture(string texture) { if (Textures.ContainsKey(texture)) { Textures[texture].Dispose(); if (!Textures.Remove(texture)) { throw new Exception("texture not found"); } } }
/// <summary> /// All textures loaded into the game. /// </summary> public Texture2D this[string name] { get { name = name.Replace('.', '\\'); if (Textures.ContainsKey(name)) { return(Textures[name]); } throw new KeyNotFoundException($"The texture {name} was not found."); } private set { Textures[name] = value; } }
/// <summary> /// Loads a texture and caches it for later use /// </summary> /// <param name="name"></param> /// <returns></returns> public static Texture2D Load(string name) { if (Textures.ContainsKey(name)) { return(Textures[name]); } var tex = AssetLoader.LoadTexture2D(GameBase.Game.Resources.Get(name)); Textures.Add(name, tex); return(tex); }
// Add a reference to an image source, i.e. a texture file. This checks // if the file exists; if it does, the reference is added to the // Textures list, else it is added to the MissingTextures list. private void AddImageReference(string imageId, string imageSource) { FileInfo sourceInfo; try { if (imageSource.StartsWith(".")) { // Let's infer that this is a path relative to the .dae location sourceInfo = new FileInfo(Path.Combine(m_DaeInfo.DirectoryName, imageSource)); } else { Uri imageUri = new Uri(imageSource); sourceInfo = new FileInfo(imageUri.LocalPath); } } catch { // It seems the source is not a well-formed URI, so let's // just take it raw, and hope it is meaningful as a path. sourceInfo = new FileInfo(imageSource); } try { if (sourceInfo.Exists) { if (!Textures.ContainsKey(imageId)) { Textures.Add(imageId, sourceInfo); } } else { if (!MissingTextures.ContainsKey(imageId)) { MissingTextures.Add(imageId, sourceInfo); } } } catch (Exception ex) { Console.Error.WriteLine( "Caught exception adding texture: id = '{0}'; source = '{1}'", imageId, imageSource); Console.Error.WriteLine(ex.Message); } }
public Texture2D LoadTexture(string texture) { if (!Textures.ContainsKey(texture)) { Textures[texture] = ContentManager.Load <Texture2D>(texture); } Texture2D texture2D = Textures[texture]; if (texture2D.IsDisposed) { throw new Exception("texture disposed"); } return(texture2D); }
/// <summary> /// Load a texture. /// </summary> /// <param name="filename">The filename of the texture to load.</param> /// <returns>The loaded texture.</returns> public static Texture GetTexture(string filename) { ValidateFilename(filename); if (Textures.ContainsKey(filename)) { return(Textures[filename]); } Texture texture = new Texture(filename); Textures.Add(filename, texture); return(texture); }
/// <summary> /// Adds a Texture2D instance to the cache, with the specified name. /// </summary> /// <param name="name">Name to use as a key in the cache.</param> /// <param name="texture">Texture to be added to the cache.</param> /// <remarks>If a texture in the cache uses the same source file, an alias to the existing texture will be created instead of adding a duplicate texture. Also, if an existing texture /// is using the same name as the name provided, the existing texture will be replaced.</remarks> public void AddTexture(string name, Texture2D texture) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } if (texture == null) { throw new ArgumentNullException("texture"); } // Look for a texture where the texture source name is the same as the source name of the texture being added, // if the source name of the texture being added is not null or empty. Matching source names means the source files are the same. Texture2D original = null; if (!string.IsNullOrEmpty(texture.Name)) { original = (from t in Textures.Values where t.Name == texture.Name select t).FirstOrDefault(); } // No match found, so this is a new texture. if (original == null) { if (Textures.ContainsKey(name)) { Textures[name] = texture; } else { Textures.Add(name, texture); } } // Match found, so this is an alias to a texture already added else { if (Textures.ContainsKey(name)) { Textures[name] = original; } else { Textures.Add(name, original); } } }
public bool TryAddTexture(Texture texture) { if ((texture == null) || string.IsNullOrEmpty(texture.Name) || Textures.ContainsKey(texture.Name)) { return(false); } if (texture.Image.Length == 0) { return(false); } if (texture.ImageFormat == ImageFormat.Invalid) { return(false); } Textures.Add(texture.Name, texture); return(true); }
public bool TryAddShader(Shader shader) { if ((shader == null) || string.IsNullOrEmpty(shader.Name) || Shaders.ContainsKey(shader.Name)) { return(false); } if (string.IsNullOrEmpty(shader.Material) || !Materials.ContainsKey(shader.Material)) { return(false); } if (!string.IsNullOrEmpty(shader.Texture) && !Textures.ContainsKey(shader.Texture)) { return(false); } Shaders.Add(shader.Name, shader); return(true); }
//Unlocks Image After Refresh public void RefreshImage(string TextureName, LockBitMap Image) { if (!Image.IsLocked) { Image.LockBits(); } if (Textures.ContainsKey(TextureName)) { Textures[TextureName].SetData(Image.Pixels); } else { Texture2D NewTexture = new Texture2D(Graphics, Image.Width, Image.Height); NewTexture.SetData(Image.Pixels); Textures.Add(TextureName, NewTexture); } Image.UnlockBits(); }
private static Texture WrapTexture(object texture, IntPtr nativePointer, int width, int height, int numLevels) { IntPtr texturePtr = Noesis_WrapTexture(nativePointer, width, height, numLevels); Noesis.Texture tex = new Noesis.Texture(texturePtr, true); // A texture with the same pointer could be enqueued for release, just remove it // now to avoid an exception when adding the new texture to the dictionary if (Textures.ContainsKey(texturePtr.ToInt64())) { Noesis_RemoveEnqueuedTexture(texturePtr); Textures.Remove(texturePtr.ToInt64()); } Textures.Add(texturePtr.ToInt64(), texture); return(tex); }
public static void GenerateTexture(string textureName) { if (!Textures.ContainsKey(textureName)) { throw new Exception("Нет такой текстуры."); } Gl.glBindTexture(Gl.GL_TEXTURE_2D, Textures[textureName].ID); Gl.glEnable(Gl.GL_TEXTURE_GEN_S); Gl.glTexGend(Gl.GL_TEXTURE_GEN_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_PLANE); Gl.glEnable(Gl.GL_TEXTURE_GEN_T); Gl.glTexGend(Gl.GL_TEXTURE_GEN_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_PLANE); Gl.glEnable(Gl.GL_TEXTURE_GEN_R); Gl.glTexGend(Gl.GL_TEXTURE_GEN_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_PLANE); //Gl.glEnable(Gl.GL_TEXTURE_GEN_Q); //Gl.glTexGend(Gl.GL_TEXTURE_GEN_Q, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_OBJECT_PLANE); }
/// <summary> /// Creates a ModelPreviewMaterial that renders as close to what the given <see cref="MaterialInstanceConstant"/> looks like as possible. /// </summary> /// <param name="texcache">The texture cache to request textures from.</param> /// <param name="mat">The material that this ModelPreviewMaterial will try to look like.</param> protected ModelPreviewMaterial(PreviewTextureCache texcache, MaterialInstanceConstant mat, PackageCache assetCache, List <PreloadedTextureData> preloadedTextures = null) { if (mat == null) { return; } Properties.Add("Name", mat.Export.ObjectName); foreach (var textureEntry in mat.Textures) { if (!Textures.ContainsKey(textureEntry.FullPath) && textureEntry.ClassName == "Texture2D") //Apparently some assets are cubemaps, we don't want these. { if (preloadedTextures != null) { var preloadedInfo = preloadedTextures.FirstOrDefault(x => x.MaterialExport == mat.Export && x.Mip.Export.ObjectName.Name == textureEntry.ObjectName.Name); //i don't like matching on object name but its export vs import here. if (preloadedInfo != null) { Textures.Add(textureEntry.FullPath, texcache.LoadTexture(preloadedInfo.Mip.Export, preloadedInfo.Mip, preloadedInfo.decompressedTextureData)); } else { Debug.WriteLine("Preloading error"); } //if (textureEntry is ExportEntry texPort && preloadedMipInfo.Export != texPort) throw new Exception(); continue; //Don't further parse } if (textureEntry is ImportEntry import) { var extAsset = EntryImporter.ResolveImport(import, null, assetCache); if (extAsset != null) { Textures.Add(textureEntry.FullPath, texcache.LoadTexture(extAsset)); } } else { Textures.Add(textureEntry.FullPath, texcache.LoadTexture(textureEntry as ExportEntry)); } } } }
public void UpdateRenderTargets() { if (Camera == null) { return; } for (int i = 0; i < RenderTargets.Count; i++) { if (RenderTargets[i].IsActive) { RenderTargets[i].RenderScene(Graphics, Camera.Position); if (Textures.ContainsKey(RenderTargets[i].DebugTextureName)) { //Textures[RenderTargets[i].DebugTextureName] = GraphicsUtil.CloneTexture(Graphics, RenderTargets[i].RenderTarget); Textures[RenderTargets[i].DebugTextureName] = RenderTargets[i].RenderTarget; } } } }
public Rect GetFaceUVRect(int face) { if (face == 0) { if (!Textures.ContainsKey("grass_generated")) {/* * Material mat = Material.Instantiate(Textures["grass_top"]); * mat.color = new Color(134f / 255, 183f / 255, 131f / 255); */ } return(Textures["grass_top"]); } else if (face == 5) { return(Textures["dirt"]); } else { return(Textures["grass_side"]); } }