Struct blue_engine::header::Object
source · pub struct Object {Show 23 fields
pub name: String,
pub vertices: Vec<Vertex>,
pub indices: Vec<u16>,
pub uniform_layout: BindGroupLayout,
pub pipeline: Pipeline,
pub instances: Vec<Instance>,
pub instance_buffer: Buffer,
pub size: Vec3,
pub scale: Vec3,
pub position: Vec3,
pub rotation: Vec3,
pub position_matrix: Mat4,
pub scale_matrix: Mat4,
pub rotation_matrix: Mat4,
pub inverse_transformation_matrix: Matrix,
pub uniform_color: Array4,
pub color: Array4,
pub shader_builder: ShaderBuilder,
pub shader_settings: ShaderSettings,
pub camera_effect: bool,
pub uniform_buffers: Vec<Buffer>,
pub is_visible: bool,
pub render_order: usize,
/* private fields */
}
Expand description
Objects make it easier to work with Blue Engine, it automates most of work needed for creating 3D objects and showing them on screen. A range of default objects are available as well as ability to customize each of them and even create your own! You can also customize almost everything there is about them!
Fields§
§name: String
Give your object a name, which can help later on for debugging.
vertices: Vec<Vertex>
A list of Vertex
indices: Vec<u16>
A list of indices that dictates the order that vertices appear
uniform_layout: BindGroupLayout
Describes how to uniform buffer is structures
pipeline: Pipeline
Pipeline holds all the data that is sent to GPU, including shaders and textures
instances: Vec<Instance>
List of instances of this object
instance_buffer: Buffer
instance buffer
size: Vec3
Dictates the size of your object in pixels
scale: Vec3
Dictates the scale of your object. Which by default it’s 1,1,1 where the screen is size of 2
position: Vec3
Dictates the position of your object in pixels
rotation: Vec3
Dictates the rotation of your object
position_matrix: Mat4
Transformation matrices helps to apply changes to your object, including position, orientation, … Best choice is to let the Object system handle it
scale_matrix: Mat4
Transformation matrices helps to apply changes to your object, including position, orientation, … Best choice is to let the Object system handle it
rotation_matrix: Mat4
Transformation matrices helps to apply changes to your object, including position, orientation, … Best choice is to let the Object system handle it
inverse_transformation_matrix: Matrix
Transformation matrix, but inversed
uniform_color: Array4
The main color of your object
color: Array4
The color of your object that is sent to gpu
shader_builder: ShaderBuilder
A struct making it easier to manipulate specific parts of shader
shader_settings: ShaderSettings
Shader settings
camera_effect: bool
Camera have any effect on the object?
uniform_buffers: Vec<Buffer>
Uniform Buffers to be sent to GPU
is_visible: bool
Should be rendered or not
render_order: usize
Objects with higher number get rendered later and appear “on top” when occupying the same space
Implementations§
source§impl Object
impl Object
sourcepub fn set_name(&mut self, name: impl StringBuffer)
pub fn set_name(&mut self, name: impl StringBuffer)
Sets the name of the object
sourcepub fn set_scale(&mut self, x: f32, y: f32, z: f32)
pub fn set_scale(&mut self, x: f32, y: f32, z: f32)
Scales an object. e.g. 2.0 doubles the size and 0.5 halves
sourcepub fn resize(
&mut self,
width: f32,
height: f32,
depth: f32,
window_size: PhysicalSize<u32>,
)
pub fn resize( &mut self, width: f32, height: f32, depth: f32, window_size: PhysicalSize<u32>, )
Resizes an object in pixels which are relative to the window
sourcepub fn set_rotatation(&mut self, angle: f32, axis: RotateAxis)
pub fn set_rotatation(&mut self, angle: f32, axis: RotateAxis)
Rotates the object in the axis you specify
sourcepub fn set_translation(&mut self, x: f32, y: f32, z: f32)
pub fn set_translation(&mut self, x: f32, y: f32, z: f32)
Moves the object by the amount you specify in the axis you specify
sourcepub fn set_position(&mut self, x: f32, y: f32, z: f32)
pub fn set_position(&mut self, x: f32, y: f32, z: f32)
Sets the position of the object in 3D space relative to the window
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
pub fn main() {
// start the engine
let mut engine = Engine::new().expect("window not created");
// create a triangle
triangle(
"Triangle",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.unwrap();
// update the triangle
engine.objects.update_object("Triangle", |object| {
// set the position of the main triangle
object.set_position(0f32, 0f32, -3f32);
// a function to make instance creation easier
let create_instance = |x: f32, y: f32, z: f32| {
Instance::new(
[x, y, z].into(),
[0f32, 0f32, 0f32].into(),
[1f32, 1f32, 1f32].into(),
)
};
// add an instance
object.add_instance(create_instance(2f32, 1f32, -2f32));
object.add_instance(create_instance(2f32, -1f32, -2f32));
object.add_instance(create_instance(-2f32, 1f32, -2f32));
object.add_instance(create_instance(-2f32, -1f32, -2f32));
});
// we manually update the instance buffer before the next frame starts
// this is due to the object updates happening after every frame, hence
// for the first frame, we need to update it ourselves.
engine
.objects
.get_mut("Triangle")
.expect("Couldn't get the triangle")
.update_instance_buffer(&mut engine.renderer)
.expect("Couldn't update instance buffer");
// run the loop as normal
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
More examples
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Start the engine
let mut engine = Engine::new().expect("window not initialized");
// build a texture as an example of resource to be shared
let texture = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
// build your main object with the texture
square(
"main",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of main square");
// add the texture to the main object as normally would
engine
.objects
.get_mut("main")
.unwrap()
.set_texture(texture)
.expect("Error during inserting texture to the main square");
// set position to make it visible
engine
.objects
.get_mut("main")
.expect("Error during setting the position of the main square")
.set_position(-1.5f32, 0f32, 0f32);
// create another object where you want to get resources shared with
square(
"alt",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of alt square");
// here you can use `reference_texture` to reference the texture from the main object
engine
.objects
.get_mut("alt")
.expect("Error during copying texture of the main square")
.reference_texture("main");
// setting position again to make it visible
engine
.objects
.get_mut("alt")
.expect("Error during setting the position of the alt square")
.set_position(1.5f32, 0f32, 0f32);
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn main() {
// initialize the engine
let mut engine = Engine::new().expect("couldn't initialize engine");
// make the first layer
square(
"layer1",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// make the second layer
square(
"layer2",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// Get layer 1 object
let layer1 = engine
.objects
.get_mut("layer1")
.expect("failed to gete object");
// set a color to differentiate it
layer1
.set_uniform_color(1f32, 0.5, 0f32, 1f32)
.expect("failed to set color");
// move it to left a bit
layer1.set_position(-0.5, 0f32, 0f32);
// set render order to 0th
layer1.set_render_order(0).unwrap();
// Get layer 2 object
let layer2 = engine
.objects
.get_mut("layer2")
.expect("failed to gete object");
// set a color to differentiate it
layer2
.set_uniform_color(0f32, 0f32, 1f32, 1f32)
.expect("failed to set color");
// move it to right a bit
layer2.set_position(0.5, 0f32, 0f32);
// set render order to 1st
layer2.set_render_order(1).unwrap();
// get a timer for order change
let start = std::time::SystemTime::now();
// start the update loop
engine
.update_loop(move |_, _, object_storage, _, _, _| {
// get the target layer to change order of
let target = object_storage.get_mut("layer1").unwrap();
// on ever 2 seconds change order
if start.elapsed().unwrap().as_secs() % 2 == 0 {
target.set_render_order(2).unwrap();
} else {
// change back to default
target.set_render_order(0).unwrap();
}
})
.expect("Error during update loop");
}
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
fn main() {
let mut engine = Engine::new_config(blue_engine::WindowDescriptor {
power_preference: blue_engine::PowerPreference::None,
present_mode: blue_engine::wgpu::PresentMode::Mailbox,
limits: blue_engine::wgpu::Limits::downlevel_defaults(),
..Default::default()
})
.expect("win");
//let test_instance = Instance::default();
//println!("{:?}", test_instance.to_raw());
let texture = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
let texture2 = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
let texture3 = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
square(
"main",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine.objects.get_mut("main").unwrap().set_texture(texture);
engine
.objects
.get_mut("main")
.unwrap()
.set_position(-1f32, 0f32, 0f32);
square(
"alt",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine.objects.get_mut("alt").unwrap().set_texture(texture2);
engine
.objects
.get_mut("alt")
.unwrap()
.set_position(0.2f32, 0f32, 0.001f32);
square(
"alt2",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine
.objects
.get_mut("alt2")
.unwrap()
.set_texture(texture3);
engine
.objects
.get_mut("alt2")
.unwrap()
.set_position(-0.2f32, 0f32, 0.001f32);
let speed = -0.05;
let mut last_time = std::time::Instant::now();
let mut frames = 0;
engine
.update_loop(move |renderer, _window, objects, input, camera, plugins| {
// calculate FPS
let current_time = std::time::Instant::now();
frames += 1;
if current_time - last_time >= std::time::Duration::from_secs(1) {
println!("{}ms/frame", 1000f32 / frames as f32);
frames = 0;
last_time = current_time;
}
let sprite = objects.get_mut("alt").unwrap();
if input.key_held(blue_engine::KeyCode::Escape) {
_window.close_engine();
}
if input.key_held(blue_engine::KeyCode::ArrowUp) {
sprite.set_position(
sprite.position.x,
sprite.position.y - speed,
sprite.position.z,
);
//lm.ambient_color.data = [1f32, 1f32, 1f32, 1f32];
}
if input.key_held(blue_engine::KeyCode::ArrowDown) {
sprite.set_position(
sprite.position.x,
sprite.position.y + speed,
sprite.position.z,
);
//lm.ambient_color.data = [0.1f32, 0.1f32, 0.1f32, 1f32];
}
if input.key_held(blue_engine::KeyCode::ArrowLeft) {
sprite.set_position(
sprite.position.x + speed,
sprite.position.y,
sprite.position.z,
);
}
if input.key_held(blue_engine::KeyCode::ArrowRight) {
sprite.set_position(
sprite.position.x - speed,
sprite.position.y,
sprite.position.z,
);
}
if input.key_held(blue_engine::KeyCode::KeyE) {
sprite.set_position(
sprite.position.x,
sprite.position.y,
sprite.position.z + speed,
);
}
if input.key_held(blue_engine::KeyCode::KeyQ) {
sprite.set_position(
sprite.position.x,
sprite.position.y,
sprite.position.z - speed,
);
}
})
.expect("Error during update loop");
println!("Engine have been closed")
}
sourcepub fn set_color(
&mut self,
red: f32,
green: f32,
blue: f32,
alpha: f32,
) -> Result<()>
pub fn set_color( &mut self, red: f32, green: f32, blue: f32, alpha: f32, ) -> Result<()>
Changes the color of the object. If textures exist, the color of textures will change
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
fn main() {
let mut engine = Engine::new().expect("win");
cube("Cube", &mut engine.renderer, &mut engine.objects).unwrap();
engine
.objects
.get_mut("Cube")
.unwrap()
.set_color(0f32, 0f32, 1f32, 1f32)
.unwrap();
let radius = 5f32;
let start = std::time::SystemTime::now();
engine
.update_loop(move |_, _, _, _, camera, _| {
let camx = start.elapsed().unwrap().as_secs_f32().sin() * radius;
let camy = start.elapsed().unwrap().as_secs_f32().sin() * radius;
let camz = start.elapsed().unwrap().as_secs_f32().cos() * radius;
camera
.set_position(camx, camy, camz)
.expect("Couldn't update the camera eye");
})
.expect("Error during update loop");
}
sourcepub fn set_uniform_color(
&mut self,
red: f32,
green: f32,
blue: f32,
alpha: f32,
) -> Result<()>
pub fn set_uniform_color( &mut self, red: f32, green: f32, blue: f32, alpha: f32, ) -> Result<()>
Changes the main color of the object hat is sent to GPU. If textures exist, the color of textures will change
Examples found in repository?
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn main() {
// initialize the engine
let mut engine = Engine::new().expect("couldn't initialize engine");
// make the first layer
square(
"layer1",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// make the second layer
square(
"layer2",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// Get layer 1 object
let layer1 = engine
.objects
.get_mut("layer1")
.expect("failed to gete object");
// set a color to differentiate it
layer1
.set_uniform_color(1f32, 0.5, 0f32, 1f32)
.expect("failed to set color");
// move it to left a bit
layer1.set_position(-0.5, 0f32, 0f32);
// set render order to 0th
layer1.set_render_order(0).unwrap();
// Get layer 2 object
let layer2 = engine
.objects
.get_mut("layer2")
.expect("failed to gete object");
// set a color to differentiate it
layer2
.set_uniform_color(0f32, 0f32, 1f32, 1f32)
.expect("failed to set color");
// move it to right a bit
layer2.set_position(0.5, 0f32, 0f32);
// set render order to 1st
layer2.set_render_order(1).unwrap();
// get a timer for order change
let start = std::time::SystemTime::now();
// start the update loop
engine
.update_loop(move |_, _, object_storage, _, _, _| {
// get the target layer to change order of
let target = object_storage.get_mut("layer1").unwrap();
// on ever 2 seconds change order
if start.elapsed().unwrap().as_secs() % 2 == 0 {
target.set_render_order(2).unwrap();
} else {
// change back to default
target.set_render_order(0).unwrap();
}
})
.expect("Error during update loop");
}
sourcepub fn set_render_order(&mut self, render_order: usize) -> Result<()>
pub fn set_render_order(&mut self, render_order: usize) -> Result<()>
Changes the render order of the Object.
Objects with higher number get rendered later and appear “on top” when occupying the same space
Examples found in repository?
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn main() {
// initialize the engine
let mut engine = Engine::new().expect("couldn't initialize engine");
// make the first layer
square(
"layer1",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// make the second layer
square(
"layer2",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("failed to create square");
// Get layer 1 object
let layer1 = engine
.objects
.get_mut("layer1")
.expect("failed to gete object");
// set a color to differentiate it
layer1
.set_uniform_color(1f32, 0.5, 0f32, 1f32)
.expect("failed to set color");
// move it to left a bit
layer1.set_position(-0.5, 0f32, 0f32);
// set render order to 0th
layer1.set_render_order(0).unwrap();
// Get layer 2 object
let layer2 = engine
.objects
.get_mut("layer2")
.expect("failed to gete object");
// set a color to differentiate it
layer2
.set_uniform_color(0f32, 0f32, 1f32, 1f32)
.expect("failed to set color");
// move it to right a bit
layer2.set_position(0.5, 0f32, 0f32);
// set render order to 1st
layer2.set_render_order(1).unwrap();
// get a timer for order change
let start = std::time::SystemTime::now();
// start the update loop
engine
.update_loop(move |_, _, object_storage, _, _, _| {
// get the target layer to change order of
let target = object_storage.get_mut("layer1").unwrap();
// on ever 2 seconds change order
if start.elapsed().unwrap().as_secs() % 2 == 0 {
target.set_render_order(2).unwrap();
} else {
// change back to default
target.set_render_order(0).unwrap();
}
})
.expect("Error during update loop");
}
sourcepub fn set_texture(&mut self, texture: Textures) -> Result<()>
pub fn set_texture(&mut self, texture: Textures) -> Result<()>
Replaces the object’s texture with provided one
Examples found in repository?
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Start the engine
let mut engine = Engine::new().expect("window not initialized");
// build a texture as an example of resource to be shared
let texture = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
// build your main object with the texture
square(
"main",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of main square");
// add the texture to the main object as normally would
engine
.objects
.get_mut("main")
.unwrap()
.set_texture(texture)
.expect("Error during inserting texture to the main square");
// set position to make it visible
engine
.objects
.get_mut("main")
.expect("Error during setting the position of the main square")
.set_position(-1.5f32, 0f32, 0f32);
// create another object where you want to get resources shared with
square(
"alt",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of alt square");
// here you can use `reference_texture` to reference the texture from the main object
engine
.objects
.get_mut("alt")
.expect("Error during copying texture of the main square")
.reference_texture("main");
// setting position again to make it visible
engine
.objects
.get_mut("alt")
.expect("Error during setting the position of the alt square")
.set_position(1.5f32, 0f32, 0f32);
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
More examples
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
fn main() {
let mut engine = Engine::new_config(blue_engine::WindowDescriptor {
power_preference: blue_engine::PowerPreference::None,
present_mode: blue_engine::wgpu::PresentMode::Mailbox,
limits: blue_engine::wgpu::Limits::downlevel_defaults(),
..Default::default()
})
.expect("win");
//let test_instance = Instance::default();
//println!("{:?}", test_instance.to_raw());
let texture = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
let texture2 = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
let texture3 = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
square(
"main",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine.objects.get_mut("main").unwrap().set_texture(texture);
engine
.objects
.get_mut("main")
.unwrap()
.set_position(-1f32, 0f32, 0f32);
square(
"alt",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine.objects.get_mut("alt").unwrap().set_texture(texture2);
engine
.objects
.get_mut("alt")
.unwrap()
.set_position(0.2f32, 0f32, 0.001f32);
square(
"alt2",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
);
engine
.objects
.get_mut("alt2")
.unwrap()
.set_texture(texture3);
engine
.objects
.get_mut("alt2")
.unwrap()
.set_position(-0.2f32, 0f32, 0.001f32);
let speed = -0.05;
let mut last_time = std::time::Instant::now();
let mut frames = 0;
engine
.update_loop(move |renderer, _window, objects, input, camera, plugins| {
// calculate FPS
let current_time = std::time::Instant::now();
frames += 1;
if current_time - last_time >= std::time::Duration::from_secs(1) {
println!("{}ms/frame", 1000f32 / frames as f32);
frames = 0;
last_time = current_time;
}
let sprite = objects.get_mut("alt").unwrap();
if input.key_held(blue_engine::KeyCode::Escape) {
_window.close_engine();
}
if input.key_held(blue_engine::KeyCode::ArrowUp) {
sprite.set_position(
sprite.position.x,
sprite.position.y - speed,
sprite.position.z,
);
//lm.ambient_color.data = [1f32, 1f32, 1f32, 1f32];
}
if input.key_held(blue_engine::KeyCode::ArrowDown) {
sprite.set_position(
sprite.position.x,
sprite.position.y + speed,
sprite.position.z,
);
//lm.ambient_color.data = [0.1f32, 0.1f32, 0.1f32, 1f32];
}
if input.key_held(blue_engine::KeyCode::ArrowLeft) {
sprite.set_position(
sprite.position.x + speed,
sprite.position.y,
sprite.position.z,
);
}
if input.key_held(blue_engine::KeyCode::ArrowRight) {
sprite.set_position(
sprite.position.x - speed,
sprite.position.y,
sprite.position.z,
);
}
if input.key_held(blue_engine::KeyCode::KeyE) {
sprite.set_position(
sprite.position.x,
sprite.position.y,
sprite.position.z + speed,
);
}
if input.key_held(blue_engine::KeyCode::KeyQ) {
sprite.set_position(
sprite.position.x,
sprite.position.y,
sprite.position.z - speed,
);
}
})
.expect("Error during update loop");
println!("Engine have been closed")
}
sourcepub fn flag_as_changed(&mut self)
pub fn flag_as_changed(&mut self)
This will flag object as changed and altered, leading to rebuilding parts, or entirety on next frame. Best used if you directly altered fields of the object. The functions normally flag the object as changed on every call anyways. But this function is to manually flag it yourself.
sourcepub fn flag_as_unchanged(&mut self)
pub fn flag_as_unchanged(&mut self)
same as flag_as_changed, but inverse
sourcepub fn inverse_matrices(&mut self)
pub fn inverse_matrices(&mut self)
build an inverse of the transformation matrix to be sent to the gpu for lighting and other things.
sourcepub fn update(&mut self, renderer: &mut Renderer) -> Result<()>
pub fn update(&mut self, renderer: &mut Renderer) -> Result<()>
Update and apply changes done to an object
sourcepub fn update_and_return(
&mut self,
renderer: &mut Renderer,
) -> Result<(VertexBuffers, UniformBuffers, Shaders)>
pub fn update_and_return( &mut self, renderer: &mut Renderer, ) -> Result<(VertexBuffers, UniformBuffers, Shaders)>
Update and apply changes done to an object and returns a pipeline
sourcepub fn update_vertex_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
pub fn update_vertex_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
Update and apply changes done to the vertex buffer
sourcepub fn update_vertex_buffer_and_return(
&mut self,
renderer: &mut Renderer,
) -> Result<VertexBuffers>
pub fn update_vertex_buffer_and_return( &mut self, renderer: &mut Renderer, ) -> Result<VertexBuffers>
Returns the buffer with ownership
sourcepub fn update_shader(&mut self, renderer: &mut Renderer) -> Result<()>
pub fn update_shader(&mut self, renderer: &mut Renderer) -> Result<()>
Update and apply changes done to the shader
sourcepub fn update_shader_and_return(
&mut self,
renderer: &mut Renderer,
) -> Result<Shaders>
pub fn update_shader_and_return( &mut self, renderer: &mut Renderer, ) -> Result<Shaders>
Returns the buffer with ownership
sourcepub fn update_uniform_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
pub fn update_uniform_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
Update and apply changes done to the uniform buffer
sourcepub fn update_uniform_buffer_and_return(
&mut self,
renderer: &mut Renderer,
) -> Result<UniformBuffers>
pub fn update_uniform_buffer_and_return( &mut self, renderer: &mut Renderer, ) -> Result<UniformBuffers>
Returns the buffer with ownership
sourcepub fn update_instance_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
pub fn update_instance_buffer(&mut self, renderer: &mut Renderer) -> Result<()>
Updates the instance buffer
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
pub fn main() {
// start the engine
let mut engine = Engine::new().expect("window not created");
// create a triangle
triangle(
"Triangle",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.unwrap();
// update the triangle
engine.objects.update_object("Triangle", |object| {
// set the position of the main triangle
object.set_position(0f32, 0f32, -3f32);
// a function to make instance creation easier
let create_instance = |x: f32, y: f32, z: f32| {
Instance::new(
[x, y, z].into(),
[0f32, 0f32, 0f32].into(),
[1f32, 1f32, 1f32].into(),
)
};
// add an instance
object.add_instance(create_instance(2f32, 1f32, -2f32));
object.add_instance(create_instance(2f32, -1f32, -2f32));
object.add_instance(create_instance(-2f32, 1f32, -2f32));
object.add_instance(create_instance(-2f32, -1f32, -2f32));
});
// we manually update the instance buffer before the next frame starts
// this is due to the object updates happening after every frame, hence
// for the first frame, we need to update it ourselves.
engine
.objects
.get_mut("Triangle")
.expect("Couldn't get the triangle")
.update_instance_buffer(&mut engine.renderer)
.expect("Couldn't update instance buffer");
// run the loop as normal
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
sourcepub fn update_instance_buffer_and_return(
&mut self,
renderer: &mut Renderer,
) -> Result<Buffer>
pub fn update_instance_buffer_and_return( &mut self, renderer: &mut Renderer, ) -> Result<Buffer>
Returns the buffer with ownership
sourcepub fn reference_vertices(&mut self, object_id: impl StringBuffer)
pub fn reference_vertices(&mut self, object_id: impl StringBuffer)
References another object’s vertices
sourcepub fn reference_shader(&mut self, object_id: impl StringBuffer)
pub fn reference_shader(&mut self, object_id: impl StringBuffer)
References another object’s shader
sourcepub fn reference_texture(&mut self, object_id: impl StringBuffer)
pub fn reference_texture(&mut self, object_id: impl StringBuffer)
References another object’s texture
Examples found in repository?
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Start the engine
let mut engine = Engine::new().expect("window not initialized");
// build a texture as an example of resource to be shared
let texture = engine
.renderer
.build_texture(
"background",
TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
blue_engine::TextureMode::Clamp,
)
.unwrap();
// build your main object with the texture
square(
"main",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of main square");
// add the texture to the main object as normally would
engine
.objects
.get_mut("main")
.unwrap()
.set_texture(texture)
.expect("Error during inserting texture to the main square");
// set position to make it visible
engine
.objects
.get_mut("main")
.expect("Error during setting the position of the main square")
.set_position(-1.5f32, 0f32, 0f32);
// create another object where you want to get resources shared with
square(
"alt",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.expect("Error during creation of alt square");
// here you can use `reference_texture` to reference the texture from the main object
engine
.objects
.get_mut("alt")
.expect("Error during copying texture of the main square")
.reference_texture("main");
// setting position again to make it visible
engine
.objects
.get_mut("alt")
.expect("Error during setting the position of the alt square")
.set_position(1.5f32, 0f32, 0f32);
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
sourcepub fn reference_uniform_buffer(&mut self, object_id: impl StringBuffer)
pub fn reference_uniform_buffer(&mut self, object_id: impl StringBuffer)
References another object’s uniform buffer
sourcepub fn add_instance(&mut self, instance: Instance)
pub fn add_instance(&mut self, instance: Instance)
Add an instance to the object
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
pub fn main() {
// start the engine
let mut engine = Engine::new().expect("window not created");
// create a triangle
triangle(
"Triangle",
ObjectSettings::default(),
&mut engine.renderer,
&mut engine.objects,
)
.unwrap();
// update the triangle
engine.objects.update_object("Triangle", |object| {
// set the position of the main triangle
object.set_position(0f32, 0f32, -3f32);
// a function to make instance creation easier
let create_instance = |x: f32, y: f32, z: f32| {
Instance::new(
[x, y, z].into(),
[0f32, 0f32, 0f32].into(),
[1f32, 1f32, 1f32].into(),
)
};
// add an instance
object.add_instance(create_instance(2f32, 1f32, -2f32));
object.add_instance(create_instance(2f32, -1f32, -2f32));
object.add_instance(create_instance(-2f32, 1f32, -2f32));
object.add_instance(create_instance(-2f32, -1f32, -2f32));
});
// we manually update the instance buffer before the next frame starts
// this is due to the object updates happening after every frame, hence
// for the first frame, we need to update it ourselves.
engine
.objects
.get_mut("Triangle")
.expect("Couldn't get the triangle")
.update_instance_buffer(&mut engine.renderer)
.expect("Couldn't update instance buffer");
// run the loop as normal
engine
.update_loop(move |_, _, _, _, _, _| {})
.expect("Error during update loop");
}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Object
impl !RefUnwindSafe for Object
impl Unpin for Object
impl !UnwindSafe for Object
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
source§fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
source§fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
source§fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
source§fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
source§fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
source§fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
source§fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
source§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
source§fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
source§fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
source§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
source§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
source§fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
source§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
source§fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
source§fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
source§fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
source§fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
source§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
source§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
source§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
source§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
source§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
source§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
source§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
source§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
source§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
source§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
source§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
source§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
source§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
source§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
source§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
source§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
source§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
source§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
source§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
source§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
source§fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
source§fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
source§fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
source§fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
source§fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
source§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
source§fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
source§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moresource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read moresource§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
source§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
source§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
source§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.