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 22 of file StdMeshUpdate.cpp.

22  :
23  MaterialManager(manager)
24 {
25 }

Member Function Documentation

void StdMeshMaterialUpdate::Cancel ( ) const

Definition at line 70 of file StdMeshUpdate.cpp.

Referenced by C4DefGraphicsPtrBackup::AssignRemoval().

71 {
72  // Reset all materials in manager
73  for(std::map<const StdMeshMaterial*, StdMeshMaterial>::const_iterator iter = Materials.begin(); iter != Materials.end(); ++iter)
74  MaterialManager.Materials[iter->second.Name] = iter->second; // TODO: could be moved
75 }

Here is the caller graph for this function:

void StdMeshMaterialUpdate::Update ( StdMesh mesh) const

Definition at line 27 of file StdMeshUpdate.cpp.

References StdMeshMatManager::GetMaterial().

Referenced by C4DefGraphicsPtrBackup::AssignUpdate().

28 {
29  for(std::vector<StdSubMesh>::iterator iter = mesh->SubMeshes.begin(); iter != mesh->SubMeshes.end(); ++iter)
30  {
31  std::map<const StdMeshMaterial*, StdMeshMaterial>::const_iterator mat_iter = Materials.find(iter->Material);
32  if(mat_iter != Materials.end())
33  {
34  const StdMeshMaterial* new_material = MaterialManager.GetMaterial(mat_iter->second.Name.getData());
35 
36  if(new_material)
37  {
38  iter->Material = new_material;
39  }
40  else
41  {
42  // If no replacement material is available, then re-insert the previous
43  // material into the material map. This is mainly just to keep things
44  // going - next time the scenario will be started the mesh will fail
45  // to load because the material cannot be found.
46  MaterialManager.Materials[mat_iter->second.Name] = mat_iter->second; // TODO: could be moved
47  iter->Material = MaterialManager.GetMaterial(mat_iter->second.Name.getData());
48  }
49  }
50  }
51 }
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 53 of file StdMeshUpdate.cpp.

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

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

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: