Models

Models are 3D objects (characters, vehicles, buildings, etc) that can be rendered to the screen. They can be loaded from files, or procedurally generated.

Importing a model

To use a model in Ambient, place it in the assets folder, and then create a assets/pipeline.toml file:

[[pipelines]]
type = "Models"

See asset pipeline for more details.

Spawning a model

The model can then be spawned using prefab_from_url, assuming that output_prefabs is enabled in your assets/pipeline.toml file (it is enabled by default). Assuming your package is named my_package:


#![allow(unused)]
fn main() {
Entity::new()
    .with_merge(Transformable::suggested())
    .with(prefab_from_url(), packages::my_package::assets::url("MyModel.fbx"))
    .spawn();
}

The prefabs generated by the pipeline include the visual model and physics colliders.

If the code above lives in your server.rs file, it will create the physics colliders on the server. The model, including any skeletons it may have, will always be loaded and spawned on the clientside, regardless of if the above code lives in server.rs or client.rs. It is not guaranteed that the model will be loaded on the server, so you should not rely on it being there.

You can also use model_from_url to load a model without the physics colliders.

Animating a model

See animations.

Getting models for your project

See getting content for a list of places where you can get models.

Manipulating bones

You can get individual bones of a loaded model using the animation::get_bone_by_bind_id function.


#![allow(unused)]
fn main() {
let unit_id = Entity::new()
    .with_merge(Transformable::suggested())
    .with(prefab_from_url(), packages::my_package::assets::url("MyModel.fbx"))
    .spawn();
let left_foot = animation::get_bone_by_bind_id(unit_id, &BindId::LeftFoot).unwrap();
entity::set_component(left_foot, rotation(), Quat::from_rotation_x(0.3));
}

This will only work on the client at present, as the skeleton is not loaded on the server.