| 977 | } |
| 978 | |
| 979 | void TerrainBlock::addMaterial( const String &name, U32 insertAt ) |
| 980 | { |
| 981 | TerrainMaterial *mat = TerrainMaterial::findOrCreate( name ); |
| 982 | |
| 983 | StringTableEntry newMatName = StringTable->insert(name.c_str()); |
| 984 | |
| 985 | if ( insertAt == -1 ) |
| 986 | { |
| 987 | //Check to ensure we're not trying to add one that already exists, as that'd be kinda dumb |
| 988 | for (U32 i = 0; i < mFile->mMaterials.size(); i++) |
| 989 | { |
| 990 | if (mFile->mMaterials[i]->getInternalName() == newMatName) |
| 991 | return; |
| 992 | } |
| 993 | |
| 994 | mFile->mMaterials.push_back( mat ); |
| 995 | mFile->_initMaterialInstMapping(); |
| 996 | |
| 997 | //now we update our asset |
| 998 | if (mTerrainAsset) |
| 999 | { |
| 1000 | StringTableEntry terrMatName = StringTable->insert(name.c_str()); |
| 1001 | |
| 1002 | AssetQuery* aq = new AssetQuery(); |
| 1003 | U32 foundCount = AssetDatabase.findAssetType(aq, "TerrainMaterialAsset"); |
| 1004 | |
| 1005 | for (U32 i = 0; i < foundCount; i++) |
| 1006 | { |
| 1007 | TerrainMaterialAsset* terrMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(aq->mAssetList[i]); |
| 1008 | if (terrMatAsset && terrMatAsset->getMaterialDefinitionName() == terrMatName) |
| 1009 | { |
| 1010 | //Do iterative logic to find the next available slot and write to it with our new mat field |
| 1011 | mTerrainAsset->setDataField(StringTable->insert("terrainMaterialAsset"), nullptr, aq->mAssetList[i]); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | |
| 1019 | // TODO: Insert and reindex! |
| 1020 | |
| 1021 | } |
| 1022 | |
| 1023 | mDetailsDirty = true; |
| 1024 | mLayerTexDirty = true; |
| 1025 | } |
| 1026 | |
| 1027 | void TerrainBlock::removeMaterial( U32 index ) |
| 1028 | { |
no test coverage detected