コード例 #1
0
ファイル: Anvil.cs プロジェクト: xFleury/NbtToObj
        private const int matchData             = 14; //red

        private Bounds ScanForBounds()
        {
            Console.WriteLine("Scanning {0} chunks for bounds.", chunks.Count);
            Bounds bounds       = new Bounds();
            int    matchesFound = 0;

            foreach (KeyValuePair <CoordinateInt, Block[]> pair in chunks)
            {
                CoordinateInt chunkCoord = pair.Key;
                Block[]       blocks     = pair.Value;
                for (int blockIdx = 0; blockIdx < blocks.Length; blockIdx++)
                {
                    if (blocks[blockIdx].id == matchType && blocks[blockIdx].data == matchData)
                    {
                        matchesFound++;
                        int relativeX = blockIdx % 16;
                        int relativeZ = (blockIdx / 16) % 16;
                        int relativeY = blockIdx / (16 * 16);
                        bounds.AddPoint(chunkCoord.X * 16 + relativeX, chunkCoord.Y * 16 + relativeY, chunkCoord.Z * 16 + relativeZ);
                    }
                }
            }
            bounds.Shrink(1);
            Console.WriteLine("Found {0} bounds markers.\nBoundary is {1}.", matchesFound, bounds);

            return(bounds);
        }
コード例 #2
0
        public void CheckTransparentPart(ColorGrabber grabber, int index)
        {
            foreach (Face f in Model.Meshes[index].Faces)
            {
                var bounds = new Bounds(new Point(9999, 9999), new Point(-9999, -9999));

                foreach (Vector2 c in f.TexCoords)
                {
                    var coord = new Vector2(c.X * Width, c.Y * Height);
                    bounds.AddPoint(new Point((int)coord.X, (int)coord.Y));
                }

                Rectangle rect   = bounds.ToRectangle();
                bool      gotOne = false;

                for (int y = rect.Y; !gotOne && y < rect.Y + rect.Height; ++y)
                {
                    for (int x = rect.X; x < rect.X + rect.Width; ++x)
                    {
                        ColorPixel pixel = grabber[x, y];

                        if (pixel.Alpha != 255)
                        {
                            gotOne = true;
                            break;
                        }
                    }
                }

                if (gotOne)
                {
                    TransparentParts[index] = gotOne;
                    return;
                }
            }

            TransparentParts[index] = false;
        }