ALCCSectionPlane:3DGS 剖切面
剖切面 Actor,用一個平面切開 LCC 場景,保留平面的一側。
| 模塊 | LCC4UnrealRuntime |
| 頭文件 | Tools/LCCSectionPlane.h |
| 父類 | AVolume |
| 面板顯示名 | LCC Section Plane |
#include "Tools/LCCSectionPlane.h"
使用步驟、演示效果與屬性面板說明見場景編輯 - 剖切平面。本頁只列接口。
編輯器裏會顯示一個箭頭指示組件,標明平面朝向,箭頭指向的一側就是 Upside。
Properties
| 屬性 | 類型 | 說明 |
|---|---|---|
bEnabled | bool | 是否參與剖切 |
Mode | ESectionType | Upside 切掉平面上方,Downside 切掉平面下方 |
上下是相對平面自身朝向而言,不是世界坐標。旋轉剖切面可以得到任意方向的剖切。取值含義見 ESectionType。
兩個屬性都沒有 Setter,運行時賦值後需要調用 Refresh 才生效。運行時改變換也一樣。
Methods
SetUpdateComponent
UFUNCTION(BlueprintCallable, Category = "XGrids")
void SetUpdateComponent(ULCCComponentBase* Component);
綁定要更新的 LCC Component。
Refresh() 需要這個綁定才能生效,它內部就是把綁定的 Component 標記為需要重建渲染狀態。沒綁定時不會觸發渲染更新。
Refresh
UFUNCTION(BlueprintCallable, Category = "XGrids")
void Refresh();
手動觸發一次剖切結果更新,內部會把綁定的 LCC Component 標記為需要重建渲染狀態。
運行時改動剖切面後必須調用它,修改才會生效,包括:
- 改屬性:
bEnabled、Mode。這兩個屬性沒有 Setter,直接賦值不會通知渲染側。 - 改變換:
SetActorLocation、SetActorRotation。
自動更新只發生在編輯器裏:細節面板改屬性走 PostEditChangeProperty,拖動 gizmo 走 EditorApplyTranslation 等函數,這些路徑都在 WITH_EDITOR 下,運行時不存在。
前提是已經調過 SetUpdateComponent 或通過 AddSectionPlane 建立了關聯。沒有綁定 Component 時不會觸發任何渲染更新。
批量修改多個剖切面時,逐個改完屬性後各自調一次 Refresh()。
運行時創建
#include "Tools/LCCSectionPlane.h"
#include "LCCComponentBase.h"
ALCCSectionPlane* AMyTool::CreateSectionPlane(
ULCCComponentBase* Component, const FVector& Location, const FRotator& Rotation)
{
ALCCSectionPlane* Plane = GetWorld()->SpawnActor<ALCCSectionPlane>(
ALCCSectionPlane::StaticClass(), Location, Rotation);
if (!Plane)
{
return nullptr;
}
Plane->Mode = ESectionType::Upside; // 切掉平面上方
Plane->bEnabled = true;
Plane->SetUpdateComponent(Component);
Component->AddSectionPlane(Plane);
return Plane;
}
幾種常見配置:
| 效果 | 位置與旋轉 | Mode |
|---|---|---|
| 俯視看建築內部 | 指定高度,FRotator::ZeroRotator | Upside |
| 豎直剖切看立面 | FRotator(0, 0, 90) 轉成豎直平面 | Upside |
| 只保留中間一層 | 上下各放一個平面 | 下界 Downside,上界 Upside |
移動剖切面就能做出逐層揭開的動畫。運行時每幀移動後都要調 Refresh():
FVector Loc = SectionPlane->GetActorLocation();
Loc.Z = FMath::FInterpTo(Loc.Z, TargetHeight, DeltaTime, 1.0f);
SectionPlane->SetActorLocation(Loc);
SectionPlane->Refresh(); // 運行時變換不會自動更新
改屬性同樣要刷新:
SectionPlane->bEnabled = false;
SectionPlane->Refresh();
藍圖節點見場景編輯 - 藍圖方法。
Notes
- 剖切只影響渲染,不影響碰撞。被切掉的部分仍可被射線打中、仍會擋住角色。
Upside與Downside相對平面自身朝向。旋轉過之後要重新確認哪邊是「上」,編輯器裏看箭頭最直觀。- 構造時 Z 軸縮放被設為 0.01(薄片),編輯器裏改縮放也會被壓回該值。運行時改縮放不受這層約束,但一般不需要改。
- 同時生效的剖切面數量有上限,未授權時為 50 個,超出的不參與渲染並輸出警告。剖切面與裁剪體共用這個配額。授權說明見版本與授權。
- 銷毀剖切面只會觸發一次渲染更新,不會從 Component 的
SectionPlanes數組裏移除元素,數組中會殘留失效指針(渲染時會自動跳過)。需要保持數組乾淨的話,銷毀前先調RemoveSectionPlane。
See Also
- 場景編輯:完整使用說明
- ALCCClippingVolume:用有界體積裁剪
- ULCCComponentBase:
AddSectionPlane與RemoveSectionPlane