Exemplo n.º 1
0
        /// <summary>
        ///     Create models for each orientation.
        /// </summary>
        /// <param name="rotateTopAndBottomTexture">Whether the top and bottom textures should be rotated.</param>
        /// <returns>All model versions.</returns>
        public (BlockModel north, BlockModel east, BlockModel south, BlockModel west) CreateAllOrientations(
            bool rotateTopAndBottomTexture)
        {
            BlockModel north = this;

            BlockModel east = new(north);

            east.RotateY(rotations: 1, rotateTopAndBottomTexture);

            BlockModel south = new(east);

            south.RotateY(rotations: 1, rotateTopAndBottomTexture);

            BlockModel west = new(south);

            west.RotateY(rotations: 1, rotateTopAndBottomTexture);

            return(north, east, south, west);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Load a block model from file. All models are loaded from a specific directory.
        /// </summary>
        /// <param name="name">The name of the file.</param>
        /// <returns>The loaded model.</returns>
        public static BlockModel Load(string name)
        {
            try
            {
                string     json  = File.ReadAllText(Path.Combine(path, name + ".json"));
                BlockModel model = JsonSerializer.Deserialize <BlockModel>(json) ?? new BlockModel();

                logger.LogDebug(Events.ResourceLoad, "Loaded BlockModel: {Name}", name);

                return(model);
            }
            catch (Exception e) when(e is IOException or FileNotFoundException or JsonException)
            {
                logger.LogWarning(
                    Events.MissingResource,
                    e,
                    "Could not load the model '{Name}' because an exception occurred, fallback will be used instead",
                    name);

                return(CreateFallback());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Copy-constructor.
 /// </summary>
 /// <param name="original">The original model to copy.</param>
 private BlockModel(BlockModel original)
 {
     TextureNames = (string[])original.TextureNames.Clone();
     Quads        = (Quad[])original.Quads.Clone();
 }