From 3bfeb1db763d6491c434b72209627cb6ff5998e2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 19:07:18 +0200 Subject: [PATCH] Add `BoxBrush::SetMaterial` --- Source/Engine/Level/Actors/BoxBrush.cpp | 34 +++++++++++++++++++- Source/Engine/Level/Actors/BoxBrush.h | 41 +++++++++---------------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Source/Engine/Level/Actors/BoxBrush.cpp b/Source/Engine/Level/Actors/BoxBrush.cpp index f02dd5bd3..4330424c7 100644 --- a/Source/Engine/Level/Actors/BoxBrush.cpp +++ b/Source/Engine/Level/Actors/BoxBrush.cpp @@ -128,6 +128,13 @@ void BoxBrush::GetSurfaces(CSG::Surface surfaces[6]) } } +void BoxBrush::SetMaterial(int32 surfaceIndex, MaterialBase* material) +{ + CHECK(Math::IsInRange(surfaceIndex, 0, 5)); + Surfaces[surfaceIndex].Material = material; + OnBrushModified(); +} + bool BoxBrush::Intersects(int32 surfaceIndex, const Ray& ray, float& distance, Vector3& normal) const { distance = MAX_float; @@ -232,6 +239,26 @@ void BoxBrush::OnDebugDrawSelected() #endif +Scene* BoxBrush::GetBrushScene() const +{ + return GetScene(); +} + +Guid BoxBrush::GetBrushID() const +{ + return GetID(); +} + +bool BoxBrush::CanUseCSG() const +{ + return IsActiveInHierarchy(); +} + +CSG::Mode BoxBrush::GetBrushMode() const +{ + return _mode; +} + void BoxBrush::GetSurfaces(Array& surfaces) { surfaces.Clear(); @@ -240,6 +267,11 @@ void BoxBrush::GetSurfaces(Array& surfaces) GetSurfaces(surfaces.Get()); } +int32 BoxBrush::GetSurfacesCount() +{ + return 6; +} + void BoxBrush::OnTransformChanged() { // Base @@ -272,7 +304,7 @@ void BoxBrush::OnParentChanged() { // Base Actor::OnParentChanged(); - + if (!IsDuringPlay()) return; diff --git a/Source/Engine/Level/Actors/BoxBrush.h b/Source/Engine/Level/Actors/BoxBrush.h index e8fc63e3f..ae9be5b83 100644 --- a/Source/Engine/Level/Actors/BoxBrush.h +++ b/Source/Engine/Level/Actors/BoxBrush.h @@ -153,6 +153,13 @@ public: /// Surfaces void GetSurfaces(CSG::Surface surfaces[6]); + /// + /// Sets the brush surface material. + /// + /// The brush surface index. + /// The material. + API_FUNCTION() void SetMaterial(int32 surfaceIndex, MaterialBase* material); + public: /// @@ -169,7 +176,7 @@ public: /// Otherwise performs simple vs test. /// For more efficient collisions detection and ray casting use physics. /// - /// The brush surface index.. + /// The brush surface index. /// The ray to test. /// When the method completes and returns true, contains the distance of the intersection (if any valid). /// When the method completes, contains the intersection surface normal vector (if any valid). @@ -179,7 +186,7 @@ public: /// /// Gets the brush surface triangles array (group by 3 vertices). /// - /// The brush surface index.. + /// The brush surface index. /// The output vertices buffer with triangles or empty if no data loaded. API_FUNCTION() void GetVertices(int32 surfaceIndex, API_PARAM(Out) Array& outputData) const; @@ -204,32 +211,12 @@ public: #endif // [CSG::Brush] - Scene* GetBrushScene() const override - { - return GetScene(); - } - - Guid GetBrushID() const override - { - return GetID(); - } - - bool CanUseCSG() const override - { - return IsActiveInHierarchy(); - } - - CSG::Mode GetBrushMode() const override - { - return _mode; - } - + Scene* GetBrushScene() const override; + Guid GetBrushID() const override; + bool CanUseCSG() const override; + CSG::Mode GetBrushMode() const override; void GetSurfaces(Array& surfaces) override; - - int32 GetSurfacesCount() override - { - return 6; - } + int32 GetSurfacesCount() override; protected: