pub trait ModelResourceExtension: Sized {
// Required methods
fn instantiate_from<Pre>(
model: ModelResource,
model_data: &Model,
handle: Handle<Node>,
dest_graph: &mut Graph,
pre_processing_callback: &mut Pre,
) -> (Handle<Node>, NodeHandleMap<Node>)
where Pre: FnMut(Handle<Node>, &mut Node);
fn begin_instantiation<'a>(
&'a self,
dest_scene: &'a mut Scene,
) -> InstantiationContext<'a>;
fn instantiate(&self, dest_scene: &mut Scene) -> Handle<Node>;
fn instantiate_at(
&self,
scene: &mut Scene,
position: Vector3<f32>,
orientation: UnitQuaternion<f32>,
) -> Handle<Node>;
fn instantiate_and_attach(
&self,
scene: &mut Scene,
parent: Handle<Node>,
position: Vector3<f32>,
face_towards: Vector3<f32>,
scale: Vector3<f32>,
) -> Handle<Node>;
fn retarget_animations_directly(
&self,
root: Handle<Node>,
graph: &Graph,
) -> Vec<Animation> ⓘ;
fn retarget_animations_to_player(
&self,
root: Handle<Node>,
dest_animation_player: Handle<Node>,
graph: &mut Graph,
) -> Vec<Handle<Animation>>;
fn retarget_animations(
&self,
root: Handle<Node>,
graph: &mut Graph,
) -> Vec<Handle<Animation>>;
fn generate_ids(&self) -> FxHashMap<Handle<Node>, SceneNodeId>;
}Expand description
Extension trait for model resources.
Required Methods§
Sourcefn instantiate_from<Pre>(
model: ModelResource,
model_data: &Model,
handle: Handle<Node>,
dest_graph: &mut Graph,
pre_processing_callback: &mut Pre,
) -> (Handle<Node>, NodeHandleMap<Node>)
fn instantiate_from<Pre>( model: ModelResource, model_data: &Model, handle: Handle<Node>, dest_graph: &mut Graph, pre_processing_callback: &mut Pre, ) -> (Handle<Node>, NodeHandleMap<Node>)
Tries to instantiate model from given resource.
Sourcefn begin_instantiation<'a>(
&'a self,
dest_scene: &'a mut Scene,
) -> InstantiationContext<'a>
fn begin_instantiation<'a>( &'a self, dest_scene: &'a mut Scene, ) -> InstantiationContext<'a>
Begins instantiation of the model.
Sourcefn instantiate(&self, dest_scene: &mut Scene) -> Handle<Node>
fn instantiate(&self, dest_scene: &mut Scene) -> Handle<Node>
Tries to instantiate model from given resource.
Sourcefn instantiate_at(
&self,
scene: &mut Scene,
position: Vector3<f32>,
orientation: UnitQuaternion<f32>,
) -> Handle<Node>
fn instantiate_at( &self, scene: &mut Scene, position: Vector3<f32>, orientation: UnitQuaternion<f32>, ) -> Handle<Node>
Instantiates a prefab and places it at specified position and orientation in global coordinates.
Sourcefn instantiate_and_attach(
&self,
scene: &mut Scene,
parent: Handle<Node>,
position: Vector3<f32>,
face_towards: Vector3<f32>,
scale: Vector3<f32>,
) -> Handle<Node>
fn instantiate_and_attach( &self, scene: &mut Scene, parent: Handle<Node>, position: Vector3<f32>, face_towards: Vector3<f32>, scale: Vector3<f32>, ) -> Handle<Node>
Instantiates a prefab and places it at specified position, orientation, scale in global coordinates and attaches it to the specified parent. This method automatically calculates required local position, rotation, scaling for the instance so it will remain at the same place in world space after attachment. This method could be useful if you need to instantiate an object at some other object.
Sourcefn retarget_animations_directly(
&self,
root: Handle<Node>,
graph: &Graph,
) -> Vec<Animation> ⓘ
fn retarget_animations_directly( &self, root: Handle<Node>, graph: &Graph, ) -> Vec<Animation> ⓘ
Tries to retarget animations from given model resource to a node hierarchy starting
from root on a given scene.
Animation retargeting allows you to “transfer” animation from a model to a model instance on a scene. Imagine you have a character that should have multiple animations like idle, run, shoot, walk, etc. and you want to store each animation in a separate file. Then when you creating a character on a level you want to have all possible animations assigned to a character, this is where this function comes into play: you just load a model of your character with skeleton, but without any animations, then you load several “models” which have only skeleton with some animation (such “models” can be considered as “animation” resources). After this you need to instantiate model on your level and retarget all animations you need to that instance from other “models”. All you have after this is a handle to a model and bunch of handles to specific animations. After this animations can be blended in any combinations you need to. For example idle animation can be blended with walk animation when your character starts walking.
§Notes
Most of the 3d model formats can contain only one animation, so in most cases this function will return vector with only one animation.
Sourcefn retarget_animations_to_player(
&self,
root: Handle<Node>,
dest_animation_player: Handle<Node>,
graph: &mut Graph,
) -> Vec<Handle<Animation>>
fn retarget_animations_to_player( &self, root: Handle<Node>, dest_animation_player: Handle<Node>, graph: &mut Graph, ) -> Vec<Handle<Animation>>
Tries to retarget animations from given model resource to a node hierarchy starting
from root on a given scene. Unlike Self::retarget_animations_directly, it automatically
adds retargetted animations to the specified animation player in the hierarchy of given root.
§Panic
Panics if dest_animation_player is invalid handle, or the node does not have AnimationContainer
component.
Sourcefn retarget_animations(
&self,
root: Handle<Node>,
graph: &mut Graph,
) -> Vec<Handle<Animation>>
fn retarget_animations( &self, root: Handle<Node>, graph: &mut Graph, ) -> Vec<Handle<Animation>>
Tries to retarget animations from given model resource to a node hierarchy starting
from root on a given scene. Unlike Self::retarget_animations_directly, it automatically
adds retargetted animations to a first animation player in the hierarchy of given root.
§Panic
Panics if there’s no animation player in the given hierarchy (descendant nodes of root).
Sourcefn generate_ids(&self) -> FxHashMap<Handle<Node>, SceneNodeId>
fn generate_ids(&self) -> FxHashMap<Handle<Node>, SceneNodeId>
Generates a set of unique IDs for every node in the model. Use this method in pair with
ModelResource::begin_instantiation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.