载入中...
搜索中...
未找到
AnimLattice.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <vector>
5
6namespace eve::model3d {
7class ModelData;
8}
9
10namespace eve::animation {
11
42public:
43 static constexpr int kMinDivisions = 2;
44
46
48 explicit AnimLattice(int divX, int divY, int divZ);
49
50 AnimLattice(const AnimLattice&) = delete;
52
53 // ---- lattice frame ----
54
56 void setDivisions(int divX, int divY, int divZ);
57 int getDivisionsX() const { return divX_; }
58 int getDivisionsY() const { return divY_; }
59 int getDivisionsZ() const { return divZ_; }
60
62 void setSize(float sx, float sy, float sz);
63 float getSizeX() const { return sizeX_; }
64 float getSizeY() const { return sizeY_; }
65 float getSizeZ() const { return sizeZ_; }
66
68 void setOrigin(float ox, float oy, float oz);
69 float getOriginX() const { return originX_; }
70 float getOriginY() const { return originY_; }
71 float getOriginZ() const { return originZ_; }
72
77 void setClamp(bool clamp) { clamp_ = clamp; }
78 bool getClamp() const { return clamp_; }
79
80 // ---- control points ----
81
83 int getPointCount() const { return static_cast<int>(points_.size()); }
84
86 void setPointScale(int ix, int iy, int iz, float sx, float sy, float sz);
88 void setPointOffset(int ix, int iy, int iz, float dx, float dy, float dz);
89
91 void setScale(float sx, float sy, float sz);
93 void reset();
94
95 float getPointScaleX(int ix, int iy, int iz) const;
96 float getPointScaleY(int ix, int iy, int iz) const;
97 float getPointScaleZ(int ix, int iy, int iz) const;
98 float getPointOffsetX(int ix, int iy, int iz) const;
99 float getPointOffsetY(int ix, int iy, int iz) const;
100 float getPointOffsetZ(int ix, int iy, int iz) const;
101
102 // ---- binding ----
103
109 static AnimLattice* fromModel(const model3d::ModelData* model, int meshIndex, int divX, int divY, int divZ);
110
112 void bindModel(const model3d::ModelData* model, int meshIndex);
113
115 void bindPositions(const float* posXYZ, int count);
116
117 void clearBind();
118 int getVertexCount() const { return vertexCount_; }
119
121 float getBindPositionX(int vertexIndex) const;
122 float getBindPositionY(int vertexIndex) const;
123 float getBindPositionZ(int vertexIndex) const;
124
125 // ---- deformation ----
126
132 void deformPositions(const float* inPosXYZ, float* outPosXYZ, int count) const;
133
135 bool deformPositionsTo(const std::vector<float>& inPosXYZ, std::vector<float>& outPosXYZ) const;
136
142 bool deformNormals(const float* posXYZ, const float* inNrmXYZ, float* outNrmXYZ, int count) const;
143
145 bool updateDeformedPositions(const std::vector<float>& inPosXYZ);
146
149
154 bool updateDeformedNormals(const std::vector<float>& posXYZ, const std::vector<float>& inNrmXYZ);
155
157 bool hasDeformedPositions() const { return deformedValid_; }
158
160 bool hasDeformedNormals() const { return deformedNrmValid_; }
161
163 float getDeformedPositionX(int vertexIndex) const;
164 float getDeformedPositionY(int vertexIndex) const;
165 float getDeformedPositionZ(int vertexIndex) const;
166
168 std::vector<float> getDeformedPositions() const;
170 std::vector<float> getDeformedNormals() const;
171
172private:
173 struct ControlPoint {
174 float ox = 0.f, oy = 0.f, oz = 0.f;
175 float sx = 1.f, sy = 1.f, sz = 1.f;
176 };
177
178 void requirePoint(int ix, int iy, int iz) const;
179 void requireVertex(int vertexIndex) const;
180 int pointIndex(int ix, int iy, int iz) const;
181 void computeCell(float x, float y, float z, int& i0, int& j0, int& k0, float& fu, float& fv, float& fw) const;
182
183 int divX_ = kMinDivisions;
184 int divY_ = kMinDivisions;
185 int divZ_ = kMinDivisions;
186 float sizeX_ = 1.f;
187 float sizeY_ = 1.f;
188 float sizeZ_ = 1.f;
189 float originX_ = 0.f;
190 float originY_ = 0.f;
191 float originZ_ = 0.f;
192 bool clamp_ = true;
193
194 std::vector<ControlPoint> points_;
195 std::vector<float> bindPos_; // xyz packed
196 int vertexCount_ = 0;
197
198 std::vector<float> deformedPos_;
199 std::vector<float> deformedNrm_;
200 bool deformedValid_ = false;
201 bool deformedNrmValid_ = false;
202};
203
204} // namespace eve::animation
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
uint32_t i0
Definition Grass.cpp:62
int x
Definition Grass.cpp:135
glm::mat4 model
CPU 3D lattice scale-deformer (晶格缩放变形).
Definition AnimLattice.h:41
void setDivisions(int divX, int divY, int divZ)
Changes divisions; resets all control points to identity and clears the bind.
float getDeformedPositionX(int vertexIndex) const
Cached deformed position component (requires updateDeformedPositions).
std::vector< float > getDeformedNormals() const
Copy of the cached deformed normals (xyz packed; empty when not updated).
std::vector< float > getDeformedPositions() const
Copy of the cached deformed positions (xyz packed; empty when not updated).
void setPointScale(int ix, int iy, int iz, float sx, float sy, float sz)
Per-control-point scale (squash / stretch about the lattice origin).
float getPointOffsetX(int ix, int iy, int iz) const
AnimLattice(const AnimLattice &)=delete
bool updateDeformedPositions()
Deform the bound bind positions into the internal cache.
bool deformNormals(const float *posXYZ, const float *inNrmXYZ, float *outNrmXYZ, int count) const
Transforms normals with the interpolated scale field and renormalizes. posXYZ provides the (deformed)...
float getBindPositionZ(int vertexIndex) const
void setOrigin(float ox, float oy, float oz)
Center of the lattice box in model space.
void setClamp(bool clamp)
When true (default), vertices outside the box are clamped to the boundary cells; when false,...
Definition AnimLattice.h:77
AnimLattice & operator=(const AnimLattice &)=delete
void bindModel(const model3d::ModelData *model, int meshIndex)
Binds the current lattice to meshIndex of model (uses current divisions).
bool updateDeformedNormals(const std::vector< float > &posXYZ, const std::vector< float > &inNrmXYZ)
Deform packed xyz normals (with packed positions for cell lookup) into the internal normal cache.
float getPointScaleX(int ix, int iy, int iz) const
void deformPositions(const float *inPosXYZ, float *outPosXYZ, int count) const
Deforms count packed xyz positions into outPosXYZ. Both buffers must hold count * 3 floats; count mus...
float getPointOffsetY(int ix, int iy, int iz) const
float getDeformedPositionY(int vertexIndex) const
int getPointCount() const
Total control point count (divX * divY * divZ).
Definition AnimLattice.h:83
void setSize(float sx, float sy, float sz)
World-space size of the lattice box (components must be > 0).
float getDeformedPositionZ(int vertexIndex) const
void setPointOffset(int ix, int iy, int iz, float dx, float dy, float dz)
Per-control-point translation offset (local bulge / pinch).
bool hasDeformedPositions() const
True after a successful updateDeformedPositions().
float getPointScaleY(int ix, int iy, int iz) const
void setScale(float sx, float sy, float sz)
Applies one scale to every control point (whole-lattice squash & stretch).
static constexpr int kMinDivisions
Definition AnimLattice.h:43
static AnimLattice * fromModel(const model3d::ModelData *model, int meshIndex, int divX, int divY, int divZ)
Builds a lattice bound to meshIndex of model (Assimp vertices). Throws on null model / invalid mesh /...
bool deformPositionsTo(const std::vector< float > &inPosXYZ, std::vector< float > &outPosXYZ) const
Convenience: deform into a vector sized count*3.
float getBindPositionX(int vertexIndex) const
Bind-pose position component for vertex v (0..vertexCount-1).
float getPointOffsetZ(int ix, int iy, int iz) const
void reset()
Resets every control point to identity (offset 0, scale 1).
bool hasDeformedNormals() const
True after a successful updateDeformedNormals().
float getPointScaleZ(int ix, int iy, int iz) const
void bindPositions(const float *posXYZ, int count)
Binds a packed xyz array (count * 3 floats). Uses current divisions/size/origin.
float getBindPositionY(int vertexIndex) const
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Definition ModelData.h:23