mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
@@ -130,6 +130,10 @@ impl BatchStorage {
|
||||
let mut batch_index = 0;
|
||||
for node in scene.graph.linear_iter() {
|
||||
if let Node::Sprite(sprite) = node {
|
||||
if !sprite.global_visibility() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let texture = sprite.texture().map_or_else(
|
||||
|| white_dummy.clone(),
|
||||
|t| {
|
||||
@@ -274,6 +278,10 @@ impl Renderer2d {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
if !light.global_visibility() || light_count == MAX_LIGHTS {
|
||||
continue;
|
||||
}
|
||||
|
||||
let (radius, half_cone_angle_cos, half_hotspot_angle_cos, direction) =
|
||||
match light {
|
||||
Light::Point(point) => (
|
||||
@@ -346,7 +354,7 @@ impl Renderer2d {
|
||||
),
|
||||
(
|
||||
self.sprite_shader.light_count.clone(),
|
||||
UniformValue::Integer(light_count),
|
||||
UniformValue::Integer(light_count as i32),
|
||||
),
|
||||
(
|
||||
self.sprite_shader.light_color_radius.clone(),
|
||||
|
||||
+19
-1
@@ -8,7 +8,7 @@ use crate::{
|
||||
};
|
||||
use std::cell::Cell;
|
||||
|
||||
#[derive(Default, Visit)]
|
||||
#[derive(Visit)]
|
||||
pub struct Base {
|
||||
transform: Transform,
|
||||
pub(in crate) global_transform: Cell<Matrix4<f32>>,
|
||||
@@ -19,11 +19,29 @@ pub struct Base {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Default for Base {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
transform: Default::default(),
|
||||
global_transform: Cell::new(Matrix4::identity()),
|
||||
visibility: true,
|
||||
global_visibility: Cell::new(true),
|
||||
parent: Default::default(),
|
||||
children: Default::default(),
|
||||
name: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Base {
|
||||
pub fn set_name<S: AsRef<str>>(&mut self, name: S) {
|
||||
self.name = name.as_ref().to_owned();
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn parent(&self) -> Handle<Node> {
|
||||
self.parent
|
||||
}
|
||||
|
||||
+28
-7
@@ -1,11 +1,10 @@
|
||||
use crate::core::algebra::Vector2;
|
||||
use crate::core::pool::Handle;
|
||||
use crate::scene2d::base::BaseBuilder;
|
||||
use crate::scene2d::graph::Graph;
|
||||
use crate::scene2d::node::Node;
|
||||
use crate::{
|
||||
core::{algebra::Matrix4, math::Rect, visitor::prelude::*},
|
||||
scene2d::base::Base,
|
||||
core::{algebra::Matrix4, algebra::Vector2, math::Rect, pool::Handle, visitor::prelude::*},
|
||||
scene2d::{
|
||||
base::{Base, BaseBuilder},
|
||||
graph::Graph,
|
||||
node::Node,
|
||||
},
|
||||
};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
@@ -57,6 +56,10 @@ impl Camera {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_viewport(&mut self, viewport: Rect<f32>) {
|
||||
self.viewport = viewport;
|
||||
}
|
||||
|
||||
pub fn view_projection_matrix(&self) -> Matrix4<f32> {
|
||||
self.projection_matrix * self.view_matrix
|
||||
}
|
||||
@@ -76,6 +79,14 @@ impl Camera {
|
||||
.try_inverse()
|
||||
.unwrap_or_else(|| Matrix4::identity());
|
||||
}
|
||||
|
||||
pub fn enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CameraBuilder {
|
||||
@@ -93,6 +104,16 @@ impl CameraBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_viewport(mut self, viewport: Rect<f32>) -> Self {
|
||||
self.viewport = viewport;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_enabled(mut self, enabled: bool) -> Self {
|
||||
self.enabled = enabled;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self, graph: &mut Graph) -> Handle<Node> {
|
||||
graph.add_node(Node::Camera(Camera {
|
||||
base: self.base_builder.build_base(),
|
||||
|
||||
@@ -45,7 +45,6 @@ impl Default for Light {
|
||||
#[derive(Default, Visit)]
|
||||
pub struct BaseLight {
|
||||
base: Base,
|
||||
enabled: bool,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
@@ -71,19 +70,10 @@ impl BaseLight {
|
||||
pub fn set_color(&mut self, color: Color) {
|
||||
self.color = color;
|
||||
}
|
||||
|
||||
pub fn enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BaseLightBuilder {
|
||||
base_builder: BaseBuilder,
|
||||
enabled: bool,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
@@ -91,16 +81,10 @@ impl BaseLightBuilder {
|
||||
pub fn new(base_builder: BaseBuilder) -> Self {
|
||||
Self {
|
||||
base_builder,
|
||||
enabled: true,
|
||||
color: Color::WHITE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_enabled(mut self, enabled: bool) -> Self {
|
||||
self.enabled = enabled;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_color(mut self, color: Color) -> Self {
|
||||
self.color = color;
|
||||
self
|
||||
@@ -109,7 +93,6 @@ impl BaseLightBuilder {
|
||||
pub fn build(self) -> BaseLight {
|
||||
BaseLight {
|
||||
base: self.base_builder.build_base(),
|
||||
enabled: self.enabled,
|
||||
color: self.color,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ impl Scene2dContainer {
|
||||
self.pool.spawn(scene)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, scene: Handle<Scene2d>) -> Scene2d {
|
||||
self.pool.free(scene)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Scene2d> {
|
||||
self.pool.iter()
|
||||
}
|
||||
|
||||
@@ -44,27 +44,6 @@ impl Default for Node {
|
||||
}
|
||||
|
||||
impl Node {
|
||||
/// Creates new Node based on variant id.
|
||||
pub fn from_id(id: u8) -> Result<Self, String> {
|
||||
match id {
|
||||
0 => Ok(Self::Base(Default::default())),
|
||||
1 => Ok(Self::Light(Default::default())),
|
||||
2 => Ok(Self::Camera(Default::default())),
|
||||
3 => Ok(Self::Sprite(Default::default())),
|
||||
_ => Err(format!("Invalid node kind {}", id)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns actual variant id.
|
||||
pub fn id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Base(_) => 0,
|
||||
Self::Light(_) => 1,
|
||||
Self::Camera(_) => 2,
|
||||
Self::Sprite(_) => 3,
|
||||
}
|
||||
}
|
||||
|
||||
define_is_as!(Node : Camera -> ref Camera => fn is_camera, fn as_camera, fn as_camera_mut);
|
||||
define_is_as!(Node : Light -> ref Light => fn is_light, fn as_light, fn as_light_mut);
|
||||
define_is_as!(Node : Sprite -> ref Sprite => fn is_sprite, fn as_sprite, fn as_sprite_mut);
|
||||
|
||||
+19
-3
@@ -1,7 +1,11 @@
|
||||
use crate::core::algebra::{Point3, Vector2};
|
||||
use crate::core::math::Rect;
|
||||
use crate::{
|
||||
core::{color::Color, pool::Handle, visitor::prelude::*},
|
||||
core::{
|
||||
algebra::{Point3, Vector2},
|
||||
color::Color,
|
||||
math::Rect,
|
||||
pool::Handle,
|
||||
visitor::prelude::*,
|
||||
},
|
||||
resource::texture::Texture,
|
||||
scene2d::{
|
||||
base::{Base, BaseBuilder},
|
||||
@@ -49,14 +53,26 @@ impl Sprite {
|
||||
self.texture.as_ref()
|
||||
}
|
||||
|
||||
pub fn set_texture(&mut self, texture: Option<Texture>) {
|
||||
self.texture = texture;
|
||||
}
|
||||
|
||||
pub fn color(&self) -> Color {
|
||||
self.color
|
||||
}
|
||||
|
||||
pub fn set_color(&mut self, color: Color) {
|
||||
self.color = color;
|
||||
}
|
||||
|
||||
pub fn size(&self) -> f32 {
|
||||
self.size
|
||||
}
|
||||
|
||||
pub fn set_size(&mut self, size: f32) {
|
||||
self.size = size;
|
||||
}
|
||||
|
||||
pub fn local_bounds(&self) -> Rect<f32> {
|
||||
Rect {
|
||||
position: self.local_transform().position(),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::core::algebra::{Matrix3, Matrix4, Vector3};
|
||||
use crate::core::{algebra::Vector2, visitor::prelude::*};
|
||||
use crate::core::{
|
||||
algebra::{Matrix3, Matrix4, Vector2, Vector3},
|
||||
visitor::prelude::*,
|
||||
};
|
||||
|
||||
#[derive(Visit)]
|
||||
pub struct Transform {
|
||||
|
||||
Reference in New Issue
Block a user