// KSeqModel.h: interface for the KSeqModel class. // ////////////////////////////////////////////////////////////////////// #pragma once #include "KSeqForm.h" #include #include "KPrimitiveSpeedTree.h" //SpeedTree Include #include #include "SSpeedTreeConfig.h" #include "SSpeedTreeMaterial.h" #include "KThreadLoader.h" const unsigned char TEXFLAG_SPEEDTREE = 0x01; class KSeqSpeedTree : public KSeqForm, public KThreadResource { public: KSeqSpeedTree( bool bInstance=false ); virtual ~KSeqSpeedTree(); /// { 쓰레드 로딩 virtual bool doLoading(); // } virtual void Render( KViewportObject *viewport, DWORD flag = RENDEREFX_NONE, const K3DMatrix * pAttachMat = NULL ); virtual int Process( DWORD dwTime ); // virtual int Process(DWORD dwTime, bool bControlLod, float fLodLevel); virtual void SetTransform( const K3DMatrix &mat ); virtual void ClipTest( const K3DVector* pFrustum ); virtual const K3DMatrix &GetTransform() { return m_matTransform; } // geometry bool LoadTree(KStream* pszSptStream, unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f, const float * pTransform = NULL); bool LoadTree(const char* pszSptFile, unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f, const float * pTransform = NULL); const K3DVector* GetPos(void) const { return &m_afPos; } void SetPos(const float* pPos); void SetPos(float x, float y,float z); const float* GetBoundingBox(void) const { return m_afBoundingBox; } virtual bool IsLoadCompleted() const { return (0 != m_bLoad); } // rendering void SetupBranchForTreeType(void); void SetupFrondForTreeType(void); void SetupLeafForTreeType(void); void EndLeafForTreeType(void); #ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT void UploadLeafTables(unsigned int uiLocation); #endif void RenderBranches(void) ; void RenderFronds(void) ; void RenderLeaves(void) ; void RenderBillboards(void) ; // instancing // KSeqSpeedTree** GetInstances(unsigned int& nCount); KSeqSpeedTree* InstanceOf(void) const { return m_pInstanceOf; } virtual bool CopyFrom( KThreadResource* pResource ); void CopyFromTree(KSeqSpeedTree* pSource); CSpeedTreeRT* GetSpeedTree(void) const { return m_pSpeedTree; } // lighting const CSpeedTreeMaterial& GetBranchMaterial(void) const { return m_cBranchMaterial; } const CSpeedTreeMaterial& GetFrondMaterial(void) const { return m_cFrondMaterial; } const CSpeedTreeMaterial& GetLeafMaterial(void) const { return m_cLeafMaterial; } float GetLeafLightingAdjustment(void) const { return m_pSpeedTree->GetLeafLightingAdjustment( ); } float GetWindStrength() { return m_fWindStrength; } // 추가 - blackfish void GetBranchTextureName(std::string& name); void GetFrondTextureName(std::string& name); void GetLeafTextureName(std::string& name); void GetCompositeTextureName(std::string& name); int GetBranchPolyCount(float fLod); int GetFrondPolyCount(float fLod); int GetLeafPolyCount(float fLod); // wind //void SetWindStrength(float fStrength) { (void) m_pSpeedTree->SetWindStrength(fStrength); } // 변경 - blackfish void SetWindStrength(float fStrength) { m_fWindStrength = fStrength; (void) m_pSpeedTree->SetWindStrength(fStrength); } void Advance(bool bControlLod = false, float fLodLevel = 1.0f); // utility static void SetRenderingDevice(class K3DRenderDevice * pDevice) { m_pDevice = pDevice; } /// CSpeedTree::SetCamera()를 실행한다 static void SetCamera(const K3DVector cameraPos, const K3DVector cameraDirection); /// 내부적으로 camera target위치를 저장한다 static void SetCameraTargetPosition(const K3DVector targetPos); static void SetTranparentMode( bool bMode ) { s_bTransparentMode = bMode; } static bool IsTranparentMode() { return s_bTransparentMode; } const K3DTexture* GetBranchTexture(void) const { return m_spTexBranchTexture; } void CleanUpMemory(void); virtual K3DBoundRotCube* GetBoundCube( const char * pName = NULL ); virtual void SetLodLevel( float fValue /*0.f~1.f*/ ); virtual void *Perform( KID id, KArg& msg ); static void ToggleSpeedTreeRender() { S_bSpeedTreeRender = !S_bSpeedTreeRender; } static void SetSpeedTreeRender( bool bFlag ) { S_bSpeedTreeRender = bFlag; } private: bool _load( unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f, const float * pTransform = NULL); void SetupBuffers(void); void SetupBranchBuffers(void); void SetupFrondBuffers(void); void SetupLeafBuffers(void); void PositionTree(void); //static K3DTexture* LoadTexture(const char* pFilename); K3DTexture* LoadTexture(const char* pFilename); void SetShaderConstants(const float* pMaterial); private: float m_fWindStrength; ///< 바람 세기~ float m_fNearLod; float m_fFarLod; bool m_bIsProcessed; // SpeedTreeRT data CSpeedTreeRT* m_pSpeedTree; ///< SpeedTree object CSpeedTreeRT::STextures* m_pTextureInfo; ///< cached texture info bool m_bIsInstance; ///< is this tree an instance? std::vector m_vInstances; ///< list of instances of this tree KSeqSpeedTree* m_pInstanceOf; ///< this tree is an instance of what // geometry cache CSpeedTreeRT::SGeometry* m_pGeometryCache; ///< geometry cache // branch buffers K3DVertexBufferSPtr m_spBranchVertexBuffer; ///< branch vertex buffer unsigned int m_unBranchVertexCount; ///< number of vertices in branches K3DIndexBufferSPtr m_spBranchIndexBuffer; ///< branch index buffer unsigned short* m_pBranchIndexCounts; ///< number of indexes per branch LOD level // frond buffers unsigned int m_unNumFrondLods; ///< number of frond LODs K3DVertexBufferSPtr m_spFrondVertexBuffer; ///< frond vertex buffer unsigned int m_unFrondVertexCount; ///< number of vertices in frond K3DIndexBufferSPtr* m_spFrondIndexBufferArray; ///< frond index buffers unsigned short* m_pFrondIndexCounts; ///< number of indexes per frond LOD level // leaf buffers unsigned short m_usNumLeafLods; ///< the number of leaf LODs K3DVertexBufferSPtr* m_spLeafVertexBufferArray; ///< leaf vertex buffer bool* m_pLeavesUpdatedByCpu; ///< stores which LOD's have been updated already per frame // tree properties K3DVector m_afPos; float m_afBoundingBox[6]; ///< tree's bounding box // materials CSpeedTreeMaterial m_cBranchMaterial; ///< branch material CSpeedTreeMaterial m_cLeafMaterial; ///< leaf material CSpeedTreeMaterial m_cFrondMaterial; ///< frond material // branch texture K3DTextureSPtr m_spTexBranchTexture; ///< branch texture object K3DTextureSPtr m_spTexFrondTexture; ///< branch texture object K3DTextureSPtr m_spTexLeafTexture; ///< branch texture object #ifdef WRAPPER_BILLBOARD_MODE K3DTextureSPtr m_spTexBillboardTexture; #endif K3DTextureSPtr m_spTexShadow; ///< shadow texture object K3DTextureSPtr m_spTexCompositeMap; ///< composite texture static unsigned int m_unNumWrappersActive; ///< texture loading float m_fCurrLodLevel; ///< 0.f~1.f LodLevel protected: static class K3DRenderDevice * m_pDevice; static K3DVector m_afCameraPos, m_afCameraDirection; ///< Camera position & direction static K3DVector m_afCameraTargetPos; ///< Camera target position (Note: 내부 계산용 값. Camera direction과는 관련 없음) static bool s_bTransparentMode; static bool S_bSpeedTreeRender; D3DXVECTOR4 m_vecConstant; SSpeedTreePrimitive m_prBranch; SSpeedTreePrimitive m_prLeaf; SSpeedTreePrimitive m_prFrond; #ifdef WRAPPER_BILLBOARD_MODE SSpeedTreePrimitive m_prBillboard; #endif /// 쉐이더 상수 float m_afUsefulConstants[4]; float m_afMaterial[8]; BOOL m_bLoad; };