Ejemplo n.º 1
0
 public void Add(List <Box> box)
 {
     Boxes.Concat(box);
     Initialize(Boxes);
 }
Ejemplo n.º 2
0
        private void ProcessModel(BlockStateModel stateModel, ResourcePackLib.Json.Models.ResourcePackModelBase model, out Vector3 min, out Vector3 max)
        {
            float facesMinX = float.MaxValue, facesMinY = float.MaxValue, facesMinZ = float.MaxValue;
            float facesMaxX = float.MinValue, facesMaxY = float.MinValue, facesMaxZ = float.MinValue;

            List <BoundingBox> boxes = new List <BoundingBox>();

            for (var index = 0; index < model.Elements.Length; index++)
            {
                var element = model.Elements[index];
                element.To *= (Scale);

                element.From *= (Scale);

                foreach (var face in element.Faces)
                {
                    var verts = GetFaceVertices(face.Key, element.From, element.To, new UVMap(), out _);

                    float minX = float.MaxValue, minY = float.MaxValue, minZ = float.MaxValue;
                    float maxX = float.MinValue, maxY = float.MinValue, maxZ = float.MinValue;

                    for (int i = 0; i < verts.Length; i++)
                    {
                        var v = verts[i];
                        //v.Position += (v.Normal * scale);

                        v.Position = FixRotation(v.Position, element, stateModel.X, stateModel.Y);

                        v.Position /= 16f;

                        if (v.Position.X < minX)
                        {
                            minX = v.Position.X;
                        }
                        else if (v.Position.X > maxX)
                        {
                            maxX = v.Position.X;
                        }

                        if (v.Position.Y < minY)
                        {
                            minY = v.Position.Y;
                        }
                        else if (v.Position.Y > maxY)
                        {
                            maxY = v.Position.Y;
                        }

                        if (v.Position.Z < minZ)
                        {
                            minZ = v.Position.Z;
                        }
                        else if (v.Position.Z > maxZ)
                        {
                            maxZ = v.Position.Z;
                        }

                        verts[i] = v;
                    }

                    FixElementScale(
                        element, verts, minX, maxX, minY, maxY, minZ, maxZ, ref facesMinX, ref facesMaxX, ref facesMinY,
                        ref facesMaxY, ref facesMinZ, ref facesMaxZ);

                    if (minX < facesMinX)
                    {
                        facesMinX = minX;
                    }
                    else if (maxX > facesMaxX)
                    {
                        facesMaxX = maxX;
                    }

                    if (minY < facesMinY)
                    {
                        facesMinY = minY;
                    }
                    else if (maxY > facesMaxY)
                    {
                        facesMaxY = maxY;
                    }

                    if (minZ < facesMinZ)
                    {
                        facesMinZ = minZ;
                    }
                    else if (maxZ > facesMaxZ)
                    {
                        facesMaxZ = maxZ;
                    }
                }

                var from = FixRotation(element.From, element, stateModel.X, stateModel.Y);
                var to   = FixRotation(element.To, element, stateModel.X, stateModel.Y);

                boxes.Add(new BoundingBox(Vector3.Min(from, to) / 16f, Vector3.Max(from, to) / 16f));
            }

            min = new Vector3(facesMinX, facesMinY, facesMinZ);
            max = new Vector3(facesMaxX, facesMaxY, facesMaxZ);

            Boxes = Boxes.Concat(boxes.ToArray()).ToArray();
        }
Ejemplo n.º 3
0
        private void GenerateBoundingBoxes(BlockStateModel stateModel, ResourcePackLib.Json.Models.ResourcePackModelBase model, out Vector3 min, out Vector3 max)
        {
            float facesMinX = float.MaxValue, facesMinY = float.MaxValue, facesMinZ = float.MaxValue;
            float facesMaxX = float.MinValue, facesMaxY = float.MinValue, facesMaxZ = float.MinValue;

            List <BoundingBox> boxes = new List <BoundingBox>();

            for (var index = 0; index < model.Elements.Length; index++)
            {
                var eMinX = float.MaxValue;
                var eMinY = float.MaxValue;
                var eMinZ = float.MaxValue;

                var eMaxX = float.MinValue;
                var eMaxY = float.MinValue;
                var eMaxZ = float.MinValue;

                var element = model.Elements[index];
                element.To   *= Scale;
                element.From *= Scale;

                foreach (var face in element.Faces)
                {
                    var facing = face.Key;

                    if (stateModel.X > 0f)
                    {
                        var offset = stateModel.X / 90;
                        facing = RotateDirection(facing, offset, FACE_ROTATION_X, INVALID_FACE_ROTATION_X);
                    }

                    if (stateModel.Y > 0f)
                    {
                        var offset = stateModel.Y / 90;
                        facing = RotateDirection(facing, offset, FACE_ROTATION, INVALID_FACE_ROTATION);
                    }

                    var verts = GetFaceVertices(face.Key, element.From, element.To, new BlockTextureData());
                    verts = ProcessVertices(verts, stateModel, element, null, facing, face.Value);

                    float minX = float.MaxValue, minY = float.MaxValue, minZ = float.MaxValue;
                    float maxX = float.MinValue, maxY = float.MinValue, maxZ = float.MinValue;

                    for (int i = 0; i < verts.Length; i++)
                    {
                        var v = verts[i];

                        if (v.Position.X < minX)
                        {
                            minX = v.Position.X;
                        }
                        else if (v.Position.X > maxX)
                        {
                            maxX = v.Position.X;
                        }

                        if (v.Position.Y < minY)
                        {
                            minY = v.Position.Y;
                        }
                        else if (v.Position.Y > maxY)
                        {
                            maxY = v.Position.Y;
                        }

                        if (v.Position.Z < minZ)
                        {
                            minZ = v.Position.Z;
                        }
                        else if (v.Position.Z > maxZ)
                        {
                            maxZ = v.Position.Z;
                        }

                        //

                        if (v.Position.X < eMinX)
                        {
                            eMinX = v.Position.X;
                        }
                        else if (v.Position.X > eMaxX)
                        {
                            eMaxX = v.Position.X;
                        }

                        if (v.Position.Y < eMinY)
                        {
                            eMinY = v.Position.Y;
                        }
                        else if (v.Position.Y > eMaxY)
                        {
                            eMaxY = v.Position.Y;
                        }

                        if (v.Position.Z < eMinZ)
                        {
                            eMinZ = v.Position.Z;
                        }
                        else if (v.Position.Z > eMaxZ)
                        {
                            eMaxZ = v.Position.Z;
                        }

                        verts[i] = v;
                    }

                    if (minX < facesMinX)
                    {
                        facesMinX = minX;
                    }
                    else if (maxX > facesMaxX)
                    {
                        facesMaxX = maxX;
                    }

                    if (minY < facesMinY)
                    {
                        facesMinY = minY;
                    }
                    else if (maxY > facesMaxY)
                    {
                        facesMaxY = maxY;
                    }

                    if (minZ < facesMinZ)
                    {
                        facesMinZ = minZ;
                    }
                    else if (maxZ > facesMaxZ)
                    {
                        facesMaxZ = maxZ;
                    }
                }

                boxes.Add(new BoundingBox(new Vector3(eMinX, eMinY, eMinZ), new Vector3(eMaxX, eMaxY, eMaxZ)));
            }

            min = new Vector3(facesMinX, facesMinY, facesMinZ);
            max = new Vector3(facesMaxX, facesMaxY, facesMaxZ);

            Boxes = Boxes.Concat(boxes.ToArray()).ToArray();
        }