Struct MODEL_MANAGER

Source
pub struct MODEL_MANAGER { /* private fields */ }
Expand description

模型管理器

Methods from Deref<Target = RustCraftWrapper<ModelManager>>§

Source

pub fn add_model(&self, name: &str, model: Box<dyn Model + Send + 'static>)

以此参数形式载入模型

§参数 Parameters
  • name: 模型名称
  • vertices: 顶点数据
  • indices: 索引数据
  • description: 顶点数据描述
§注解 Note

此函数只有在 OpenGL 上下文激活后才能调用

Source

pub fn load_from_file(&self, path: &str)

从文件中载入模型

§参数 Parameters
  • path: 模型文件路径
§注解 Note

此函数只有在 OpenGL 上下文激活后才能调用

目前仅支持从 JSON 文件中载入简单几何体模型: 格式:

  • 仅顶点数据模型
{
    "type": "array",
    "vertices": [...],
    "description": "..."
}

其中: vertices 为顶点数据,description 为顶点数据描述

  • 含索引数据模型
{
    "type": "element",
    "vertices": [...],
    "indices": [...],
    "description": "..."
}

其中: vertices 为顶点数据,indices 为索引数据,description 为顶点数据描述

顶点数据结果描述的格式为: [<num><type>;...]

  • num: 值个数
  • type: 值类型
    • f: 单精度浮点数
    • i: 整型
    • u: 无符号整型
    • _: 一字节占位符

例如:"3f;2f", "3f;3f;2f"

Source

pub fn draw_model(&self, name: &str)

渲染参数所指定的模型

§参数 Parameters
  • name: 模型名称
§注解 Note

此函数只有在 OpenGL 上下文激活后才能调用

Source

pub fn apply<F>(&self, f: F)
where F: FnOnce(&mut T),

向内部数据应用一个函数 该函数接收内部数据的可变引用,允许对其进行修改

§参数 Parameters
  • f: 一个函数,接收内部数据的可变引用作为参数
§注解 Note

在运行函数的过程中,互斥锁处于锁定状态,直至函数执行完毕; 在函数内不应再次调用此函数,否则会导致死锁

§示例 Examples
use rustcraft::RustCraftWrapper;
use lazy_static::lazy_static;

lazy_static! {
    static ref RUSTCRAFT: RustCraftWrapper<i32> = RustCraftWrapper::new(42);
}

fn main() {
    RUSTCRAFT.apply(|data| {
        *data += 1;
    });
    RUSTCRAFT.apply(|data| {
        assert_eq!(*data, 43);
    });
}

Trait Implementations§

Source§

impl Deref for MODEL_MANAGER

Source§

type Target = RustCraftWrapper<ModelManager>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &RustCraftWrapper<ModelManager>

Dereferences the value.
Source§

impl LazyStatic for MODEL_MANAGER

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.