#include "jp/ggaf/dx/model/FramedBoardModel.h"

#include "jp/ggaf/dx/exception/CriticalException.h"
#include "jp/ggaf/dx/God.h"
#include "jp/ggaf/dx/effect/FramedBoardEffect.h"
#include "jp/ggaf/dx/actor/FramedBoardActor.h"
#include "jp/ggaf/dx/manager/TextureConnection.h"
#include "jp/ggaf/dx/manager/ModelManager.h"
#include "jp/ggaf/dx/manager/EffectManager.h"
#include "jp/ggaf/dx/texture/Texture.h"

#include "jp/ggaf/dx/manager/TextureManager.h"

#include "jp/ggaf/dx/model/MassModel.h"

using namespace GgafDx;

DWORD FramedBoardModel::FVF = (D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_TEX1);
FramedBoardModel::FramedBoardModel(const char* prm_model_name) : Model(prm_model_name) {
    _TRACE3_("_model_name="<<_model_name);
    _paVertexBuffer_data = nullptr;
    _pIndexBuffer_data = nullptr;

    _model_width_px = 32.0f;
    _model_height_px = 32.0f;
    _row_texture_split = 1;
    _col_texture_split = 1;
    _model_frame_width_px = 32.0f;
    _model_frame_height_px = 32.0f;
    _row_frame_texture_split = 1;
    _col_frame_texture_split = 1;
    _pVertexBuffer = nullptr;
    _pIndexBuffer = nullptr;
    _size_vertices = 0;
    _size_vertex_unit = 0;
    _obj_model |= Obj_GgafDx_FramedBoardModel;
    _set_num = 9;
}

HRESULT FramedBoardModel::draw(FigureActor* prm_pActor_target, int prm_draw_set_num, void* prm_pPrm) {
    _TRACE4_("FramedBoardModel::draw("<<prm_pActor_target->getName()<<") this="<<getName());
    IDirect3DDevice9* const pDevice = God::_pID3DDevice9;
    //懳徾Actor
    const FramedBoardActor* const pTargetActor = (FramedBoardActor*)prm_pActor_target;
    //懳徾FramedBoardActor偺僄僼僃僋僩儔僢僷
    FramedBoardEffect* const pFramedBoardEffect = (FramedBoardEffect*)prm_pActor_target->getEffect();
    //懳徾僄僼僃僋僩
    ID3DXEffect* const pID3DXEffect = pFramedBoardEffect->_pID3DXEffect;

    HRESULT hr;
    //儌僨儖偑摨偠側傜偽捀揰僶僢僼傽摍丄偺愝掕偼僗僉僢僾偱偒傞
    Model* pModelLastDraw = ModelManager::_pModelLastDraw;
    if (pModelLastDraw != this) {
        if (pModelLastDraw && (pModelLastDraw->_obj_model & Obj_GgafDx_MassModel)) {
            ((MassModel*)pModelLastDraw)->resetStreamSourceFreq();
        }
        pDevice->SetStreamSource(0, _pVertexBuffer, 0, _size_vertex_unit);
        pDevice->SetFVF(FramedBoardModel::FVF);
        pDevice->SetTexture(0, _papTextureConnection[0]->peek()->_pIDirect3DBaseTexture9);
        pDevice->SetTexture(1, _papTextureConnection[1]->peek()->_pIDirect3DBaseTexture9);
        pDevice->SetIndices(_pIndexBuffer);

        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_tex_blink_power, _power_blink);
        checkDxException(hr, D3D_OK, "SetFloat(_h_tex_blink_power) 偵幐攕偟傑偟偨丅");
        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_tex_blink_threshold, _blink_threshold);
        checkDxException(hr, D3D_OK, "SetFloat(_h_tex_blink_threshold) 偵幐攕偟傑偟偨丅");

        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_center_width, _model_width_px);
        checkDxException(hr, D3D_OK, "SetFloat(_h_unit_width) 偵幐攕偟傑偟偨丅");
        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_center_height, _model_height_px);
        checkDxException(hr, D3D_OK, "SetFloat(_h_unit_height) 偵幐攕偟傑偟偨丅");

        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_frame_width, _model_frame_width_px);
        checkDxException(hr, D3D_OK, "SetFloat(_h_unit_width) 偵幐攕偟傑偟偨丅");
        hr = pID3DXEffect->SetFloat(pFramedBoardEffect->_h_frame_height, _model_frame_height_px);
        checkDxException(hr, D3D_OK, "SetFloat(_h_unit_height) 偵幐攕偟傑偟偨丅");

    }
    Effect* pEffect_active = EffectManager::_pEffect_active;
    if (FigureActor::_hash_technique_last_draw != prm_pActor_target->_hash_technique)  {
        if (pEffect_active) {
           _TRACE4_("EndPass("<<pEffect_active->_pID3DXEffect<<"): /_pEffect_active="<<pEffect_active->_effect_name<<"("<<pEffect_active<<")");
            hr = pEffect_active->_pID3DXEffect->EndPass();
            checkDxException(hr, D3D_OK, "EndPass() 偵幐攕偟傑偟偨丅");
            hr = pEffect_active->_pID3DXEffect->End();
            checkDxException(hr, D3D_OK, "End() 偵幐攕偟傑偟偨丅");
#ifdef MY_DEBUG
            if (pEffect_active->_begin == false) {
                throwCriticalException("begin 偟偰偄傑偣傫 "<<(pEffect_active==nullptr?"nullptr":pEffect_active->_effect_name)<<"");
            } else {
                pEffect_active->_begin = false;
            }
#endif
        }
        _TRACE4_("SetTechnique("<<pTargetActor->_technique<<"): /actor="<<pTargetActor->getName()<<"/model="<<_model_name<<" effect="<<pFramedBoardEffect->_effect_name);
        hr = pID3DXEffect->SetTechnique(pTargetActor->_technique);
        checkDxException(hr, S_OK, "SetTechnique("<<pTargetActor->_technique<<") 偵幐攕偟傑偟偨丅");

        _TRACE4_("BeginPass("<<pID3DXEffect<<"): /actor="<<pTargetActor->getName()<<"/model="<<_model_name<<" effect="<<pFramedBoardEffect->_effect_name<<"("<<pFramedBoardEffect<<")");
        UINT numPass;
        hr = pID3DXEffect->Begin( &numPass, D3DXFX_DONOTSAVESTATE );
        checkDxException(hr, D3D_OK, "Begin() 偵幐攕偟傑偟偨丅");
        hr = pID3DXEffect->BeginPass(0);
        checkDxException(hr, D3D_OK, "BeginPass(0) 偵幐攕偟傑偟偨丅");

#ifdef MY_DEBUG
        if (pFramedBoardEffect->_begin) {
            throwCriticalException("End 偟偰偄傑偣傫 "<<(EffectManager::_pEffect_active==nullptr?"nullptr":EffectManager::_pEffect_active->_effect_name)<<"");
        } else {
            pFramedBoardEffect->_begin = true;
        }
#endif

    } else {
        hr = pID3DXEffect->CommitChanges();
        checkDxException(hr, D3D_OK, "CommitChanges() 偵幐攕偟傑偟偨丅");
    }
    _TRACE4_("DrawIndexedPrimitive: /actor="<<pTargetActor->getName()<<"/model="<<_model_name<<" effect="<<pFramedBoardEffect->_effect_name);
    pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
                                    _indexParam.BaseVertexIndex,
                                    _indexParam.MinIndex,
                                    _indexParam.NumVertices,
                                    _indexParam.StartIndex,
                                    _indexParam.PrimitiveCount);

    //慜夞昤夋儌僨儖曐帩
    ModelManager::_pModelLastDraw = this;
    EffectManager::_pEffect_active = pFramedBoardEffect;
    FigureActor::_hash_technique_last_draw = prm_pActor_target->_hash_technique;
#ifdef MY_DEBUG
        GgafCore::God::_num_drawing++;
#endif

    return D3D_OK;
}

void FramedBoardModel::restore() {
    _TRACE3_("_model_name=" << _model_name << " start");
    if (_paVertexBuffer_data == nullptr) {
        _set_num = 9;

        ModelManager* pModelManager = pGOD->_pModelManager;
        _papTextureConnection = nullptr;
        HRESULT hr;

        std::string xfile_name = ModelManager::getSpriteFileName(_model_name, "sprx");
        ModelManager::SpriteXFileFmt xdata;
        pModelManager->obtainSpriteInfo(&xdata, xfile_name);
        _model_width_px  = xdata.width;
        _model_height_px = xdata.height;
        _row_texture_split = xdata.row_texture_split;
        _col_texture_split = xdata.col_texture_split;

        std::string xfile_name_frame = ModelManager::getSpriteFileName(std::string(_model_name)+"_frame", "sprx");
        ModelManager::SpriteXFileFmt xdata_frame;
        pModelManager->obtainSpriteInfo(&xdata_frame, xfile_name_frame);
        _model_frame_width_px  = xdata_frame.width;
        _model_frame_height_px = xdata_frame.height;
        _row_frame_texture_split = xdata_frame.row_texture_split;
        _col_frame_texture_split = xdata_frame.col_texture_split;
        _pa_texture_filenames = NEW std::string[2];
        _pa_texture_filenames[0] = std::string(xdata.texture_file);
        _pa_texture_filenames[1] = std::string(xdata_frame.texture_file);

        _size_vertices = sizeof(FramedBoardModel::VERTEX)*4;
        _size_vertex_unit = sizeof(FramedBoardModel::VERTEX);
        _paVertexBuffer_data = NEW FramedBoardModel::VERTEX[4 * _set_num];
        //    劇劅劍劅劍劅劉
        //    劆侽劆侾劆俀劆
        //    劌劅劑劅劑劅劎
        //    劆俁劆係劆俆劆
        //    劌劅劑劅劑劅劎
        //    劆俇劆俈劆俉劆
        //    劋劅劏劅劏劅劊

        //1px偁偨傝偺uv偺戝偒偝傪媮傔傞
        double du = 0.0;
        double dv = 0.0;
        for (int i = 0; i < _set_num; i++) {
            if (i == 4) {
                //拞怱
                //嵍忋
                _paVertexBuffer_data[i*4 + 0].x = 0.0f;
                _paVertexBuffer_data[i*4 + 0].y = 0.0f;
                _paVertexBuffer_data[i*4 + 0].z = 0.0f;
                _paVertexBuffer_data[i*4 + 0].tu = (float)du;
                _paVertexBuffer_data[i*4 + 0].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 0].index = (float)i;
                //塃忋
                _paVertexBuffer_data[i*4 + 1].x = xdata.width;
                _paVertexBuffer_data[i*4 + 1].y = 0.0f;
                _paVertexBuffer_data[i*4 + 1].z = 0.0f;
                _paVertexBuffer_data[i*4 + 1].tu = (float)((1.0 / xdata.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 1].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 1].index = (float)i;
                //嵍壓
                _paVertexBuffer_data[i*4 + 2].x = 0.0f;
                _paVertexBuffer_data[i*4 + 2].y = xdata.height;
                _paVertexBuffer_data[i*4 + 2].z = 0.0f;
                _paVertexBuffer_data[i*4 + 2].tu = (float)du;
                _paVertexBuffer_data[i*4 + 2].tv = (float)((1.0 / xdata.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 2].index = (float)i;
                //塃壓
                _paVertexBuffer_data[i*4 + 3].x = xdata.width;
                _paVertexBuffer_data[i*4 + 3].y = xdata.height;
                _paVertexBuffer_data[i*4 + 3].z = 0.0f;
                _paVertexBuffer_data[i*4 + 3].tu = (float)((1.0 / xdata.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 3].tv = (float)((1.0 / xdata.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 3].index = (float)i;
            } else if (i == 0 || i == 2 || i == 6 || i == 8 ) {
                //係妏
                //嵍忋
                _paVertexBuffer_data[i*4 + 0].x = 0.0f;
                _paVertexBuffer_data[i*4 + 0].y = 0.0f;
                _paVertexBuffer_data[i*4 + 0].z = 0.0f;
                _paVertexBuffer_data[i*4 + 0].tu = (float)du;
                _paVertexBuffer_data[i*4 + 0].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 0].index = (float)i;
                //塃忋
                _paVertexBuffer_data[i*4 + 1].x = xdata_frame.width;
                _paVertexBuffer_data[i*4 + 1].y = 0.0f;
                _paVertexBuffer_data[i*4 + 1].z = 0.0f;
                _paVertexBuffer_data[i*4 + 1].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 1].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 1].index = (float)i;
                //嵍壓
                _paVertexBuffer_data[i*4 + 2].x = 0.0f;
                _paVertexBuffer_data[i*4 + 2].y = xdata_frame.height;
                _paVertexBuffer_data[i*4 + 2].z = 0.0f;
                _paVertexBuffer_data[i*4 + 2].tu = (float)du;
                _paVertexBuffer_data[i*4 + 2].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 2].index = (float)i;
                //塃壓
                _paVertexBuffer_data[i*4 + 3].x = xdata_frame.width;
                _paVertexBuffer_data[i*4 + 3].y = xdata_frame.height;
                _paVertexBuffer_data[i*4 + 3].z = 0.0f;
                _paVertexBuffer_data[i*4 + 3].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 3].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 3].index = (float)i;
            } else if (i == 1 || i == 7) {
                //廲偺恀傫拞
                //嵍忋
                _paVertexBuffer_data[i*4 + 0].x = 0.0f;
                _paVertexBuffer_data[i*4 + 0].y = 0.0f;
                _paVertexBuffer_data[i*4 + 0].z = 0.0f;
                _paVertexBuffer_data[i*4 + 0].tu = (float)du;
                _paVertexBuffer_data[i*4 + 0].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 0].index = (float)i;
                //塃忋
                _paVertexBuffer_data[i*4 + 1].x = xdata.width;
                _paVertexBuffer_data[i*4 + 1].y = 0.0f;
                _paVertexBuffer_data[i*4 + 1].z = 0.0f;
                _paVertexBuffer_data[i*4 + 1].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 1].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 1].index = (float)i;
                //嵍壓
                _paVertexBuffer_data[i*4 + 2].x = 0.0f;
                _paVertexBuffer_data[i*4 + 2].y = xdata_frame.height;
                _paVertexBuffer_data[i*4 + 2].z = 0.0f;
                _paVertexBuffer_data[i*4 + 2].tu = (float)du;
                _paVertexBuffer_data[i*4 + 2].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 2].index = (float)i;
                //塃壓
                _paVertexBuffer_data[i*4 + 3].x = xdata.width;
                _paVertexBuffer_data[i*4 + 3].y = xdata_frame.height;
                _paVertexBuffer_data[i*4 + 3].z = 0.0f;
                _paVertexBuffer_data[i*4 + 3].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 3].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 3].index = (float)i;
            } else if (i == 3 || i == 5) {
                //墶偺恀傫拞
                //嵍忋
                _paVertexBuffer_data[i*4 + 0].x = 0.0f;
                _paVertexBuffer_data[i*4 + 0].y = 0.0f;
                _paVertexBuffer_data[i*4 + 0].z = 0.0f;
                _paVertexBuffer_data[i*4 + 0].tu = (float)du;
                _paVertexBuffer_data[i*4 + 0].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 0].index = (float)i;
                //塃忋
                _paVertexBuffer_data[i*4 + 1].x = xdata_frame.width;
                _paVertexBuffer_data[i*4 + 1].y = 0.0f;
                _paVertexBuffer_data[i*4 + 1].z = 0.0f;
                _paVertexBuffer_data[i*4 + 1].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 1].tv = (float)dv;
                _paVertexBuffer_data[i*4 + 1].index = (float)i;
                //嵍壓
                _paVertexBuffer_data[i*4 + 2].x = 0.0f;
                _paVertexBuffer_data[i*4 + 2].y = xdata.height;
                _paVertexBuffer_data[i*4 + 2].z = 0.0f;
                _paVertexBuffer_data[i*4 + 2].tu = (float)du;
                _paVertexBuffer_data[i*4 + 2].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 2].index = (float)i;
                //塃壓
                _paVertexBuffer_data[i*4 + 3].x = xdata_frame.width;
                _paVertexBuffer_data[i*4 + 3].y = xdata.height;
                _paVertexBuffer_data[i*4 + 3].z = 0.0f;
                _paVertexBuffer_data[i*4 + 3].tu = (float)((1.0 / xdata_frame.col_texture_split) - du);
                _paVertexBuffer_data[i*4 + 3].tv = (float)((1.0 / xdata_frame.row_texture_split) - dv);
                _paVertexBuffer_data[i*4 + 3].index = (float)i;
            }
        }

        int nVertices = 4;
        int nFaces = 2;
        WORD* unit_paIdxBuffer = NEW WORD[(nFaces*3)];
        unit_paIdxBuffer[0] = 0;
        unit_paIdxBuffer[1] = 1;
        unit_paIdxBuffer[2] = 2;
        unit_paIdxBuffer[3] = 1;
        unit_paIdxBuffer[4] = 3;
        unit_paIdxBuffer[5] = 2;
        _pIndexBuffer_data = NEW WORD[(nFaces*3) * _set_num];
        for (int i = 0; i < _set_num; i++) {
            for (int j = 0; j < nFaces; j++) {
                _pIndexBuffer_data[((i*nFaces*3)+(j*3)) + 0] = unit_paIdxBuffer[j*3 + 0] + (nVertices*i);
                _pIndexBuffer_data[((i*nFaces*3)+(j*3)) + 1] = unit_paIdxBuffer[j*3 + 1] + (nVertices*i);
                _pIndexBuffer_data[((i*nFaces*3)+(j*3)) + 2] = unit_paIdxBuffer[j*3 + 2] + (nVertices*i);
            }
        }
        GGAF_DELETEARR(unit_paIdxBuffer);

        //昤夋帪僷儔儊乕僞乕
        _indexParam.MaterialNo = 0;
        _indexParam.BaseVertexIndex = 0;
        _indexParam.MinIndex = 0;
        _indexParam.NumVertices = nVertices*_set_num;
        _indexParam.StartIndex = 0;
        _indexParam.PrimitiveCount = nFaces*_set_num;


        _num_materials = 1;
        D3DMATERIAL9* paMaterial = NEW D3DMATERIAL9[_num_materials];
        for ( DWORD i = 0; i < _num_materials; i++) {
            //paMaterial[i] = paD3DMaterial9_tmp[i].MatD3D;
            paMaterial[i].Diffuse.r = 1.0f;
            paMaterial[i].Diffuse.g = 1.0f;
            paMaterial[i].Diffuse.b = 1.0f;
            paMaterial[i].Diffuse.a = 1.0f;
            paMaterial[i].Ambient.r = 1.0f;
            paMaterial[i].Ambient.g = 1.0f;
            paMaterial[i].Ambient.b = 1.0f;
            paMaterial[i].Ambient.a = 1.0f;
        }
        _paMaterial_default = paMaterial;

    }


    if (_pVertexBuffer == nullptr) {
        HRESULT hr;
        //僶僢僼傽嶌惉
        hr = God::_pID3DDevice9->CreateVertexBuffer(
                _size_vertices * _set_num,
                D3DUSAGE_WRITEONLY,
                FramedBoardModel::FVF,
                D3DPOOL_DEFAULT, //D3DPOOL_DEFAULT
                &(_pVertexBuffer),
                nullptr);
        checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateVertexBuffer 幐攕 model="<<(_model_name));
        //捀揰僶僢僼傽嶌惉
        //捀揰忣曬傪價僨僆僇乕僪捀揰僶僢僼傽傊儘乕僪
        void *pVertexBuffer;
        hr = _pVertexBuffer->Lock(
                                 0,
                                 _size_vertices * _set_num,
                                 (void**)&pVertexBuffer,
                                 0
                               );
        checkDxException(hr, D3D_OK, "捀揰僶僢僼傽偺儘僢僋庢摼偵幐攕 model="<<_model_name);
        memcpy(
          pVertexBuffer,
          _paVertexBuffer_data,
          _size_vertices * _set_num
        ); //pVertexBuffer 仼 _paVertexBuffer_data
        _pVertexBuffer->Unlock();

    }


    //僀儞僨僢僋僗僶僢僼傽嶌惉
    if (_pIndexBuffer == nullptr) {
        HRESULT hr;
        int nVertices = 4;
        int nFaces = 2;
        hr = God::_pID3DDevice9->CreateIndexBuffer(
                                sizeof(WORD) * nFaces * 3 * _set_num,
                                D3DUSAGE_WRITEONLY,
                                D3DFMT_INDEX16,
                                D3DPOOL_DEFAULT,
                                &(_pIndexBuffer),
                                nullptr);
        checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateIndexBuffer 幐攕 model="<<(_model_name));

        void* pIndexBuffer;
        _pIndexBuffer->Lock(0,0,(void**)&pIndexBuffer,0);
        memcpy(
          pIndexBuffer ,
          _pIndexBuffer_data,
          sizeof(WORD) * nFaces * 3 * _set_num
        );
        _pIndexBuffer->Unlock();
    }

    if (_papTextureConnection == nullptr) {
        //僥僋僗僠儍庢摼偟儌僨儖偵曐帩偝偣傞
        ModelManager* pModelManager = pGOD->_pModelManager;
        _papTextureConnection = NEW TextureConnection*[2];
        _papTextureConnection[0] = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(_pa_texture_filenames[0].c_str(), this)); //拞恎梡
        _papTextureConnection[1] = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(_pa_texture_filenames[1].c_str(), this)); //僼儗乕儉梡
    }
}

void FramedBoardModel::onDeviceLost() {
    _TRACE3_("_model_name=" << _model_name << " start");
    release();
    _TRACE3_("_model_name=" << _model_name << " end");
}

void FramedBoardModel::release() {
    _TRACE3_("_model_name=" << _model_name << " start");
    GGAF_RELEASE(_pVertexBuffer);
    GGAF_RELEASE(_pIndexBuffer);
    //僥僋僗僠儍傪夝曻
    if (_papTextureConnection) {
        _papTextureConnection[0]->close();
        _papTextureConnection[1]->close(); //僼儗乕儉
    }
    GGAF_DELETEARR(_papTextureConnection);
    _TRACE3_("_model_name=" << _model_name << " end");
}

FramedBoardModel::~FramedBoardModel() {
    GGAF_DELETEARR(_paVertexBuffer_data);
    GGAF_DELETEARR(_pIndexBuffer_data);
    GGAF_DELETEARR(_paMaterial_default);
    GGAF_DELETEARR_NULLABLE(_pa_texture_filenames);
    //release();
    //偼ModelConnection::processReleaseResource(Model* prm_pResource) 偱屇傃弌偝傟傞
}

