Ejemplo n.º 1
0
        private Int2 SetVertices(MeshStripeHigh stripe, Corner corner)
        {
            var  coord = stripe.GetPixelAtCorner(corner).VertPosition(corner);
            Int2 result;

            if (_vertMatrix[coord.X, coord.Y].X < 0)
            {
                result = new Int2(_verts.Count, _verts.Count + 1);
                _vertMatrix[coord.X, coord.Y] = new Int2(_verts.Count, _verts.Count + 1);
                _verts.Add(stripe.GetPixelAtCorner(corner).GetVertCoordinates(corner, Side.Front, _scale) - _offset);
                _verts.Add(stripe.GetPixelAtCorner(corner).GetVertCoordinates(corner, Side.Back, _scale) - _offset);
                _uvs.Add(stripe.GetPixelAtCorner(corner).GetUvAtCorner(corner));
                _uvs.Add(stripe.GetPixelAtCorner(corner).GetUvAtCorner(corner));
                if (!_recalcNormals)
                {
                    _normals.Add(GetNormal(corner, Side.Front));
                    _normals.Add(GetNormal(corner, Side.Back));
                }
            }
            else
            {
                result = _vertMatrix[coord.X, coord.Y];
            }

            return(result);
        }
Ejemplo n.º 2
0
            public bool MergeableToTheBottom(MeshStripeHigh stripeHigh)
            {
                if (_bottomLeftPixel.Position.X == stripeHigh._bottomLeftPixel.Position.X && _bottomRightPixel.Position.X == stripeHigh._bottomRightPixel.Position.X && _bottomLeftPixel.Position.Y - stripeHigh._topLeftPixel.Position.Y == 1)
                {
                    MergeStripeTotheBottom(stripeHigh);
                    return(true);
                }

                return(false);
            }
Ejemplo n.º 3
0
        private void ReadData(Sprite sprite)
        {
            for (int y = _yMax - 1; y >= _yMin; y--)
            {
                for (int x = _xMin; x < _xMax; x++)
                {
                    if (sprite.texture.GetPixel(x, y).a > 0.0f)
                    {
                        _pixels[x, y] = new PixelDataHigh(x, y, _size);

                        var stripe = new MeshStripeHigh(_pixels[x, y]);

                        x++;
                        while (sprite.texture.GetPixel(x, y).a > 0.0f && x < _xMax)
                        {
                            _pixels[x, y] = new PixelDataHigh(x, y, _size);
                            stripe.AddPixelToTheStripe(_pixels[x, y]);
                            x++;
                        }

                        bool any = false;
                        foreach (var s in _stripes)
                        {
                            if (s.MergeableToTheBottom(stripe))
                            {
                                any = true;
                                break;
                            }
                        }
                        if (!any)
                        {
                            _stripes.Add(stripe);
                        }
                    }
                }
            }

            for (int y = _yMax - 1; y >= _yMin; y--)
            {
                for (int x = _xMin; x < _xMax; x++)
                {
                    if (_pixels[x, y] == null)
                    {
                        continue;
                    }
                    _pixels[x, y].TopCovered    = y != _yMax - 1 && _pixels[x, y + 1] != null;
                    _pixels[x, y].RightCovered  = x != _xMax - 1 && _pixels[x + 1, y] != null;
                    _pixels[x, y].LeftCovered   = x != _xMin && _pixels[x - 1, y] != null;
                    _pixels[x, y].BottomCovered = y != _yMin && _pixels[x, y - 1] != null;
                }
            }
        }
Ejemplo n.º 4
0
 private void MergeStripeTotheBottom(MeshStripeHigh stripeHigh)
 {
     _bottomLeftPixel  = stripeHigh._bottomLeftPixel;
     _bottomRightPixel = stripeHigh._bottomRightPixel;
 }