Struct Instance

Source
pub struct Instance<'a> {
    pub type_name: String,
    pub data: InstanceDataFormat<'a>,
    pub fields: LinkedHashMap<String, FieldTemplate>,
    /* private fields */
}
Expand description

Represents a block of data inside the blend file. An Instance can be a camera, a mesh, a material, or anything else Blender uses internally, like material nodes, user settings or render options. An Instance is conceptually a struct: a collection of named fields which can themselves be structs or primitives.

Fields§

§type_name: String§data: InstanceDataFormat<'a>

The raw binary data this Instance owns.

§fields: LinkedHashMap<String, FieldTemplate>

The fields of this Instance.

Implementations§

Source§

impl<'a> Instance<'a>

Source

pub fn dna(&self) -> &Dna

Source

pub fn raw(&self) -> &RawBlend

Source

pub fn code(&self) -> [u8; 4]

If this Instance was created from a primary/root Block it will have a code. Possible codes include “OB” for objects, “ME” for meshes, “CA” for cameras, etc.

§Panics

Panics if the instance’s underlying data doesn’t have a code

Source

pub fn memory_address(&self) -> NonZeroU64

If this Instance was created from a primary/root or subsidiary Block it will have a memory address. Blender dumps its memory into the blend file when saving and the old memory addresses are used the recreate the connections between blocks when loading the file again.

§Panics

Panics if the instance underlying data doesn’t have an old memory address.

Source

pub fn is_valid<T: AsRef<str>>(&self, name: T) -> bool

Tests whether a field is valid and can be accessed using the get methods without panicking. Which get method you have to use depends on the field type.

Source

pub fn get_u8<T: AsRef<str>>(&self, name: T) -> u8

Source

pub fn get_i8<T: AsRef<str>>(&self, name: T) -> i8

Source

pub fn get_char<T: AsRef<str>>(&self, name: T) -> char

Source

pub fn get_u16<T: AsRef<str>>(&self, name: T) -> u16

Source

pub fn get_i16<T: AsRef<str>>(&self, name: T) -> i16

Source

pub fn get_i32<T: AsRef<str>>(&self, name: T) -> i32

Source

pub fn get_u32<T: AsRef<str>>(&self, name: T) -> u32

Source

pub fn get_f32<T: AsRef<str>>(&self, name: T) -> f32

Source

pub fn get_f64<T: AsRef<str>>(&self, name: T) -> f64

Source

pub fn get_u64<T: AsRef<str>>(&self, name: T) -> u64

Source

pub fn get_i64<T: AsRef<str>>(&self, name: T) -> i64

Source

pub fn get_u8_vec<T: AsRef<str>>(&self, name: T) -> Vec<u8>

Source

pub fn get_i8_vec<T: AsRef<str>>(&self, name: T) -> Vec<i8>

Source

pub fn get_i32_vec<T: AsRef<str>>(&self, name: T) -> Vec<i32>

Source

pub fn get_u32_vec<T: AsRef<str>>(&self, name: T) -> Vec<u32>

Source

pub fn get_i16_vec<T: AsRef<str>>(&self, name: T) -> Vec<i16>

Source

pub fn get_u16_vec<T: AsRef<str>>(&self, name: T) -> Vec<u16>

Source

pub fn get_f32_vec<T: AsRef<str>>(&self, name: T) -> Vec<f32>

Source

pub fn get_f64_vec<T: AsRef<str>>(&self, name: T) -> Vec<f64>

Source

pub fn get_u64_vec<T: AsRef<str>>(&self, name: T) -> Vec<u64>

Source

pub fn get_i64_vec<T: AsRef<str>>(&self, name: T) -> Vec<i64>

Source

pub fn get_string<T: AsRef<str>>(&self, name: T) -> String

§Example
let obj = blend.instances_with_code(*b"OB").next().unwrap();
let name = obj.get("id").get_string("name");
§Panics
  • Panics if the field cannot be read as a string.
Source

pub fn get<T: AsRef<str>>(&self, name: T) -> Instance<'a>

Used to access fields which are structs.

§Example
let obj = blend.instances_with_code(*b"OB").next().expect("no object found");
let id = obj.get("id");
let data = obj.get("data");
§Panics
  • Panics if the field is not a valid struct.
Source

pub fn get_iter<T: AsRef<str>>( &self, name: T, ) -> impl Iterator<Item = Instance<'a>>

Used to access fields which are lists of structs.

§Example
let obj = blend.instances_with_code(*b"OB").skip(1).next().unwrap();
let materials = obj.get_iter("mat").collect::<Vec<_>>();
§Panics
  • Panics if the field is not a valid list of structs.

Trait Implementations§

Source§

impl<'a> Clone for Instance<'a>

Source§

fn clone(&self) -> Instance<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Instance<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Instance<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Instance<'a>

§

impl<'a> RefUnwindSafe for Instance<'a>

§

impl<'a> Send for Instance<'a>

§

impl<'a> Sync for Instance<'a>

§

impl<'a> Unpin for Instance<'a>

§

impl<'a> UnwindSafe for Instance<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.