コード例 #1
0
        private string ResolveTexture(ResourcePackLib.Json.Models.Blocks.BlockModel var, string texture)
        {
            if (texture[0] != '#')
            {
                return(texture);
            }

            var modified = texture.Substring(1);

            if (var.Textures.TryGetValue(modified, out texture))
            {
                if (texture[0] == '#')
                {
                    if (!var.Textures.TryGetValue(texture.Substring(1), out texture))
                    {
                        texture = "no_texture";
                    }
                }
            }

            return(texture);
        }
コード例 #2
0
        private void ProcessModel(BlockStateModel stateModel, ResourcePackLib.Json.Models.Blocks.BlockModel 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();
        }