Struct minecraft_assets::api::ModelResolver[][src]

pub struct ModelResolver;
Expand description

Methods for resolving the properties of a Model with respect to its parents.

Implementations

Iterates through a Model and all of its parents to resolve all of the model’s properties in a way that reflects the intended inheritance and/or override behavior of the Minecraft model format.

The method takes in an iterator of Models where the first element is the model being resolved, and the subsequent elements (if any) are the chain of parents of that model.

Example
use maplit::hashmap;

use minecraft_assets::schemas::models::*;

let parent = Model {
    textures: Some(Textures::from(hashmap! {
        "up" => "#side",
        "down" => "#side"
    })),
    elements: Some(vec![
        Element {
            faces: hashmap! {
                BlockFace::Up => ElementFace {
                    texture: Texture::from("#up"),
                    ..Default::default()
                },
                BlockFace::Down => ElementFace {
                    texture: Texture::from("#down"),
                    ..Default::default()
                },
                BlockFace::East => ElementFace {
                    texture: Texture::from("#side"),
                    ..Default::default()
                },
                BlockFace::West => ElementFace {
                    texture: Texture::from("#side"),
                    ..Default::default()
                }
            },
            ..Default::default()
        }
    ]),
    ..Default::default()
};

let child = Model {
    textures: Some(Textures::from(hashmap! {
        "up" => "textures/up",
        "side" => "textures/side"
    })),
    ..Default::default()
};

let expected = Model {
    textures: Some(Textures::from(hashmap! {
        "up" => "textures/up",
        "down" => "textures/side",
        "side" => "textures/side"
    })),
    elements: Some(vec![
        Element {
            faces: hashmap! {
                BlockFace::Up => ElementFace {
                    texture: Texture::from("textures/up"),
                    ..Default::default()
                },
                BlockFace::Down => ElementFace {
                    texture: Texture::from("textures/side"),
                    ..Default::default()
                },
                BlockFace::East => ElementFace {
                    texture: Texture::from("textures/side"),
                    ..Default::default()
                },
                BlockFace::West => ElementFace {
                    texture: Texture::from("textures/side"),
                    ..Default::default()
                }
            },
            ..Default::default()
        }
    ]),
    ..Default::default()
};

let resolved = ModelResolver::resolve_model([&child, &parent].into_iter());

assert_eq!(resolved, expected);

Iterates through a Model and all of its parents to resolve all of the model’s texture variables.

This works by merging together the Textures maps from all models in the parent-child chain, and then substituting texture variables with concrete values where possible.

Example
use maplit::hashmap;

use minecraft_assets::schemas::models::{Model, Textures};

let child = Model {
    textures: Some(Textures::from(hashmap! {
        "child_texture" => "textures/child",
        "bar" => "#parent_texture"
    })),
    ..Default::default()
};

let parent = Model {
    textures: Some(Textures::from(hashmap! {
        "parent_texture" => "textures/parent",
        "foo" => "#child_texture"
    })),
    ..Default::default()
};

// Provide models in increasing level of parenthood.
let models = [child, parent];
let resolved = ModelResolver::resolve_textures(models.iter());

let expected = Textures::from(hashmap! {
    "parent_texture" => "textures/parent",
    "foo" => "textures/child",              // <------- resolved
    "child_texture" => "textures/child",
    "bar" => "textures/parent"              // <------- resolved    
});

assert_eq!(resolved, expected);

Iterates through a Model and all of its parents to resolve the model’s cuboid Elements.

This works by taking the first set of elements present in the chain of parents. Unlike textures, child definitions for model elements completely override elements from the parent(s).

Example
use minecraft_assets::schemas::models::{Model, Element};

let element1 = Element {
    from: [0.0, 0.0, 0.0],
    to: [1.0, 1.0, 1.0],
    ..Default::default()
};

let element2 = Element {
    from: [5.0, 6.0, 7.0],
    to: [4.0, 3.0, 2.0],
    ..Default::default()
};

let model1 = Model {
    elements: Some(vec![element1.clone()]),
    ..Default::default()
};

let model2 = Model {
    elements: Some(vec![element2.clone()]),
    ..Default::default()
};

let empty = Model::default();

let resolved = ModelResolver::resolve_elements([&empty, &model1].into_iter());
assert_eq!(resolved, Some(vec![element1.clone()]));

let resolved = ModelResolver::resolve_elements([&empty, &model2].into_iter());
assert_eq!(resolved, Some(vec![element2.clone()]));

let resolved = ModelResolver::resolve_elements([&model1, &model2].into_iter());
assert_eq!(resolved, Some(vec![element1.clone()]));

let resolved = ModelResolver::resolve_elements([&model2, &model1].into_iter());
assert_eq!(resolved, Some(vec![element2.clone()]));

let resolved = ModelResolver::resolve_elements([&empty, &empty].into_iter());
assert_eq!(resolved, None);

Iterates through each ElementFace in each Element and resolves any texture variables using the provided map.

Iterates through a Model and all of its parents to resolve the model’s Display properties.

Similar to elements works by taking the first set of properties present in the chain of parents.

Iterates through a Model and all of its parents to resolve the model’s ambient occlusion setting.

Similar to elements works by taking the first property value present in the chain of parents.

Iterates through a Model and all of its parents to resolve the model’s GUI light mode setting.

Similar to elements works by taking the first property value present in the chain of parents.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.