private void SetVertsTextureCoordinates(PositionTextureColor[] verts, int startIndex, Rectangle srcRect) { TextureCoordinates texCoords = GetTextureCoordinates(srcRect); SetVertsTextureCoordinates(verts, startIndex, texCoords); }
public override bool ApplyVar(string var, string value) { switch (var) { case "textures": string[] texes = value.Split('|'); if (texes.Length != 6) { return(false); } Textures = texes; return(true); case "coords": string[] coords = value.Split('|'); if (coords.Length != 6) { return(false); } Coords = new TextureCoordinates[] { TextureCoordinates.FromString(coords[0]), TextureCoordinates.FromString(coords[1]), TextureCoordinates.FromString(coords[2]), TextureCoordinates.FromString(coords[3]), TextureCoordinates.FromString(coords[4]), TextureCoordinates.FromString(coords[5]) }; return(true); case "water": Water = value.ToLower() == "true"; return(true); default: return(base.ApplyVar(var, value)); } }
public override void DrawTexture() { if (!isInitialized) { if (!string.IsNullOrEmpty(TextInfo.Text)) { Texture = TextInfo.Text.StringToBitmapSource(FontSize, Media.Colors.White, Media.Colors.Black, this.FontFamily, this.FontWeight, this.FontStyle, Padding); Texture.Freeze(); if (!predefinedSize) { Width = (float)Texture.Width; Height = (float)Texture.Height; } DrawCharacter(TextInfo.Text, TextInfo.Origin, Width, Height, TextInfo); } else { Texture = null; if (!predefinedSize) { Width = 0; Height = 0; } Positions.Clear(); Colors.Clear(); TextureCoordinates.Clear(); TextInfo.Offsets.Clear(); } isInitialized = true; UpdateBounds(); } }
private void DrawCharacter(string text, Vector3 origin, float w, float h, TextInfo info) { Positions.Clear(); Colors.Clear(); TextureCoordinates.Clear(); info.Offsets.Clear(); // CCW from top left var a = new Vector2(-w / 2, -h / 2); var b = new Vector2(-w / 2, h / 2); var c = new Vector2(w / 2, -h / 2); var d = new Vector2(w / 2, h / 2); var uv_a = new Vector2(0, 0); var uv_b = new Vector2(0, 1); var uv_c = new Vector2(1, 0); var uv_d = new Vector2(1, 1); // Create foreground data Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Colors.Add(FontColor); Colors.Add(FontColor); Colors.Add(FontColor); Colors.Add(FontColor); TextureCoordinates.Add(uv_b); TextureCoordinates.Add(uv_d); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_c); info.Offsets.Add(a); info.Offsets.Add(c); info.Offsets.Add(b); info.Offsets.Add(d); // Create background data Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Colors.Add(BackgroundColor); Colors.Add(BackgroundColor); Colors.Add(BackgroundColor); Colors.Add(BackgroundColor); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_a); info.Offsets.Add(a); info.Offsets.Add(c); info.Offsets.Add(b); info.Offsets.Add(d); }
private void SetVertsTextureCoordinates(PositionTextureColor[] verts, int startIndex, TextureCoordinates texCoords) { verts[startIndex].TexCoord = new Vector2(texCoords.Left, texCoords.Top); verts[startIndex + 1].TexCoord = new Vector2(texCoords.Right, texCoords.Top); verts[startIndex + 2].TexCoord = new Vector2(texCoords.Left, texCoords.Bottom); verts[startIndex + 3].TexCoord = new Vector2(texCoords.Right, texCoords.Bottom); }
protected override void OnClearAllGeometryData() { base.OnClearAllGeometryData(); Normals?.Clear(); Normals?.TrimExcess(); TextureCoordinates?.Clear(); TextureCoordinates?.TrimExcess(); Tangents?.Clear(); Tangents?.TrimExcess(); BiTangents?.Clear(); BiTangents?.TrimExcess(); }
private void SetVertsTextureCoordinates(PositionColorNormalTexture[] verts, int startIndex, TextureCoordinates texCoords) { verts[startIndex].Tu = texCoords.Left; verts[startIndex].Tv = texCoords.Top; verts[startIndex + 1].Tu = texCoords.Right; verts[startIndex + 1].Tv = texCoords.Top; verts[startIndex + 2].Tu = texCoords.Left; verts[startIndex + 2].Tv = texCoords.Bottom; verts[startIndex + 3].Tu = texCoords.Right; verts[startIndex + 3].Tv = texCoords.Bottom; }
private void DrawCharacter(Character character, Vector3 origin, float w, float h, float kerning, TextInfo info) { var cw = character.Bounds.Width; var ch = character.Bounds.Height; var cu = character.Bounds.Left; var cv = character.Bounds.Top; // CCW from top left var a = new Vector2(origin.X + kerning, origin.Y); var b = new Vector2(origin.X + kerning, origin.Y + ch); var c = new Vector2(origin.X + cw + kerning, origin.Y); var d = new Vector2(origin.X + cw + kerning, origin.Y + ch); var uv_a = new Vector2(cu / w, cv / h); var uv_b = new Vector2(cu / w, (cv + ch) / h); var uv_c = new Vector2((cu + cw) / w, cv / h); var uv_d = new Vector2((cu + cw) / w, (cv + ch) / h); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); Positions.Add(info.Origin); var color = FontColor.ToColor4(); Colors.Add(color); Colors.Add(color); Colors.Add(color); Colors.Add(color); Colors.Add(color); Colors.Add(color); TextureCoordinates.Add(uv_b); TextureCoordinates.Add(uv_d); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_d); TextureCoordinates.Add(uv_c); info.Offsets.Add(a); info.Offsets.Add(c); info.Offsets.Add(b); info.Offsets.Add(b); info.Offsets.Add(c); info.Offsets.Add(d); }
public Mesh ToMesh(string name) { var mesh = new Mesh() { name = name, vertices = Vertices.ToArray(), uv = TextureCoordinates.ToArray(), triangles = Faces.ToArray() }; mesh.RecalculateNormals(); mesh.RecalculateTangents(); mesh.RecalculateBounds(); return(mesh); }
private void Connect() { TextureCoordinates.InitializeTextures(); NetworkHandler netHandler = new NetworkHandler(); _networkThread = new Thread(netHandler.NetThread); _networkThread.IsBackground = true; _networkThread.Start(); RenderFIFO fifo = new RenderFIFO(); _render = new Thread(fifo.CreateThreads); _render.IsBackground = true; _render.Start(GraphicsDevice); }
public override void DrawTexture() { Positions.Clear(); Colors.Clear(); TextureCoordinates.Clear(); // http://www.cyotek.com/blog/angelcode-bitmap-font-parsing-using-csharp foreach (var textInfo in TextInfo) { textInfo.Offsets.Clear(); int x = 0; int y = 0; var w = bmpFont.TextureSize.Width; var h = bmpFont.TextureSize.Height; char previousCharacter; previousCharacter = ' '; var normalizedText = textInfo.Text; foreach (char character in normalizedText) { switch (character) { case '\n': x = 0; y -= bmpFont.LineHeight; break; default: Character data = bmpFont[character]; int kerning = bmpFont.GetKerning(previousCharacter, character); //DrawCharacter(data, x + data.Offset.X + kerning, y + data.Offset.Y, builder); DrawCharacter(data, new Vector3(x, y, 0), w, h, kerning, textInfo); x += data.XAdvance + kerning; break; } previousCharacter = character; } } UpdateBounds(); }
public override void DrawTexture() { Positions.Clear(); Colors.Clear(); TextureCoordinates.Clear(); mTextInfoOffsets = new List <Vector2>(4); var w = Width; var h = Height; // CCW from top left var a = new Vector2(-w / 2, -h / 2); var b = new Vector2(-w / 2, h / 2); var c = new Vector2(w / 2, -h / 2); var d = new Vector2(w / 2, h / 2); var uv_a = new Vector2(0, 0); var uv_b = new Vector2(0, 1); var uv_c = new Vector2(1, 0); var uv_d = new Vector2(1, 1); // Create foreground data Positions.Add(Center); Positions.Add(Center); Positions.Add(Center); Positions.Add(Center); Colors.Add(MaskColor); Colors.Add(MaskColor); Colors.Add(MaskColor); Colors.Add(MaskColor); TextureCoordinates.Add(uv_b); TextureCoordinates.Add(uv_d); TextureCoordinates.Add(uv_a); TextureCoordinates.Add(uv_c); mTextInfoOffsets.Add(a); mTextInfoOffsets.Add(c); mTextInfoOffsets.Add(b); mTextInfoOffsets.Add(d); UpdateBounds(); }
internal override void Parse(byte[] buffer, int globalOffset, int offset) { base.Parse(buffer, globalOffset, offset); int verticesCount = BitConverter.ToInt32(buffer, offset + 16); int verticesOffset = BitConverter.ToInt32(buffer, offset + 20); if (verticesCount == 0 || verticesOffset == 0) { return; } this.TextureVertices = new List <TextureCoordinates>(verticesCount); verticesOffset -= globalOffset; for (int i = 0; i < verticesCount; i++) { this.TextureVertices.Add(TextureCoordinates.FromByteArray(buffer, verticesOffset + (i * 8))); } }
/// <inheritdoc/> public override void Draw(Matrix parentTransformation, Matrix transformation) { double barLength = Size.X * Meter.RelativeValue; if (BarImage != null) { TextureCoordinates tex = new TextureCoordinates(); tex.TopLeft = new Vector(0, 0); tex.TopRight = new Vector(Meter.RelativeValue, 0); tex.BottomLeft = new Vector(0, TextureWrapSize.Y); tex.BottomRight = new Vector(Meter.RelativeValue, TextureWrapSize.Y); Renderer.DrawImage(parentTransformation, BarImage, tex, Position + new Vector(barLength / 2 - Size.X / 2, 0), new Vector(barLength, Size.Y), (float)Angle.Radians); } else { Renderer.DrawFilledShape(shapeCache, ref parentTransformation, Position - Vector.FromLengthAndAngle(barLength / 2 - Size.X / 2, Angle), new Vector(barLength, Size.Y), (float)Angle.Radians, BarColor); } base.Draw(parentTransformation, transformation); }
private TextureCoordinates GetTextureCoordinates(RectangleF srcRect) { // if you change these, besure to uncomment the divisions below. const float leftBias = 0.0f; const float topBias = 0.0f; const float rightBias = 0.0f; const float bottomBias = 0.0f; /* * leftBias /= DisplayWidth; * rightBias /= DisplayWidth; * topBias /= DisplayHeight; * bottomBias /= DisplayHeight; */ float uLeft = srcRect.Left / (float)mTextureSize.Width + leftBias; float vTop = srcRect.Top / (float)mTextureSize.Height + topBias; float uRight = srcRect.Right / (float)mTextureSize.Width + rightBias; float vBottom = srcRect.Bottom / (float)mTextureSize.Height + bottomBias; TextureCoordinates texCoords = new TextureCoordinates(uLeft, vTop, uRight, vBottom); return(texCoords); }
public void DrawText() { if (!isInitialized) { if (!string.IsNullOrEmpty(TextInfo.Text)) { Texture = TextInfo.Text.StringToBitmapSource(FontSize, System.Windows.Media.Colors.White, System.Windows.Media.Colors.Black); Width = (float)Texture.Width; Height = (float)Texture.Height; DrawCharacter(TextInfo.Text, TextInfo.Origin, (float)Texture.Width, (float)Texture.Height, TextInfo); } else { Texture = null; Width = 0; Height = 0; Positions.Clear(); Colors.Clear(); TextureCoordinates.Clear(); TextInfo.Offsets.Clear(); } isInitialized = true; } }
/// <summary> /// Returns a string representation of the current object. /// </summary> /// <returns> /// A <see cref="T:System.String"/> representing the vertex. /// </returns> public override string ToString() { return(string.Format(CultureInfo.CurrentCulture, "{0} ({1}, {2})", Position.ToString(), System.Drawing.Color.FromArgb(Color).ToString(), TextureCoordinates.ToString())); }
/// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns> /// A 32-bit signed integer that is the hash code for this instance. /// </returns> public override int GetHashCode() { return(Position.GetHashCode() + Color.GetHashCode() + TextureCoordinates.GetHashCode()); }
private void GenerateCap(bool top, ref int index, ref List <List <int> > indexArray, ref float halfHeight) { // save the index of the first center vertex int centerIndexStart = index; Float3 uv = new(); Float3 vertex = new(); float radius = top ? radiusTop : radiusBottom; float sign = top ? 1.0f : -1.0f; // first we generate the center vertex data of the cap. // because the geometry needs one set of uvs per face, // we must generate a center vertex per face/segment for (int x = 1; x <= radialSegments; x++) { // vertex Positions.Add(new(0.0f, halfHeight * sign, 0.0f)); // normal Normals.Add(new(0.0f, sign, 0.0f)); // uv TextureCoordinates.Add(new(0.5f, 0.5f, 0.0f)); // increase index index++; } // save the index of the last center vertex int centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs for (int x = 0; x <= radialSegments; x++) { float u = (float)x / radialSegments; double theta = u * thetaLength + thetaStart; double cosTheta = Math.Cos(theta); double sinTheta = Math.Sin(theta); // vertex vertex.X = (float)(radius * sinTheta); vertex.Y = halfHeight * sign; vertex.Z = (float)(radius * cosTheta); Positions.Add(vertex); // normal Normals.Add(new(0.0f, sign, 0.0f)); // uv uv.X = (float)((cosTheta * 0.5) + 0.5); uv.Y = (float)((sinTheta * 0.5 * sign) + 0.5); TextureCoordinates.Add(uv); // increase index index++; } // generate indices for (int x = 0; x < radialSegments; x++) { int c = centerIndexStart + x; int i = centerIndexEnd + x; if (top) { // face top Indices.Add(c); Indices.Add(i + 1); Indices.Add(i); } else { // face bottom Indices.Add(c); Indices.Add(i); Indices.Add(i + 1); } } }
public void loadFile(String fileName) { StreamReader objReader = new StreamReader(fileName); ArrayList al = new ArrayList(); string texLineTem = ""; while (objReader.Peek() != -1) { texLineTem = objReader.ReadLine(); if (texLineTem.Length < 2) { continue; } if (texLineTem.IndexOf("v") == 0) { if (texLineTem.IndexOf("t") == 1) { string[] tempArray = texLineTem.Split(' '); TextureCoordinates vt = new TextureCoordinates(); vt.TU = double.Parse(tempArray[1]); vt.TV = double.Parse(tempArray[2]); mesh.VT.Add(vt); } else if (texLineTem.IndexOf("n") == 1) { string[] tempArray = texLineTem.Split(new char[] { '/', ' ' }, System.StringSplitOptions.RemoveEmptyEntries); NormalVector vn = new NormalVector(); vn.NX = double.Parse(tempArray[1]); vn.NY = double.Parse(tempArray[2]); if (tempArray[3] == "\\") { texLineTem = objReader.ReadLine(); vn.NZ = double.Parse(texLineTem); } else { vn.NZ = double.Parse(tempArray[3]); } mesh.VN.Add(vn); } else { string[] tempArray = texLineTem.Split(' '); POINT3 v = new POINT3(); v.X = double.Parse(tempArray[1]); v.Y = double.Parse(tempArray[2]); v.Z = double.Parse(tempArray[3]); mesh.V.Add(v); } } else if (texLineTem.IndexOf("f") == 0) { string[] tempArray = texLineTem.Split(new char[] { '/', ' ' }, System.StringSplitOptions.RemoveEmptyEntries); Surface f = new Surface(); int i = 0; int k = 1; while (i < 3) { if (mesh.V.Count != 0) { f.V[i] = int.Parse(tempArray[k]) - 1; k++; } if (mesh.VT.Count != 0) { f.T[i] = int.Parse(tempArray[k]) - 1; k++; } if (mesh.VN.Count != 0) { f.N[i] = int.Parse(tempArray[k]) - 1; k++; } i++; } mesh.F.Add(f); } } }
private void ReadObjFile(string pathObjFile) { using (var myStream = new FileStream(pathObjFile, FileMode.Open)) { var myReader = new StreamReader(myStream); var coord = new double[3]; var tri = new int[3]; var tex = new int[4]; var quad = new int[4]; string line; while ((line = myReader.ReadLine()) != null) { if (line != "") { line = line.Trim(' '); string[] array; switch (line[0]) { case 'v': { if (line[1] != 't' && line[1] != 'n') { line = line.Trim('v', ' '); array = line.Split(' '); for (var i = 0; i < 3; i++) { coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture); } var v = new Vertex(coord[0], coord[1], coord[2]); Vertices.Add(v); } else { if (line[1] == 't') { line = line.Trim('t', 'v', ' '); array = line.Split(' '); for (var i = 0; i < 2; i++) { coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture); } var v = new Vertex2D(coord[0], coord[1]); TextureCoordinates.Add(v); } } break; } case 'f': { line = line.Trim('f', ' '); array = line.Split(new[] { ' ', '/' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length == 9) { for (int i = 0, j = 0; i < 3 && j < array.Length; i++, j += 3) { tri[i] = int.Parse(array[j]); tex[i] = int.Parse(array[j + 1]); } var t = new Triangle(Vertices[tri[0] - 1], Vertices[tri[1] - 1], Vertices[tri[2] - 1], TextureCoordinates[tex[0] - 1], TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1]); Triangles.Add(t); } if (array.Length == 12) { for (int i = 0, j = 0; i < 4 && j < array.Length; i++, j += 3) { quad[i] = int.Parse(array[j]); tex[i] = int.Parse(array[j + 1]); } var q = new Quad(Vertices[quad[0] - 1], Vertices[quad[1] - 1], Vertices[quad[2] - 1], Vertices[quad[3] - 1], TextureCoordinates[tex[0] - 1], TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1], TextureCoordinates[tex[3] - 1]); Quads.Add(q); } } break; } } } } }
protected void AddVertex(Point3D position, Vector3D normal, Point2D textureCoordinate) { AddVertex(position, normal); TextureCoordinates.Add(textureCoordinate); }
//Constructor public TextureCoordinatesModification(int index, TextureCoordinates newTextureCoord) : base(index) { this._NewTextureCoord = newTextureCoord; }
protected void DrawWithoutVB(float destX, float destY, Rectangle srcRect, float rotationCenterX, float rotationCenterY, bool alphaBlend) { if (DisplayWidth < 0) { destX -= DisplayWidth; rotationCenterX += DisplayWidth; } if (DisplayHeight < 0) { destY -= DisplayHeight; rotationCenterY += DisplayHeight; } mDevice.Interpolation = InterpolationHint; if (TesselateFactor == 1) { SetVertsTextureCoordinates(mVerts, 0, srcRect); SetVertsColor(mVerts, 0, 4); SetVertsPosition(mVerts, 0, new RectangleF(destX, destY, srcRect.Width * (float)ScaleWidth, srcRect.Height * (float)ScaleHeight), rotationCenterX, rotationCenterY); mDevice.DrawBuffer.CacheDrawIndexedTriangles(mVerts, mIndices, mTexture.Value, alphaBlend); } else { TextureCoordinates texCoords = GetTextureCoordinates(mSrcRect); float texWidth = texCoords.Right - texCoords.Left; float texHeight = texCoords.Bottom - texCoords.Top; float displayWidth = DisplayWidth / (float)TesselateFactor; float displayHeight = DisplayHeight / (float)TesselateFactor; for (int j = 0; j < TesselateFactor; j++) { TextureCoordinates coords = texCoords; coords.Top = texCoords.Top + j * texHeight / TesselateFactor; coords.Bottom = coords.Top + texHeight / TesselateFactor; for (int i = 0; i < TesselateFactor; i++) { coords.Left = texCoords.Left + i * texWidth / TesselateFactor; coords.Right = coords.Left + texWidth / TesselateFactor; float dx = destX + i * displayWidth * mRotationCos + j * displayHeight * mRotationSin; float dy = destY - i * displayWidth * mRotationSin + j * displayHeight * mRotationCos; SetVertsPosition(mExtraVerts, 0, new RectangleF(dx, dy, displayWidth, displayHeight), rotationCenterX, rotationCenterY); SetVertsColor(mExtraVerts, 0, 4, i / (double)TesselateFactor, j / (double)TesselateFactor, 1.0 / TesselateFactor, 1.0 / TesselateFactor); SetVertsTextureCoordinates(mExtraVerts, 0, coords); mDevice.DrawBuffer.CacheDrawIndexedTriangles( mExtraVerts, mIndices, mTexture.Value, alphaBlend); } } } }
/// <summary> /// Loads an ascii format ply file. /// </summary> /// <param name="s"></param> private void Load_ascii(Stream s) { using (var reader = new StreamReader(s)) { while (!reader.EndOfStream) { var curline = reader.ReadLine(); string[] strarr = curline.Split(' '); if (curline == null) { //reader.Close(); } #region Heading //comment Line else if (strarr[0] == "comment" || strarr[0] == "format" || strarr[0] == "ply") { } //obj_info Line else if (strarr[0] == "obj_info") { //ObjectInformation.Add(strarr[1], double.Parse(strarr[2])); } //element Line else if (strarr[0] == "element") { /* Supported elements * vertex * face */ if (strarr[1] == "vertex") { VerticesNumber = int.Parse(strarr[2]); //Add the vertex element to the dictionary, including its contextual range elements_range.Add("vertex", new PLYElement(elementLines_Count + 1, elementLines_Count + VerticesNumber)); elementLines_Count += int.Parse(strarr[2]); //set the current element as a "vertex"element currentElement = PlyElements.vertex; } else if (strarr[1] == "face") { FacesNumber = int.Parse(strarr[2]); elements_range.Add("face", new PLYElement(elementLines_Count + 1, elementLines_Count + FacesNumber)); elementLines_Count += int.Parse(strarr[2]); currentElement = PlyElements.face; } else { int miscElementNumber = int.Parse(strarr[2]); elements_range.Add(strarr[1], new PLYElement(elementLines_Count, elementLines_Count + miscElementNumber)); elementLines_Count += int.Parse(strarr[2]); currentElement = PlyElements.none; } } //property Line else if (strarr[0] == "property") { //Ignore the numerical data type for now switch (currentElement) { case PlyElements.vertex: { int propInd = elements_range["vertex"].PropertyIndex; elements_range["vertex"].Property_with_Index.Add(strarr[2], propInd); //Increase the property index if there's an element which has/hasn't been supported. elements_range["vertex"].PropertyIndex += 1; if (strarr[2] == "nx" || strarr[2] == "ny" || strarr[2] == "nz") { elements_range["vertex"].ContainsNormals = true; } else if (strarr[2] == "s" || strarr[2] == "t") { elements_range["vertex"].ContainsTextureCoordinates = true; } break; } case PlyElements.face: { //nothing to do yet break; } default: break; } } else if (strarr[0] == "end_header") { //end info, begin number collection. elementLine_Current = 0; } #endregion /* We pick the elements and its properties by checking whether the current * element line is contained in the element range. * The picking occurs if the first character in the string indicates a number follows. */ else if (IsDigitChar(strarr[0][0]) == true) { elementLine_Current++; if (elements_range.ContainsKey("vertex")) { if (elements_range["vertex"].ContainsNumber(elementLine_Current) == true) { //Get vertices int x_Indx = elements_range["vertex"].Property_with_Index["x"]; int y_Indx = elements_range["vertex"].Property_with_Index["y"]; int z_Indx = elements_range["vertex"].Property_with_Index["z"]; Point3D pt = new Point3D() { X = double.Parse(strarr[x_Indx]), Y = double.Parse(strarr[y_Indx]), Z = double.Parse(strarr[z_Indx]) }; Vertices.Add(pt); if (elements_range["vertex"].ContainsNormals == true) { int nx_Indx = elements_range["vertex"].Property_with_Index["nx"]; int ny_Indx = elements_range["vertex"].Property_with_Index["ny"]; int nz_Indx = elements_range["vertex"].Property_with_Index["nz"]; Vector3D vect3d = new Vector3D { X = double.Parse(strarr[nx_Indx]), Y = double.Parse(strarr[ny_Indx]), Z = double.Parse(strarr[nz_Indx]) }; Normals.Add(vect3d); } if (elements_range["vertex"].ContainsTextureCoordinates == true) { int s_Indx = elements_range["vertex"].Property_with_Index["s"]; int t_Indx = elements_range["vertex"].Property_with_Index["t"]; Point texpt = new Point { X = double.Parse(strarr[s_Indx]), Y = double.Parse(strarr[t_Indx]), }; TextureCoordinates.Add(texpt); } } } if (elements_range.ContainsKey("face")) { if (elements_range["face"].ContainsNumber(elementLine_Current) == true) { List <int> facepos = new List <int>(); for (int i = 1; i <= int.Parse(strarr[0]); i++) { facepos.Add(int.Parse(strarr[i])); } Faces.Add(facepos.ToArray()); } } else { continue; } //should increase the elementLine_Current iff //the line contains element data. } else { continue; } } } }
/// <summary> /// /// </summary> public PolyhedronMeshBase() { TextureCoordinates = TextureCoordinates.Clone(); }
public void ReadJson(JsonReader reader) { int count = 0; while (reader.Read()) { if (reader.TokenType == JsonToken.EndObject) { break; } if (reader.TokenType == JsonToken.PropertyName) { switch ((string)reader.Value) { case nameof(Header): Header.ReadJson(reader); break; case nameof(ExtendedHeader): ExtendedHeader.ReadJson(reader); break; case nameof(UserDataEntries): while (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { continue; } if (reader.TokenType == JsonToken.EndArray) { break; } // TODO } break; case nameof(particleData): while (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { continue; } if (reader.TokenType == JsonToken.EndArray) { break; } // TODO } break; case nameof(NonUniformKeys): while (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { continue; } if (reader.TokenType == JsonToken.EndArray) { break; } NonUniformKeys.Add((float)(double)reader.Value); } break; case nameof(Attachpoints): while (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { continue; } if (reader.TokenType == JsonToken.EndArray) { break; } BrgAttachpoint a = new BrgAttachpoint(); a.ReadJson(reader); Attachpoints.Add(a); } break; case nameof(Vertices): reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Vector3 v = reader.ReadAsVector3(); Vertices.Add(v); } break; case nameof(Normals): reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Vector3 v = reader.ReadAsVector3(); Normals.Add(v); } break; case nameof(TextureCoordinates): reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Vector3 v = reader.ReadAsVector3(); TextureCoordinates.Add(v); } break; case nameof(Colors): reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Color4D c = new Color4D(); c.ReadJson(reader); Colors.Add(c); } break; case nameof(Faces): count = 0; reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Face f; if (Faces.Count <= count) { f = new Face(); Faces.Add(f); } else { f = Faces[count]; } ++count; while (reader.Read()) { if (reader.TokenType == JsonToken.StartArray) { continue; } if (reader.TokenType == JsonToken.EndArray) { break; } f.Indices.Add((Int16)(Int64)reader.Value); } } break; case "FaceMaterials": count = 0; reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } Face f; if (Faces.Count <= count) { f = new Face(); Faces.Add(f); } else { f = Faces[count]; } ++count; f.MaterialIndex = (Int16)(Int64)reader.Value; } break; case nameof(MeshAnimations): reader.Read(); // StartArray while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; } BrgMesh m = new BrgMesh(this.ParentFile); m.ReadJson(reader); MeshAnimations.Add(m); } break; default: throw new Exception("Unexpected property name!"); } } else if (reader.TokenType != JsonToken.StartObject) { throw new Exception("Unexpected token type! " + reader.TokenType); } } }