OpenClonk
StdSubMeshInstance Class Reference

#include <StdMesh.h>

Collaboration diagram for StdSubMeshInstance:
[legend]

Classes

struct  Pass
 
struct  TexUnit
 

Public Types

enum  FaceOrdering { FO_Fixed, FO_FarthestToNearest, FO_NearestToFarthest }
 

Public Member Functions

 StdSubMeshInstance (class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
 
void LoadFacesForCompletion (class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
 
void CompileFunc (StdCompiler *pComp)
 
const StdMeshFaceGetFaces () const
 
size_t GetNumFaces () const
 
const StdSubMeshGetSubMesh () const
 
unsigned int GetTexturePhase (size_t pass, size_t texunit) const
 
double GetTexturePosition (size_t pass, size_t texunit) const
 
const StdMeshMaterialGetMaterial () const
 
FaceOrdering GetFaceOrdering () const
 

Protected Member Functions

void SetMaterial (const StdMeshMaterial &material)
 
void SetFaceOrdering (class StdMeshInstance &instance, const StdSubMesh &submesh, FaceOrdering ordering)
 
void SetFaceOrderingForClrModulation (class StdMeshInstance &instance, const StdSubMesh &submesh, uint32_t clrmod)
 

Protected Attributes

const StdSubMeshbase
 
std::vector< StdMeshFaceFaces
 
const StdMeshMaterialMaterial
 
std::vector< PassPassData
 
FaceOrdering CurrentFaceOrdering
 

Friends

class StdMeshInstance
 
class StdMeshMaterialUpdate
 

Detailed Description

Definition at line 242 of file StdMesh.h.


Class Documentation

◆ StdSubMeshInstance::Pass

struct StdSubMeshInstance::Pass

Definition at line 295 of file StdMesh.h.

Class Members
vector< TexUnit > TexUnits

◆ StdSubMeshInstance::TexUnit

struct StdSubMeshInstance::TexUnit

Definition at line 284 of file StdMesh.h.

Class Members
unsigned int Phase
float PhaseDelay
double Position

Member Enumeration Documentation

◆ FaceOrdering

Enumerator
FO_Fixed 
FO_FarthestToNearest 
FO_NearestToFarthest 

Definition at line 248 of file StdMesh.h.

Constructor & Destructor Documentation

◆ StdSubMeshInstance()

StdSubMeshInstance::StdSubMeshInstance ( class StdMeshInstance instance,
const StdSubMesh submesh,
float  completion 
)

Definition at line 658 of file StdMesh.cpp.

References StdSubMesh::GetMaterial(), LoadFacesForCompletion(), and SetMaterial().

658  :
659  base(&submesh), Material(nullptr), CurrentFaceOrdering(FO_Fixed)
660 {
661 #ifndef USE_CONSOLE
662  LoadFacesForCompletion(instance, submesh, completion);
663 #endif
664 
665  SetMaterial(submesh.GetMaterial());
666 }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:301
void LoadFacesForCompletion(class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
Definition: StdMesh.cpp:668
const StdMeshMaterial * Material
Definition: StdMesh.h:282
const StdMeshMaterial & GetMaterial() const
Definition: StdMesh.h:170
const StdSubMesh * base
Definition: StdMesh.h:278
void SetMaterial(const StdMeshMaterial &material)
Definition: StdMesh.cpp:696
Here is the call graph for this function:

Member Function Documentation

◆ CompileFunc()

void StdSubMeshInstance::CompileFunc ( StdCompiler pComp)

Definition at line 753 of file StdMesh.cpp.

References StdCompiler::excCorrupt(), StdStrBuf::Format(), StdStrBuf::getData(), StdMeshMatManager::GetMaterial(), StdCompiler::isDeserializer(), Material, MeshMaterialManager, mkNamingAdapt(), StdMeshMaterial::Name, SetMaterial(), and StdCompiler::Value().

754 {
755  // TODO: We should also serialize the texture animation positions
756  if(pComp->isDeserializer())
757  {
758  StdCopyStrBuf material_name;
759  pComp->Value(mkNamingAdapt(material_name, "Material"));
760  if(material_name != Material->Name)
761  {
762  const StdMeshMaterial* material = ::MeshMaterialManager.GetMaterial(material_name.getData());
763  if(!material)
764  {
765  StdStrBuf buf;
766  buf.Format(R"(There is no such material with name "%s")", material_name.getData());
767  pComp->excCorrupt(buf.getData());
768  }
769 
770  SetMaterial(*material);
771  }
772  }
773  else
774  {
775  StdCopyStrBuf material_name = Material->Name;
776  pComp->Value(mkNamingAdapt(material_name, "Material"));
777  }
778 }
const StdMeshMaterial * Material
Definition: StdMesh.h:282
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
const StdMeshMaterial * GetMaterial(const char *material_name) const
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Value(const T &rStruct)
Definition: StdCompiler.h:161
const char * getData() const
Definition: StdBuf.h:442
virtual bool isDeserializer()
Definition: StdCompiler.h:53
void SetMaterial(const StdMeshMaterial &material)
Definition: StdMesh.cpp:696
StdCopyStrBuf Name
StdMeshMatManager MeshMaterialManager
Here is the call graph for this function:

◆ GetFaceOrdering()

FaceOrdering StdSubMeshInstance::GetFaceOrdering ( ) const
inline

Definition at line 272 of file StdMesh.h.

272 { return CurrentFaceOrdering; }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:301

◆ GetFaces()

const StdMeshFace* StdSubMeshInstance::GetFaces ( ) const
inline

Definition at line 263 of file StdMesh.h.

263 { return Faces.size() > 0 ? &Faces[0] : nullptr; }
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:280

◆ GetMaterial()

const StdMeshMaterial& StdSubMeshInstance::GetMaterial ( ) const
inline

Definition at line 270 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimation(), and CStdGL::PrepareMaterial().

270 { return *Material; }
const StdMeshMaterial * Material
Definition: StdMesh.h:282
Here is the caller graph for this function:

◆ GetNumFaces()

size_t StdSubMeshInstance::GetNumFaces ( ) const
inline

Definition at line 264 of file StdMesh.h.

264 { return Faces.size(); }
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:280

◆ GetSubMesh()

const StdSubMesh& StdSubMeshInstance::GetSubMesh ( ) const
inline

Definition at line 265 of file StdMesh.h.

Referenced by CStdGL::PrepareMaterial(), and StdMeshInstance::ReorderFaces().

265 { return *base; }
const StdSubMesh * base
Definition: StdMesh.h:278
Here is the caller graph for this function:

◆ GetTexturePhase()

unsigned int StdSubMeshInstance::GetTexturePhase ( size_t  pass,
size_t  texunit 
) const
inline

Definition at line 267 of file StdMesh.h.

267 { return PassData[pass].TexUnits[texunit].Phase; }
std::vector< Pass > PassData
Definition: StdMesh.h:300

◆ GetTexturePosition()

double StdSubMeshInstance::GetTexturePosition ( size_t  pass,
size_t  texunit 
) const
inline

Definition at line 268 of file StdMesh.h.

Referenced by CStdGL::PrepareMaterial().

268 { return PassData[pass].TexUnits[texunit].Position; }
std::vector< Pass > PassData
Definition: StdMesh.h:300
Here is the caller graph for this function:

◆ LoadFacesForCompletion()

void StdSubMeshInstance::LoadFacesForCompletion ( class StdMeshInstance instance,
const StdSubMesh submesh,
float  completion 
)

Definition at line 668 of file StdMesh.cpp.

References Faces, FO_FarthestToNearest, StdSubMesh::GetFace(), StdSubMesh::GetNumFaces(), StdSubMesh::GetNumVertices(), StdMeshInstance::GetSharedVertices(), StdSubMesh::GetVertices(), and StdMeshMatrix::Identity().

Referenced by SetFaceOrdering(), and StdSubMeshInstance().

669 {
670 #ifndef USE_CONSOLE
671  // First: Copy all faces
672  Faces.resize(submesh.GetNumFaces());
673  for (unsigned int i = 0; i < submesh.GetNumFaces(); ++i)
674  Faces[i] = submesh.GetFace(i);
675 
676  if(completion < 1.0f)
677  {
678  // Second: Order by Y position. StdMeshInstanceFaceOrderingCmpPred orders by Z position,
679  // however we can simply give an appropriate transformation matrix to the face ordering.
680  // At this point, all vertices are in the OGRE coordinate frame, and Z in OGRE equals
681  // Y in Clonk, so we are fine without additional transformation.
682  const StdMeshVertex* vertices;
683  if(submesh.GetNumVertices() > 0)
684  vertices = &submesh.GetVertices()[0];
685  else
686  vertices = &instance.GetSharedVertices()[0];
687  SortFacesArray(vertices, Faces, FO_FarthestToNearest, StdMeshMatrix::Identity());
688 
689  // Third: Only use the first few ones
690  assert(submesh.GetNumFaces() >= 1);
691  Faces.resize(Clamp<unsigned int>(static_cast<unsigned int>(completion * submesh.GetNumFaces() + 0.5), 1, submesh.GetNumFaces()));
692  }
693 #endif
694 }
size_t GetNumFaces() const
Definition: StdMesh.h:168
size_t GetNumVertices() const
Definition: StdMesh.h:165
const std::vector< Vertex > & GetVertices() const
Definition: StdMesh.h:163
static StdMeshMatrix Identity()
const StdMeshFace & GetFace(size_t i) const
Definition: StdMesh.h:167
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:280
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFaceOrdering()

void StdSubMeshInstance::SetFaceOrdering ( class StdMeshInstance instance,
const StdSubMesh submesh,
FaceOrdering  ordering 
)
protected

Definition at line 725 of file StdMesh.cpp.

References CurrentFaceOrdering, FO_Fixed, StdMeshInstance::GetCompletion(), and LoadFacesForCompletion().

Referenced by SetFaceOrderingForClrModulation().

726 {
727 #ifndef USE_CONSOLE
728  if (CurrentFaceOrdering != ordering)
729  {
730  CurrentFaceOrdering = ordering;
731  if (ordering == FO_Fixed)
732  {
733  LoadFacesForCompletion(instance, submesh, instance.GetCompletion());
734  }
735  }
736 #endif
737 }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:301
void LoadFacesForCompletion(class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
Definition: StdMesh.cpp:668
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFaceOrderingForClrModulation()

void StdSubMeshInstance::SetFaceOrderingForClrModulation ( class StdMeshInstance instance,
const StdSubMesh submesh,
uint32_t  clrmod 
)
protected

Definition at line 739 of file StdMesh.cpp.

References FO_FarthestToNearest, FO_Fixed, FO_NearestToFarthest, StdMeshMaterial::IsOpaque(), Material, and SetFaceOrdering().

740 {
741 #ifndef USE_CONSOLE
742  bool opaque = Material->IsOpaque();
743 
744  if(!opaque)
745  SetFaceOrdering(instance, submesh, FO_FarthestToNearest);
746  else if( ((clrmod >> 24) & 0xff) != 0xff)
747  SetFaceOrdering(instance, submesh, FO_NearestToFarthest);
748  else
749  SetFaceOrdering(instance, submesh, FO_Fixed);
750 #endif
751 }
const StdMeshMaterial * Material
Definition: StdMesh.h:282
void SetFaceOrdering(class StdMeshInstance &instance, const StdSubMesh &submesh, FaceOrdering ordering)
Definition: StdMesh.cpp:725
bool IsOpaque() const
Here is the call graph for this function:

◆ SetMaterial()

void StdSubMeshInstance::SetMaterial ( const StdMeshMaterial material)
protected

Definition at line 696 of file StdMesh.cpp.

References StdMeshMaterial::BestTechniqueIndex, Material, PassData, StdMeshMaterialTechnique::Passes, StdSubMeshInstance::TexUnit::Phase, StdSubMeshInstance::TexUnit::PhaseDelay, StdSubMeshInstance::TexUnit::Position, StdMeshMaterial::Techniques, and StdMeshMaterialPass::TextureUnits.

Referenced by CompileFunc(), StdSubMeshInstance(), and StdMeshMaterialUpdate::Update().

697 {
698  Material = &material;
699 
700 #ifndef USE_CONSOLE
701  // Setup initial texture animation data
702  assert(Material->BestTechniqueIndex >= 0);
704  PassData.resize(technique.Passes.size());
705  for (unsigned int i = 0; i < PassData.size(); ++i)
706  {
707  const StdMeshMaterialPass& pass = technique.Passes[i];
708  // Clear from previous material
709  PassData[i].TexUnits.clear();
710 
711  for (unsigned int j = 0; j < pass.TextureUnits.size(); ++j)
712  {
713  TexUnit unit;
714  unit.Phase = 0;
715  unit.PhaseDelay = 0.0f;
716  unit.Position = 0.0;
717  PassData[i].TexUnits.push_back(unit);
718  }
719  }
720 
721  // TODO: Reset face ordering
722 #endif
723 }
const StdMeshMaterial * Material
Definition: StdMesh.h:282
std::vector< Pass > PassData
Definition: StdMesh.h:300
std::vector< StdMeshMaterialPass > Passes
std::vector< StdMeshMaterialTextureUnit > TextureUnits
std::vector< StdMeshMaterialTechnique > Techniques
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ StdMeshInstance

friend class StdMeshInstance
friend

Definition at line 244 of file StdMesh.h.

◆ StdMeshMaterialUpdate

friend class StdMeshMaterialUpdate
friend

Definition at line 245 of file StdMesh.h.

Member Data Documentation

◆ base

const StdSubMesh* StdSubMeshInstance::base
protected

Definition at line 278 of file StdMesh.h.

◆ CurrentFaceOrdering

FaceOrdering StdSubMeshInstance::CurrentFaceOrdering
protected

Definition at line 301 of file StdMesh.h.

Referenced by StdMeshInstance::ReorderFaces(), and SetFaceOrdering().

◆ Faces

std::vector<StdMeshFace> StdSubMeshInstance::Faces
protected

Definition at line 280 of file StdMesh.h.

Referenced by LoadFacesForCompletion(), and StdMeshInstance::ReorderFaces().

◆ Material

const StdMeshMaterial* StdSubMeshInstance::Material
protected

◆ PassData

std::vector<Pass> StdSubMeshInstance::PassData
protected

Definition at line 300 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimation(), and SetMaterial().


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