File: ModelScalePreserver.h

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 (52 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (4)
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
#pragma once

#include <string>
#include <functional>
#include <sigc++/trackable.h>

#include "imodel.h"
#include "imap.h"

class Entity;

namespace map
{

/**
 * Helper class dealing with any models that still have an unmodified
 * scale when they're being passed to the IMapWriters.
 * During a regular save operation, all models with modified scale are
 * processed and have their model files generated with the desired scale.
 * In auto-save and prefab export scenarios, no new models are generated
 * (in order not to mess up the user's map project folder with models 
 * generated by auto-saves). To still preserve the model scale as it has 
 * been set by the user at the time of the auto-save, this class will
 * write the modified scale to an editor_* spawnarg, such that it can be
 * reconstructed when loading an auto-save or a partial export (#5220).
 */
class ModelScalePreserver :
    public sigc::trackable
{
private:
    const std::string _modelScaleKey;

public:
    ModelScalePreserver();

    // Noncopyable
    ModelScalePreserver(const ModelScalePreserver&) = delete;
    ModelScalePreserver& operator=(const ModelScalePreserver&) = delete;

private:
    void forEachScaledModel(const scene::IMapRootNodePtr& root, 
        const std::function<void(Entity&, model::ModelNode&)>& func);

    void onResourceExporting(const scene::IMapRootNodePtr& root);
    void onResourceExported(const scene::IMapRootNodePtr& root);

    void restoreModelScale(const scene::IMapRootNodePtr& root);

    void onMapEvent(IMap::MapEvent ev);
};

}