use bitflags::bitflags;
use crate::Vector3D;
use crate::media::Color;
use crate::rendering::composition::ICompositionObject;
use crate::rendering::composition::animations::AnimationInstanceFactory;
use crate::rendering::composition::animations::ICompositionAnimation;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::AsServerRenderResource;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerObject;
use crate::rendering::composition::server::ServerPropertyValue;
use crate::rendering::composition::server::ServerValueChange;
use crate::rendering::composition::server::props_of;
use crate::rendering::composition::server::read_server_object;
use crate::rendering::composition::transport::BatchStreamReader;
use crate::rendering::composition::transport::BatchStreamWriter;
use crate::rendering::composition::transport::BatchValue;
use crate::rendering::composition::transport::BatchValueReader;
use std::any::Any;
use std::any::TypeId;
use std::cell::Cell;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::OnceLock;
use std::time::Duration;
use super::CompositionLightHooks;
use super::CompositionLightProps;
use super::ServerCompositionLightHooks;
use super::ServerCompositionLightProps;
bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpotLightChangedFields: u32 {
const CONSTANT_ATTENUATION = 1;
const CONSTANT_ATTENUATION_ANIMATED = 2;
const LINEAR_ATTENUATION = 4;
const LINEAR_ATTENUATION_ANIMATED = 8;
const QUADRATIC_ATTENUATION = 16;
const QUADRATIC_ATTENUATION_ANIMATED = 32;
const COORDINATE_SPACE = 64;
const DIRECTION = 128;
const DIRECTION_ANIMATED = 256;
const INNER_CONE_ANGLE = 512;
const INNER_CONE_ANGLE_ANIMATED = 1024;
const INNER_CONE_COLOR = 2048;
const INNER_CONE_COLOR_ANIMATED = 4096;
const INNER_CONE_INTENSITY = 8192;
const INNER_CONE_INTENSITY_ANIMATED = 16384;
const OUTER_CONE_ANGLE = 32768;
const OUTER_CONE_ANGLE_ANIMATED = 65536;
const OUTER_CONE_COLOR = 131072;
const OUTER_CONE_COLOR_ANIMATED = 262144;
const OUTER_CONE_INTENSITY = 524288;
const OUTER_CONE_INTENSITY_ANIMATED = 1048576;
const OFFSET = 2097152;
const OFFSET_ANIMATED = 4194304;
const MIN_ATTENUATION_CUTOFF = 8388608;
const MIN_ATTENUATION_CUTOFF_ANIMATED = 16777216;
const MAX_ATTENUATION_CUTOFF = 33554432;
const MAX_ATTENUATION_CUTOFF_ANIMATED = 67108864;
}
}
impl BatchValue for SpotLightChangedFields {
#[inline]
fn write_to(&self, out: &mut Vec<u8>) {
self.bits().write_to(out);
}
#[inline]
fn read_from(input: &mut BatchValueReader<'_>) -> Self {
SpotLightChangedFields::from_bits_retain(u32::read_from(input))
}
}
pub trait SpotLightHooks: CompositionLightHooks {
fn initialize_defaults_extra(&self) {}
fn validate_constant_attenuation_change(&self, _old_value: f32, _new_value: f32) {}
fn on_constant_attenuation_changed(&self) {}
fn on_constant_attenuation_changing(&self) {}
fn validate_linear_attenuation_change(&self, _old_value: f32, _new_value: f32) {}
fn on_linear_attenuation_changed(&self) {}
fn on_linear_attenuation_changing(&self) {}
fn validate_quadratic_attenuation_change(&self, _old_value: f32, _new_value: f32) {}
fn on_quadratic_attenuation_changed(&self) {}
fn on_quadratic_attenuation_changing(&self) {}
fn validate_coordinate_space_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
fn on_coordinate_space_changed(&self) {}
fn on_coordinate_space_changing(&self) {}
fn validate_direction_change(&self, _old_value: Vector3D, _new_value: Vector3D) {}
fn on_direction_changed(&self) {}
fn on_direction_changing(&self) {}
fn validate_inner_cone_angle_change(&self, _old_value: f32, _new_value: f32) {}
fn on_inner_cone_angle_changed(&self) {}
fn on_inner_cone_angle_changing(&self) {}
fn validate_inner_cone_color_change(&self, _old_value: Color, _new_value: Color) {}
fn on_inner_cone_color_changed(&self) {}
fn on_inner_cone_color_changing(&self) {}
fn validate_inner_cone_intensity_change(&self, _old_value: f32, _new_value: f32) {}
fn on_inner_cone_intensity_changed(&self) {}
fn on_inner_cone_intensity_changing(&self) {}
fn validate_outer_cone_angle_change(&self, _old_value: f32, _new_value: f32) {}
fn on_outer_cone_angle_changed(&self) {}
fn on_outer_cone_angle_changing(&self) {}
fn validate_outer_cone_color_change(&self, _old_value: Color, _new_value: Color) {}
fn on_outer_cone_color_changed(&self) {}
fn on_outer_cone_color_changing(&self) {}
fn validate_outer_cone_intensity_change(&self, _old_value: f32, _new_value: f32) {}
fn on_outer_cone_intensity_changed(&self) {}
fn on_outer_cone_intensity_changing(&self) {}
fn validate_offset_change(&self, _old_value: Vector3D, _new_value: Vector3D) {}
fn on_offset_changed(&self) {}
fn on_offset_changing(&self) {}
fn validate_min_attenuation_cutoff_change(&self, _old_value: f32, _new_value: f32) {}
fn on_min_attenuation_cutoff_changed(&self) {}
fn on_min_attenuation_cutoff_changing(&self) {}
fn validate_max_attenuation_cutoff_change(&self, _old_value: f32, _new_value: f32) {}
fn on_max_attenuation_cutoff_changed(&self) {}
fn on_max_attenuation_cutoff_changing(&self) {}
}
pub struct SpotLightProps {
base: CompositionLightProps,
changed_fields_of_spot_light: Cell<SpotLightChangedFields>,
constant_attenuation: Cell<f32>,
linear_attenuation: Cell<f32>,
quadratic_attenuation: Cell<f32>,
coordinate_space: RefCell<Option<Rc<dyn ICompositionObject>>>,
direction: Cell<Vector3D>,
inner_cone_angle: Cell<f32>,
inner_cone_color: Cell<Color>,
inner_cone_intensity: Cell<f32>,
outer_cone_angle: Cell<f32>,
outer_cone_color: Cell<Color>,
outer_cone_intensity: Cell<f32>,
offset: Cell<Vector3D>,
min_attenuation_cutoff: Cell<f32>,
max_attenuation_cutoff: Cell<f32>,
}
impl Default for SpotLightProps {
fn default() -> Self {
Self::new()
}
}
impl SpotLightProps {
pub fn new() -> Self {
Self {
base: CompositionLightProps::new(),
changed_fields_of_spot_light: Cell::new(SpotLightChangedFields::empty()),
constant_attenuation: Cell::new(Default::default()),
linear_attenuation: Cell::new(Default::default()),
quadratic_attenuation: Cell::new(Default::default()),
coordinate_space: RefCell::new(None),
direction: Cell::new(Default::default()),
inner_cone_angle: Cell::new(Default::default()),
inner_cone_color: Cell::new(Default::default()),
inner_cone_intensity: Cell::new(Default::default()),
outer_cone_angle: Cell::new(Default::default()),
outer_cone_color: Cell::new(Default::default()),
outer_cone_intensity: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
min_attenuation_cutoff: Cell::new(Default::default()),
max_attenuation_cutoff: Cell::new(Default::default()),
}
}
pub fn base(&self) -> &CompositionLightProps {
&self.base
}
pub fn initialize_defaults(&self, host: &dyn SpotLightHooks) {
self.base.initialize_defaults(host);
self.initialize_own_defaults(host);
}
pub fn initialize_own_defaults(&self, host: &dyn SpotLightHooks) {
SpotLightHooks::initialize_defaults_extra(host);
self.set_constant_attenuation(host, 1.0);
self.set_direction(host, Vector3D::new(0.0, 0.0, -1.0));
self.set_inner_cone_color(host, crate::media::Colors::WHITE);
self.set_inner_cone_intensity(host, 1.0);
self.set_outer_cone_angle(host, std::f32::consts::FRAC_PI_4);
self.set_outer_cone_color(host, crate::media::Colors::WHITE);
self.set_outer_cone_intensity(host, 1.0);
self.set_max_attenuation_cutoff(host, f32::MAX);
}
pub fn constant_attenuation(&self) -> f32 {
self.constant_attenuation.get()
}
pub fn set_constant_attenuation(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.constant_attenuation.get();
if old_value.differs(&value) {
SpotLightHooks::validate_constant_attenuation_change(host, old_value, value);
SpotLightHooks::on_constant_attenuation_changing(host);
changed = true;
self.constant_attenuation.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::CONSTANT_ATTENUATION);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_constant_attenuation_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::CONSTANT_ATTENUATION_ANIMATED);
if let Some(animation) = host.implicit_animation("ConstantAttenuation") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::CONSTANT_ATTENUATION_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_constant_attenuation_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "ConstantAttenuation", ExpressionVariant::create(value));
}
}
self.constant_attenuation.set(value);
if changed {
SpotLightHooks::on_constant_attenuation_changed(host);
}
}
pub fn linear_attenuation(&self) -> f32 {
self.linear_attenuation.get()
}
pub fn set_linear_attenuation(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.linear_attenuation.get();
if old_value.differs(&value) {
SpotLightHooks::validate_linear_attenuation_change(host, old_value, value);
SpotLightHooks::on_linear_attenuation_changing(host);
changed = true;
self.linear_attenuation.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::LINEAR_ATTENUATION);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_linear_attenuation_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::LINEAR_ATTENUATION_ANIMATED);
if let Some(animation) = host.implicit_animation("LinearAttenuation") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::LINEAR_ATTENUATION_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_linear_attenuation_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "LinearAttenuation", ExpressionVariant::create(value));
}
}
self.linear_attenuation.set(value);
if changed {
SpotLightHooks::on_linear_attenuation_changed(host);
}
}
pub fn quadratic_attenuation(&self) -> f32 {
self.quadratic_attenuation.get()
}
pub fn set_quadratic_attenuation(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.quadratic_attenuation.get();
if old_value.differs(&value) {
SpotLightHooks::validate_quadratic_attenuation_change(host, old_value, value);
SpotLightHooks::on_quadratic_attenuation_changing(host);
changed = true;
self.quadratic_attenuation.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::QUADRATIC_ATTENUATION);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_quadratic_attenuation_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::QUADRATIC_ATTENUATION_ANIMATED);
if let Some(animation) = host.implicit_animation("QuadraticAttenuation") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::QUADRATIC_ATTENUATION_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_quadratic_attenuation_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "QuadraticAttenuation", ExpressionVariant::create(value));
}
}
self.quadratic_attenuation.set(value);
if changed {
SpotLightHooks::on_quadratic_attenuation_changed(host);
}
}
pub fn coordinate_space(&self) -> Option<Rc<dyn ICompositionObject>> {
self.coordinate_space.borrow().clone()
}
pub fn set_coordinate_space(&self, host: &dyn SpotLightHooks, value: Option<Rc<dyn ICompositionObject>>) {
let mut changed = false;
let old_value = self.coordinate_space.borrow().clone();
if old_value.differs(&value) {
SpotLightHooks::validate_coordinate_space_change(host, &old_value, &value);
SpotLightHooks::on_coordinate_space_changing(host);
changed = true;
*self.coordinate_space.borrow_mut() = value.clone();
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::COORDINATE_SPACE);
host.register_for_serialization();
}
*self.coordinate_space.borrow_mut() = value;
if changed {
SpotLightHooks::on_coordinate_space_changed(host);
}
}
pub fn direction(&self) -> Vector3D {
self.direction.get()
}
pub fn set_direction(&self, host: &dyn SpotLightHooks, value: Vector3D) {
let mut changed = false;
let old_value = self.direction.get();
if old_value.differs(&value) {
SpotLightHooks::validate_direction_change(host, old_value, value);
SpotLightHooks::on_direction_changing(host);
changed = true;
self.direction.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::DIRECTION);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_direction_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::DIRECTION_ANIMATED);
if let Some(animation) = host.implicit_animation("Direction") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::DIRECTION_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_direction_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Direction", ExpressionVariant::create(value));
}
}
self.direction.set(value);
if changed {
SpotLightHooks::on_direction_changed(host);
}
}
pub fn inner_cone_angle(&self) -> f32 {
self.inner_cone_angle.get()
}
pub fn set_inner_cone_angle(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.inner_cone_angle.get();
if old_value.differs(&value) {
SpotLightHooks::validate_inner_cone_angle_change(host, old_value, value);
SpotLightHooks::on_inner_cone_angle_changing(host);
changed = true;
self.inner_cone_angle.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_ANGLE);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_inner_cone_angle_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::INNER_CONE_ANGLE_ANIMATED);
if let Some(animation) = host.implicit_animation("InnerConeAngle") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_ANGLE_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_inner_cone_angle_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "InnerConeAngle", ExpressionVariant::create(value));
}
}
self.inner_cone_angle.set(value);
if changed {
SpotLightHooks::on_inner_cone_angle_changed(host);
}
}
pub fn inner_cone_color(&self) -> Color {
self.inner_cone_color.get()
}
pub fn set_inner_cone_color(&self, host: &dyn SpotLightHooks, value: Color) {
let mut changed = false;
let old_value = self.inner_cone_color.get();
if old_value.differs(&value) {
SpotLightHooks::validate_inner_cone_color_change(host, old_value, value);
SpotLightHooks::on_inner_cone_color_changing(host);
changed = true;
self.inner_cone_color.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_COLOR);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_inner_cone_color_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::INNER_CONE_COLOR_ANIMATED);
if let Some(animation) = host.implicit_animation("InnerConeColor") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_COLOR_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_inner_cone_color_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "InnerConeColor", ExpressionVariant::create(value));
}
}
self.inner_cone_color.set(value);
if changed {
SpotLightHooks::on_inner_cone_color_changed(host);
}
}
pub fn inner_cone_intensity(&self) -> f32 {
self.inner_cone_intensity.get()
}
pub fn set_inner_cone_intensity(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.inner_cone_intensity.get();
if old_value.differs(&value) {
SpotLightHooks::validate_inner_cone_intensity_change(host, old_value, value);
SpotLightHooks::on_inner_cone_intensity_changing(host);
changed = true;
self.inner_cone_intensity.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_INTENSITY);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_inner_cone_intensity_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::INNER_CONE_INTENSITY_ANIMATED);
if let Some(animation) = host.implicit_animation("InnerConeIntensity") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_INTENSITY_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_inner_cone_intensity_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "InnerConeIntensity", ExpressionVariant::create(value));
}
}
self.inner_cone_intensity.set(value);
if changed {
SpotLightHooks::on_inner_cone_intensity_changed(host);
}
}
pub fn outer_cone_angle(&self) -> f32 {
self.outer_cone_angle.get()
}
pub fn set_outer_cone_angle(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.outer_cone_angle.get();
if old_value.differs(&value) {
SpotLightHooks::validate_outer_cone_angle_change(host, old_value, value);
SpotLightHooks::on_outer_cone_angle_changing(host);
changed = true;
self.outer_cone_angle.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_ANGLE);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_outer_cone_angle_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::OUTER_CONE_ANGLE_ANIMATED);
if let Some(animation) = host.implicit_animation("OuterConeAngle") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_ANGLE_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_outer_cone_angle_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "OuterConeAngle", ExpressionVariant::create(value));
}
}
self.outer_cone_angle.set(value);
if changed {
SpotLightHooks::on_outer_cone_angle_changed(host);
}
}
pub fn outer_cone_color(&self) -> Color {
self.outer_cone_color.get()
}
pub fn set_outer_cone_color(&self, host: &dyn SpotLightHooks, value: Color) {
let mut changed = false;
let old_value = self.outer_cone_color.get();
if old_value.differs(&value) {
SpotLightHooks::validate_outer_cone_color_change(host, old_value, value);
SpotLightHooks::on_outer_cone_color_changing(host);
changed = true;
self.outer_cone_color.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_COLOR);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_outer_cone_color_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::OUTER_CONE_COLOR_ANIMATED);
if let Some(animation) = host.implicit_animation("OuterConeColor") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_COLOR_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_outer_cone_color_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "OuterConeColor", ExpressionVariant::create(value));
}
}
self.outer_cone_color.set(value);
if changed {
SpotLightHooks::on_outer_cone_color_changed(host);
}
}
pub fn outer_cone_intensity(&self) -> f32 {
self.outer_cone_intensity.get()
}
pub fn set_outer_cone_intensity(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.outer_cone_intensity.get();
if old_value.differs(&value) {
SpotLightHooks::validate_outer_cone_intensity_change(host, old_value, value);
SpotLightHooks::on_outer_cone_intensity_changing(host);
changed = true;
self.outer_cone_intensity.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_INTENSITY);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_outer_cone_intensity_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::OUTER_CONE_INTENSITY_ANIMATED);
if let Some(animation) = host.implicit_animation("OuterConeIntensity") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_INTENSITY_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_outer_cone_intensity_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "OuterConeIntensity", ExpressionVariant::create(value));
}
}
self.outer_cone_intensity.set(value);
if changed {
SpotLightHooks::on_outer_cone_intensity_changed(host);
}
}
pub fn offset(&self) -> Vector3D {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn SpotLightHooks, value: Vector3D) {
let mut changed = false;
let old_value = self.offset.get();
if old_value.differs(&value) {
SpotLightHooks::validate_offset_change(host, old_value, value);
SpotLightHooks::on_offset_changing(host);
changed = true;
self.offset.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OFFSET);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_offset_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::OFFSET_ANIMATED);
if let Some(animation) = host.implicit_animation("Offset") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OFFSET_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_offset_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Offset", ExpressionVariant::create(value));
}
}
self.offset.set(value);
if changed {
SpotLightHooks::on_offset_changed(host);
}
}
pub fn min_attenuation_cutoff(&self) -> f32 {
self.min_attenuation_cutoff.get()
}
pub fn set_min_attenuation_cutoff(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.min_attenuation_cutoff.get();
if old_value.differs(&value) {
SpotLightHooks::validate_min_attenuation_cutoff_change(host, old_value, value);
SpotLightHooks::on_min_attenuation_cutoff_changing(host);
changed = true;
self.min_attenuation_cutoff.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MIN_ATTENUATION_CUTOFF);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_min_attenuation_cutoff_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::MIN_ATTENUATION_CUTOFF_ANIMATED);
if let Some(animation) = host.implicit_animation("MinAttenuationCutoff") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MIN_ATTENUATION_CUTOFF_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_min_attenuation_cutoff_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "MinAttenuationCutoff", ExpressionVariant::create(value));
}
}
self.min_attenuation_cutoff.set(value);
if changed {
SpotLightHooks::on_min_attenuation_cutoff_changed(host);
}
}
pub fn max_attenuation_cutoff(&self) -> f32 {
self.max_attenuation_cutoff.get()
}
pub fn set_max_attenuation_cutoff(&self, host: &dyn SpotLightHooks, value: f32) {
let mut changed = false;
let old_value = self.max_attenuation_cutoff.get();
if old_value.differs(&value) {
SpotLightHooks::validate_max_attenuation_cutoff_change(host, old_value, value);
SpotLightHooks::on_max_attenuation_cutoff_changing(host);
changed = true;
self.max_attenuation_cutoff.set(value);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MAX_ATTENUATION_CUTOFF);
host.register_for_serialization();
host.pending_animations().remove(ServerSpotLightProps::id_of_max_attenuation_cutoff_property().base());
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() & !SpotLightChangedFields::MAX_ATTENUATION_CUTOFF_ANIMATED);
if let Some(animation) = host.implicit_animation("MaxAttenuationCutoff") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MAX_ATTENUATION_CUTOFF_ANIMATED);
host.pending_animations().set(
ServerSpotLightProps::id_of_max_attenuation_cutoff_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "MaxAttenuationCutoff", ExpressionVariant::create(value));
}
}
self.max_attenuation_cutoff.set(value);
if changed {
SpotLightHooks::on_max_attenuation_cutoff_changed(host);
}
}
pub fn start_animation(
&self,
host: &dyn SpotLightHooks,
property_name: &str,
animation: &dyn ICompositionAnimation,
final_value: Option<ExpressionVariant>,
) -> bool {
if property_name == "ConstantAttenuation" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_constant_attenuation_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::CONSTANT_ATTENUATION_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "LinearAttenuation" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_linear_attenuation_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::LINEAR_ATTENUATION_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "QuadraticAttenuation" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_quadratic_attenuation_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::QUADRATIC_ATTENUATION_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Direction" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_direction_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::DIRECTION_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "InnerConeAngle" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_inner_cone_angle_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_ANGLE_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "InnerConeColor" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_inner_cone_color_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_COLOR_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "InnerConeIntensity" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_inner_cone_intensity_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::INNER_CONE_INTENSITY_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "OuterConeAngle" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_outer_cone_angle_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_ANGLE_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "OuterConeColor" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_outer_cone_color_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_COLOR_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "OuterConeIntensity" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_outer_cone_intensity_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OUTER_CONE_INTENSITY_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Offset" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_offset_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::OFFSET_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "MinAttenuationCutoff" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_min_attenuation_cutoff_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MIN_ATTENUATION_CUTOFF_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "MaxAttenuationCutoff" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerSpotLightProps::id_of_max_attenuation_cutoff_property().base(), server);
self.changed_fields_of_spot_light.set(self.changed_fields_of_spot_light.get() | SpotLightChangedFields::MAX_ATTENUATION_CUTOFF_ANIMATED);
host.register_for_serialization();
return true;
}
false
}
pub fn serialize_changes_core(&self, host: &dyn SpotLightHooks, writer: &mut BatchStreamWriter<'_>) {
self.base.serialize_changes_core(host, writer);
let changed = self.changed_fields_of_spot_light.get();
writer.write(changed);
if changed.contains(SpotLightChangedFields::CONSTANT_ATTENUATION_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_constant_attenuation_property().base()));
} else if changed.contains(SpotLightChangedFields::CONSTANT_ATTENUATION) {
writer.write(self.constant_attenuation.get());
}
if changed.contains(SpotLightChangedFields::LINEAR_ATTENUATION_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_linear_attenuation_property().base()));
} else if changed.contains(SpotLightChangedFields::LINEAR_ATTENUATION) {
writer.write(self.linear_attenuation.get());
}
if changed.contains(SpotLightChangedFields::QUADRATIC_ATTENUATION_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_quadratic_attenuation_property().base()));
} else if changed.contains(SpotLightChangedFields::QUADRATIC_ATTENUATION) {
writer.write(self.quadratic_attenuation.get());
}
if changed.contains(SpotLightChangedFields::COORDINATE_SPACE) {
writer.write_server_object(self.coordinate_space.borrow().clone().map(|o| o.server()));
}
if changed.contains(SpotLightChangedFields::DIRECTION_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_direction_property().base()));
} else if changed.contains(SpotLightChangedFields::DIRECTION) {
writer.write(self.direction.get());
}
if changed.contains(SpotLightChangedFields::INNER_CONE_ANGLE_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_inner_cone_angle_property().base()));
} else if changed.contains(SpotLightChangedFields::INNER_CONE_ANGLE) {
writer.write(self.inner_cone_angle.get());
}
if changed.contains(SpotLightChangedFields::INNER_CONE_COLOR_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_inner_cone_color_property().base()));
} else if changed.contains(SpotLightChangedFields::INNER_CONE_COLOR) {
writer.write(self.inner_cone_color.get());
}
if changed.contains(SpotLightChangedFields::INNER_CONE_INTENSITY_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_inner_cone_intensity_property().base()));
} else if changed.contains(SpotLightChangedFields::INNER_CONE_INTENSITY) {
writer.write(self.inner_cone_intensity.get());
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_ANGLE_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_outer_cone_angle_property().base()));
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_ANGLE) {
writer.write(self.outer_cone_angle.get());
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_COLOR_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_outer_cone_color_property().base()));
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_COLOR) {
writer.write(self.outer_cone_color.get());
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_INTENSITY_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_outer_cone_intensity_property().base()));
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_INTENSITY) {
writer.write(self.outer_cone_intensity.get());
}
if changed.contains(SpotLightChangedFields::OFFSET_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_offset_property().base()));
} else if changed.contains(SpotLightChangedFields::OFFSET) {
writer.write(self.offset.get());
}
if changed.contains(SpotLightChangedFields::MIN_ATTENUATION_CUTOFF_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_min_attenuation_cutoff_property().base()));
} else if changed.contains(SpotLightChangedFields::MIN_ATTENUATION_CUTOFF) {
writer.write(self.min_attenuation_cutoff.get());
}
if changed.contains(SpotLightChangedFields::MAX_ATTENUATION_CUTOFF_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerSpotLightProps::id_of_max_attenuation_cutoff_property().base()));
} else if changed.contains(SpotLightChangedFields::MAX_ATTENUATION_CUTOFF) {
writer.write(self.max_attenuation_cutoff.get());
}
self.changed_fields_of_spot_light.set(SpotLightChangedFields::empty());
}
}
pub trait ServerSpotLightHooks: ServerCompositionLightHooks {
fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
fn on_fields_deserialized(&self, _changed: SpotLightChangedFields) {}
fn on_coordinate_space_changed(&self) {}
fn on_coordinate_space_changing(&self) {}
}
pub struct ServerSpotLightProps {
base: ServerCompositionLightProps,
constant_attenuation: Cell<f32>,
linear_attenuation: Cell<f32>,
quadratic_attenuation: Cell<f32>,
coordinate_space: RefCell<Option<Rc<dyn IServerObject>>>,
direction: Cell<Vector3D>,
inner_cone_angle: Cell<f32>,
inner_cone_color: Cell<Color>,
inner_cone_intensity: Cell<f32>,
outer_cone_angle: Cell<f32>,
outer_cone_color: Cell<Color>,
outer_cone_intensity: Cell<f32>,
offset: Cell<Vector3D>,
min_attenuation_cutoff: Cell<f32>,
max_attenuation_cutoff: Cell<f32>,
}
impl Default for ServerSpotLightProps {
fn default() -> Self {
Self::new()
}
}
impl ServerSpotLightProps {
pub fn new() -> Self {
Self {
base: ServerCompositionLightProps::new(),
constant_attenuation: Cell::new(Default::default()),
linear_attenuation: Cell::new(Default::default()),
quadratic_attenuation: Cell::new(Default::default()),
coordinate_space: RefCell::new(None),
direction: Cell::new(Default::default()),
inner_cone_angle: Cell::new(Default::default()),
inner_cone_color: Cell::new(Default::default()),
inner_cone_intensity: Cell::new(Default::default()),
outer_cone_angle: Cell::new(Default::default()),
outer_cone_color: Cell::new(Default::default()),
outer_cone_intensity: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
min_attenuation_cutoff: Cell::new(Default::default()),
max_attenuation_cutoff: Cell::new(Default::default()),
}
}
pub fn base(&self) -> &ServerCompositionLightProps {
&self.base
}
pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
if type_id == TypeId::of::<Self>() {
return Some(self);
}
self.base.find_props(type_id)
}
pub fn id_of_constant_attenuation_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"ConstantAttenuation",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).constant_attenuation.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).constant_attenuation.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).constant_attenuation.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).constant_attenuation.set(v.cast_or_default::<f32>())),
)
})
}
pub fn constant_attenuation(&self) -> f32 {
self.constant_attenuation.get()
}
pub fn set_constant_attenuation(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.constant_attenuation.set(value);
host.remove_animation_for_property(Self::id_of_constant_attenuation_property().base());
}
pub fn id_of_linear_attenuation_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"LinearAttenuation",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).linear_attenuation.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).linear_attenuation.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).linear_attenuation.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).linear_attenuation.set(v.cast_or_default::<f32>())),
)
})
}
pub fn linear_attenuation(&self) -> f32 {
self.linear_attenuation.get()
}
pub fn set_linear_attenuation(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.linear_attenuation.set(value);
host.remove_animation_for_property(Self::id_of_linear_attenuation_property().base());
}
pub fn id_of_quadratic_attenuation_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"QuadraticAttenuation",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).quadratic_attenuation.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).quadratic_attenuation.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).quadratic_attenuation.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).quadratic_attenuation.set(v.cast_or_default::<f32>())),
)
})
}
pub fn quadratic_attenuation(&self) -> f32 {
self.quadratic_attenuation.get()
}
pub fn set_quadratic_attenuation(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.quadratic_attenuation.set(value);
host.remove_animation_for_property(Self::id_of_quadratic_attenuation_property().base());
}
pub fn id_of_coordinate_space_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, Option<Rc<dyn IServerObject>>>(
"CoordinateSpace",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).coordinate_space.borrow().clone(),
|obj, v| *props_of::<ServerSpotLightProps>(obj).coordinate_space.borrow_mut() = v,
None,
None,
)
})
}
pub fn coordinate_space(&self) -> Option<Rc<dyn IServerObject>> {
self.coordinate_space.borrow().clone()
}
pub fn set_coordinate_space(&self, host: &dyn ServerSpotLightHooks, value: Option<Rc<dyn IServerObject>>) {
let old_value = self.coordinate_space.borrow().clone();
let mut changed = false;
if old_value.differs(&value) {
ServerSpotLightHooks::on_coordinate_space_changing(host);
changed = true;
}
host.set_value(
Self::id_of_coordinate_space_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: old_value.as_server_render_resource(),
new_resource: value.as_server_render_resource(),
assign: &mut || *self.coordinate_space.borrow_mut() = value.clone(),
},
);
if changed {
ServerSpotLightHooks::on_coordinate_space_changed(host);
}
}
pub fn id_of_direction_property() -> &'static CompositionPropertyOf<Vector3D> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector3D>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, Vector3D>(
"Direction",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).direction.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).direction.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).direction.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).direction.set(v.cast_or_default::<Vector3D>())),
)
})
}
pub fn direction(&self) -> Vector3D {
self.direction.get()
}
pub fn set_direction(&self, host: &dyn ServerSpotLightHooks, value: Vector3D) {
self.direction.set(value);
host.remove_animation_for_property(Self::id_of_direction_property().base());
}
pub fn id_of_inner_cone_angle_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"InnerConeAngle",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).inner_cone_angle.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).inner_cone_angle.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).inner_cone_angle.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).inner_cone_angle.set(v.cast_or_default::<f32>())),
)
})
}
pub fn inner_cone_angle(&self) -> f32 {
self.inner_cone_angle.get()
}
pub fn set_inner_cone_angle(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.inner_cone_angle.set(value);
host.remove_animation_for_property(Self::id_of_inner_cone_angle_property().base());
}
pub fn id_of_inner_cone_color_property() -> &'static CompositionPropertyOf<Color> {
static PROPERTY: OnceLock<CompositionPropertyOf<Color>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, Color>(
"InnerConeColor",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).inner_cone_color.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).inner_cone_color.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).inner_cone_color.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).inner_cone_color.set(v.cast_or_default::<Color>())),
)
})
}
pub fn inner_cone_color(&self) -> Color {
self.inner_cone_color.get()
}
pub fn set_inner_cone_color(&self, host: &dyn ServerSpotLightHooks, value: Color) {
self.inner_cone_color.set(value);
host.remove_animation_for_property(Self::id_of_inner_cone_color_property().base());
}
pub fn id_of_inner_cone_intensity_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"InnerConeIntensity",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).inner_cone_intensity.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).inner_cone_intensity.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).inner_cone_intensity.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).inner_cone_intensity.set(v.cast_or_default::<f32>())),
)
})
}
pub fn inner_cone_intensity(&self) -> f32 {
self.inner_cone_intensity.get()
}
pub fn set_inner_cone_intensity(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.inner_cone_intensity.set(value);
host.remove_animation_for_property(Self::id_of_inner_cone_intensity_property().base());
}
pub fn id_of_outer_cone_angle_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"OuterConeAngle",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).outer_cone_angle.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).outer_cone_angle.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).outer_cone_angle.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).outer_cone_angle.set(v.cast_or_default::<f32>())),
)
})
}
pub fn outer_cone_angle(&self) -> f32 {
self.outer_cone_angle.get()
}
pub fn set_outer_cone_angle(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.outer_cone_angle.set(value);
host.remove_animation_for_property(Self::id_of_outer_cone_angle_property().base());
}
pub fn id_of_outer_cone_color_property() -> &'static CompositionPropertyOf<Color> {
static PROPERTY: OnceLock<CompositionPropertyOf<Color>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, Color>(
"OuterConeColor",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).outer_cone_color.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).outer_cone_color.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).outer_cone_color.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).outer_cone_color.set(v.cast_or_default::<Color>())),
)
})
}
pub fn outer_cone_color(&self) -> Color {
self.outer_cone_color.get()
}
pub fn set_outer_cone_color(&self, host: &dyn ServerSpotLightHooks, value: Color) {
self.outer_cone_color.set(value);
host.remove_animation_for_property(Self::id_of_outer_cone_color_property().base());
}
pub fn id_of_outer_cone_intensity_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"OuterConeIntensity",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).outer_cone_intensity.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).outer_cone_intensity.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).outer_cone_intensity.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).outer_cone_intensity.set(v.cast_or_default::<f32>())),
)
})
}
pub fn outer_cone_intensity(&self) -> f32 {
self.outer_cone_intensity.get()
}
pub fn set_outer_cone_intensity(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.outer_cone_intensity.set(value);
host.remove_animation_for_property(Self::id_of_outer_cone_intensity_property().base());
}
pub fn id_of_offset_property() -> &'static CompositionPropertyOf<Vector3D> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector3D>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, Vector3D>(
"Offset",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).offset.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).offset.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).offset.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).offset.set(v.cast_or_default::<Vector3D>())),
)
})
}
pub fn offset(&self) -> Vector3D {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn ServerSpotLightHooks, value: Vector3D) {
self.offset.set(value);
host.remove_animation_for_property(Self::id_of_offset_property().base());
}
pub fn id_of_min_attenuation_cutoff_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"MinAttenuationCutoff",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).min_attenuation_cutoff.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).min_attenuation_cutoff.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).min_attenuation_cutoff.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).min_attenuation_cutoff.set(v.cast_or_default::<f32>())),
)
})
}
pub fn min_attenuation_cutoff(&self) -> f32 {
self.min_attenuation_cutoff.get()
}
pub fn set_min_attenuation_cutoff(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.min_attenuation_cutoff.set(value);
host.remove_animation_for_property(Self::id_of_min_attenuation_cutoff_property().base());
}
pub fn id_of_max_attenuation_cutoff_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerSpotLightProps, f32>(
"MaxAttenuationCutoff",
"ServerSpotLight",
|obj| props_of::<ServerSpotLightProps>(obj).max_attenuation_cutoff.get(),
|obj, v| props_of::<ServerSpotLightProps>(obj).max_attenuation_cutoff.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerSpotLightProps>(obj).max_attenuation_cutoff.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerSpotLightProps>(obj).max_attenuation_cutoff.set(v.cast_or_default::<f32>())),
)
})
}
pub fn max_attenuation_cutoff(&self) -> f32 {
self.max_attenuation_cutoff.get()
}
pub fn set_max_attenuation_cutoff(&self, host: &dyn ServerSpotLightHooks, value: f32) {
self.max_attenuation_cutoff.set(value);
host.remove_animation_for_property(Self::id_of_max_attenuation_cutoff_property().base());
}
pub fn deserialize_changes_core(
&self,
host: &dyn ServerSpotLightHooks,
reader: &mut BatchStreamReader<'_>,
committed_at: Duration,
) {
let compositor = host.server_compositor();
self.base.deserialize_changes_core(host, reader, committed_at);
ServerSpotLightHooks::deserialize_changes_extra(host, reader);
let changed = reader.read::<SpotLightChangedFields>();
if changed.contains(SpotLightChangedFields::CONSTANT_ATTENUATION_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `ConstantAttenuation` without an animation instance");
};
host.set_animated_value(
Self::id_of_constant_attenuation_property().base(),
ExpressionVariant::create(self.constant_attenuation.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::CONSTANT_ATTENUATION) {
let value = reader.read::<f32>();
self.set_constant_attenuation(host, value);
}
if changed.contains(SpotLightChangedFields::LINEAR_ATTENUATION_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `LinearAttenuation` without an animation instance");
};
host.set_animated_value(
Self::id_of_linear_attenuation_property().base(),
ExpressionVariant::create(self.linear_attenuation.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::LINEAR_ATTENUATION) {
let value = reader.read::<f32>();
self.set_linear_attenuation(host, value);
}
if changed.contains(SpotLightChangedFields::QUADRATIC_ATTENUATION_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `QuadraticAttenuation` without an animation instance");
};
host.set_animated_value(
Self::id_of_quadratic_attenuation_property().base(),
ExpressionVariant::create(self.quadratic_attenuation.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::QUADRATIC_ATTENUATION) {
let value = reader.read::<f32>();
self.set_quadratic_attenuation(host, value);
}
if changed.contains(SpotLightChangedFields::COORDINATE_SPACE) {
let value = read_server_object(reader, compositor.as_ref());
self.set_coordinate_space(host, value);
}
if changed.contains(SpotLightChangedFields::DIRECTION_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Direction` without an animation instance");
};
host.set_animated_value(
Self::id_of_direction_property().base(),
ExpressionVariant::create(self.direction.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::DIRECTION) {
let value = reader.read::<Vector3D>();
self.set_direction(host, value);
}
if changed.contains(SpotLightChangedFields::INNER_CONE_ANGLE_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `InnerConeAngle` without an animation instance");
};
host.set_animated_value(
Self::id_of_inner_cone_angle_property().base(),
ExpressionVariant::create(self.inner_cone_angle.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::INNER_CONE_ANGLE) {
let value = reader.read::<f32>();
self.set_inner_cone_angle(host, value);
}
if changed.contains(SpotLightChangedFields::INNER_CONE_COLOR_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `InnerConeColor` without an animation instance");
};
host.set_animated_value(
Self::id_of_inner_cone_color_property().base(),
ExpressionVariant::create(self.inner_cone_color.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::INNER_CONE_COLOR) {
let value = reader.read::<Color>();
self.set_inner_cone_color(host, value);
}
if changed.contains(SpotLightChangedFields::INNER_CONE_INTENSITY_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `InnerConeIntensity` without an animation instance");
};
host.set_animated_value(
Self::id_of_inner_cone_intensity_property().base(),
ExpressionVariant::create(self.inner_cone_intensity.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::INNER_CONE_INTENSITY) {
let value = reader.read::<f32>();
self.set_inner_cone_intensity(host, value);
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_ANGLE_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `OuterConeAngle` without an animation instance");
};
host.set_animated_value(
Self::id_of_outer_cone_angle_property().base(),
ExpressionVariant::create(self.outer_cone_angle.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_ANGLE) {
let value = reader.read::<f32>();
self.set_outer_cone_angle(host, value);
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_COLOR_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `OuterConeColor` without an animation instance");
};
host.set_animated_value(
Self::id_of_outer_cone_color_property().base(),
ExpressionVariant::create(self.outer_cone_color.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_COLOR) {
let value = reader.read::<Color>();
self.set_outer_cone_color(host, value);
}
if changed.contains(SpotLightChangedFields::OUTER_CONE_INTENSITY_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `OuterConeIntensity` without an animation instance");
};
host.set_animated_value(
Self::id_of_outer_cone_intensity_property().base(),
ExpressionVariant::create(self.outer_cone_intensity.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::OUTER_CONE_INTENSITY) {
let value = reader.read::<f32>();
self.set_outer_cone_intensity(host, value);
}
if changed.contains(SpotLightChangedFields::OFFSET_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Offset` without an animation instance");
};
host.set_animated_value(
Self::id_of_offset_property().base(),
ExpressionVariant::create(self.offset.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::OFFSET) {
let value = reader.read::<Vector3D>();
self.set_offset(host, value);
}
if changed.contains(SpotLightChangedFields::MIN_ATTENUATION_CUTOFF_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `MinAttenuationCutoff` without an animation instance");
};
host.set_animated_value(
Self::id_of_min_attenuation_cutoff_property().base(),
ExpressionVariant::create(self.min_attenuation_cutoff.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::MIN_ATTENUATION_CUTOFF) {
let value = reader.read::<f32>();
self.set_min_attenuation_cutoff(host, value);
}
if changed.contains(SpotLightChangedFields::MAX_ATTENUATION_CUTOFF_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `MaxAttenuationCutoff` without an animation instance");
};
host.set_animated_value(
Self::id_of_max_attenuation_cutoff_property().base(),
ExpressionVariant::create(self.max_attenuation_cutoff.get()),
committed_at,
animation,
);
} else if changed.contains(SpotLightChangedFields::MAX_ATTENUATION_CUTOFF) {
let value = reader.read::<f32>();
self.set_max_attenuation_cutoff(host, value);
}
ServerSpotLightHooks::on_fields_deserialized(host, changed);
}
pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
if name == "ConstantAttenuation" {
return Some(Self::id_of_constant_attenuation_property().base());
}
if name == "LinearAttenuation" {
return Some(Self::id_of_linear_attenuation_property().base());
}
if name == "QuadraticAttenuation" {
return Some(Self::id_of_quadratic_attenuation_property().base());
}
if name == "Direction" {
return Some(Self::id_of_direction_property().base());
}
if name == "InnerConeAngle" {
return Some(Self::id_of_inner_cone_angle_property().base());
}
if name == "InnerConeColor" {
return Some(Self::id_of_inner_cone_color_property().base());
}
if name == "InnerConeIntensity" {
return Some(Self::id_of_inner_cone_intensity_property().base());
}
if name == "OuterConeAngle" {
return Some(Self::id_of_outer_cone_angle_property().base());
}
if name == "OuterConeColor" {
return Some(Self::id_of_outer_cone_color_property().base());
}
if name == "OuterConeIntensity" {
return Some(Self::id_of_outer_cone_intensity_property().base());
}
if name == "Offset" {
return Some(Self::id_of_offset_property().base());
}
if name == "MinAttenuationCutoff" {
return Some(Self::id_of_min_attenuation_cutoff_property().base());
}
if name == "MaxAttenuationCutoff" {
return Some(Self::id_of_max_attenuation_cutoff_property().base());
}
ServerCompositionLightProps::get_composition_property(name)
}
}