File: ModelScale.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (63 lines) | stat: -rw-r--r-- 1,877 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "RadiantTest.h"

#include "algorithm/Scene.h"
#include "iscenegraph.h"
#include "imodel.h"
#include "itransformable.h"
#include "icommandsystem.h"
#include "iselectable.h"
#include "iselection.h"
#include "math/Vector3.h"
#include "registry/registry.h"

namespace test
{

// #5263: "Model Scaler" doesn't handle model duplication correctly
TEST_F(RadiantTest, DuplicateScaledModel)
{
    loadMap("duplicate_scaled_model.map");

    const std::string funcStaticName("moss01");
    const Vector3 scale(3, 4, 2);
    auto func_static = algorithm::getEntityByName(GlobalSceneGraph().root(), funcStaticName);

    // Apply the scale to the model beneath the entity
    func_static->foreachNode([&](const scene::INodePtr& node)
    {
        ITransformablePtr transformable = scene::node_cast<ITransformable>(node);

        if (transformable)
        {
            transformable->setType(TRANSFORM_PRIMITIVE);
            transformable->setScale(scale);
            transformable->freezeTransform();
        }

        return true;
    });

    auto model = algorithm::findChildModel(func_static);

    ASSERT_TRUE(model->hasModifiedScale());
    ASSERT_TRUE(model->getModelScale() == scale);

    // Select the func_static and duplicate it
    GlobalSelectionSystem().setSelectedAll(false);
    Node_setSelected(func_static, true);

    registry::setValue("user/ui/offsetClonedObjects", 0);
    GlobalCommandSystem().executeCommand("CloneSelection");

    auto duplicate = GlobalSelectionSystem().ultimateSelected();

    // This must be the duplicate
    ASSERT_TRUE(Node_getEntity(duplicate)->getKeyValue("name") != funcStaticName);

    // The new model must have a modified scale too
    auto duplicatedModel = algorithm::findChildModel(duplicate);
    ASSERT_TRUE(duplicatedModel->hasModifiedScale());
    ASSERT_TRUE(duplicatedModel->getModelScale() == scale);
}

}