void SpriteModel::restore() { _TRACE3_("_model_name=" << _model_name << " start"); 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; //テクスチャ取得しモデルに保持させる TextureConnection* model_pTextureConnection = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(xdata.texture_file, this)); //テクスチャの参照を保持させる。 _papTextureConnection = NEW TextureConnection*[1]; _papTextureConnection[0] = model_pTextureConnection; SpriteModel::VERTEX* paVertex = NEW SpriteModel::VERTEX[4]; _size_vertices = sizeof(SpriteModel::VERTEX)*4; _size_vertex_unit = sizeof(SpriteModel::VERTEX); //頂点配列情報をモデルに保持させる //UVは左上の1つ分(アニメパターン0)をデフォルトで設定する。 //シェーダーが描画時にアニメパターン番号をみてUV座標をずらす仕様としよっと。 //x,y の ÷2 とは、モデル中心をローカル座標の原点中心としたいため // float tex_width = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Width); //テクスチャの幅(px) // float tex_height = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Height); //テクスチャの高さ(px) double du = 0.0; double dv = 0.0; //左上 paVertex[0].x = PX_DX(xdata.width) / -2.0; paVertex[0].y = PX_DX(xdata.height) / 2.0; paVertex[0].z = 0.0f; paVertex[0].nx = 0.0f; paVertex[0].ny = 0.0f; paVertex[0].nz = -1.0f; paVertex[0].color = D3DCOLOR_ARGB(255,255,255,255); paVertex[0].tu = (float)du; paVertex[0].tv = (float)dv; //右上 paVertex[1].x = PX_DX(xdata.width) / 2.0; paVertex[1].y = PX_DX(xdata.height) / 2.0; paVertex[1].z = 0.0f; paVertex[1].nx = 0.0f; paVertex[1].ny = 0.0f; paVertex[1].nz = -1.0f; paVertex[1].color = D3DCOLOR_ARGB(255,255,255,255); paVertex[1].tu = (float)((1.0 / xdata.col_texture_split) - du); paVertex[1].tv = (float)dv; //左下 paVertex[2].x = PX_DX(xdata.width) / -2.0; paVertex[2].y = PX_DX(xdata.height) / -2.0; paVertex[2].z = 0.0f; paVertex[2].nx = 0.0f; paVertex[2].ny = 0.0f; paVertex[2].nz = -1.0f; paVertex[2].color = D3DCOLOR_ARGB(255,255,255,255); paVertex[2].tu = (float)du; paVertex[2].tv = (float)((1.0 / xdata.row_texture_split) - dv); //右下 paVertex[3].x = PX_DX(xdata.width) / 2.0; paVertex[3].y = PX_DX(xdata.height) / -2.0; paVertex[3].z = 0.0f; paVertex[3].nx = 0.0f; paVertex[3].ny = 0.0f; paVertex[3].nz = -1.0f; paVertex[3].color = D3DCOLOR_ARGB(255,255,255,255); paVertex[3].tu = (float)((1.0 / xdata.col_texture_split) - du); paVertex[3].tv = (float)((1.0 / xdata.row_texture_split) - dv); //距離 FLOAT model_bounding_sphere_radius = (FLOAT)(sqrt(paVertex[0].x * paVertex[0].x + paVertex[0].y * paVertex[0].y + paVertex[0].z * paVertex[0].z)); _bounding_sphere_radius = model_bounding_sphere_radius; //バッファ作成 if (_pVertexBuffer == nullptr) { hr = God::_pID3DDevice9->CreateVertexBuffer( _size_vertices, D3DUSAGE_WRITEONLY, SpriteModel::FVF, D3DPOOL_DEFAULT, //D3DPOOL_DEFAULT &(_pVertexBuffer), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateVertexBuffer 失敗 model="<<(_model_name)); } //頂点バッファ作成 //頂点情報をビデオカード頂点バッファへロード void *pVertexBuffer; hr = _pVertexBuffer->Lock(0, _size_vertices, (void**)&pVertexBuffer, 0); checkDxException(hr, D3D_OK, "頂点バッファのロック取得に失敗 model="<<_model_name); memcpy(pVertexBuffer, paVertex, _size_vertices); //pVertexBuffer ← paVertex _pVertexBuffer->Unlock(); _num_materials = 1; D3DMATERIAL9* paMaterial; 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; //後始末 GGAF_DELETEARR(paVertex); _TRACE3_("_model_name=" << _model_name << " end"); }
void MassSpriteModel::restore() { _TRACE3_("_model_name=" << _model_name << " start"); ModelManager* pModelManager = pGOD->_pModelManager; HRESULT hr; if (!_paVtxBuffer_data_model) { //静的な情報設定 std::vector<std::string> names = UTIL::split(std::string(_model_name), ","); std::string xfile_name = ""; //読み込むXファイル名 if (names.size() == 1) { _TRACE_(FUNC_NAME<<" "<<_model_name<<" の最大同時描画オブジェクト数は、デフォルトの"<<GGAFDXMASS_MAX_INSTANCE_NUM<<" が設定されました。"); _set_num = GGAFDXMASS_MAX_INSTANCE_NUM; xfile_name = ModelManager::getSpriteFileName(names[0], "sprx"); } else if (names.size() == 2) { _set_num = STOI(names[0]); xfile_name = ModelManager::getSpriteFileName(names[1], "sprx"); } else { throwCriticalException("_model_name には \"xxxxxx\" or \"8/xxxxx\" 形式を指定してください。 \n" "実際は、_model_name="<<_model_name<<" でした。"); } if (_set_num < 1 || _set_num > GGAFDXMASS_MAX_INSTANCE_NUM) { throwCriticalException(_model_name<<"の最大同時描画オブジェクト数が不正。範囲は 1〜"<<GGAFDXMASS_MAX_INSTANCE_NUM<<"セットです。_set_num="<<_set_num); } if (xfile_name == "") { throwCriticalException("スプライト定義ファイル(*.sprx)が見つかりません。model_name="<<(_model_name)); } ModelManager::SpriteXFileFmt xdata; pModelManager->obtainSpriteInfo(&xdata, xfile_name); _model_width_px = xdata.width; _model_height_px = xdata.height; _model_half_width_px = _model_width_px/2; _model_half_height_px = _model_height_px/2; _row_texture_split = xdata.row_texture_split; _col_texture_split = xdata.col_texture_split; _nVertices = 4; _nFaces = 2; _paVtxBuffer_data_model = NEW MassSpriteModel::VERTEX_model[_nVertices]; _size_vertex_unit_model = sizeof(MassSpriteModel::VERTEX_model); _size_vertices_model = sizeof(MassSpriteModel::VERTEX_model) * _nVertices; // float tex_width = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Width); //テクスチャの幅(px) // float tex_height = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Height); //テクスチャの高さ(px) double du = 0.0; double dv = 0.0; //左上 _paVtxBuffer_data_model[0].x = PX_DX(xdata.width) / -2.0; _paVtxBuffer_data_model[0].y = PX_DX(xdata.height) / 2.0; _paVtxBuffer_data_model[0].z = 0.0f; _paVtxBuffer_data_model[0].nx = 0.0f; _paVtxBuffer_data_model[0].ny = 0.0f; _paVtxBuffer_data_model[0].nz = -1.0f; _paVtxBuffer_data_model[0].tu = du; _paVtxBuffer_data_model[0].tv = dv; //右上 _paVtxBuffer_data_model[1].x = PX_DX(xdata.width) / 2.0; _paVtxBuffer_data_model[1].y = PX_DX(xdata.height) / 2.0; _paVtxBuffer_data_model[1].z = 0.0f; _paVtxBuffer_data_model[1].nx = 0.0f; _paVtxBuffer_data_model[1].ny = 0.0f; _paVtxBuffer_data_model[1].nz = -1.0f; _paVtxBuffer_data_model[1].tu = (1.0/xdata.col_texture_split) - du; _paVtxBuffer_data_model[1].tv = dv; //左下 _paVtxBuffer_data_model[2].x = PX_DX(xdata.width) / -2.0; _paVtxBuffer_data_model[2].y = PX_DX(xdata.height) / -2.0; _paVtxBuffer_data_model[2].z = 0.0f; _paVtxBuffer_data_model[2].nx = 0.0f; _paVtxBuffer_data_model[2].ny = 0.0f; _paVtxBuffer_data_model[2].nz = -1.0f; _paVtxBuffer_data_model[2].tu = du; _paVtxBuffer_data_model[2].tv = (1.0/xdata.row_texture_split) - dv; //右下 _paVtxBuffer_data_model[3].x = PX_DX(xdata.width) / 2.0; _paVtxBuffer_data_model[3].y = PX_DX(xdata.height) / -2.0; _paVtxBuffer_data_model[3].z = 0.0f; _paVtxBuffer_data_model[3].nx = 0.0f; _paVtxBuffer_data_model[3].ny = 0.0f; _paVtxBuffer_data_model[3].nz = -1.0f; _paVtxBuffer_data_model[3].tu = 1.0/xdata.col_texture_split; _paVtxBuffer_data_model[3].tv = 1.0/xdata.row_texture_split; _paIndexBuffer_data = NEW WORD[(_nFaces*3)]; _paIndexBuffer_data[0] = 0; _paIndexBuffer_data[1] = 1; _paIndexBuffer_data[2] = 2; _paIndexBuffer_data[3] = 1; _paIndexBuffer_data[4] = 3; _paIndexBuffer_data[5] = 2; //距離 FLOAT model_bounding_sphere_radius = (FLOAT)(sqrt(_paVtxBuffer_data_model[0].x * _paVtxBuffer_data_model[0].x + _paVtxBuffer_data_model[0].y * _paVtxBuffer_data_model[0].y + _paVtxBuffer_data_model[0].z * _paVtxBuffer_data_model[0].z)); _bounding_sphere_radius = model_bounding_sphere_radius; setMaterial(); _pa_texture_filenames[0] = std::string(xdata.texture_file); } //デバイスに頂点バッファ作成(モデル) if (_pVertexBuffer_model == nullptr) { hr = God::_pID3DDevice9->CreateVertexBuffer( _size_vertices_model, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &(_pVertexBuffer_model), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateVertexBuffer 失敗 model="<<(_model_name)); //バッファへ作成済み頂点データを流し込む void* pDeviceMemory = 0; hr = _pVertexBuffer_model->Lock(0, _size_vertices_model, (void**)&pDeviceMemory, 0); checkDxException(hr, D3D_OK, "頂点バッファのロック取得に失敗 model="<<_model_name); memcpy(pDeviceMemory, _paVtxBuffer_data_model, _size_vertices_model); hr = _pVertexBuffer_model->Unlock(); checkDxException(hr, D3D_OK, "頂点バッファのアンロック取得に失敗 model="<<_model_name); } //デバイスにインデックスバッファ作成 if (_pIndexBuffer == nullptr) { hr = God::_pID3DDevice9->CreateIndexBuffer( sizeof(WORD) * _nFaces * 3, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &(_pIndexBuffer), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateIndexBuffer 失敗 model="<<_model_name); void* pDeviceMemory = 0; hr = _pIndexBuffer->Lock(0, 0, (void**)&pDeviceMemory,0); checkDxException(hr, D3D_OK, "インデックスバッファのロック取得に失敗 model="<<_model_name); memcpy(pDeviceMemory, _paIndexBuffer_data, sizeof(WORD)*_nFaces*3); hr = _pIndexBuffer->Unlock(); checkDxException(hr, D3D_OK, "インデックスバッファのアンロック取得に失敗 model="<<_model_name); } //デバイスにテクスチャ作成 if (!_papTextureConnection) { _papTextureConnection = NEW TextureConnection*[_num_materials]; for (DWORD n = 0; n < _num_materials; n++) { _papTextureConnection[n] = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(_pa_texture_filenames[n].c_str(), this)); } }
void RegularPolygonBoardModel::restore() { _TRACE3_("_model_name=" << _model_name << " start"); HRESULT hr; std::string model_name = std::string(_model_name); //_model_name は "8,CW,XXXX" or "8,XXXX" std::vector<std::string> names = UTIL::split(model_name, ","); std::string filenamae = ""; if (names.size() == 2) { filenamae = names[1]; } else if (names.size() == 3) { filenamae = names[2]; } ModelManager* pModelManager = pGOD->_pModelManager; std::string xfile_name = ModelManager::getSpriteFileName(filenamae, "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; //テクスチャ取得しモデルに保持させる _papTextureConnection = NEW TextureConnection*[1]; _papTextureConnection[0] = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(xdata.texture_file, this)); RegularPolygonBoardModel::VERTEX* paVertex = NEW RegularPolygonBoardModel::VERTEX[_angle_num+2]; _size_vertices = sizeof(RegularPolygonBoardModel::VERTEX)*(_angle_num+2); _size_vertex_unit = sizeof(RegularPolygonBoardModel::VERTEX); float model_width = _model_width_px; float model_height = _model_height_px; float tu_rate = 1.0 / _col_texture_split; float tv_rate = 1.0 / _row_texture_split; _u_center = tu_rate * 0.5; _v_center = tv_rate * 0.5; _x_center = model_width * 0.5; _y_center = model_height * 0.5; //中心 paVertex[0].x = _x_center; paVertex[0].y = _y_center; paVertex[0].z = 0.0f; paVertex[0].tu = _u_center; paVertex[0].tv = _v_center; if (_drawing_order == 0) { //反計回り for (int ang = 0; ang < _angle_num; ang++) { double rad = (PI2 * ang) / _angle_num; paVertex[ang+1].x = paVertex[0].x + (cos(rad) * model_width * 0.5); paVertex[ang+1].y = paVertex[0].y - (sin(rad) * model_height * 0.5); paVertex[ang+1].z = 0.0f; paVertex[ang+1].tu = paVertex[0].tu + (cos(rad) * tu_rate * 0.5); paVertex[ang+1].tv = paVertex[0].tv - (sin(rad) * tv_rate * 0.5); } paVertex[_angle_num+1] = paVertex[1]; } else { //時計回り for (int ang = 0; ang < _angle_num; ang++) { double rad = PI2 - ((PI2 * ang) / _angle_num); paVertex[ang+1].x = paVertex[0].x + (cos(rad) * model_width * 0.5); paVertex[ang+1].y = paVertex[0].y - (sin(rad) * model_height * 0.5); paVertex[ang+1].z = 0.0f; paVertex[ang+1].tu = paVertex[0].tu + (cos(rad) * tu_rate * 0.5); paVertex[ang+1].tv = paVertex[0].tv - (sin(rad) * tv_rate * 0.5); } paVertex[_angle_num+1] = paVertex[1]; } // RegularPolygonBoardModel::VERTEX* paVertex = NEW RegularPolygonBoardModel::VERTEX[_angle_num+2]; // _size_vertices = sizeof(RegularPolygonBoardModel::VERTEX)*(_angle_num+2); // _size_vertex_unit = sizeof(RegularPolygonBoardModel::VERTEX); // // double du = 0.0; // double dv = 0.0; // // //左上 // paVertex[0].x = 0.0f; // paVertex[0].y = 0.0f; // paVertex[0].z = 0.0f; // paVertex[0].tu = (float)du; // paVertex[0].tv = (float)dv; // //右上 // paVertex[1].x = xdata.width; // paVertex[1].y = 0.0f; // paVertex[1].z = 0.0f; // paVertex[1].tu = (float)((1.0 / xdata.col_texture_split) - du); // paVertex[1].tv = (float)dv; // //左下 // paVertex[2].x = 0.0f; // paVertex[2].y = xdata.height; // paVertex[2].z = 0.0f; // paVertex[2].tu = (float)du; // paVertex[2].tv = (float)((1.0 / xdata.row_texture_split) - dv); // //右下 // paVertex[3].x = xdata.width; // paVertex[3].y = xdata.height; // paVertex[3].z = 0.0f; // paVertex[3].tu = (float)((1.0 / xdata.col_texture_split) - du); // paVertex[3].tv = (float)((1.0 / xdata.row_texture_split) - dv); //バッファ作成 if (_pVertexBuffer == nullptr) { hr = God::_pID3DDevice9->CreateVertexBuffer( _size_vertices, D3DUSAGE_WRITEONLY, RegularPolygonBoardModel::FVF, D3DPOOL_DEFAULT, //D3DPOOL_DEFAULT &(_pVertexBuffer), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateVertexBuffer 失敗 model="<<(_model_name)); } //頂点バッファ作成 //頂点情報をビデオカード頂点バッファへロード void *pVertexBuffer; hr = _pVertexBuffer->Lock(0, _size_vertices, (void**)&pVertexBuffer, 0); checkDxException(hr, D3D_OK, "頂点バッファのロック取得に失敗 model="<<_model_name); memcpy(pVertexBuffer, paVertex, _size_vertices); //pVertexBuffer ← paVertex _pVertexBuffer->Unlock(); _num_materials = 1; D3DMATERIAL9* paMaterial; paMaterial = NEW D3DMATERIAL9[_num_materials]; for ( DWORD i = 0; i < _num_materials; i++) { 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; GGAF_DELETEARR(paVertex); _TRACE3_("_model_name=" << _model_name << " end"); }