public override async Task <UVCoord[]> GetUVsAsync() { if (CachedUVs != null) { return(CachedUVs); } var uArr = await Stream.GetAttributeArray(VertexAttribute.U); var vArr = await Stream.GetAttributeArray(VertexAttribute.V); var uvArr = new UVCoord[Stream.Length]; for (int i = 0; i < uvArr.Length; i++) { var u = BitConverter.Int32BitsToSingle(uArr[i]); var v = BitConverter.Int32BitsToSingle(vArr[i]); uvArr[i] = new UVCoord(i, u, 1 - v); } CachedUVs = uvArr; return(uvArr); }
private void ParseData() { BinaryDataReader dataReader = new BinaryDataReader(new MemoryStream(data)); dataReader.ByteOrder = order; dataReader.Position = 0x54 - 8; ColorTopLeft = dataReader.ReadColorRGBA(); ColorTopRight = dataReader.ReadColorRGBA(); ColorBottomLeft = dataReader.ReadColorRGBA(); ColorBottomRight = dataReader.ReadColorRGBA(); MaterialIndex = dataReader.ReadUInt16(); byte UVCount = dataReader.ReadByte(); dataReader.ReadByte(); //padding UVCoords = new UVCoord[UVCount]; for (int i = 0; i < UVCount; i++) { UVCoords[i] = new UVCoord() { TopLeft = dataReader.ReadVector2(), TopRight = dataReader.ReadVector2(), BottomLeft = dataReader.ReadVector2(), BottomRight = dataReader.ReadVector2() }; } }
public BSLightingShaderProperty() { this.shaderType = 0U; this.shaderFlags1 = 2185233152U; this.shaderFlags2 = 32801U; this.uvOffset = new UVCoord(0.0f, 0.0f); this.uvScale = new UVCoord(1f, 1f); this.textureSet = -1; this.emissiveColor = new Color3(0.0f, 0.0f, 0.0f); this.emissiveMultiple = 1f; this.wetMaterialIdx = -1; this.wetMaterialName = ""; this.textureClampMode = 3U; this.alpha = 1f; this.refractionStrength = 0.0f; this.glossiness = 80f; this.specularColor = new Color3(1f, 1f, 1f); this.specularStrength = 1f; this.lightingEffect1 = 0.3f; this.lightingEffect2 = 2f; this.subsurfaceRolloff = 0.0f; this.unkownFloat1 = float.MaxValue; this.backlightPower = 0.0f; this.grayscaleToPaletteScale = 1.0f;; this.fresnelPower = 5.0f; this.wetnessSpecScale = -1.0f; this.wetnessSpecPower = -1.0f; this.wetnessMinVar = -1.0f; this.wetnessEnvMapScale = -1.0f; this.wetnessFresnelPower = -1.0f; this.wetnessMetalness = -1.0f; }
public override void Read(NiHeader header, BinaryReader reader) { base.Read(header, reader); this.shaderFlags1 = reader.ReadUInt32(); this.shaderFlags2 = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.sourceTexture = Utils.ReadSizedString(reader); this.textureClampMode = reader.ReadUInt32(); this.falloffStartAngle = reader.ReadSingle(); this.falloffStopAngle = reader.ReadSingle(); this.falloffStartOpacity = reader.ReadSingle(); this.falloffStopOpacity = reader.ReadSingle(); this.emissiveColor = Utils.ReadColor4(reader); this.emissiveMultiple = reader.ReadSingle(); this.softFalloffDepth = reader.ReadSingle(); this.greyscaleTexture = Utils.ReadSizedString(reader); if (header.GetVersion() == 335675399U && header.GetUserVersion2() == 130) { this.envMapTexture = Utils.ReadSizedString(reader); this.normalTexture = Utils.ReadSizedString(reader); this.envMaskTexture = Utils.ReadSizedString(reader); this.enviromentMapScale = reader.ReadSingle(); } }
public override void Read(NiHeader header, BinaryReader reader) { this.shaderType = reader.ReadUInt32(); base.Read(header, reader); this.shaderFlags1 = reader.ReadUInt32(); this.shaderFlags2 = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.textureSet = reader.ReadInt32(); this.emissiveColor = Utils.ReadColor3(reader); this.emissiveMultiplier = reader.ReadSingle(); this.textureClampMode = reader.ReadUInt32(); this.alpha = reader.ReadSingle(); this.unknownFloat2 = reader.ReadSingle(); this.glossiness = reader.ReadSingle(); this.specularColor = Utils.ReadColor3(reader); this.specularStrength = reader.ReadSingle(); this.lightingEffect1 = reader.ReadSingle(); this.lightingEffect2 = reader.ReadSingle(); if ((int)this.shaderType == 1) { this.environmentMapScale = reader.ReadSingle(); } else if ((int)this.shaderType == 5) { this.skinTintColor = Utils.ReadColor3(reader); } else if ((int)this.shaderType == 6) { this.hairTintColor = Utils.ReadColor3(reader); } else if ((int)this.shaderType == 7) { this.maxPasses = reader.ReadSingle(); this.scale = reader.ReadSingle(); } else if ((int)this.shaderType == 11) { this.parallaxInnerLayerThickness = reader.ReadSingle(); this.parallaxRefractionScale = reader.ReadSingle(); this.parallaxInnerLayerTextureScale = Utils.ReadUVCoord(reader); this.parallaxEnvmapStrength = reader.ReadSingle(); } else if ((int)this.shaderType == 14) { this.sparkleParameters = Utils.ReadVector4(reader); } else { if ((int)this.shaderType != 16) { return; } this.eyeCubemapScale = reader.ReadSingle(); this.leftEyeReflectionCenter = Utils.ReadVector3(reader); this.rightEyeReflectionCenter = Utils.ReadVector3(reader); } }
public BSWaterShaderProperty() { this.shaderFlags1 = 0; this.shaderFlags2 = 0; this.uvOffset = new UVCoord(0.0f, 0.0f); this.uvScale = new UVCoord(1f, 1f); this.waterShaderFlags = 0; this.waterDirection = 0; this.unknown = 0; }
public override void Read(NiHeader header, BinaryReader reader) { base.Read(header, reader); this.shaderFlags1 = reader.ReadUInt32(); this.shaderFlags2 = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.waterShaderFlags = reader.ReadByte(); this.waterDirection = reader.ReadByte(); this.unknown = reader.ReadUInt16(); }
public BSEffectShaderProperty() { this.shaderFlags1 = 0U; this.shaderFlags2 = 0U; this.uvOffset = new UVCoord(0.0f, 0.0f); this.uvScale = new UVCoord(1f, 1f); this.sourceTexture = ""; this.textureClampMode = 0U; this.falloffStartAngle = 0.0f; this.falloffStopAngle = 0.0f; this.falloffStartOpacity = 1f; this.falloffStopOpacity = 1f; this.emissiveColor = new Color4(0.0f, 0.0f, 0.0f, 0.0f); this.emissiveMultiple = 1f; this.softFalloffDepth = 0.0f; this.greyscaleTexture = ""; }
public override void Read(NiHeader header, BinaryReader reader) { base.Read(header, reader); this.shaderFlags1 = reader.ReadUInt32(); this.shaderFlags2 = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.sourceTexture = Utils.ReadSizedString(reader); this.textureClampMode = reader.ReadUInt32(); this.falloffStartAngle = reader.ReadSingle(); this.falloffStopAngle = reader.ReadSingle(); this.falloffStartOpacity = reader.ReadSingle(); this.falloffStopOpacity = reader.ReadSingle(); this.emissiveColor = Utils.ReadColor4(reader); this.emissiveMultiple = reader.ReadSingle(); this.softFalloffDepth = reader.ReadSingle(); this.greyscaleTexture = Utils.ReadSizedString(reader); }
public BSLightingShaderProperty() { this.shaderType = 0U; this.shaderFlags1 = 2185233152U; this.shaderFlags2 = 32801U; this.uvOffset = new UVCoord(0.0f, 0.0f); this.uvScale = new UVCoord(1f, 1f); this.textureSet = -1; this.emissiveColor = new Color3(0.0f, 0.0f, 0.0f); this.emissiveMultiplier = 1f; this.textureClampMode = 3U; this.alpha = 1f; this.unknownFloat2 = 0.0f; this.glossiness = 80f; this.specularColor = new Color3(1f, 1f, 1f); this.specularStrength = 1f; this.lightingEffect1 = 0.3f; this.lightingEffect2 = 2f; }
// ... more public BGSMFile() { this.headerString = "BGSM"; this.version = 3U; this.textureClampMode = 0U; this.uvOffset = new UVCoord(0.0f, 0.0f); this.uvScale = new UVCoord(1f, 1f); this.alpha = 1f; this.alphamode0 = 0; this.alphamode1 = 0; this.alphamode2 = 0; this.alphaThreshold = 0; this.alphaFlag = 0; this.zBufferWrite = 0; this.zBufferTest = 0; this.reflections = 0; this.wetreflections = 0; this.decal = 0; this.doubleSided = 0; this.decalnofade = 0; this.noocclude = 0; this.refraction = 0; this.refractionfalloff = 0; this.refractionpower = 0; this.envmap = 0; this.envmapscale = 0; this.graytocolor = 0; this.textures = new string[9]; this.textures[0] = ""; this.textures[1] = ""; this.textures[2] = ""; this.textures[3] = ""; this.textures[4] = ""; this.textures[5] = ""; this.textures[6] = ""; this.textures[7] = ""; this.textures[8] = ""; this.enablealpha = 0; this.rimlighting = 0; this.rimPower = 0; this.backlightPower = 0; }
public ViewerVertex(Coord coord, Coord normal, UVCoord uv) { this.v = coord; this.n = normal; this.uv = uv; }
public void Read(string gameDir, string fileName, LogFile logFile) { MemoryStream memoryStream = new MemoryStream(); try { if (File.Exists(gameDir + fileName)) { try { FileStream fileStream = (FileStream)null; while (fileStream == null) { fileStream = Utils.GetFileStream(new FileInfo(gameDir + fileName), logFile); } BinaryReader binaryReader = new BinaryReader((Stream)fileStream); long length = binaryReader.BaseStream.Length; memoryStream.Write(binaryReader.ReadBytes((int)length), 0, (int)length); binaryReader.Close(); } catch (Exception ex) { logFile.WriteLog("Error reading " + fileName + " " + ex.Message); logFile.Close(); System.Environment.Exit(500); } } else if (BSAArchive.FileExists(fileName)) { try { byte[] newfile = BSAArchive.GetFile(fileName); int length = newfile.Length; memoryStream.Write(newfile, 0, length); } catch (Exception ex) { logFile.WriteLog("Error reading " + fileName + " from BSA/BA2 " + ex.Message); logFile.Close(); System.Environment.Exit(501); } } else { logFile.WriteLog(fileName + " not found!"); return; //logFile.Close(); //System.Environment.Exit(404); } } catch (Exception ex) { logFile.WriteLog("Error accessing " + gameDir + fileName + " " + ex.Message); logFile.WriteLog("In case Mod Organizer is used, set output path outside of game and MO virtual file system directory"); logFile.Close(); System.Environment.Exit(502); } memoryStream.Position = 0L; BinaryReader reader = new BinaryReader((Stream)memoryStream); try { this.headerString = ""; byte[] data = reader.ReadBytes(4); for (int index = 0; index < 4; index++) { this.headerString += (object)(char)data[index]; } this.version = reader.ReadUInt32(); this.textureClampMode = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.alpha = reader.ReadSingle(); this.alphamode0 = reader.ReadByte(); this.alphamode1 = reader.ReadUInt32(); this.alphamode2 = reader.ReadUInt32(); this.alphaThreshold = reader.ReadByte(); this.alphaFlag = reader.ReadByte(); this.zBufferWrite = reader.ReadByte(); this.zBufferTest = reader.ReadByte(); this.reflections = reader.ReadByte(); this.wetreflections = reader.ReadByte(); this.decal = reader.ReadByte(); this.doubleSided = reader.ReadByte(); this.decalnofade = reader.ReadByte(); this.noocclude = reader.ReadByte(); this.refraction = reader.ReadByte(); this.refractionfalloff = reader.ReadByte(); this.refractionpower = reader.ReadSingle(); this.envmap = reader.ReadByte(); this.envmapscale = reader.ReadSingle(); this.graytocolor = reader.ReadByte(); for (int index = 0; index < 9; index++) { this.textures[index] = Utils.ReadSizedString(reader).ToLower(CultureInfo.InvariantCulture).Replace("/", "\\").Replace("\0", string.Empty); } this.enablealpha = reader.ReadByte(); this.rimlighting = reader.ReadByte(); this.rimPower = reader.ReadSingle(); this.backlightPower = reader.ReadSingle(); // do no care what comes after this } catch (Exception ex) { logFile.WriteLog("Error BGSM " + fileName + " " + ex.Message); logFile.Close(); System.Environment.Exit(501); } reader.Close(); }
public static void ReadOBJFile(string InputFile) { string[] OBJFile = File.ReadAllLines(InputFile); int CurrentMaterial = -1; foreach (string j in OBJFile) { if (j.Length > 2) { if (j.Substring(0, 2) == "v ") { if (j.Substring(2, 1) == " ") { string[] SubStrings = j.Split(' '); Vertex TempVertex = new Vertex(); TempVertex.PositionX = Convert.ToSingle(SubStrings[2]); TempVertex.PositionY = Convert.ToSingle(SubStrings[3]); TempVertex.PositionZ = Convert.ToSingle(SubStrings[4]); VertexStream.Add(TempVertex); } else { string[] SubStrings = j.Split(' '); Vertex TempVertex = new Vertex(); TempVertex.PositionX = Convert.ToSingle(SubStrings[1]); TempVertex.PositionY = Convert.ToSingle(SubStrings[2]); TempVertex.PositionZ = Convert.ToSingle(SubStrings[3]); VertexStream.Add(TempVertex); } } else if (j.Substring(0, 3) == "vt ") { string[] SubStrings = j.Split(' '); UVCoord TempUV = new UVCoord(); TempUV.PositionU = Convert.ToSingle(SubStrings[1]); TempUV.PositionV = Convert.ToSingle(SubStrings[2]); UVStream.Add(TempUV); } else if (j.StartsWith("f ")) { string[] SubStrings = j.Split(' '); Triangle TempTriangle = new Triangle(); TempTriangle.MaterialIndex = CurrentMaterial; TempTriangle.Vertex1 = Convert.ToInt32(SubStrings[1].Split('/')[0]) - 1; TempTriangle.UVCoord1 = Convert.ToInt32(SubStrings[1].Split('/')[1]) - 1; TempTriangle.Vertex2 = Convert.ToInt32(SubStrings[2].Split('/')[0]) - 1; TempTriangle.UVCoord2 = Convert.ToInt32(SubStrings[2].Split('/')[1]) - 1; TempTriangle.Vertex3 = Convert.ToInt32(SubStrings[3].Split('/')[0]) - 1; TempTriangle.UVCoord3 = Convert.ToInt32(SubStrings[3].Split('/')[1]) - 1; TriangleStream.Add(TempTriangle); } else if (j.Length > 7) { if (j.Substring(0, 7) == "usemtl ") { MaterialStream.Add(j.Substring(7)); CurrentMaterial += 1; } else if (j.Substring(0, 7) == "mtllib ") { MTLLib = j.Substring(7); } } } } try { ReplaceMaterialNames(); } catch { Console.WriteLine("Unable to load material lib. Will use material names as texture names."); } FixUVCoords(); }
public override void Read(NiHeader header, BinaryReader reader) { this.shaderType = reader.ReadUInt32(); base.Read(header, reader); this.shaderFlags1 = reader.ReadUInt32(); this.shaderFlags2 = reader.ReadUInt32(); this.uvOffset = Utils.ReadUVCoord(reader); this.uvScale = Utils.ReadUVCoord(reader); this.textureSet = reader.ReadInt32(); this.emissiveColor = Utils.ReadColor3(reader); this.emissiveMultiple = reader.ReadSingle(); if (header.GetVersion() == 335675399U && header.GetUserVersion2() == 130) { this.wetMaterialIdx = reader.ReadInt32(); if (this.wetMaterialIdx != -1) { this.wetMaterialName = header.GetString((uint)this.wetMaterialIdx); } } this.textureClampMode = reader.ReadUInt32(); this.alpha = reader.ReadSingle(); this.refractionStrength = reader.ReadSingle(); this.glossiness = reader.ReadSingle(); this.specularColor = Utils.ReadColor3(reader); this.specularStrength = reader.ReadSingle(); if (header.GetVersion() == 335675399U && header.GetUserVersion2() == 130) { this.subsurfaceRolloff = reader.ReadSingle(); this.unkownFloat1 = reader.ReadSingle(); this.backlightPower = reader.ReadSingle(); this.grayscaleToPaletteScale = reader.ReadSingle(); this.fresnelPower = reader.ReadSingle(); this.wetnessSpecScale = reader.ReadSingle(); this.wetnessSpecPower = reader.ReadSingle(); this.wetnessMinVar = reader.ReadSingle(); this.wetnessEnvMapScale = reader.ReadSingle(); this.wetnessFresnelPower = reader.ReadSingle(); this.wetnessMetalness = reader.ReadSingle(); } else { this.lightingEffect1 = reader.ReadSingle(); this.lightingEffect2 = reader.ReadSingle(); } if ((int)this.shaderType == 1) { this.environmentMapScale = reader.ReadSingle(); if (header.GetVersion() == 335675399U && header.GetUserVersion2() == 130) { this.unkownEnvMapInt = reader.ReadUInt16(); } } else if ((int)this.shaderType == 5) { this.skinTintColor = Utils.ReadColor3(reader); if (header.GetVersion() == 335675399U && header.GetUserVersion2() == 130) { this.unkownSkinTintInt = reader.ReadUInt32(); } } else if ((int)this.shaderType == 6) { this.hairTintColor = Utils.ReadColor3(reader); } else if ((int)this.shaderType == 7) { this.maxPasses = reader.ReadSingle(); this.scale = reader.ReadSingle(); } else if ((int)this.shaderType == 11) { this.parallaxInnerLayerThickness = reader.ReadSingle(); this.parallaxRefractionScale = reader.ReadSingle(); this.parallaxInnerLayerTextureScale = Utils.ReadUVCoord(reader); this.parallaxEnvmapStrength = reader.ReadSingle(); } else if ((int)this.shaderType == 14) { this.sparkleParameters = Utils.ReadVector4(reader); } else { if ((int)this.shaderType != 16) { return; } this.eyeCubemapScale = reader.ReadSingle(); this.leftEyeReflectionCenter = Utils.ReadVector3(reader); this.rightEyeReflectionCenter = Utils.ReadVector3(reader); } }
internal static MeshLOD SculptMeshToMesh(this Bitmap bitmap, ObjectPart.PrimitiveShape.Decoded shape, bool generate_uv = false) { bool mirror = shape.IsSculptMirrored; var mesh = new MeshLOD(); bool reverse_horizontal = shape.IsSculptInverted ? !mirror : mirror; PrimitiveSculptType sculptType = shape.SculptType; int sculptSizeS; int sculptSizeT; int sculptVerts = bitmap.Width * bitmap.Height / 4; if (sculptVerts > 32 * 32) { sculptVerts = 32 * 32; } double ratio = (double)bitmap.Width / bitmap.Height; sculptSizeS = (int)Math.Sqrt(sculptVerts / ratio); sculptSizeS = Math.Max(sculptSizeS, 4); sculptSizeT = sculptVerts / sculptSizeS; sculptSizeT = Math.Max(sculptSizeT, 4); sculptSizeS = sculptVerts / sculptSizeT; /* generate vertex map */ for (int s = 0; s < sculptSizeS; ++s) { for (int t = 0; t < sculptSizeT; ++t) { int reversed_t = t; if (reverse_horizontal) { reversed_t = sculptSizeT - t - 1; } var x = (int)((double)reversed_t / (sculptSizeT - 1) * bitmap.Width); var y = (int)((double)s / (sculptSizeS - 1) * bitmap.Height); if (y == 0) { if (sculptType == PrimitiveSculptType.Sphere) { x = bitmap.Width / 2; } } else if (y == bitmap.Height) { y = (sculptType == PrimitiveSculptType.Torus) ? 0 : bitmap.Height - 1; if (sculptType == PrimitiveSculptType.Sphere) { x = bitmap.Width / 2; } } if (x == bitmap.Width) { switch (sculptType) { case PrimitiveSculptType.Sphere: case PrimitiveSculptType.Torus: case PrimitiveSculptType.Cylinder: x = 0; break; default: x = bitmap.Width - 1; break; } } Vector3 v = bitmap.GetVertex(x, y, mirror); mesh.Vertices.Add(v); if (generate_uv) { var uv = new UVCoord { U = (float)reversed_t / (sculptSizeS - t), V = (float)s / (sculptSizeS - 1) }; mesh.UVCoords.Add(uv); } } } /* generate triangles */ for (int row = 0; row < sculptSizeS - 1; ++row) { int rowIndex = row * sculptSizeT; int row2Index = rowIndex + sculptSizeT; for (int col = 0; col < sculptSizeT - 1; ++col) { var tri = new Triangle { Vertex1 = rowIndex + col, Vertex2 = row2Index + col + 1, Vertex3 = rowIndex + col + 1 }; mesh.Triangles.Add(tri); tri = new Triangle { Vertex1 = rowIndex + col, Vertex2 = row2Index + col, Vertex3 = row2Index + col + 1 }; mesh.Triangles.Add(tri); } } return(mesh); }
public void SetUVOffset(UVCoord value) { this.uvOffset = value; }
public void SetUVScale(UVCoord value) { this.uvScale = value; }