-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#248 Fixed dynamic materials behaviour
- Loading branch information
Showing
4 changed files
with
81 additions
and
14 deletions.
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
34 changes: 34 additions & 0 deletions
34
Source/Cloud9/Character/Components/Cloud9SkeletalMeshComponent.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,34 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#include "Cloud9SkeletalMeshComponent.h" | ||
|
||
#include "Cloud9/Tools/Extensions/TContainer.h" | ||
|
||
void UCloud9SkeletalMeshComponent::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
MakeDynamicMaterials(GetMaterials()); | ||
} | ||
|
||
void UCloud9SkeletalMeshComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, bool bReinitPose) | ||
{ | ||
Super::SetSkeletalMesh(NewMesh, bReinitPose); | ||
let Materials = NewMesh->GetMaterials() | ||
| ETContainer::Transform{[](let It) { return It.MaterialInterface; }} | ||
| ETContainer::ToArray{}; | ||
MakeDynamicMaterials(Materials); | ||
} | ||
|
||
void UCloud9SkeletalMeshComponent::MakeDynamicMaterials(const TArray<UMaterialInterface*>& Materials) | ||
{ | ||
Materials | ||
| ETContainer::WithIndex{} | ||
| ETContainer::Filter{[](let It) { return not Cast<UMaterialInstanceDynamic>(It.Value); }} | ||
| ETContainer::ForEach{ | ||
[this](let It) | ||
{ | ||
let DynamicMaterial = UMaterialInstanceDynamic::Create(It.Value, this); | ||
SetMaterial(It.Key, DynamicMaterial); | ||
} | ||
}; | ||
} |
21 changes: 21 additions & 0 deletions
21
Source/Cloud9/Character/Components/Cloud9SkeletalMeshComponent.h
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,21 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/SkeletalMeshComponent.h" | ||
#include "Cloud9SkeletalMeshComponent.generated.h" | ||
|
||
UCLASS() | ||
class CLOUD9_API UCloud9SkeletalMeshComponent : public USkeletalMeshComponent | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
virtual void BeginPlay() override; | ||
|
||
virtual void SetSkeletalMesh(USkeletalMesh* NewMesh, bool bReinitPose) override; | ||
|
||
protected: | ||
void MakeDynamicMaterials(const TArray<UMaterialInterface*>& Materials); | ||
}; |