New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for rendering points #1037
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4bb96b
Get CesiumGltfPointsComponent to render
j9liu 8d0bb92
Fix material bug
j9liu 1affac3
Cleanup
j9liu 0d45014
Try to fix formatting error
j9liu 1f05ab6
Fix typo, update tooltip and changelog
j9liu 44108a5
Don't use deprecated getter
j9liu a2715d7
Don't hardcode static and dynamic relevance
j9liu 559a7db
Remove unnecessary imports
j9liu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
Source/CesiumRuntime/Private/CesiumGltfPointsComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2020-2021 CesiumGS, Inc. and Contributors | ||
|
||
#include "CesiumGltfPointsComponent.h" | ||
#include "Engine/StaticMesh.h" | ||
|
||
class FGltfPointsSceneProxy final : public FPrimitiveSceneProxy { | ||
public: | ||
SIZE_T GetTypeHash() const override { | ||
static size_t UniquePointer; | ||
return reinterpret_cast<size_t>(&UniquePointer); | ||
} | ||
|
||
FGltfPointsSceneProxy( | ||
UCesiumGltfPointsComponent* InComponent, | ||
ERHIFeatureLevel::Type InFeatureLevel) | ||
: FPrimitiveSceneProxy(InComponent) { | ||
const auto RenderData = InComponent->GetStaticMesh()->GetRenderData(); | ||
LODResources = &RenderData->LODResources[0]; | ||
VertexFactory = &RenderData->LODVertexFactories[0].VertexFactory; | ||
Material = InComponent->GetMaterial(0); | ||
MaterialRelevance = | ||
InComponent->GetMaterialRelevance(GetScene().GetFeatureLevel()); | ||
} | ||
|
||
virtual ~FGltfPointsSceneProxy() {} | ||
|
||
virtual void DrawStaticElements(FStaticPrimitiveDrawInterface* PDI) override { | ||
if (!HasViewDependentDPG()) { | ||
FMeshBatch Mesh; | ||
CreateMesh(Mesh); | ||
PDI->DrawMesh(Mesh, FLT_MAX); | ||
} | ||
} | ||
|
||
virtual void GetDynamicMeshElements( | ||
const TArray<const FSceneView*>& Views, | ||
const FSceneViewFamily& ViewFamily, | ||
uint32 VisibilityMap, | ||
FMeshElementCollector& Collector) const override { | ||
QUICK_SCOPE_CYCLE_COUNTER(STAT_GltfPointsSceneProxy_GetDynamicMeshElements); | ||
|
||
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++) { | ||
if (VisibilityMap & (1 << ViewIndex)) { | ||
const FSceneView* View = Views[ViewIndex]; | ||
FMeshBatch& Mesh = Collector.AllocateMesh(); | ||
CreateMesh(Mesh); | ||
Collector.AddMesh(ViewIndex, Mesh); | ||
} | ||
} | ||
} | ||
|
||
virtual FPrimitiveViewRelevance | ||
GetViewRelevance(const FSceneView* View) const override { | ||
FPrimitiveViewRelevance Result; | ||
Result.bDrawRelevance = IsShown(View); | ||
if (HasViewDependentDPG()) { | ||
Result.bDynamicRelevance = true; | ||
} else { | ||
Result.bStaticRelevance = true; | ||
} | ||
|
||
Result.bRenderCustomDepth = ShouldRenderCustomDepth(); | ||
Result.bRenderInMainPass = ShouldRenderInMainPass(); | ||
Result.bRenderInDepthPass = ShouldRenderInDepthPass(); | ||
Result.bUsesLightingChannels = | ||
GetLightingChannelMask() != GetDefaultLightingChannelMask(); | ||
Result.bShadowRelevance = IsShadowCast(View); | ||
Result.bVelocityRelevance = | ||
IsMovable() & Result.bOpaque & Result.bRenderInMainPass; | ||
|
||
MaterialRelevance.SetPrimitiveViewRelevance(Result); | ||
|
||
return Result; | ||
} | ||
|
||
virtual uint32 GetMemoryFootprint(void) const override { | ||
return (sizeof(*this) + GetAllocatedSize()); | ||
} | ||
|
||
private: | ||
FLocalVertexFactory* VertexFactory; | ||
FStaticMeshLODResources* LODResources; | ||
UMaterialInterface* Material; | ||
FMaterialRelevance MaterialRelevance; | ||
|
||
void CreateMesh(FMeshBatch& Mesh) const { | ||
Mesh.VertexFactory = VertexFactory; | ||
Mesh.MaterialRenderProxy = Material->GetRenderProxy(); | ||
Mesh.ReverseCulling = IsLocalToWorldDeterminantNegative(); | ||
Mesh.Type = PT_PointList; | ||
Mesh.DepthPriorityGroup = SDPG_World; | ||
Mesh.LODIndex = 0; | ||
Mesh.bCanApplyViewModeOverrides = false; | ||
Mesh.bUseAsOccluder = false; | ||
Mesh.bWireframe = false; | ||
|
||
auto pIndexBuffer = &LODResources->IndexBuffer; | ||
FMeshBatchElement& BatchElement = Mesh.Elements[0]; | ||
BatchElement.IndexBuffer = pIndexBuffer; | ||
BatchElement.NumPrimitives = pIndexBuffer->GetNumIndices(); | ||
BatchElement.FirstIndex = 0; | ||
BatchElement.MinVertexIndex = 0; | ||
BatchElement.MaxVertexIndex = BatchElement.NumPrimitives - 1; | ||
} | ||
}; | ||
|
||
// Sets default values for this component's properties | ||
UCesiumGltfPointsComponent::UCesiumGltfPointsComponent() {} | ||
|
||
UCesiumGltfPointsComponent::~UCesiumGltfPointsComponent() {} | ||
|
||
FPrimitiveSceneProxy* UCesiumGltfPointsComponent::CreateSceneProxy() { | ||
return new FGltfPointsSceneProxy(this, GetScene()->GetFeatureLevel()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2020-2021 CesiumGS, Inc. and Contributors | ||
|
||
#pragma once | ||
|
||
#include "CesiumGltfPrimitiveComponent.h" | ||
#include "CesiumGltfPointsComponent.generated.h" | ||
|
||
UCLASS() | ||
class UCesiumGltfPointsComponent : public UCesiumGltfPrimitiveComponent { | ||
GENERATED_BODY() | ||
|
||
public: | ||
// Sets default values for this component's properties | ||
UCesiumGltfPointsComponent(); | ||
virtual ~UCesiumGltfPointsComponent(); | ||
|
||
// Override UPrimitiveComponent interface. | ||
virtual FPrimitiveSceneProxy* CreateSceneProxy() override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cesium-native
updated
27 files
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied this from the
CesiumGltfPrimitiveComponent
file -- should we update this for 2023?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah we should update it everywhere. But that can be a separate PR. It's unfortunate that Epic's marketplace guidelines require us to put this nonsense in every file.
https://www.unrealengine.com/en-US/marketplace-guidelines#262b