Ejemplo n.º 1
0
 private static void CreateUv(TexCoord texture, float bleed, out Uv tc00, out Uv tc10, out Uv tc01, out Uv tc11)
 {
     tc00 = new Uv(texture.MinU + bleed, texture.MinV + bleed);
     tc10 = new Uv(texture.MaxU - bleed, texture.MinV + bleed);
     tc01 = new Uv(texture.MinU + bleed, texture.MaxV - bleed);
     tc11 = new Uv(texture.MaxU - bleed, texture.MaxV - bleed);
 }
Ejemplo n.º 2
0
        public void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi)
        {
            var block     = structure[x, y, z];
            var blockData = blockAtlas[block.Id];
            var tex       = blockData.Textures[0];

            var tc00 = new Uv(0, 0);
            var tc10 = new Uv(1, 0);
            var tc01 = new Uv(0, 1);
            var tc11 = new Uv(1, 1);

            if (tex != null)
            {
                var d = 0.0002f;                 // bleed compensation
                tc00 = new Uv(tex.MinU + d, tex.MinV + d);
                tc10 = new Uv(tex.MaxU - d, tex.MinV + d);
                tc01 = new Uv(tex.MinU + d, tex.MaxV - d);
                tc11 = new Uv(tex.MaxU - d, tex.MaxV - d);
            }

            var norm = (Vector3.UnitX + Vector3.UnitZ).Normalized();

            vbi.Append(new Vertex(x, y, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc01);
            vbi.Append(new Vertex(x + 1, y, z), new Vertex(norm.X, norm.Y, norm.Z), tc11);
            vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(norm.X, norm.Y, norm.Z), tc10);
            vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc00);

            norm = (Vector3.UnitX - Vector3.UnitZ).Normalized();
            vbi.Append(new Vertex(x, y, z), new Vertex(norm.X, norm.Y, norm.Z), tc01);
            vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc11);
            vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc10);
            vbi.Append(new Vertex(x, y + 1, z), new Vertex(norm.X, norm.Y, norm.Z), tc00);
        }
Ejemplo n.º 3
0
        public object Clone()
        {
            var cube = (Cube)MemberwiseClone();

            cube.Origin = (float[])Origin?.Clone();
            cube.Size   = (float[])Size?.Clone();
            cube.Uv     = (float[])Uv?.Clone();

            return(cube);
        }
Ejemplo n.º 4
0
        // Methods

        public override byte[] Datas()
        {
            byte[] bytes = new byte[GetSize()];

            System.Buffer.BlockCopy(Position.ToArray(), 0, bytes, 0, 3 * sizeof(float));
            System.Buffer.BlockCopy(Normal.ToArray(), 0, bytes, 3 * sizeof(float), 3 * sizeof(float));
            System.Buffer.BlockCopy(Tangent.ToArray(), 0, bytes, 6 * sizeof(float), 4 * sizeof(float));
            System.Buffer.BlockCopy(Uv.ToArray(), 0, bytes, 10 * sizeof(float), 2 * sizeof(float));
            return(bytes);
        }
Ejemplo n.º 5
0
 public int Append(Vertex pos, Vertex normal, Uv uv)
 {
     lock (LockHandle)
     {
         VertexBuffer.Add(pos);
         NormalBuffer.Add(normal);
         TexCoordBuffer.Add(uv);
         IndexBuffer.Add(Length);
         Length++;
         return(Length - 1);
     }
 }
Ejemplo n.º 6
0
    protected override void MakeVerticesAndUV(int i)
    {
        float theta = GetThetaAtIthSpoke(i - 1);
        float cT    = Mathf.Cos(theta);
        float sT    = Mathf.Sin(theta);

        // Create vertices for front of gear
        Vertices.Add(new Vector3(0, Radius * cT, Radius * sT));
        Uv.Add(new Vector2(0, Radius * sT));

        Vertices.Add(new Vector3(0, OuterRadius * cT, OuterRadius * sT));
        Uv.Add(new Vector2(0, Radius * sT));
    }
Ejemplo n.º 7
0
        private void RunLoop()
        {
            Uv = new Uv();

            Loop = new UvLoopHandle();
            Loop.Init(Uv);

            _postHandle = new UvAsyncHandle();
            _postHandle.Init(Loop, OnPost, _queueCloseCallback);

            _running.Set();

            Uv.run(Loop, 0);
        }
Ejemplo n.º 8
0
        public void ApplyTextMesh()
        {
            var clearMesh = (_textGenerator.Vertices.Length != Vertices.Count);

            Vertices.Clear();
            Triangles.Clear();
            Uv.Clear();
            for (var index = 0; index < _textGenerator.Vertices.Length; index++)
            {
                Vertices.Add(_textGenerator.Vertices[index]);
            }
            for (var index = 0; index < _textGenerator.Triangles.Length; index++)
            {
                Triangles.Add(_textGenerator.Triangles[index]);
            }
            for (var index = 0; index < _textGenerator.UV.Length; index++)
            {
                Uv.Add(_textGenerator.UV[index]);
            }

            var vertices = _textGenerator.Vertices;

            for (var index = 0; index < vertices.Length; index++)
            {
                vertices[index].x += X;
                vertices[index].y += Y;
            }
            _mesh.MarkDynamic();
            if (clearMesh)
            {
                _mesh.Clear();
                _mesh.vertices  = vertices;
                _mesh.uv        = _textGenerator.UV;
                _mesh.triangles = _textGenerator.Triangles;
                _mesh.colors    = _textGenerator.Colors;
            }
            else
            {
                _mesh.colors   = _textGenerator.Colors;
                _mesh.vertices = vertices;
            }
            _mesh.RecalculateBounds();
            for (var index = 0; index < vertices.Length; index++)
            {
                vertices[index].x -= X;
                vertices[index].y -= Y;
            }
        }
Ejemplo n.º 9
0
    public override void Add(Vector3 scale, Vector3 origin, Quaternion rotation)
    {
        int verticesLength = Vertices.Count;

        for (int i = 0; i < QuadVertices.Length; i++)
        {
            Vertices.Add(TransformVert(QuadVertices[i], scale, origin, rotation));
        }

        for (int i = 0; i < QuadUV.Length; i++)
        {
            Uv.Add(QuadUV[i]);
        }
        for (int i = 0; i < QuadTriangles.Length; i++)
        {
            Triangles.Add(verticesLength + QuadTriangles[i]);
        }
    }
Ejemplo n.º 10
0
        private void RunLoop()
        {
            Uv = new Uv();

            Loop = new UvLoopHandle();
            Loop.Init(Uv);

            _shutdownPostHandle = new UvAsyncHandle();
            _shutdownPostHandle.Init(Loop, OnPost, _queueCloseCallback);

            _listenSocket = new UvTcpHandle();
            _listenSocket.Init(Loop, _queueCloseCallback);
            _listenSocket.NoDelay(true);
            _listenSocket.Bind(new IPEndPoint(_ip, _port));

            _listenSocket.Listen(10, _onConnectionCallback, this);

            Uv.run(Loop, 0);
        }
Ejemplo n.º 11
0
        private void RunLoop()
        {
            Uv = new Uv();

            Loop = new UvLoopHandle();
            Loop.Init(Uv);

            _postHandle = new UvAsyncHandle();
            _postHandle.Init(Loop, OnPost, null);

            _running.Set();

            Uv.run(Loop, 0);

            _postHandle.Reference();
            _postHandle.Dispose();

            Uv.run(Loop, 0);

            Loop.Dispose();
        }
Ejemplo n.º 12
0
        private void RunLoop()
        {
            Uv = new Uv();

            Loop = new UvLoopHandle();
            Loop.Init(Uv);

            _shutdownPostHandle = new UvAsyncHandle();
            _shutdownPostHandle.Init(Loop, OnPost, _queueCloseCallback);

            _connectSocket = new UvTcpHandle();
            _connectSocket.Init(Loop, _queueCloseCallback);
            _connectSocket.NoDelay(true);

            var connectReq = new UvConnectRequest();

            connectReq.Init(Loop);
            connectReq.Connect(_connectSocket, new IPEndPoint(_ip, _port), OnConnection, this);

            Uv.run(Loop, 0);
        }
Ejemplo n.º 13
0
    public void AssignBasicMeshValue()
    {
        mesh     = new Mesh();
        vertices = new Vector3[4 * 10000];
        uv       = new Vector2[4 * 10000];
        triangle = new int[6 * 10000];

        int width  = material.mainTexture.width;
        int height = material.mainTexture.height;

        List <Uv> uvBulletList = new List <Uv>();

        foreach (Pixels pixels in pixelsArray)
        {
            Uv uvBulletCoords = new Uv {
                uv00 = new Vector2(pixels.pixel00.x / width, pixels.pixel00.y / height),
                uv11 = new Vector2(pixels.pixel11.x / width, pixels.pixel11.y / height)
            };
            uvBulletList.Add(uvBulletCoords);
        }
        uvCoordsArray = uvBulletList.ToArray();
    }
Ejemplo n.º 14
0
 public static Vector2 AsVector2(this Uv uv)
 {
     return(new Vector2(uv.X, uv.Y));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Converts a collection of TTMs to a single obj model, including UV mapping
        /// </summary>
        private FileStreamResult ConvertMultipleToObj(IList <TrimbleTINModel> tins, double eastingOffset, double northingOffset)
        {
            // FileStreamResult will dispose of this once the response has been completed
            // See here: https://github.com/aspnet/Mvc/blob/25eb50120eceb62fd24ab5404210428fcdf0c400/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs#L82
            var outputStream = new MemoryStream();

            using (var writer = new StreamWriter(outputStream, Encoding.UTF8, 32, true))
            {
                var
                    vertexOffset =
                    1; // With multiple objects in a file, the vertex indices used by faces does NOT reset between objects, therefor we have to keep a count
                var currentUvIndex = 1;
                var objIdx         = 1;

                var zModifier = tins.SelectMany(t => t.Vertices.Items).Min(v => v.Z);

                var minX  = tins.SelectMany(t => t.Vertices.Items).Min(v => v.X);
                var maxX  = tins.SelectMany(t => t.Vertices.Items).Max(v => v.X);
                var width = maxX - minX;

                var minY   = tins.SelectMany(t => t.Vertices.Items).Min(v => v.Y);
                var maxY   = tins.SelectMany(t => t.Vertices.Items).Max(v => v.Y);
                var height = maxY - minY;

                foreach (var tin in tins)
                {
                    var faces = new List <Face>();
                    var uvs   = new List <Uv>();
                    writer.WriteLine($"o {tin.ModelName.Replace(" ", "")}.{objIdx++}");

                    foreach (var vertex in tin.Vertices.Items)
                    {
                        writer.WriteLine($"v {(float) (vertex.X - eastingOffset)} " +
                                         $"{(float) (vertex.Y - northingOffset)} " +
                                         $"{(float) (vertex.Z - zModifier)}");
                    }

                    writer.WriteLine("");

                    foreach (var face in tin.Triangles.Items)
                    {
                        var f = new Face
                        {
                            VertexIdx0 = face.Vertex0 + vertexOffset,
                            VertexIdx1 = face.Vertex1 + vertexOffset,
                            VertexIdx2 = face.Vertex2 + vertexOffset
                        };

                        foreach (var vertexIdx in new List <int> {
                            face.Vertex0, face.Vertex1, face.Vertex2
                        })
                        {
                            var vertex = tin.Vertices.Items[vertexIdx];
                            var u      = (vertex.X - minX) / width;
                            var v      = (vertex.Y - minY) / height;
                            var uv     = new Uv()
                            {
                                U = u,
                                V = v
                            };
                            uvs.Add(uv);
                            if (f.UvIdx0 == 0)
                            {
                                f.UvIdx0 = currentUvIndex++;
                            }
                            else if (f.UvIdx1 == 0)
                            {
                                f.UvIdx1 = currentUvIndex++;
                            }
                            else if (f.UvIdx2 == 0)
                            {
                                f.UvIdx2 = currentUvIndex++;
                            }
                        }

                        faces.Add(f);
                    }

                    foreach (var uv in uvs)
                    {
                        writer.WriteLine($"vt {uv.U} {uv.V}");
                    }

                    writer.WriteLine("");
                    foreach (var face in faces)
                    {
                        writer.WriteLine($"f {face.VertexIdx0}/{face.UvIdx0} " +
                                         $"{face.VertexIdx1}/{face.UvIdx1} " +
                                         $"{face.VertexIdx2}/{face.UvIdx2}");
                    }

                    writer.WriteLine("");

                    // Update the vertex index for the next object, as the vertex index is global for the file (not per object)
                    vertexOffset += tin.Vertices.Items.Length;
                    writer.Flush();
                }

                outputStream.Seek(0, SeekOrigin.Begin);
                Log.LogInformation($"GetMapTileData completed: ExportData size={outputStream.Length}");
                return(new FileStreamResult(outputStream, ContentTypeConstants.TextPlain));
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dirPath">マテリアルを読み込むために必要。</param>
        /// <returns></returns>
        public static Obj LoadObjWithMaterial(string[] data, string dirPath)
        {
            var obj = new Obj(data.Length / 3);

            foreach (var line in data)
            {
                string[] parts = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length > 0)
                {
                    switch (parts[0])
                    {
                    case "usemtl":
                        obj.CurrentMtl = parts[1];
                        break;

                    case "mtllib":
                        obj.MtlFileList.Add(parts[1]);
                        break;

                    case "v":
                        var v = Vertex.LoadFromStringArray(parts);
                        obj.VertexList.Add(v);
                        v.Index = obj.VertexList.Count;

                        if (parts.Length == 7)
                        {
                            var vc = VertexColor.LoadFromStringArray(parts);
                            obj.VertexColorList.Add(vc);
                            vc.Index = obj.VertexColorList.Count;
                        }

                        break;

                    case "f":
                        var f = Face.LoadFromStringArray(parts);
                        f.UseMtl = obj.CurrentMtl;
                        obj.FaceList.Add(f);
                        break;

                    case "vt":
                        var uv = Uv.LoadFromStringArray(parts);
                        obj.UvList.Add(uv);
                        uv.Index = obj.UvList.Count;
                        break;

                    case "vn":
                        var vn = NormalVector.LoadFromStringArray(parts);
                        obj.NormalVectorList.Add(vn);
                        vn.Index = obj.NormalVectorList.Count;
                        break;
                    }
                }
            }

            if (obj.VertexColorList.Count != 0)
            {
                obj.ColorType = ColorType.VertexColor;
            }

            var hasTexture = obj.FaceList.FirstOrDefault()?.IsTextureEnable ?? false;

            if (hasTexture)
            {
                obj.ColorType = ColorType.TextureColor;
            }

            foreach (var mtlFile in obj.MtlFileList)
            {
                var lines = File.ReadAllLines(Path.Combine(dirPath, mtlFile));
                var mtl   = MtlLoader.LoadMtl(lines);
                obj.MtlList.Add(mtl);
            }

            return(obj);
        }
Ejemplo n.º 17
0
 public static Point ToPoint(Uv uv, bool swap) => new Point(swap ? uv.V : uv.U, swap ? uv.U : uv.V);
Ejemplo n.º 18
0
        public HelveticaB()
        {
            Type = "Core";
            Name = "Helvetica-Bold";
            UnderlinePosition  = -100;
            UnderlineThickness = 50;
            Encoding           = "1252"; // cp1252

            #region CharacterWidths
            CharacterWidths.Add((char)0, 278);
            CharacterWidths.Add((char)1, 278);
            CharacterWidths.Add((char)2, 278);
            CharacterWidths.Add((char)3, 278);
            CharacterWidths.Add((char)4, 278);
            CharacterWidths.Add((char)5, 278);
            CharacterWidths.Add((char)6, 278);
            CharacterWidths.Add((char)7, 278);
            CharacterWidths.Add((char)8, 278);
            CharacterWidths.Add((char)9, 278);
            CharacterWidths.Add((char)10, 278);
            CharacterWidths.Add((char)11, 278);
            CharacterWidths.Add((char)12, 278);
            CharacterWidths.Add((char)13, 278);
            CharacterWidths.Add((char)14, 278);
            CharacterWidths.Add((char)15, 278);
            CharacterWidths.Add((char)16, 278);
            CharacterWidths.Add((char)17, 278);
            CharacterWidths.Add((char)18, 278);
            CharacterWidths.Add((char)19, 278);
            CharacterWidths.Add((char)20, 278);
            CharacterWidths.Add((char)21, 278);
            CharacterWidths.Add((char)22, 278);
            CharacterWidths.Add((char)23, 278);
            CharacterWidths.Add((char)24, 278);
            CharacterWidths.Add((char)25, 278);
            CharacterWidths.Add((char)26, 278);
            CharacterWidths.Add((char)27, 278);
            CharacterWidths.Add((char)28, 278);
            CharacterWidths.Add((char)29, 278);
            CharacterWidths.Add((char)30, 278);
            CharacterWidths.Add((char)31, 278);
            CharacterWidths.Add((char)32, 278);
            CharacterWidths.Add((char)33, 333);
            CharacterWidths.Add((char)34, 474);
            CharacterWidths.Add((char)35, 556);
            CharacterWidths.Add((char)36, 556);
            CharacterWidths.Add((char)37, 889);
            CharacterWidths.Add((char)38, 722);
            CharacterWidths.Add((char)39, 238);
            CharacterWidths.Add((char)40, 333);
            CharacterWidths.Add((char)41, 333);
            CharacterWidths.Add((char)42, 389);
            CharacterWidths.Add((char)43, 584);
            CharacterWidths.Add((char)44, 278);
            CharacterWidths.Add((char)45, 333);
            CharacterWidths.Add((char)46, 278);
            CharacterWidths.Add((char)47, 278);
            CharacterWidths.Add((char)48, 556);
            CharacterWidths.Add((char)49, 556);
            CharacterWidths.Add((char)50, 556);
            CharacterWidths.Add((char)51, 556);
            CharacterWidths.Add((char)52, 556);
            CharacterWidths.Add((char)53, 556);
            CharacterWidths.Add((char)54, 556);
            CharacterWidths.Add((char)55, 556);
            CharacterWidths.Add((char)56, 556);
            CharacterWidths.Add((char)57, 556);
            CharacterWidths.Add((char)58, 333);
            CharacterWidths.Add((char)59, 333);
            CharacterWidths.Add((char)60, 584);
            CharacterWidths.Add((char)61, 584);
            CharacterWidths.Add((char)62, 584);
            CharacterWidths.Add((char)63, 611);
            CharacterWidths.Add((char)64, 975);
            CharacterWidths.Add((char)65, 722);
            CharacterWidths.Add((char)66, 722);
            CharacterWidths.Add((char)67, 722);
            CharacterWidths.Add((char)68, 722);
            CharacterWidths.Add((char)69, 667);
            CharacterWidths.Add((char)70, 611);
            CharacterWidths.Add((char)71, 778);
            CharacterWidths.Add((char)72, 722);
            CharacterWidths.Add((char)73, 278);
            CharacterWidths.Add((char)74, 556);
            CharacterWidths.Add((char)75, 722);
            CharacterWidths.Add((char)76, 611);
            CharacterWidths.Add((char)77, 833);
            CharacterWidths.Add((char)78, 722);
            CharacterWidths.Add((char)79, 778);
            CharacterWidths.Add((char)80, 667);
            CharacterWidths.Add((char)81, 778);
            CharacterWidths.Add((char)82, 722);
            CharacterWidths.Add((char)83, 667);
            CharacterWidths.Add((char)84, 611);
            CharacterWidths.Add((char)85, 722);
            CharacterWidths.Add((char)86, 667);
            CharacterWidths.Add((char)87, 944);
            CharacterWidths.Add((char)88, 667);
            CharacterWidths.Add((char)89, 667);
            CharacterWidths.Add((char)90, 611);
            CharacterWidths.Add((char)91, 333);
            CharacterWidths.Add((char)92, 278);
            CharacterWidths.Add((char)93, 333);
            CharacterWidths.Add((char)94, 584);
            CharacterWidths.Add((char)95, 556);
            CharacterWidths.Add((char)96, 333);
            CharacterWidths.Add((char)97, 556);
            CharacterWidths.Add((char)98, 611);
            CharacterWidths.Add((char)99, 556);
            CharacterWidths.Add((char)100, 611);
            CharacterWidths.Add((char)101, 556);
            CharacterWidths.Add((char)102, 333);
            CharacterWidths.Add((char)103, 611);
            CharacterWidths.Add((char)104, 611);
            CharacterWidths.Add((char)105, 278);
            CharacterWidths.Add((char)106, 278);
            CharacterWidths.Add((char)107, 556);
            CharacterWidths.Add((char)108, 278);
            CharacterWidths.Add((char)109, 889);
            CharacterWidths.Add((char)110, 611);
            CharacterWidths.Add((char)111, 611);
            CharacterWidths.Add((char)112, 611);
            CharacterWidths.Add((char)113, 611);
            CharacterWidths.Add((char)114, 389);
            CharacterWidths.Add((char)115, 556);
            CharacterWidths.Add((char)116, 333);
            CharacterWidths.Add((char)117, 611);
            CharacterWidths.Add((char)118, 556);
            CharacterWidths.Add((char)119, 778);
            CharacterWidths.Add((char)120, 556);
            CharacterWidths.Add((char)121, 556);
            CharacterWidths.Add((char)122, 500);
            CharacterWidths.Add((char)123, 389);
            CharacterWidths.Add((char)124, 280);
            CharacterWidths.Add((char)125, 389);
            CharacterWidths.Add((char)126, 584);
            CharacterWidths.Add((char)127, 350);
            CharacterWidths.Add((char)128, 556);
            CharacterWidths.Add((char)129, 350);
            CharacterWidths.Add((char)130, 278);
            CharacterWidths.Add((char)131, 556);
            CharacterWidths.Add((char)132, 500);
            CharacterWidths.Add((char)133, 1000);
            CharacterWidths.Add((char)134, 556);
            CharacterWidths.Add((char)135, 556);
            CharacterWidths.Add((char)136, 333);
            CharacterWidths.Add((char)137, 1000);
            CharacterWidths.Add((char)138, 667);
            CharacterWidths.Add((char)139, 333);
            CharacterWidths.Add((char)140, 1000);
            CharacterWidths.Add((char)141, 350);
            CharacterWidths.Add((char)142, 611);
            CharacterWidths.Add((char)143, 350);
            CharacterWidths.Add((char)144, 350);
            CharacterWidths.Add((char)145, 278);
            CharacterWidths.Add((char)146, 278);
            CharacterWidths.Add((char)147, 500);
            CharacterWidths.Add((char)148, 500);
            CharacterWidths.Add((char)149, 350);
            CharacterWidths.Add((char)150, 556);
            CharacterWidths.Add((char)151, 1000);
            CharacterWidths.Add((char)152, 333);
            CharacterWidths.Add((char)153, 1000);
            CharacterWidths.Add((char)154, 556);
            CharacterWidths.Add((char)155, 333);
            CharacterWidths.Add((char)156, 944);
            CharacterWidths.Add((char)157, 350);
            CharacterWidths.Add((char)158, 500);
            CharacterWidths.Add((char)159, 667);
            CharacterWidths.Add((char)160, 278);
            CharacterWidths.Add((char)161, 333);
            CharacterWidths.Add((char)162, 556);
            CharacterWidths.Add((char)163, 556);
            CharacterWidths.Add((char)164, 556);
            CharacterWidths.Add((char)165, 556);
            CharacterWidths.Add((char)166, 280);
            CharacterWidths.Add((char)167, 556);
            CharacterWidths.Add((char)168, 333);
            CharacterWidths.Add((char)169, 737);
            CharacterWidths.Add((char)170, 370);
            CharacterWidths.Add((char)171, 556);
            CharacterWidths.Add((char)172, 584);
            CharacterWidths.Add((char)173, 333);
            CharacterWidths.Add((char)174, 737);
            CharacterWidths.Add((char)175, 333);
            CharacterWidths.Add((char)176, 400);
            CharacterWidths.Add((char)177, 584);
            CharacterWidths.Add((char)178, 333);
            CharacterWidths.Add((char)179, 333);
            CharacterWidths.Add((char)180, 333);
            CharacterWidths.Add((char)181, 611);
            CharacterWidths.Add((char)182, 556);
            CharacterWidths.Add((char)183, 278);
            CharacterWidths.Add((char)184, 333);
            CharacterWidths.Add((char)185, 333);
            CharacterWidths.Add((char)186, 365);
            CharacterWidths.Add((char)187, 556);
            CharacterWidths.Add((char)188, 834);
            CharacterWidths.Add((char)189, 834);
            CharacterWidths.Add((char)190, 834);
            CharacterWidths.Add((char)191, 611);
            CharacterWidths.Add((char)192, 722);
            CharacterWidths.Add((char)193, 722);
            CharacterWidths.Add((char)194, 722);
            CharacterWidths.Add((char)195, 722);
            CharacterWidths.Add((char)196, 722);
            CharacterWidths.Add((char)197, 722);
            CharacterWidths.Add((char)198, 1000);
            CharacterWidths.Add((char)199, 722);
            CharacterWidths.Add((char)200, 667);
            CharacterWidths.Add((char)201, 667);
            CharacterWidths.Add((char)202, 667);
            CharacterWidths.Add((char)203, 667);
            CharacterWidths.Add((char)204, 278);
            CharacterWidths.Add((char)205, 278);
            CharacterWidths.Add((char)206, 278);
            CharacterWidths.Add((char)207, 278);
            CharacterWidths.Add((char)208, 722);
            CharacterWidths.Add((char)209, 722);
            CharacterWidths.Add((char)210, 778);
            CharacterWidths.Add((char)211, 778);
            CharacterWidths.Add((char)212, 778);
            CharacterWidths.Add((char)213, 778);
            CharacterWidths.Add((char)214, 778);
            CharacterWidths.Add((char)215, 584);
            CharacterWidths.Add((char)216, 778);
            CharacterWidths.Add((char)217, 722);
            CharacterWidths.Add((char)218, 722);
            CharacterWidths.Add((char)219, 722);
            CharacterWidths.Add((char)220, 722);
            CharacterWidths.Add((char)221, 667);
            CharacterWidths.Add((char)222, 667);
            CharacterWidths.Add((char)223, 611);
            CharacterWidths.Add((char)224, 556);
            CharacterWidths.Add((char)225, 556);
            CharacterWidths.Add((char)226, 556);
            CharacterWidths.Add((char)227, 556);
            CharacterWidths.Add((char)228, 556);
            CharacterWidths.Add((char)229, 556);
            CharacterWidths.Add((char)230, 889);
            CharacterWidths.Add((char)231, 556);
            CharacterWidths.Add((char)232, 556);
            CharacterWidths.Add((char)233, 556);
            CharacterWidths.Add((char)234, 556);
            CharacterWidths.Add((char)235, 556);
            CharacterWidths.Add((char)236, 278);
            CharacterWidths.Add((char)237, 278);
            CharacterWidths.Add((char)238, 278);
            CharacterWidths.Add((char)239, 278);
            CharacterWidths.Add((char)240, 611);
            CharacterWidths.Add((char)241, 611);
            CharacterWidths.Add((char)242, 611);
            CharacterWidths.Add((char)243, 611);
            CharacterWidths.Add((char)244, 611);
            CharacterWidths.Add((char)245, 611);
            CharacterWidths.Add((char)246, 611);
            CharacterWidths.Add((char)247, 584);
            CharacterWidths.Add((char)248, 611);
            CharacterWidths.Add((char)249, 611);
            CharacterWidths.Add((char)250, 611);
            CharacterWidths.Add((char)251, 611);
            CharacterWidths.Add((char)252, 611);
            CharacterWidths.Add((char)253, 556);
            CharacterWidths.Add((char)254, 611);
            CharacterWidths.Add((char)255, 556);
            #endregion

            #region Uw
            Uv.Add(0, new int[] { 0, 128 });
            Uv.Add(128, new int[] { 8364 });
            Uv.Add(130, new int[] { 8218 });
            Uv.Add(131, new int[] { 402 });
            Uv.Add(132, new int[] { 8222 });
            Uv.Add(133, new int[] { 8230 });
            Uv.Add(134, new int[] { 8224, 2 });
            Uv.Add(136, new int[] { 710 });
            Uv.Add(137, new int[] { 8240 });
            Uv.Add(138, new int[] { 352 });
            Uv.Add(139, new int[] { 8249 });
            Uv.Add(140, new int[] { 338 });
            Uv.Add(142, new int[] { 381 });
            Uv.Add(145, new int[] { 8216, 2 });
            Uv.Add(147, new int[] { 8220, 2 });
            Uv.Add(149, new int[] { 8226 });
            Uv.Add(150, new int[] { 8211, 2 });
            Uv.Add(152, new int[] { 732 });
            Uv.Add(153, new int[] { 8482 });
            Uv.Add(154, new int[] { 353 });
            Uv.Add(155, new int[] { 8250 });
            Uv.Add(156, new int[] { 339 });
            Uv.Add(158, new int[] { 382 });
            Uv.Add(159, new int[] { 376 });
            Uv.Add(160, new int[] { 160, 96 });
            #endregion
        }
Ejemplo n.º 19
0
        public void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi)
        {
            var block     = structure[x, y, z];
            var blockData = blockAtlas[block.Id];
            var tex       = blockData.Textures[0];

            var tc00 = new Uv(0, 0);
            var tc10 = new Uv(1, 0);
            var tc01 = new Uv(0, 1);
            var tc11 = new Uv(1, 1);

            if (tex != null)
            {
                var d = 0.0002f;                 // bleed compensation
                tc00 = new Uv(tex.MinU + d, tex.MinV + d);
                tc10 = new Uv(tex.MaxU - d, tex.MinV + d);
                tc01 = new Uv(tex.MinU + d, tex.MaxV - d);
                tc11 = new Uv(tex.MaxU - d, tex.MaxV - d);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosX, blockAtlas))
            {
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosX), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosX), tc10);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosX), tc11);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.PosX), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegX, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegX), tc01);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegX), tc11);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.NegX), tc10);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegX), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosY, blockAtlas))
            {
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosY), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosY), tc10);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosY), tc11);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.PosY), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegY, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegY), tc01);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegY), tc11);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.NegY), tc10);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegY), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosZ, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.PosZ), tc01);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosZ), tc11);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc10);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegZ, blockAtlas))
            {
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegZ), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.NegZ), tc10);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegZ), tc11);
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegZ), tc01);
            }
        }
Ejemplo n.º 20
0
 public static Size ToSize(Uv uv, bool swap) => new Size(swap ? uv.V : uv.U, swap ? uv.U : uv.V);
Ejemplo n.º 21
0
        private void AddPolygon(PrimitiveState state, ObjModel objModel, Polygon poly)
        {
            var v1      = poly.Vertices[0];
            var v2      = poly.Vertices[1];
            var v3      = poly.Vertices[2];
            var v1Index = (int)(v1.V - 1);
            var v2Index = (int)(v2.V - 1);
            var v3Index = (int)(v3.V - 1);
            var v1v     = objModel.Positions[v1Index];
            var v2v     = objModel.Positions[v2Index];
            var v3v     = objModel.Positions[v3Index];

            UpdateMinMax(state.VertexXMM, v1v.X, v2v.X, v3v.X);
            UpdateMinMax(state.VertexYMM, v1v.Y, v2v.Y, v3v.Y);
            UpdateMinMax(state.VertexZMM, v1v.Z, v2v.Z, v3v.Z);

            var hasNormal = v1.VN.HasValue;
            var hasUV     = v1.VT.HasValue;

            Normal n1, n2, n3;

            if (hasNormal)
            {
                var n1Index = (int)(v1.VN.Value - 1);
                var n2Index = (int)(v2.VN.Value - 1);
                var n3Index = (int)(v3.VN.Value - 1);
                n1 = objModel.Normals[n1Index];
                n2 = objModel.Normals[n2Index];
                n3 = objModel.Normals[n3Index];
                UpdateMinMax(state.NormalXMM, n1.X, n2.X, n3.X);
                UpdateMinMax(state.NormalYMM, n1.Y, n2.Y, n3.Y);
                UpdateMinMax(state.NormalZMM, n1.Z, n2.Z, n3.Z);
            }
            else
            {
                n1 = new Normal();
                n2 = n1;
                n3 = n1;
            }

            Uv t1, t2, t3;

            if (hasUV)
            {
                var t1Index = (int)(v1.VT.Value - 1);
                var t2Index = (int)(v2.VT.Value - 1);
                var t3Index = (int)(v3.VT.Value - 1);
                t1 = objModel.TextureCoords[t1Index];
                t2 = objModel.TextureCoords[t2Index];
                t3 = objModel.TextureCoords[t3Index];
                UpdateMinMax(state.UvUMM, t1.U, t2.U, t3.U);
                UpdateMinMax(state.UvVMM, 1 - t1.V, 1 - t2.V, 1 - t3.V);
            }
            else
            {
                t1 = new Uv();
                t2 = t1;
                t3 = t1;
            }

            if (state.AddVertex(v1))
            {
                state.VertexCount++;
                FillBytes(state.VertexBuffers, v1v.ToArray());
                if (hasNormal)
                {
                    state.NormalCount++;
                    FillBytes(state.NormalBuffers, n1.ToArray());
                }
                if (hasUV)
                {
                    state.UvCount++;
                    FillBytes(state.TextureBuffers, new Uv(t1.U, 1 - t1.V).ToArray());
                }
            }

            if (state.AddVertex(v2))
            {
                state.VertexCount++;
                FillBytes(state.VertexBuffers, v2v.ToArray());
                if (hasNormal)
                {
                    state.NormalCount++;
                    FillBytes(state.NormalBuffers, n2.ToArray());
                }
                if (hasUV)
                {
                    state.UvCount++;
                    FillBytes(state.TextureBuffers, new Uv(t2.U, 1 - t2.V).ToArray());
                }
            }

            if (state.AddVertex(v3))
            {
                state.VertexCount++;
                FillBytes(state.VertexBuffers, v3v.ToArray());
                if (hasNormal)
                {
                    state.NormalCount++;
                    FillBytes(state.NormalBuffers, n3.ToArray());
                }
                if (hasUV)
                {
                    state.UvCount++;
                    FillBytes(state.TextureBuffers, new Uv(t3.U, 1 - t3.V).ToArray());
                }
            }

            var correctWinding = CheckWindingCorrect(v1v, v2v, v3v, n1);

            if (correctWinding)
            {
                state.Indices.AddRange(new[] {
                    state.PolyVertexCache[v1], state.PolyVertexCache[v2], state.PolyVertexCache[v3]
                });
            }
            else
            {
                state.Indices.AddRange(new[] {
                    state.PolyVertexCache[v1], state.PolyVertexCache[v3], state.PolyVertexCache[v2]
                });
            }
        }