MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / LoadAuxFromImage

Method LoadAuxFromImage

Source/Graphics/model.cpp:1347–1398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1345};
1346
1347bool Model::LoadAuxFromImage(const std::string &image_path) {
1348 bool ret = true;
1349 if (aux.empty()) {
1350 ImageSamplerRef image = Engine::Instance()->GetAssetManager()->LoadSync<ImageSampler>(image_path);
1351
1352 if (image.valid()) {
1353 image_samplers.insert(image);
1354
1355 aux.resize(vertices.size());
1356 for (int i = 0, len = vertices.size() / 3; i < len; i++) {
1357 vec4 color = image->GetInterpolatedColorUV(tex_coords[i * 2 + 0], tex_coords[i * 2 + 1]);
1358 aux[i * 3 + 0] = color.r();
1359 aux[i * 3 + 1] = color.g();
1360 aux[i * 3 + 2] = color.b();
1361 }
1362
1363 // Duplicate map keeps a list of all vertices that share the same position
1364 std::map<vec3, AuxVertData> dup_map;
1365 unsigned vert_index = 0;
1366 for (int i = 0, len = vertices.size() / 3; i < len; i++) {
1367 vec3 index(vertices[vert_index + 0],
1368 vertices[vert_index + 1],
1369 vertices[vert_index + 2]);
1370 AuxVertData &avd = dup_map[index];
1371 avd.verts.push_back(i);
1372 avd.total_aux[0] += aux[vert_index + 0];
1373 avd.total_aux[1] += aux[vert_index + 1];
1374 avd.total_aux[2] += aux[vert_index + 2];
1375 vert_index += 3;
1376 }
1377 std::map<vec3, AuxVertData>::iterator iter;
1378 for (iter = dup_map.begin(); iter != dup_map.end(); ++iter) {
1379 AuxVertData &avd = iter->second;
1380 if (avd.verts.size() > 1) {
1381 avd.total_aux /= (float)avd.verts.size();
1382 for (unsigned i = 0; i < avd.verts.size(); ++i) {
1383 int index = avd.verts[i] * 3;
1384 aux[index + 0] = avd.total_aux[0];
1385 aux[index + 1] = avd.total_aux[2];
1386 aux[index + 2] = avd.total_aux[1];
1387 }
1388 }
1389 }
1390 } else {
1391 LOGE << "Failed to load wind map from image: " << image_path << std::endl;
1392 ret = false;
1393 }
1394 } else {
1395 // Nop instruction, this state is ok.
1396 }
1397 return ret;
1398}
1399
1400void Model::DrawAltTexCoords() {
1401 PROFILER_GPU_ZONE(g_profiler_ctx, "Model::DrawAltTexCoords");

Callers 2

LoadMethod · 0.80
LoadMethod · 0.80

Calls 11

GetAssetManagerMethod · 0.80
emptyMethod · 0.45
validMethod · 0.45
insertMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
gMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected