MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / performPatchScaleTest

Function performPatchScaleTest

test/TextureManipulation.cpp:278–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278void performPatchScaleTest(const Vector2& scale)
279{
280 // We create two patches, each of them should be scaled independently
281 auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
282 auto patchNode1 = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1");
283 auto patchNode2 = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, -5), Vector3(64, 128, 64)), "textures/numbers/1");
284
285 auto patch1 = Node_getIPatch(patchNode1);
286 auto patch2 = Node_getIPatch(patchNode2);
287 patch1->scaleTextureNaturally();
288 patch1->controlPointsChanged();
289 patch2->scaleTextureNaturally();
290 patch2->controlPointsChanged();
291
292 Node_setSelected(patchNode1, true);
293 Node_setSelected(patchNode2, true);
294
295 std::vector<Vector2> oldTexCoords1;
296 std::vector<Vector2> oldTexCoords2;
297 algorithm::foreachPatchVertex(*patch1, [&](const PatchControl& ctrl) { oldTexCoords1.push_back(ctrl.texcoord); });
298 algorithm::foreachPatchVertex(*patch2, [&](const PatchControl& ctrl) { oldTexCoords2.push_back(ctrl.texcoord); });
299
300 // The incoming scale values are absolute 1.05 == 105%, the command accepts relative values, 0.05 == 105%
301 auto zeroBasedScale = scale - Vector2(1, 1);
302 GlobalCommandSystem().executeCommand("TexScale", { cmd::Argument(zeroBasedScale) });
303
304 auto uvBounds1 = algorithm::getTextureSpaceBounds(*patch1);
305 auto uvBounds2 = algorithm::getTextureSpaceBounds(*patch2);
306
307 std::vector<Vector2> newTexCoords1;
308 std::vector<Vector2> newTexCoords2;
309 algorithm::foreachPatchVertex(*patch1, [&](const PatchControl& ctrl) { newTexCoords1.push_back(ctrl.texcoord); });
310 algorithm::foreachPatchVertex(*patch2, [&](const PatchControl& ctrl) { newTexCoords2.push_back(ctrl.texcoord); });
311
312 Vector2 pivot(uvBounds1.origin.x(), uvBounds1.origin.y());
313 assumeVerticesHaveBeenScaled(oldTexCoords1, newTexCoords1, scale, pivot);
314
315 Vector2 pivot2(uvBounds2.origin.x(), uvBounds2.origin.y());
316 assumeVerticesHaveBeenScaled(oldTexCoords2, newTexCoords2, scale, pivot2);
317}
318
319}
320

Callers 1

TEST_FFunction · 0.85

Calls 14

createPatchFromBoundsFunction · 0.85
Node_getIPatchFunction · 0.85
Node_setSelectedFunction · 0.85
foreachPatchVertexFunction · 0.85
getTextureSpaceBoundsFunction · 0.85
scaleTextureNaturallyMethod · 0.80
xMethod · 0.80
yMethod · 0.80
AABBClass · 0.50
ArgumentClass · 0.50
controlPointsChangedMethod · 0.45

Tested by

no test coverage detected