OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshMaterialUpdate Class Reference

#include <StdMeshUpdate.h>

Public Member Functions

 StdMeshMaterialUpdate (StdMeshMatManager &manager)
 
void Update (StdMesh *mesh) const
 
void Update (StdMeshInstance *instance) const
 
void Cancel () const
 

Friends

class StdMeshMatManager
 

Detailed Description

Definition at line 26 of file StdMeshUpdate.h.

Constructor & Destructor Documentation

StdMeshMaterialUpdate::StdMeshMaterialUpdate ( StdMeshMatManager manager)

Definition at line 23 of file StdMeshUpdate.cpp.

23  :
24  MaterialManager(manager)
25 {
26 }

Member Function Documentation

void StdMeshMaterialUpdate::Cancel ( ) const

Definition at line 71 of file StdMeshUpdate.cpp.

Referenced by C4DefGraphicsPtrBackup::AssignRemoval().

72 {
73  // Reset all materials in manager
74  for(const auto & Material : Materials)
75  MaterialManager.Materials[Material.second.Name] = Material.second; // TODO: could be moved
76 }

Here is the caller graph for this function:

void StdMeshMaterialUpdate::Update ( StdMesh mesh) const

Definition at line 28 of file StdMeshUpdate.cpp.

References StdMeshMatManager::GetMaterial().

Referenced by C4DefGraphicsPtrBackup::AssignUpdate().

29 {
30  for(auto & SubMesh : mesh->SubMeshes)
31  {
32  auto mat_iter = Materials.find(SubMesh.Material);
33  if(mat_iter != Materials.end())
34  {
35  const StdMeshMaterial* new_material = MaterialManager.GetMaterial(mat_iter->second.Name.getData());
36 
37  if(new_material)
38  {
39  SubMesh.Material = new_material;
40  }
41  else
42  {
43  // If no replacement material is available, then re-insert the previous
44  // material into the material map. This is mainly just to keep things
45  // going - next time the scenario will be started the mesh will fail
46  // to load because the material cannot be found.
47  MaterialManager.Materials[mat_iter->second.Name] = mat_iter->second; // TODO: could be moved
48  SubMesh.Material = MaterialManager.GetMaterial(mat_iter->second.Name.getData());
49  }
50  }
51  }
52 }
const StdMeshMaterial * GetMaterial(const char *material_name) const

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshMaterialUpdate::Update ( StdMeshInstance instance) const

Definition at line 54 of file StdMeshUpdate.cpp.

References StdMeshMatManager::GetMaterial(), StdMeshInstance::GetMesh(), StdMesh::GetSubMesh(), StdSubMeshInstance::Material, StdSubMeshInstance::SetMaterial(), and StdMeshInstance::SubMeshInstances.

55 {
56  for(unsigned int i = 0; i < instance->SubMeshInstances.size(); ++i)
57  {
58  StdSubMeshInstance* sub_instance = instance->SubMeshInstances[i];
59  std::map<const StdMeshMaterial*, StdMeshMaterial>::const_iterator mat_iter = Materials.find(sub_instance->Material);
60  if(mat_iter != Materials.end())
61  {
62  // Material needs to be updated
63  const StdMeshMaterial* new_material = MaterialManager.GetMaterial(mat_iter->second.Name.getData());
64  // If new material is not available, fall back to StdMesh (definition) material
65  if(!new_material) new_material = instance->GetMesh().GetSubMesh(i).Material;
66  sub_instance->SetMaterial(*new_material);
67  }
68  }
69 }
const StdMeshMaterial * Material
Definition: StdMesh.h:282
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:198
void SetMaterial(const StdMeshMaterial &material)
Definition: StdMesh.cpp:696
const StdMeshMaterial * GetMaterial(const char *material_name) const
const StdMesh & GetMesh() const
Definition: StdMesh.h:622
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:655

Here is the call graph for this function:

Friends And Related Function Documentation

friend class StdMeshMatManager
friend

Definition at line 28 of file StdMeshUpdate.h.


The documentation for this class was generated from the following files: