363 lines
8.8 KiB
C++
363 lines
8.8 KiB
C++
#pragma once
|
|
|
|
#include "K3DTypes.h"
|
|
#include "KResource.h"
|
|
//#include <vector>
|
|
#include "KPrimitive.h"
|
|
#include "kRenderDefine.h"
|
|
|
|
class KViewportObject;
|
|
class K3DRenderDevice;
|
|
|
|
|
|
class KMeshPrimitive : public K3DPrimitive
|
|
{
|
|
public:
|
|
KMeshPrimitive();
|
|
virtual ~KMeshPrimitive();
|
|
void Clear();
|
|
|
|
void SetRenderState( int renderstate )
|
|
{
|
|
m_nRenderState = renderstate;
|
|
}
|
|
|
|
void SetUVTransform( K3DMatrix *transform ) { m_pUVTransform = transform; }
|
|
K3DMatrix* GetUVTransform() { return m_pUVTransform; }
|
|
|
|
void SetIndexBuffer(/* int index,*/ K3DIndexBuffer *buf )
|
|
{
|
|
//if( index >= m_nSubCount ) return;
|
|
//m_ppIB[index] = buf;
|
|
m_spIB = buf;
|
|
}
|
|
K3DIndexBuffer* GetIndexBuffer(/* int index*/)
|
|
{
|
|
//if( index >= m_nSubCount ) return NULL;
|
|
return m_spIB/*[index]*/;
|
|
}
|
|
|
|
void SetVertexBuffer(/* int index,*/ K3DVertexBuffer *buf )
|
|
{
|
|
//if( index >= m_nSubCount ) return;
|
|
m_spVB/*[index]*/ = buf;
|
|
}
|
|
K3DVertexBuffer* GetVertexBuffer(/*int index*/)
|
|
{
|
|
//if( index >= m_nSubCount ) return NULL;
|
|
return m_spVB/*[index]*/;
|
|
}
|
|
|
|
void SetPrimitivesCount(/*int i,*/ int n) { m_nPrimitivesCount/*[i]*/ = n; }
|
|
int GetPrimitivesCount(/*int i*/) { return m_nPrimitivesCount/*[i]*/; }
|
|
|
|
inline void SetWeight( K3DWeight *buf )
|
|
{
|
|
m_pWeight = buf;
|
|
}
|
|
K3DWeight* GetWeight()
|
|
{
|
|
return m_pWeight;
|
|
}
|
|
|
|
void SetMaterial( K3DMaterial *mtl )
|
|
{
|
|
m_pMtl = mtl;
|
|
}
|
|
K3DMaterial* GetMaterial()
|
|
{
|
|
return m_pMtl;
|
|
}
|
|
void SetTexture( struct TEXPACK * pTexPack )
|
|
{
|
|
SetBump( false );
|
|
SetSpecular( false );
|
|
|
|
if(pTexPack->spTexture_Bump != NULL)
|
|
{
|
|
SetBump( true );
|
|
}
|
|
else if( pTexPack->spTexture_Specular != NULL && pTexPack->spTexture_SpecularColor != NULL)
|
|
{
|
|
SetSpecular( true ); //스페큘러 설정 <= 더 적절한 곳에서 설정 하도록 수정 요망
|
|
}
|
|
|
|
if(pTexPack->spTexture_Light != NULL)
|
|
SetUseLightMap(true );
|
|
|
|
m_TexPack = *pTexPack;
|
|
}
|
|
|
|
struct TEXPACK *GetTexPack() { return &m_TexPack; }
|
|
|
|
void SetDiffuseTexture(K3DTexture* pTex)
|
|
{
|
|
m_TexPack.spTexture = pTex;
|
|
}
|
|
|
|
void SetSpecularTexture(K3DTexture* pTex)
|
|
{
|
|
m_TexPack.spTexture_Specular = pTex;
|
|
}
|
|
|
|
void SetBumpTexture(K3DTexture* pTex)
|
|
{
|
|
m_TexPack.spTexture_Bump = pTex;
|
|
}
|
|
|
|
K3DTexture* GetDiffuseTexture()
|
|
{
|
|
return m_TexPack.spTexture;
|
|
}
|
|
K3DTexture* GetSpecularColorTexture()
|
|
{
|
|
return m_TexPack.spTexture_SpecularColor;
|
|
}
|
|
K3DTexture* GetSpecularTexture()
|
|
{
|
|
return m_TexPack.spTexture_Specular;
|
|
}
|
|
K3DTexture* GetBumpTexture()
|
|
{
|
|
return m_TexPack.spTexture_Bump;
|
|
}
|
|
K3DTexture* GetSelfIlluminationTexture()
|
|
{
|
|
return m_TexPack.spTexture_Illumin;
|
|
}
|
|
|
|
K3DTexture* GetLightMapTexture()
|
|
{
|
|
return m_TexPack.spTexture_Light;
|
|
}
|
|
void SetLightMapTexture(K3DTexture* pTex)
|
|
{
|
|
m_TexPack.spTexture_Light = pTex;
|
|
SetUseLightMap(NULL != pTex);
|
|
}
|
|
|
|
void SetFixMapTexture(K3DTexture* pTex)
|
|
{
|
|
m_TexPack.spTexture_Fix = pTex;
|
|
SetUseFixMap(NULL != pTex);
|
|
}
|
|
|
|
void SetBlendedInfo( int nBoneCount, K3DMatrix * pOffMat, K3DMatrix * pBoneMat )
|
|
{
|
|
m_nBoneCount = nBoneCount;
|
|
m_pOffSetMat = pOffMat;
|
|
m_pBoneMat = pBoneMat;
|
|
}
|
|
|
|
int getBoneCount() { return m_nBoneCount; }
|
|
K3DMatrix *getOffsetMatrix() { return m_pOffSetMat; }
|
|
K3DMatrix *getBoneMatrix() { return m_pBoneMat; }
|
|
|
|
|
|
/// Render to viewport.
|
|
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
|
|
|
|
virtual DWORD GetMagicNumber()
|
|
{
|
|
//if(m_nSubCount <= 0) return 0;
|
|
K3DVertexBuffer* tbuf = m_spVB;
|
|
// warning 안보려고 강제로 이렇게 했슴. 버그 아니에요.
|
|
return (*((DWORD *)&tbuf)&0x00FFFFFF) + (((BYTE)(m_fVisibility*255))<<24);
|
|
}
|
|
|
|
void SetSkinDiffuse( KColor & diffuse )
|
|
{
|
|
m_SkinDiffuse = diffuse;
|
|
}
|
|
|
|
void SetBoundOcclusion( class K3DBoundOcclusion* pBoundOcclusion )
|
|
{
|
|
m_pBoundOcclusion = pBoundOcclusion;
|
|
}
|
|
|
|
bool SupportsBoundOcclusion()
|
|
{
|
|
return m_pBoundOcclusion != NULL ? true : false;
|
|
}
|
|
|
|
void RenderBoundOcclusion( KViewportObject* pViewport, K3DRenderDevice* pDev );
|
|
|
|
void SetMTETexture( K3DTexture* pTex )
|
|
{
|
|
m_TexPack.spTexture_MTE = pTex;
|
|
m_bIsMTE = ( NULL != pTex );
|
|
}
|
|
|
|
protected:
|
|
/// Manager에서 texture를 읽어옴
|
|
K3DTexture *getTexture(const char *texname);
|
|
|
|
private:
|
|
void _SetMatrixArrayForVS(KViewportObject* pViewport, K3DRenderDevice* pDev, bool bUseAccum);
|
|
void _SetSpecularBumpTexture(KViewportObject* pViewport, K3DRenderDevice* pDev);
|
|
void _SetHalfWay(KViewportObject* pViewport, K3DRenderDevice* pDev);
|
|
|
|
private:
|
|
//int m_nSubCount;
|
|
|
|
K3DIndexBufferSPtr m_spIB;
|
|
K3DVertexBufferSPtr m_spVB;
|
|
int m_nPrimitivesCount;
|
|
|
|
struct TEXPACK m_TexPack;
|
|
K3DMaterial* m_pMtl;
|
|
|
|
K3DMatrix* m_pUVTransform;
|
|
int m_nRenderState;
|
|
//Shader HW
|
|
int m_nBoneCount;
|
|
K3DMatrix* m_pOffSetMat;
|
|
K3DMatrix* m_pBoneMat;
|
|
|
|
K3DWeight* m_pWeight;
|
|
float m_fHalfWay[4];
|
|
|
|
KColor m_SkinDiffuse; ///< a는 안쓴다
|
|
|
|
|
|
class K3DBoundOcclusion* m_pBoundOcclusion;
|
|
};
|
|
|
|
class KPlanUtilPrimitive : public K3DPrimitive
|
|
{
|
|
public:
|
|
KPlanUtilPrimitive();
|
|
virtual ~KPlanUtilPrimitive();
|
|
void Clear();
|
|
|
|
void SetTransform( const K3DMatrix &transform ) { m_matTransform = transform; }
|
|
void SetMaterial( const K3DMaterial &mtl ) { m_Mtl = mtl; }
|
|
|
|
void AddVertex( const K3DVector &vertex1, const K3DVector &vertex2, const K3DVector &vertex3, const KColor &diffuse );
|
|
|
|
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
|
|
|
|
int GetWireVertexCnt() { return (int)m_verts.size(); }
|
|
|
|
struct PLANVERTEX
|
|
{
|
|
K3DVector pos;
|
|
KColor diffuse;
|
|
};
|
|
|
|
int m_nVtxFormat;
|
|
int m_nVtxStride;
|
|
std::vector<PLANVERTEX> m_verts;
|
|
int m_nCurCount;
|
|
int m_nVerCount;
|
|
K3DMaterial m_Mtl;
|
|
K3DMatrix m_matTransform;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
class KWireUtilPrimitive : public K3DPrimitive
|
|
{
|
|
public:
|
|
|
|
enum
|
|
{
|
|
DRAW_LINE = 0,
|
|
DRAW_STRIP,
|
|
};
|
|
|
|
KWireUtilPrimitive();
|
|
virtual ~KWireUtilPrimitive();
|
|
void Clear();
|
|
|
|
void SetTransform( const K3DMatrix &transform ) { m_matTransform = transform; }
|
|
void SetMaterial( const K3DMaterial &mtl ) { m_Mtl = mtl; }
|
|
|
|
void SetDrawType( int nDrawType ) { m_nDrawType = nDrawType; }
|
|
|
|
void AddLine( const K3DVector &pos1, const K3DVector &pos2, const KColor &diffuse );
|
|
void AddSphere( const K3DVector ¢er, float radius, const KColor& diffuse, int lineCount );
|
|
|
|
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
|
|
|
|
int GetWireVertexCnt() { return (int)m_verts.size(); }
|
|
|
|
struct WIREVERTEX
|
|
{
|
|
K3DVector pos;
|
|
KColor diffuse;
|
|
};
|
|
|
|
private:
|
|
int m_nDrawType;
|
|
int m_nVtxFormat;
|
|
int m_nVtxStride;
|
|
std::vector<WIREVERTEX> m_verts;
|
|
int m_nCurCount;
|
|
int m_nVerCount;
|
|
K3DMaterial m_Mtl;
|
|
K3DMatrix m_matTransform;
|
|
};
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
class KIndexBufferDX_dynamic;
|
|
class KVertexBufferDX_dynamic;
|
|
|
|
/// 무기강화 용, 스케일 적용한 Mesh에 모두 응용 가능
|
|
class MorphedPrimitive : public KMeshPrimitive
|
|
{
|
|
public:
|
|
MorphedPrimitive();
|
|
virtual ~MorphedPrimitive();
|
|
|
|
virtual void init(KMeshPrimitive *source);
|
|
virtual void close();
|
|
|
|
virtual void Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum = true );
|
|
|
|
void SetEnable( bool bFlag ) { m_bEnableFlag = bFlag; }
|
|
|
|
protected:
|
|
/// called by init(), to initialize mesh
|
|
virtual void initMesh(KMeshPrimitive *source);
|
|
|
|
// Utility functions
|
|
void copyMesh(KMeshPrimitive *source); ///< source메쉬를 DynamicVertex포맷으로 카피
|
|
void calculateVertexNormals(); ///< Vertex normal을 싹 새로 계산
|
|
void offsetVertexPosition(float offset); ///< vertex.pos += vertex.normal * offset;
|
|
void setVertexColors(DWORD color0, DWORD color1); ///< 모든 vertex에 대해 색깔 변환
|
|
|
|
KIndexBufferDX_dynamic *indexBuffer; ///< Actual index buffer
|
|
KVertexBufferDX_dynamic *vertexBuffer; ///< Actual vertex buffer
|
|
int polygonCount; ///< copied to m_nPrimitivesCount
|
|
|
|
TEXPACK texpack; ///< Texture holder
|
|
int Additive;
|
|
|
|
bool m_bIsValidMinMax;
|
|
K3DVertex m_vMin, m_vMax;
|
|
|
|
bool m_bEnableFlag;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//=========================================================
|
|
/// 확대/축소된 mesh
|
|
//=========================================================
|
|
class FxResizedPrimitive : public MorphedPrimitive {
|
|
public:
|
|
FxResizedPrimitive();
|
|
void init(KMeshPrimitive *source ///< 오리지널 메쉬
|
|
, float _offset ///< 확대/축소할 크기, in global dimension
|
|
, DWORD _color0, DWORD _color1 ///< vertex color. ALPHATEX renderer포맷
|
|
, const char *_textureName=NULL ///< 텍스처 이름
|
|
, int nAdditive = 0 ///< Addtive
|
|
);
|
|
|
|
protected:
|
|
/// called by init(), to initialize mesh
|
|
virtual void initMesh(KMeshPrimitive *source);
|
|
float offset;
|
|
DWORD color0, color1;
|
|
const char *texName;
|
|
}; |