Add waiting for model to be loaded in SetMaterial
This commit is contained in:
@@ -895,3 +895,9 @@ void AnimatedModel::OnTransformChanged()
|
|||||||
if (_sceneRenderingKey != -1)
|
if (_sceneRenderingKey != -1)
|
||||||
GetSceneRendering()->UpdateActor(this, _sceneRenderingKey);
|
GetSceneRendering()->UpdateActor(this, _sceneRenderingKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimatedModel::WaitForModelLoad()
|
||||||
|
{
|
||||||
|
if (SkinnedModel)
|
||||||
|
SkinnedModel->WaitForLoaded();
|
||||||
|
}
|
||||||
|
|||||||
@@ -376,4 +376,5 @@ protected:
|
|||||||
void OnDisable() override;
|
void OnDisable() override;
|
||||||
void OnActiveInTreeChanged() override;
|
void OnActiveInTreeChanged() override;
|
||||||
void OnTransformChanged() override;
|
void OnTransformChanged() override;
|
||||||
|
void WaitForModelLoad() override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ ModelInstanceActor::ModelInstanceActor(const SpawnParams& params)
|
|||||||
|
|
||||||
void ModelInstanceActor::SetEntries(const Array<ModelInstanceEntry>& value)
|
void ModelInstanceActor::SetEntries(const Array<ModelInstanceEntry>& value)
|
||||||
{
|
{
|
||||||
|
WaitForModelLoad();
|
||||||
bool anyChanged = false;
|
bool anyChanged = false;
|
||||||
Entries.Resize(value.Count());
|
Entries.Resize(value.Count());
|
||||||
for (int32 i = 0; i < value.Count(); i++)
|
for (int32 i = 0; i < value.Count(); i++)
|
||||||
@@ -24,6 +25,7 @@ void ModelInstanceActor::SetEntries(const Array<ModelInstanceEntry>& value)
|
|||||||
|
|
||||||
void ModelInstanceActor::SetMaterial(int32 entryIndex, MaterialBase* material)
|
void ModelInstanceActor::SetMaterial(int32 entryIndex, MaterialBase* material)
|
||||||
{
|
{
|
||||||
|
WaitForModelLoad();
|
||||||
CHECK(entryIndex >= 0 && entryIndex < Entries.Count());
|
CHECK(entryIndex >= 0 && entryIndex < Entries.Count());
|
||||||
if (Entries[entryIndex].Material == material)
|
if (Entries[entryIndex].Material == material)
|
||||||
return;
|
return;
|
||||||
@@ -34,6 +36,8 @@ void ModelInstanceActor::SetMaterial(int32 entryIndex, MaterialBase* material)
|
|||||||
|
|
||||||
MaterialInstance* ModelInstanceActor::CreateAndSetVirtualMaterialInstance(int32 entryIndex)
|
MaterialInstance* ModelInstanceActor::CreateAndSetVirtualMaterialInstance(int32 entryIndex)
|
||||||
{
|
{
|
||||||
|
WaitForModelLoad();
|
||||||
|
CHECK_RETURN(entryIndex >= 0 && entryIndex < Entries.Count(), nullptr);
|
||||||
auto material = Entries[entryIndex].Material.Get();
|
auto material = Entries[entryIndex].Material.Get();
|
||||||
CHECK_RETURN(material && !material->WaitForLoaded(), nullptr);
|
CHECK_RETURN(material && !material->WaitForLoaded(), nullptr);
|
||||||
const auto result = material->CreateVirtualInstance();
|
const auto result = material->CreateVirtualInstance();
|
||||||
@@ -43,6 +47,10 @@ MaterialInstance* ModelInstanceActor::CreateAndSetVirtualMaterialInstance(int32
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelInstanceActor::WaitForModelLoad()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ModelInstanceActor::OnLayerChanged()
|
void ModelInstanceActor::OnLayerChanged()
|
||||||
{
|
{
|
||||||
if (_sceneRenderingKey != -1)
|
if (_sceneRenderingKey != -1)
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void WaitForModelLoad();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [Actor]
|
// [Actor]
|
||||||
void OnLayerChanged() override;
|
void OnLayerChanged() override;
|
||||||
|
|||||||
@@ -544,3 +544,9 @@ void StaticModel::OnDisable()
|
|||||||
_residencyChangedModel = nullptr;
|
_residencyChangedModel = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StaticModel::WaitForModelLoad()
|
||||||
|
{
|
||||||
|
if (Model)
|
||||||
|
Model->WaitForLoaded();
|
||||||
|
}
|
||||||
|
|||||||
@@ -187,4 +187,5 @@ protected:
|
|||||||
void OnTransformChanged() override;
|
void OnTransformChanged() override;
|
||||||
void OnEnable() override;
|
void OnEnable() override;
|
||||||
void OnDisable() override;
|
void OnDisable() override;
|
||||||
|
void WaitForModelLoad() override;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user