Skip to content

Commit

Permalink
implement copy and clone for lights
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Jun 11, 2024
1 parent d8a50c8 commit 8ba32f8
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/threepp/lights/AmbientLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace threepp {

protected:
explicit AmbientLight(const Color& color, std::optional<float> intensity);

std::shared_ptr<Object3D> createDefault() override {

return create();
}
};

}// namespace threepp
Expand Down
7 changes: 7 additions & 0 deletions include/threepp/lights/DirectionalLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ namespace threepp {

void dispose() override;

void copy(const Object3D& source, bool recursive) override;

static std::shared_ptr<DirectionalLight> create(const Color& color = 0xffffff, std::optional<float> intensity = std::nullopt);

protected:
DirectionalLight(const Color& color, std::optional<float> intensity);

std::shared_ptr<Object3D> createDefault() override {

return create();
}
};

}// namespace threepp
Expand Down
7 changes: 7 additions & 0 deletions include/threepp/lights/HemisphereLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ namespace threepp {

[[nodiscard]] std::string type() const override;

void copy(const Object3D& source, bool recursive) override;

static std::shared_ptr<HemisphereLight> create(const Color& skyColor = 0xffffff, const Color& groundColor = 0xffffff, std::optional<float> intensity = std::nullopt);

protected:
HemisphereLight(const Color& skyColor, const Color& groundColor, std::optional<float> intensity);

std::shared_ptr<Object3D> createDefault() override {

return create();
}
};

}// namespace threepp
Expand Down
2 changes: 2 additions & 0 deletions include/threepp/lights/Light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace threepp {

[[nodiscard]] std::string type() const override;

void copy(const Object3D& source, bool recursive) override;

virtual void dispose();

protected:
Expand Down
2 changes: 2 additions & 0 deletions include/threepp/lights/PointLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace threepp {

void dispose() override;

void copy(const Object3D& source, bool recursive) override;

static std::shared_ptr<PointLight> create(const Color& color = 0xffffff, std::optional<float> intensity = std::nullopt, float distance = 0, float decay = 1);

protected:
Expand Down
7 changes: 7 additions & 0 deletions include/threepp/lights/SpotLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ namespace threepp {

void dispose() override;

void copy(const Object3D& source, bool recursive) override;

static std::shared_ptr<SpotLight> create(const Color& color = 0xffffff, std::optional<float> intensity = std::nullopt, float distance = 0, float angle = math::PI / 3, float penumbra = 0, float decay = 1);

protected:
SpotLight(const Color& color, std::optional<float> intensity, float distance, float angle, float penumbra, float decay);

std::shared_ptr<Object3D> createDefault() override {

return create();
}
};

}// namespace threepp
Expand Down
6 changes: 6 additions & 0 deletions src/threepp/lights/DirectionalLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> DirectionalLight::create(const Color& color, std::optional<float> intensity) {

return std::shared_ptr<DirectionalLight>(new DirectionalLight(color, intensity));
Expand Down
9 changes: 9 additions & 0 deletions src/threepp/lights/HemisphereLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HemisphereLight>()) {

groundColor.copy(l->groundColor);
}
}

std::shared_ptr<HemisphereLight> HemisphereLight::create(const Color& skyColor, const Color& groundColor, std::optional<float> intensity) {

return std::shared_ptr<HemisphereLight>(new HemisphereLight(skyColor, groundColor, intensity));
Expand Down
10 changes: 10 additions & 0 deletions src/threepp/lights/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Light>()) {

color.copy(l->color);
intensity = l->intensity;
}
}

void Light::dispose() {}
10 changes: 10 additions & 0 deletions src/threepp/lights/PointLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PointLight>()) {

this->distance = l->distance;
this->decay = l->decay;
}
}

std::shared_ptr<PointLight> PointLight::create(const Color& color, std::optional<float> intensity, float distance, float decay) {

return std::shared_ptr<PointLight>(new PointLight(color, intensity, distance, decay));
Expand Down
12 changes: 12 additions & 0 deletions src/threepp/lights/SpotLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpotLight>()) {

this->distance = l->distance;
this->angle = l->angle;
this->penumbra = l->penumbra;
this->decay = l->decay;
}
}

std::shared_ptr<SpotLight> SpotLight::create(const Color& color, std::optional<float> intensity, float distance, float angle, float penumbra, float decay) {

return std::shared_ptr<SpotLight>(new SpotLight(color, intensity, distance, angle, penumbra, decay));
Expand Down

0 comments on commit 8ba32f8

Please sign in to comment.