载入中...
搜索中...
未找到
TransformGizmo.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <string>
6#include <vector>
7
8#include <glm/mat4x4.hpp>
9#include <glm/vec3.hpp>
10
11namespace eve::editor {
12
19public:
22
24 void setMode(const std::string &mode);
26 std::string getMode() const { return mode_; }
27
29 void setSpace(const std::string &space);
31 std::string getSpace() const { return space_; }
32
34 void setSize(float size);
36 float getSize() const { return size_; }
37
39 void setPosition(float x, float y, float z);
41 float getPositionX() const { return position_.x; }
43 float getPositionY() const { return position_.y; }
45 float getPositionZ() const { return position_.z; }
46
48 void setRotationEuler(float x, float y, float z);
50 float getRotationX() const { return rotation_.x; }
52 float getRotationY() const { return rotation_.y; }
54 float getRotationZ() const { return rotation_.z; }
55
57 void setScale(float x, float y, float z);
59 float getScaleX() const { return scale_.x; }
61 float getScaleY() const { return scale_.y; }
63 float getScaleZ() const { return scale_.z; }
64
66 void setBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
68 float getBoundsMinX() const { return boundsMin_.x; }
70 float getBoundsMinY() const { return boundsMin_.y; }
72 float getBoundsMinZ() const { return boundsMin_.z; }
74 float getBoundsMaxX() const { return boundsMax_.x; }
76 float getBoundsMaxY() const { return boundsMax_.y; }
78 float getBoundsMaxZ() const { return boundsMax_.z; }
79
81 void setSnapTranslate(float x, float y, float z);
83 void setSnapRotate(float degrees);
85 void setSnapScale(float s);
87 float getSnapTranslateX() const { return snapTranslate_.x; }
89 float getSnapTranslateY() const { return snapTranslate_.y; }
91 float getSnapTranslateZ() const { return snapTranslate_.z; }
93 float getSnapRotate() const { return snapRotateDeg_; }
95 float getSnapScale() const { return snapScale_; }
96
98 float getMatrix(int index) const;
99
104 std::string pick(float ox, float oy, float oz, float dx, float dy, float dz);
105
107 bool beginDrag(const std::string &axis, float ox, float oy, float oz, float dx, float dy,
108 float dz);
110 bool updateDrag(float ox, float oy, float oz, float dx, float dy, float dz);
112 void endDrag();
113
115 bool isDragging() const { return dragging_; }
117 bool isHovered() const { return !hoverAxis_.empty(); }
119 std::string getActiveAxis() const { return activeAxis_; }
121 std::string getHoverAxis() const { return hoverAxis_; }
122
124 void rebuildParts();
125
127 int getPartCount() const { return static_cast<int>(parts_.size()); }
129 std::string getPartKind(int index) const;
131 std::string getPartAxis(int index) const;
133 float getPartColorR(int index) const;
135 float getPartColorG(int index) const;
137 float getPartColorB(int index) const;
139 float getPartColorA(int index) const;
141 float getPartOriginX(int index) const;
143 float getPartOriginY(int index) const;
145 float getPartOriginZ(int index) const;
147 float getPartDirX(int index) const;
149 float getPartDirY(int index) const;
151 float getPartDirZ(int index) const;
153 float getPartLength(int index) const;
155 float getPartRadius(int index) const;
156
157private:
158 struct Part {
159 std::string kind; // axis | plane | ring | box | center | handle
160 std::string axis;
161 glm::vec3 origin{0.f};
162 glm::vec3 dir{1.f, 0.f, 0.f};
163 float length = 1.f;
164 float radius = 0.05f;
165 glm::vec4 color{1.f, 0.f, 0.f, 1.f};
166 };
167
168 glm::mat4 localRotationMatrix() const;
169 glm::mat4 worldMatrix() const;
170 glm::vec3 axisWorld(int axis) const; // 0=x,1=y,2=z
171 void colorForAxis(const std::string &axis, glm::vec4 &out) const;
172
173 float hitAxis(const glm::vec3 &ro, const glm::vec3 &rd, int axisIndex, float &outT) const;
174 float hitPlane(const glm::vec3 &ro, const glm::vec3 &rd, int planeMask, float &outT) const;
175 float hitRing(const glm::vec3 &ro, const glm::vec3 &rd, int axisIndex, float &outT) const;
176 float hitBoundHandle(const glm::vec3 &ro, const glm::vec3 &rd, int handle, float &outT) const;
177
178 glm::vec3 projectToDragPlane(const glm::vec3 &ro, const glm::vec3 &rd) const;
179 void applySnapTranslate(glm::vec3 &v) const;
180 float applySnapRotate(float radians) const;
181 float applySnapScale(float s) const;
182
183 bool validPart(int index) const;
184
185 std::string mode_ = "translate";
186 std::string space_ = "world";
187 float size_ = 1.f;
188
189 glm::vec3 position_{0.f};
190 glm::vec3 rotation_{0.f};
191 glm::vec3 scale_{1.f};
192 glm::vec3 boundsMin_{-0.5f};
193 glm::vec3 boundsMax_{0.5f};
194
195 glm::vec3 snapTranslate_{0.f};
196 float snapRotateDeg_ = 0.f;
197 float snapScale_ = 0.f;
198
199 bool dragging_ = false;
200 std::string activeAxis_;
201 std::string hoverAxis_;
202
203 glm::vec3 dragStartPos_{0.f};
204 glm::vec3 dragStartRot_{0.f};
205 glm::vec3 dragStartScale_{0.f};
206 glm::vec3 dragStartHit_{0.f};
207 glm::vec3 dragPlaneNormal_{0.f, 1.f, 0.f};
208 glm::vec3 dragAxisDir_{1.f, 0.f, 0.f};
209
210 std::vector<Part> parts_;
211};
212
213} // namespace eve::editor
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
const std::string & s
float degrees
Definition CardTypes.cpp:35
float length
Definition CaveMesh.cpp:94
#define EVENGINE_API_ORCHESTRATION
Definition Export.h:111
float v
TokenKind kind
float radius
PrimitiveHandle handle
V3 origin
Definition RoadBake.cpp:138
float dz
float dy
float dx
float size
Definition TreeMesh.cpp:156
V3 dir
Definition TreeMesh.cpp:150
uint32_t index
double oy
double ox
3D transform gizmo (Three.js TransformControls + ImGuizmo style). Owns TRS + optional local bounds; i...
float getSnapTranslateY() const
Returns the snap translate y.
std::string getHoverAxis() const
Returns the hover axis.
float getBoundsMinY() const
Returns the bounds min y.
float getSnapTranslateZ() const
Returns the snap translate z.
float getRotationZ() const
Returns the rotation z.
float getPositionY() const
Returns the position y.
bool isDragging() const
True when dragging.
float getBoundsMinZ() const
Returns the bounds min z.
float getSize() const
Returns the size.
bool isHovered() const
True when hovered.
float getRotationX() const
Returns the rotation x.
float getBoundsMinX() const
Returns the bounds min x.
std::string getMode() const
Returns the mode.
float getBoundsMaxZ() const
Returns the bounds max z.
float getSnapRotate() const
Returns the snap rotate.
float getScaleZ() const
Returns the scale z.
float getPositionZ() const
Returns the position z.
std::string getActiveAxis() const
Returns the active axis.
float getScaleX() const
Returns the scale x.
float getScaleY() const
Returns the scale y.
float getSnapTranslateX() const
Returns the snap translate x.
float getBoundsMaxX() const
Returns the bounds max x.
float getRotationY() const
Returns the rotation y.
float getSnapScale() const
Returns the snap scale.
std::string getSpace() const
Returns the space.
float getBoundsMaxY() const
Returns the bounds max y.
int getPartCount() const
Returns the part count.
float getPositionX() const
Returns the position x.
glm::vec4 color