public static void UpdateTexture(ChaControl cc, TexType type) { if (cc == null) { return; } if (cc.customTexCtrlBody == null || cc.customTexCtrlFace == null) { return; } switch (type) { case TexType.BodyOver: case TexType.BodyUnder: cc.AddUpdateCMBodyTexFlags(true, true, true, true); cc.CreateBodyTexture(); break; case TexType.FaceOver: case TexType.FaceUnder: cc.AddUpdateCMFaceTexFlags(true, true, true, true, true, true, true); cc.CreateFaceTexture(); break; default: cc.AddUpdateCMBodyTexFlags(true, true, true, true); cc.CreateBodyTexture(); cc.AddUpdateCMFaceTexFlags(true, true, true, true, true, true, true); cc.CreateFaceTexture(); break; } }
public NiTextureTransformController(NIFReader file, BinaryReader reader) : base(file, reader) { Unknown2 = reader.ReadByte(); TextureSlot = (TexType)reader.ReadUInt32(); Operation = (TexTransform)reader.ReadUInt32(); Data = new NiRef <NiFloatData>(reader); }
public OverlayTexture SetOverlayTex(byte[] overlayTex, TexType overlayType) { _overlays.TryGetValue(overlayType, out var existing); if (overlayTex == null) { // Remove the overlay existing?.Dispose(); _overlays.Remove(overlayType); existing = null; } else { // Update or add if (existing == null) { existing = new OverlayTexture(overlayTex); _overlays.Add(overlayType, existing); } else { existing.Data = overlayTex; } } UpdateTexture(overlayType); return(existing); }
/// <summary> /// Old loading logic from folders /// </summary> internal static Texture2D GetOldStyleOverlayTex(TexType texType, ChaControl chaControl) { var charFullname = chaControl.fileParam?.fullname; if (!string.IsNullOrEmpty(charFullname)) { var texFilename = GetTexFilename(charFullname, texType); if (File.Exists(texFilename)) { Logger.Log(LogLevel.Info, $"[KSOX] Importing texture data for {charFullname} from file {texFilename}"); try { var fileTexBytes = File.ReadAllBytes(texFilename); var overlayTex = Util.TextureFromBytes(fileTexBytes); if (overlayTex != null) { return(overlayTex); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "[KSOX] Failed to load texture from file - " + ex.Message); } } } return(null); }
private void SetTexAndUpdate(byte[] tex, TexType texType) { var ctrl = GetOverlayController(); var overlay = ctrl.SetOverlayTex(tex, texType); _textureChanged.OnNext(new KeyValuePair <TexType, Texture2D>(texType, overlay.Texture)); }
public NiFlipController() { textureSlot = (TexType)0; startTime = 0.0f; delta = 0.0f; numSources = (uint)0; }
/// <summary> /// Create a texture from a stream /// </summary> /// <param name="stream">The stream that contains the texture</param> /// <param name="type">The type of the texture to create, or <see cref="TexType.RuntimeDetect"/> to automatically detect</param> /// <param name="loaderFlags">The flags passed to the texture loader</param> /// <param name="maxMipMapSize">The maximum permitted size of a mipmap, or 0 to indicate the maximum size permitted by hardware</param> /// <returns>A texture description</returns> public static FormatTexture LoadTextureDesc( Stream stream, TexType type = TexType.RuntimeDetect, LoaderFlags loaderFlags = LoaderFlags.None, uint maxMipMapSize = 0 ) { if (stream is null) { ThrowHelper.ThrowArgumentNullException(nameof(stream)); } long streamSize = stream !.Length; if (streamSize > int.MaxValue) { ThrowHelper.ThrowArgumentException($"File too large (only files up to {int.MaxValue} bytes are supported)"); } var data = new byte[streamSize]; var read = stream.Read(data); return(LoadTextureDesc( data, type, loaderFlags, maxMipMapSize )); }
/// <summary> /// Create a new additional overlay texture. /// </summary> /// <param name="texture">Overlay texture</param> /// <param name="overlayType">What part to apply the overlay to</param> /// <param name="tag">Tag for self use</param> /// <param name="applyOrder">Order in which the overlay isapplied relative to other additional overlay textures. Lower number is applied earlier. Default is 0.</param> public AdditionalTexture(Texture2D texture, TexType overlayType, object tag, int applyOrder) { Texture = texture; Tag = tag; OverlayType = overlayType; ApplyOrder = applyOrder; }
public TxpMipMap(Stream s) { #if (DEBUG) Console.Write("TxpMipMap - Begin at " + s.Position + "\n"); #endif if (DataStream.ReadString(s, 3) != magic) { return; } #if (DEBUG) Console.Write("TxpMipMap - Magic correct \n"); #endif flag = DataStream.ReadByte(s); #if (DEBUG) Console.Write("TxpMipMap - Flag is " + flag + "\n"); #endif if (flag != 2) { Console.Write("TxpMipMap - Flag is not 0x2 \n"); return; } width = DataStream.ReadUInt32(s); height = DataStream.ReadUInt32(s); type = (TexType)DataStream.ReadUInt32(s); id = DataStream.ReadUInt32(s); byteSize = DataStream.ReadUInt32(s); data = DataStream.ReadBytes(s, (int)byteSize); //Array.Reverse(data); }
public NiTextureTransformController() { shaderMap = false; textureSlot = (TexType)0; operation = (TransformMember)0; data = null; }
/// <summary> /// Create a new PC Texture with the specified information; Cubemap and Mipmaps are determined based on bytes. /// </summary> public Texture(string name, byte format, byte flags1, int flags2, byte[] bytes) { Name = name; Format = format; Flags1 = flags1; Flags2 = flags2; Bytes = bytes; Header = null; DDS dds = new DDS(bytes); if (dds.dwCaps2.HasFlag(DDS.DDSCAPS2.CUBEMAP)) { Type = TexType.Cubemap; } else if (dds.dwCaps2.HasFlag(DDS.DDSCAPS2.VOLUME)) { Type = TexType.Volume; } else { Type = TexType.Texture; } Mipmaps = (byte)dds.dwMipMapCount; }
public void ApplyOverlayToRT(RenderTexture bodyTexture, TexType overlayType) { foreach (var overlayTexture in GetOverlayTextures(overlayType)) { ApplyOverlay(bodyTexture, overlayTexture); } }
/// <summary> /// Old loading logic from folders /// </summary> internal static byte[] GetOldStyleOverlayTex(TexType texType, ChaControl chaControl) { var charFullname = chaControl.fileParam?.fullname; if (!string.IsNullOrEmpty(charFullname)) { var texFilename = GetTexFilename(charFullname, texType); if (File.Exists(texFilename)) { Log(LogLevel.Info, $"[KSOX] Importing texture data for {charFullname} from file {texFilename}"); try { var fileTexBytes = File.ReadAllBytes(texFilename); var overlayTex = Util.TextureFromBytes(fileTexBytes, TextureFormat.ARGB32); // todo re-convert the texture, check for size if (overlayTex != null) { return(overlayTex.EncodeToPNG()); } } catch (Exception ex) { Log(LogLevel.Error, "[KSOX] Failed to load texture from file - " + ex.Message); } } } return(null); }
internal TextureDescription( Memory <byte> bitData, D3D12_RESOURCE_DIMENSION resourceDimension, Size3 size, uint mipCount, uint arraySize, DXGI_FORMAT format, LoaderFlags loaderFlags, bool isCubeMap, Memory <ManagedSubresourceData> subresourceData, AlphaMode alphaMode, TexType underlyingTextureType) { BitData = bitData; ResourceDimension = resourceDimension; _size = size; MipCount = mipCount; ArraySize = arraySize; Format = format; LoaderFlags = loaderFlags; IsCubeMap = isCubeMap; SubresourceData = subresourceData; AlphaMode = alphaMode; UnderlyingTextureType = underlyingTextureType; }
internal static string GetTexFilename(string charFullname, TexType texType) { string name; switch (texType) { case TexType.BodyOver: name = "Body"; break; case TexType.FaceOver: name = "Face"; break; case TexType.Unknown: return(null); default: name = texType.ToString(); break; } var legacyDir = Path.Combine(Paths.PluginPath, "KoiSkinOverlay"); var charFolder = $"{legacyDir}/{charFullname}"; var texFilename = $"{charFolder}/{name}.png"; return(texFilename); }
/// <summary> /// Old loading logic from folders /// </summary> internal static byte[] GetOldStyleOverlayTex(TexType texType, ChaControl chaControl) { #if KK var charFullname = chaControl.fileParam?.fullname; if (!string.IsNullOrEmpty(charFullname)) { var texFilename = GetTexFilename(charFullname, texType); if (File.Exists(texFilename)) { Logger.LogInfo($"Importing texture data for {charFullname} from file {texFilename}"); try { var fileTexBytes = File.ReadAllBytes(texFilename); var overlayTex = Util.TextureFromBytes(fileTexBytes, TextureFormat.ARGB32); if (overlayTex != null) { return(overlayTex.EncodeToPNG()); } } catch (Exception ex) { Logger.LogError("[KSOX] Failed to load texture from file - " + ex.Message); } } } #endif return(null); }
/* * Retrieves the texture index of the texture that is used by the specified * texture slot. * \param[in] slot The type of texture slot to get the texture index of. * \return The index of the texture used by the specified material at the * given slot, or NO_TEXTURE if no match is found. */ public uint GetTextureIndex(TexType slot) { if (texing_prop != null) { if (!texing_prop.HasTexture((int)slot)) { return(MatTexCollection.NO_TEXTURE); } var td = texing_prop.GetTexture((int)slot); if (td.source == null) { return(MatTexCollection.NO_TEXTURE); } return(_creator.GetTextureIndex(td.source)); } if (tex_prop != null && slot == TexType.BASE_MAP) { var img = tex_prop.GetImage(); if (img == null) { return(MatTexCollection.NO_TEXTURE); } return(_creator.GetTextureIndex(img)); } //TODO: Figure out which slots are what in NiMultiTextureProperty so this can be implemented for that too //Texture not found return(MatTexCollection.NO_TEXTURE); }
public GeoTexture(string name = null) { Type = TexType.Diffuse; Filename = "undefined."; OpenGLID = -1; UVMapIndex = 0; UVTransform = new Vector2(1, 1); }
private void SetTexAndUpdate(Texture2D tex, TexType texType) { var ctrl = GetOverlayController(); ctrl.SetOverlayTex(tex, texType); ctrl.UpdateTexture(texType); _textureChanged.OnNext(new KeyValuePair <TexType, Texture2D>(texType, tex)); }
public static string GetTexTypeExtension(TexType type) { switch (type) { case TexType.PNG: return(".png"); case TexType.JPEG: return(".jpg"); } return(""); }
//CoordinateType coordinateType public Texture2D GetTexture(TexType type) { var texs = GetCurrentOverlayTextures(); if (texs.TryGetValue(type, out var id)) { return(_textureStorage.GetSharedTexture(id)); } return(null); }
public void ApplyOverlayToRT(RenderTexture bodyTexture, TexType overlayType) { if (_overlays.TryGetValue(overlayType, out var tex)) { ApplyOverlay(bodyTexture, tex.Texture); } foreach (var additionalTexture in AdditionalTextures.Where(x => x.OverlayType == overlayType && x.Texture != null).OrderBy(x => x.ApplyOrder)) { ApplyOverlay(bodyTexture, additionalTexture.Texture); } }
private bool IsShown(TexType overlayType) { #if !EC if (!KKAPI.Studio.StudioAPI.InsideStudio) { return(true); } return(EnableInStudioSkin && overlayType <= TexType.FaceUnder || EnableInStudioIris && overlayType > TexType.FaceUnder); #else return(true); #endif }
internal void activateTexture(TexType type, ref int texunit, ref int handle) { string name = type.ToString(); int texid = getTextureId(type); if (texid != 0) { GL.ActiveTexture(TextureUnit.Texture0 + texunit); GL.BindTexture(TextureTarget.Texture2D, texid); GL.Uniform1(GL.GetUniformLocation(handle, name), texunit); texunit++; } }
private void OnFileAccept(string[] strings, TexType type) { if (strings == null || strings.Length == 0) { return; } var texPath = strings[0]; if (string.IsNullOrEmpty(texPath)) { return; } _typeToLoad = type; void ReadTex(string texturePath) { try { _bytesToLoad = File.ReadAllBytes(texturePath); } catch (Exception ex) { _bytesToLoad = null; _lastError = ex; } } ReadTex(texPath); _texChangeWatcher?.Dispose(); if (WatchLoadedTexForChanges.Value) { var directory = Path.GetDirectoryName(texPath); if (directory != null) { _texChangeWatcher = new FileSystemWatcher(directory, Path.GetFileName(texPath)); _texChangeWatcher.Changed += (sender, args) => { if (File.Exists(texPath)) { ReadTex(texPath); } }; _texChangeWatcher.Deleted += (sender, args) => _texChangeWatcher?.Dispose(); _texChangeWatcher.Error += (sender, args) => _texChangeWatcher?.Dispose(); _texChangeWatcher.EnableRaisingEvents = true; } } }
/* * Sets the texture filter mode of the specified texture slot. This * specifies the way the texure will look when it's minified or magnified. * \param[in] slot The type of texture slot to set the filter mode for. * \param[in] mode The new texture filter mode for the specified texture * slot. */ public void SetTexFilterMode(TexType slot, TexFilterMode mode) { if (texing_prop != null) { if (!texing_prop.HasTexture((int)slot)) { throw new Exception("The texture at the specified index does not exist."); } var td = texing_prop.GetTexture((int)slot); td.filterMode = mode; texing_prop.SetTexture((int)slot, td); } //Just silently fail for now. Not sure where this data may or may not be stored in the old style texture properties. }
public void SetTexture(TexType type, byte[] pngData) { var texs = GetCurrentOverlayTextures(); if (pngData == null) { texs.Remove(type); } else { var id = _textureStorage.StoreTexture(pngData); texs[type] = id; } }
/* * Retrieves the UV Set Index of the texture in the specified slot. This * is the index into the array of UV sets in the NiTriBasedGeom object that * this material will be applied to. * \param[in] slot The type of texture slot to get the UV set index for. * \return The UV set index used by the specified texture slot. */ public uint GetTexUVSetIndex(TexType slot) { if (texing_prop != null) { if (!texing_prop.HasTexture((int)slot)) { throw new Exception("The texture at the specified index does not exist."); } var td = texing_prop.GetTexture((int)slot); return(td.uvSet); } //Just return default value for now. Not sure where this data may or may not be stored in the old style texture properties. return(0); }
/* * Retrieves the texture filter mode of the specified texture slot. This * specifies the way the texure will look when it's minified or magnified. * \param[in] slot The type of texture slot to set the filter mode for. * \return The texture filter mode of the specified texture slot. */ public TexFilterMode GetTexFilterMode(TexType slot) { if (texing_prop != null) { if (!texing_prop.HasTexture((int)slot)) { throw new Exception("The texture at the specified index does not exist."); } var td = texing_prop.GetTexture((int)slot); return(td.filterMode); } //Just return default value for now. Not sure where this data may or may not be stored in the old style texture properties. return(TexFilterMode.FILTER_BILERP); }
private void SetTexAndUpdate(byte[] tex, TexType texType) { var ctrl = GetOverlayController(); var overlay = ctrl.SetOverlayTex(tex, texType); #if KK if (!_tPerCoord[0].Value) { ctrl.OverlayStorage.CopyToOtherCoords(); } #endif _textureChanged.OnNext(new KeyValuePair <TexType, Texture2D>(texType, overlay)); }
public void setTexture(TexType type, Texture texture) { textures[(int)type] = texture; }
public string getTextureName(TexType type) { return textures[(int)type].name; }
public void Set( int MTXPLT_COUNT, bool ENABLE_VERTEX_COLOR, int TEX_COUNT, bool ENABLE_TEXANIM, int LIGHT_COUNT, LightingType LIGHTING_TYPE, NormalMapType NORMALMAP_TYPE, int[] TEXCOORD, TexType[] TEXTYPE, TexBlendFunc[] BLENDFUNC, bool ENABLE_ALPHA_THRESHHOLD ) { this.MTXPLT_COUNT = MTXPLT_COUNT; this.ENABLE_VERTEX_COLOR = ENABLE_VERTEX_COLOR; this.TEX_COUNT = TEX_COUNT; this.ENABLE_TEXANIM = ENABLE_TEXANIM; this.LIGHT_COUNT = LIGHT_COUNT; this.LIGHTING_TYPE = LIGHTING_TYPE; if( this.LIGHT_COUNT <= 0 ){ this.LIGHTING_TYPE = LightingType.kLIGHTING_NONE; } this.NORMALMAP_TYPE = NORMALMAP_TYPE; for( int i = 0; i < this.TEXCOORD.Length; i++ ){ if( i < TEX_COUNT ){ this.TEXCOORD[i] = TEXCOORD[i]; this.TEXTYPE[i] = TEXTYPE[i]; this.BLENDFUNC[i] = BLENDFUNC[i]; }else{ this.TEXCOORD[i] = 0; this.TEXTYPE[i] = TexType.kTEXTYPE_NONE; this.BLENDFUNC[i] = TexBlendFunc.kBLEND_NONE; } } this.ENABLE_ALPHA_THRESHHOLD = ENABLE_ALPHA_THRESHHOLD; makeNames(); }
/// キーとして利用する TexType に符号化する string toTexTypeCode( TexType flg ) { if( flg == TexType.kTEXTYPE_IMAGE ){ return "I"; }else if( flg == TexType.kTEXTYPE_VERTEXNORMAL ){ return "V"; }else if( flg == TexType.kTEXTYPE_IMAGENORMALL ){ return "M"; } return "N"; }
/// 引数付コンストラクタ public BasicShaderName( int MTXPLT_COUNT, bool ENABLE_VERTEX_COLOR, int TEX_COUNT, bool ENABLE_TEXANIM, int LIGHT_COUNT, LightingType LIGHTING_TYPE, NormalMapType NORMALMAP_TYPE, int[] TEXCOORD, TexType[] TEXTYPE, TexBlendFunc[] BLENDFUNC, bool ENABLE_ALPHA_THRESHHOLD ) { this.Set( MTXPLT_COUNT, ENABLE_VERTEX_COLOR, TEX_COUNT, ENABLE_TEXANIM, LIGHT_COUNT, LIGHTING_TYPE, NORMALMAP_TYPE, TEXCOORD, TEXTYPE, BLENDFUNC, ENABLE_ALPHA_THRESHHOLD ); }
public int getTextureId(TexType type) { return textures[(int)type].texture; }
public ShaderPropTex(PropKey key, TexType type) : base(key, ValType.Tex) { this.texType = type; }
public ShaderPropTex(string name, PropKey key, int id, TexType type) : base(name, key, id, ValType.Tex) { this.texType = type; }
/// テクスチャのブレンドファンクション public BasicLayer() { Texture = -1 ; TexAnimBoneName = ""; TexAnimBoneIdx = -1; TexType = 0; // 通常 TangentID = 0; // BlindData = new Dictionary< string, int >(); }
internal void activateTexture(TexType type, ref int texunit,ref int handle) { string name = type.ToString(); int texid = getTextureId(type); if (texid != 0) { GL.ActiveTexture(TextureUnit.Texture0 + texunit); GL.BindTexture(TextureTarget.Texture2D, texid); GL.Uniform1(GL.GetUniformLocation(handle, name), texunit); texunit++; } }
/** * TexType * 0 ... 通常テクスチャ * 1 ... 頂点座標系変換済みノーマルマップ * 2 ... テクスチャ座標系ノーマルマップ */ public void SetTexType( int idx, TexType TexType ) { if( idx == 0 && idTEXTYPE00 >= 0 ){ this.SetUniformValue( idTEXTYPE00, (int)TexType ); }else if( idx == 1 && idTEXTYPE01 >= 0 ){ this.SetUniformValue( idTEXTYPE01, (int)TexType ); }else if( idx == 2 && idTEXTYPE01 >= 0 ){ this.SetUniformValue( idTEXTYPE02, (int)TexType ); } }