diff --git a/include/threepp/lights/AmbientLight.hpp b/include/threepp/lights/AmbientLight.hpp index 3db47fd9..98c384d2 100644 --- a/include/threepp/lights/AmbientLight.hpp +++ b/include/threepp/lights/AmbientLight.hpp @@ -18,6 +18,11 @@ namespace threepp { protected: explicit AmbientLight(const Color& color, std::optional intensity); + + std::shared_ptr createDefault() override { + + return create(); + } }; }// namespace threepp diff --git a/include/threepp/lights/DirectionalLight.hpp b/include/threepp/lights/DirectionalLight.hpp index fa07327b..4c89a743 100644 --- a/include/threepp/lights/DirectionalLight.hpp +++ b/include/threepp/lights/DirectionalLight.hpp @@ -15,10 +15,17 @@ namespace threepp { void dispose() override; + void copy(const Object3D& source, bool recursive) override; + static std::shared_ptr create(const Color& color = 0xffffff, std::optional intensity = std::nullopt); protected: DirectionalLight(const Color& color, std::optional intensity); + + std::shared_ptr createDefault() override { + + return create(); + } }; }// namespace threepp diff --git a/include/threepp/lights/HemisphereLight.hpp b/include/threepp/lights/HemisphereLight.hpp index 1b629504..5e65ca27 100644 --- a/include/threepp/lights/HemisphereLight.hpp +++ b/include/threepp/lights/HemisphereLight.hpp @@ -14,10 +14,17 @@ namespace threepp { [[nodiscard]] std::string type() const override; + void copy(const Object3D& source, bool recursive) override; + static std::shared_ptr create(const Color& skyColor = 0xffffff, const Color& groundColor = 0xffffff, std::optional intensity = std::nullopt); protected: HemisphereLight(const Color& skyColor, const Color& groundColor, std::optional intensity); + + std::shared_ptr createDefault() override { + + return create(); + } }; }// namespace threepp diff --git a/include/threepp/lights/Light.hpp b/include/threepp/lights/Light.hpp index ddaf560f..3977f24e 100644 --- a/include/threepp/lights/Light.hpp +++ b/include/threepp/lights/Light.hpp @@ -18,6 +18,8 @@ namespace threepp { [[nodiscard]] std::string type() const override; + void copy(const Object3D& source, bool recursive) override; + virtual void dispose(); protected: diff --git a/include/threepp/lights/PointLight.hpp b/include/threepp/lights/PointLight.hpp index 85d03b67..d9821946 100644 --- a/include/threepp/lights/PointLight.hpp +++ b/include/threepp/lights/PointLight.hpp @@ -22,6 +22,8 @@ namespace threepp { void dispose() override; + void copy(const Object3D& source, bool recursive) override; + static std::shared_ptr create(const Color& color = 0xffffff, std::optional intensity = std::nullopt, float distance = 0, float decay = 1); protected: diff --git a/include/threepp/lights/SpotLight.hpp b/include/threepp/lights/SpotLight.hpp index 3c1a3b17..3420cd2f 100644 --- a/include/threepp/lights/SpotLight.hpp +++ b/include/threepp/lights/SpotLight.hpp @@ -25,10 +25,17 @@ namespace threepp { void dispose() override; + void copy(const Object3D& source, bool recursive) override; + static std::shared_ptr create(const Color& color = 0xffffff, std::optional intensity = std::nullopt, float distance = 0, float angle = math::PI / 3, float penumbra = 0, float decay = 1); protected: SpotLight(const Color& color, std::optional intensity, float distance, float angle, float penumbra, float decay); + + std::shared_ptr createDefault() override { + + return create(); + } }; }// namespace threepp diff --git a/src/threepp/lights/DirectionalLight.cpp b/src/threepp/lights/DirectionalLight.cpp index c98e3a05..7e26ab27 100644 --- a/src/threepp/lights/DirectionalLight.cpp +++ b/src/threepp/lights/DirectionalLight.cpp @@ -25,6 +25,12 @@ void DirectionalLight::dispose() { this->shadow->dispose(); } +void DirectionalLight::copy(const Object3D& source, bool recursive) { + Light::copy(source, recursive); + + // TODO +} + std::shared_ptr DirectionalLight::create(const Color& color, std::optional intensity) { return std::shared_ptr(new DirectionalLight(color, intensity)); diff --git a/src/threepp/lights/HemisphereLight.cpp b/src/threepp/lights/HemisphereLight.cpp index 4c7a2dd7..9e76a976 100644 --- a/src/threepp/lights/HemisphereLight.cpp +++ b/src/threepp/lights/HemisphereLight.cpp @@ -18,6 +18,15 @@ std::string HemisphereLight::type() const { return "HemisphereLight"; } +void HemisphereLight::copy(const Object3D& source, bool recursive) { + Light::copy(source, recursive); + + if (auto l = source.as()) { + + groundColor.copy(l->groundColor); + } +} + std::shared_ptr HemisphereLight::create(const Color& skyColor, const Color& groundColor, std::optional intensity) { return std::shared_ptr(new HemisphereLight(skyColor, groundColor, intensity)); diff --git a/src/threepp/lights/Light.cpp b/src/threepp/lights/Light.cpp index 6c42764e..8397c98e 100644 --- a/src/threepp/lights/Light.cpp +++ b/src/threepp/lights/Light.cpp @@ -13,4 +13,14 @@ std::string Light::type() const { return "Light"; } +void Light::copy(const Object3D& source, bool recursive) { + Object3D::copy(source, recursive); + + if (const auto l = source.as()) { + + color.copy(l->color); + intensity = l->intensity; + } +} + void Light::dispose() {} diff --git a/src/threepp/lights/PointLight.cpp b/src/threepp/lights/PointLight.cpp index 89c6a332..47f3c79d 100644 --- a/src/threepp/lights/PointLight.cpp +++ b/src/threepp/lights/PointLight.cpp @@ -37,6 +37,16 @@ void PointLight::dispose() { this->shadow->dispose(); } +void PointLight::copy(const Object3D& source, bool recursive) { + Light::copy(source, recursive); + + if (auto l = source.as()) { + + this->distance = l->distance; + this->decay = l->decay; + } +} + std::shared_ptr PointLight::create(const Color& color, std::optional intensity, float distance, float decay) { return std::shared_ptr(new PointLight(color, intensity, distance, decay)); diff --git a/src/threepp/lights/SpotLight.cpp b/src/threepp/lights/SpotLight.cpp index 8a0e2fd6..bd5ae08e 100644 --- a/src/threepp/lights/SpotLight.cpp +++ b/src/threepp/lights/SpotLight.cpp @@ -38,6 +38,18 @@ void SpotLight::dispose() { this->shadow->dispose(); } +void SpotLight::copy(const Object3D& source, bool recursive) { + Light::copy(source, recursive); + + if (auto l = source.as()) { + + this->distance = l->distance; + this->angle = l->angle; + this->penumbra = l->penumbra; + this->decay = l->decay; + } +} + std::shared_ptr SpotLight::create(const Color& color, std::optional intensity, float distance, float angle, float penumbra, float decay) { return std::shared_ptr(new SpotLight(color, intensity, distance, angle, penumbra, decay));