summaryrefslogtreecommitdiff
path: root/apps/opencs/view/render/object.hpp
blob: ef136abb9c0d9e1ac6f2f2864f16ee416349f43a (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef OPENCS_VIEW_OBJECT_H
#define OPENCS_VIEW_OBJECT_H

#include <memory>
#include <string>

#include <osg/ref_ptr>
#include <osg/Geometry>
#include <osg/Referenced>

#include <components/esm/defs.hpp>

#include "tagbase.hpp"

class QModelIndex;
class QUndoStack;

namespace osg
{
    class PositionAttitudeTransform;
    class Group;
    class Node;
}

namespace osgFX
{
    class Scribe;
}

namespace Resource
{
    class ResourceSystem;
}

namespace CSMWorld
{
    class Data;
    struct CellRef;
    class CommandMacro;
}

namespace CSVRender
{
    class Actor;
    class Object;

    // An object to attach as user data to the osg::Node, allows us to get an Object back from a Node when we are doing a ray query
    class ObjectTag : public TagBase
    {
        public:

            ObjectTag (Object* object);

            Object* mObject;

            QString getToolTip (bool hideBasics, const WorldspaceHitResult& hit) const override;
    };

    class ObjectMarkerTag : public ObjectTag
    {
        public:

            ObjectMarkerTag (Object* object, int axis);

            int mAxis;
    };

    class Object
    {
        public:

            enum OverrideFlags
            {
                Override_Position = 1,
                Override_Rotation = 2,
                Override_Scale = 4
            };

        private:

            static const float MarkerShaftWidth;
            static const float MarkerShaftBaseLength;
            static const float MarkerHeadWidth;
            static const float MarkerHeadLength;

            CSMWorld::Data& mData;
            std::string mReferenceId;
            std::string mReferenceableId;
            osg::ref_ptr<osg::PositionAttitudeTransform> mRootNode;
            osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
            osg::ref_ptr<osgFX::Scribe> mOutline;
            bool mSelected;
            osg::Group* mParentNode;
            Resource::ResourceSystem* mResourceSystem;
            bool mForceBaseToZero;
            ESM::Position mPositionOverride{};
            float mScaleOverride;
            int mOverrideFlags;
            osg::ref_ptr<osg::Node> mMarker[3];
            int mSubMode;
            float mMarkerTransparency;
            std::unique_ptr<Actor> mActor;

            /// Not implemented
            Object (const Object&);

            /// Not implemented
            Object& operator= (const Object&);

            /// Remove object from node (includes deleting)
            void clear();

            /// Update model
            /// @note Make sure adjustTransform() was called first so world space particles get positioned correctly
            void update();

            /// Adjust position, orientation and scale
            void adjustTransform();

            /// Throws an exception if *this was constructed with referenceable
            const CSMWorld::CellRef& getReference() const;

            void updateMarker();

            osg::ref_ptr<osg::Node> makeMoveOrScaleMarker (int axis);
            osg::ref_ptr<osg::Node> makeRotateMarker (int axis);

            /// Sets up a stateset with properties common to all marker types.
            void setupCommonMarkerState(const osg::ref_ptr<osg::Geometry>& geometry);

            osg::Vec3f getMarkerPosition (float x, float y, float z, int axis);

        public:

            Object (CSMWorld::Data& data, osg::Group *cellNode,
                const std::string& id, bool referenceable,
                bool forceBaseToZero = false);
            /// \param forceBaseToZero If this is a reference ignore the coordinates and place
            /// it at 0, 0, 0 instead.

            ~Object();

            /// Mark the object as selected, selected objects show an outline effect
            void setSelected(bool selected);

            bool getSelected() const;

            /// Get object node with GUI graphics
            osg::ref_ptr<osg::Group> getRootNode();

            /// Get object node without GUI graphics
            osg::ref_ptr<osg::Group> getBaseNode();

            /// \return Did this call result in a modification of the visual representation of
            /// this object?
            bool referenceableDataChanged (const QModelIndex& topLeft,
                const QModelIndex& bottomRight);

            /// \return Did this call result in a modification of the visual representation of
            /// this object?
            bool referenceableAboutToBeRemoved (const QModelIndex& parent, int start, int end);

            /// \return Did this call result in a modification of the visual representation of
            /// this object?
            bool referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);

            /// Reloads the underlying asset
            void reloadAssets();

            /// Returns an empty string if this is a refereceable-type object.
            std::string getReferenceId() const;

            std::string getReferenceableId() const;

            osg::ref_ptr<TagBase> getTag() const;

            /// Is there currently an editing operation running on this object?
            bool isEdited() const;

            void setEdited (int flags);

            ESM::Position getPosition() const;

            float getScale() const;

            /// Set override position.
            void setPosition (const float position[3]);

            /// Set override rotation
            void setRotation (const float rotation[3]);

            /// Set override scale
            void setScale (float scale);

            void setMarkerTransparency(float value);

            /// Apply override changes via command and end edit mode
            void apply (CSMWorld::CommandMacro& commands);

            void setSubMode (int subMode);

            /// Erase all overrides and restore the visual representation of the object to its
            /// true state.
            void reset();
    };
}

#endif