metaverse_agent 0.3.0

Agent handling for the open metaverse
Documentation
use actix::Message;
use std::path::PathBuf;
use std::time::SystemTime;

use glam::Mat4;
use metaverse_messages::utils::skeleton::Joint;
use metaverse_messages::utils::skeleton::JointName;
use metaverse_messages::utils::skeleton::Transform;

use glam::Vec3;
use metaverse_messages::utils::skeleton::Skeleton;
use uuid::Uuid;

// Definitions for an avatar object
#[derive(Debug, Clone, Message)]
#[rtype(result = "()")]
/// This contains information about the agent appearances as they come into the scene.
/// this is used to collect agent items, and trigger generation of the GLTF once their assets have
/// been loaded.
pub struct Avatar {
    /// The UUID of the agent
    pub agent_id: Uuid,
    /// The items in the outfit. Contains mesh and other data that will be used to construct the
    /// gltf file.
    pub items: Vec<OutfitObject>,
    /// The position of the agent in the world
    pub position: Vec3,
    /// The global skeleton of the agent
    pub skeleton: Skeleton,
    /// the location on disk of the avatar model for rendering
    pub path: Option<PathBuf>,

    pub outfit_size: usize,

    pub last_update: SystemTime,
}

impl Avatar {
    pub fn new(agent_id: Uuid, position: Vec3) -> Self {
        Avatar {
            agent_id,
            position,
            items: Vec::new(),
            // default_skeleton.rs is generated by build.rs. This is generated at compile time from the gltf
            // skeleton file in the benthic_default_model dir. It is a Skeleton object, with the
            // default transforms and parent-child relationships hardcoded in. This is used to
            // calculate rotations for the transforms that are given from the server
            skeleton: include!(concat!(env!("OUT_DIR"), "/default_skeleton.rs")),
            path: None,
            last_update: SystemTime::now(),
            outfit_size: 0,
        }
    }
}

#[derive(Debug, Clone)]
/// The items that can be stored in an outfit. It can contain generic Items, or SceneGroups, which
/// contain mesh data.
pub enum OutfitObject {
    /// A MeshObject, containing a json containing mesh data that can be rendered
    MeshObject(PathBuf),
    /// A generic bodypart, part of the original SL spec
    Bodypart,
    /// A generic clothing object, part of the original SL spec
    Clothing,
    /// Other
    Other,
}