载入中...
搜索中...
未找到
AnimSkin.cpp
浏览该文件的文档.
60 const std::size_t vertices = streams.vertexCount > 0 ? static_cast<std::size_t>(streams.vertexCount) : 0U;
70 for (float value : streams.bindPositions) if (!std::isfinite(value)) return fail("AnimSkin position is non-finite");
71 for (float value : streams.bindNormals) if (!std::isfinite(value)) return fail("AnimSkin normal is non-finite");
98 skin->influences_[index].bone = streams.vertexWeights[index] > 0.F ? streams.vertexSkinJoints[index] : -1;
137 if (!matrixPaletteValid_) throw Exception("AnimSkin.getMatrixPaletteElement: call updateMatrixPalette first");
164 if (!mesh || !mesh->hasGpuSkinning() || !updateMatrixPalette(pose) || skinMatrices_.empty()) return false;
165 return mesh->setSkinPalette(skinMatrices_.front().m, static_cast<int>(skinMatrices_.size())).ok();
186 const Influence& inf = influences_[static_cast<size_t>(vertexIndex) * kMaxInfluences + influenceIndex];
194 throw Exception("AnimSkin.getVertexSkinJoint: influenceIndex must be 0..%d", kMaxInfluences - 1);
260 if (!skinnedValid_) throw Exception("AnimSkin.getSkinnedPositionX: call updateSkinnedPositions first");
265 if (!skinnedValid_) throw Exception("AnimSkin.getSkinnedPositionY: call updateSkinnedPositions first");
270 if (!skinnedValid_) throw Exception("AnimSkin.getSkinnedPositionZ: call updateSkinnedPositions first");
341bool AnimSkin::applyToMesh(graphics::Graphics* gfx, graphics::Mesh* mesh, const AnimPose* pose) {
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
int getSkeletonBone(int skinBoneIndex) const
Skeleton bone index used by skin joint i (-1 if unused).
Definition AnimSkin.cpp:104
bool applyToMesh(graphics::Graphics *gfx, graphics::Mesh *mesh, const AnimPose *pose)
Skin positions (and normals when available) and write the result back to a GPU mesh in one call....
Definition AnimSkin.cpp:341
float getInverseBindElement(int skinBoneIndex, int elementIndex) const
Inverse-bind matrix element (column-major, 0..15) for skin joint i.
Definition AnimSkin.cpp:114
std::vector< float > getSkinnedPositions() const
Packed skinned positions (xyz, vertexCount*3) as a copy. Empty when updateSkinnedPositions() has not ...
Definition AnimSkin.cpp:274
float getSkinnedPositionX(int vertexIndex) const
Cached skinned position component (requires updateSkinnedPositions).
Definition AnimSkin.cpp:258
bool updateMatrixPalette(const AnimPose *pose) const
Build and cache the column-major skinning matrix palette for a pose. The palette contains boneWorld *...
Definition AnimSkin.cpp:122
float getBindPositionX(int vertexIndex) const
Bind-pose (unskinned) position component for vertex v (0..vertexCount-1).
Definition AnimSkin.cpp:168
int getVertexBone(int vertexIndex, int influenceIndex) const
Influence slot i (0..3) for vertex: skeleton bone index or -1.
Definition AnimSkin.cpp:181
bool updateSkinnedPositions(const AnimPose *pose)
Skin into an internal cache readable via getSkinnedPosition*. Returns false if pose is null or there ...
Definition AnimSkin.cpp:247
float getMatrixPaletteElement(int skinBoneIndex, int elementIndex) const
Cached palette element for one skin bone (elementIndex 0..15).
Definition AnimSkin.cpp:135
bool updateSkinnedNormals(const AnimPose *pose)
Skin the bind-pose normals captured at fromModel with the pose. pose must already have computeWorld(s...
Definition AnimSkin.cpp:279
bool skinPositionsTo(const AnimPose *pose, std::vector< float > &outPosXYZ) const
Convenience: skin into a vector sized vertexCount*3. Returns false if pose is null or bone count mism...
Definition AnimSkin.cpp:240
float getVertexWeight(int vertexIndex, int influenceIndex) const
Returns the vertex weight.
Definition AnimSkin.cpp:198
std::string getSkinBoneName(int skinBoneIndex) const
Returns the skin bone name.
Definition AnimSkin.cpp:109
bool bindGpuMesh(graphics::Graphics *gfx, graphics::Mesh *mesh)
Upload this skin's joint/weight vertex stream to an existing GPU mesh.
Definition AnimSkin.cpp:144
std::vector< float > getSkinnedNormals() const
Packed skinned normals (xyz, vertexCount*3) as a copy.
Definition AnimSkin.cpp:336
float getBindPositionZ(int vertexIndex) const
Returns the bind position z.
Definition AnimSkin.cpp:176
bool updateGpuMesh(graphics::Mesh *mesh, const AnimPose *pose) const
Update a bound GPU mesh's matrix palette from a world-computed pose.
Definition AnimSkin.cpp:163
static Result< std::unique_ptr< AnimSkin > > fromStreams(AnimSkinStreamData streams)
Construct a caller-owned skin from validated native streams.
Definition AnimSkin.cpp:55
int getVertexSkinJoint(int vertexIndex, int influenceIndex) const
Influence slot i (0..3) for vertex: skin-local joint index or -1.
Definition AnimSkin.cpp:191
float getSkinnedPositionZ(int vertexIndex) const
Returns the skinned position z.
Definition AnimSkin.cpp:268
float getSkinnedPositionY(int vertexIndex) const
Returns the skinned position y.
Definition AnimSkin.cpp:263
float getBindPositionY(int vertexIndex) const
Returns the bind position y.
Definition AnimSkin.cpp:172
void skinPositions(const AnimPose *pose, float *outPosXYZ) const
Linear-blend skin bind-pose positions into outPosXYZ (vertexCount*3 floats). pose must already have c...
Definition AnimSkin.cpp:206
Definition Graphics.h:125
virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
In-place update of a mesh's vertex/index data (CPU -> host-visible VBO). Mirrors bakeMeshMorph: the u...
virtual bool setMeshSkinningData(Mesh *mesh, const uint16_t *joints4, const float *weights4, int vertexCount)
Upload four joint indices and weights per vertex for built-in GPU skinning.
Definition Graphics.h:882
Definition Animation.cpp:58
@ Exception
@ InvalidArgument
Owned native streams for constructing a skin outside the model importer.
Definition AnimSkin.h:28
std::vector< std::array< float, 16 > > inverseBindMatrices
Definition AnimSkin.h:34
std::vector< int > vertexSkinJoints
Definition AnimSkin.h:35
std::vector< std::string > boneNames
Definition AnimSkin.h:33
std::vector< int > skeletonBones
Definition AnimSkin.h:32
std::vector< float > bindPositions
Definition AnimSkin.h:30
std::vector< float > bindNormals
Definition AnimSkin.h:31
std::vector< float > vertexWeights
Definition AnimSkin.h:36
Column-major 4x4 matrix (OpenGL / glTF / Assimp-compatible layout). Elements: m[col * 4 + row].
Definition AnimMath.h:156