| 170 | } |
| 171 | |
| 172 | void StaticModel::SetVertexColor(int32 lodIndex, int32 meshIndex, int32 vertexIndex, const Color32& color) |
| 173 | { |
| 174 | if (!Model || Model->WaitForLoaded()) |
| 175 | { |
| 176 | LOG(Warning, "Cannot set vertex color if model is missing or failed to load."); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | if (lodIndex < 0 || lodIndex >= Model->GetLODsCount()) |
| 181 | { |
| 182 | LOG(Warning, "Specified model LOD index {0} was out of range.", lodIndex); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | if (_vertexColorsCount != Model->GetLODsCount()) |
| 187 | { |
| 188 | // Initialize vertex colors data for all LODs |
| 189 | RemoveVertexColors(); |
| 190 | _vertexColorsCount = Model->GetLODsCount(); |
| 191 | for (int32 i = 0; i < _vertexColorsCount; i++) |
| 192 | _vertexColorsBuffer[i] = nullptr; |
| 193 | _vertexColorsDirty = false; |
| 194 | } |
| 195 | |
| 196 | int32 index = 0; |
| 197 | const ModelLOD& lod = Model->LODs[lodIndex]; |
| 198 | auto& vertexColorsData = _vertexColorsData[lodIndex]; |
| 199 | if (vertexColorsData.Count() != lod.GetVertexCount()) |
| 200 | { |
| 201 | vertexColorsData.Resize(lod.GetVertexCount()); |
| 202 | vertexColorsData.SetAll(Color32::Black); |
| 203 | } |
| 204 | for (int32 i = 0; i < lod.Meshes.Count(); i++) |
| 205 | { |
| 206 | const Mesh& mesh = lod.Meshes[i]; |
| 207 | if (i == meshIndex) |
| 208 | { |
| 209 | if (vertexIndex < 0 || vertexIndex >= mesh.GetVertexCount()) |
| 210 | { |
| 211 | LOG(Warning, "Specified vertex index {3} was out of range. LOD{0} mesh {1} has {2}.", lodIndex, meshIndex, mesh.GetVertexCount(), vertexIndex); |
| 212 | return; |
| 213 | } |
| 214 | index += vertexIndex; |
| 215 | vertexColorsData[index] = color; |
| 216 | _vertexColorsDirty = true; |
| 217 | return; |
| 218 | } |
| 219 | index += mesh.GetVertexCount(); |
| 220 | } |
| 221 | |
| 222 | LOG(Warning, "Specified model mesh index was out of range. LOD{0} mesh {1}.", lodIndex, meshIndex); |
| 223 | } |
| 224 | |
| 225 | bool StaticModel::HasVertexColors() const |
| 226 | { |
no test coverage detected