2014-06-04 18:17:09 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCMESHSKIN_H__
|
|
|
|
#define __CCMESHSKIN_H__
|
|
|
|
|
2014-06-17 10:49:52 +08:00
|
|
|
#include "3d/CCBundle3DData.h"
|
2014-06-04 18:17:09 +08:00
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "base/CCVector.h"
|
|
|
|
#include "math/CCMath.h"
|
2019-02-15 14:30:10 +08:00
|
|
|
#include <vector>
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-27 14:10:41 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-07-30 18:32:34 +08:00
|
|
|
class Bone3D;
|
|
|
|
class Skeleton3D;
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
2015-03-27 14:10:41 +08:00
|
|
|
* @brief MeshSkin, A class maintain a collection of bones that affect Mesh vertex.
|
2015-12-09 00:45:39 +08:00
|
|
|
* And it is responsible for computing matrix palettes that used by skin mesh rendering.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-06-19 14:11:14 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
class CC_DLL MeshSkin : public Ref
|
2014-06-04 18:17:09 +08:00
|
|
|
{
|
2014-10-20 22:53:24 +08:00
|
|
|
friend class Mesh;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
public:
|
2014-06-19 14:11:14 +08:00
|
|
|
/**create a new meshskin if do not want to share meshskin*/
|
2014-07-30 18:32:34 +08:00
|
|
|
static MeshSkin* create(Skeleton3D* skeleton, const std::string& filename, const std::string& name);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
static MeshSkin* create(Skeleton3D* skeleton,
|
|
|
|
const std::vector<std::string>& boneNames,
|
|
|
|
const std::vector<Mat4>& invBindPose);
|
|
|
|
|
2014-06-26 21:58:26 +08:00
|
|
|
/**get total bone count, skin bone + node bone*/
|
|
|
|
ssize_t getBoneCount() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get bone*/
|
2014-07-11 10:17:36 +08:00
|
|
|
Bone3D* getBoneByIndex(unsigned int index) const;
|
|
|
|
Bone3D* getBoneByName(const std::string& id) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get bone index*/
|
2014-07-11 10:17:36 +08:00
|
|
|
int getBoneIndex(Bone3D* bone) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**compute matrix palette used by gpu skin*/
|
2014-06-09 18:37:58 +08:00
|
|
|
Vec4* getMatrixPalette();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**getSkinBoneCount() * 3*/
|
2014-06-19 12:01:03 +08:00
|
|
|
ssize_t getMatrixPaletteSize() const;
|
2019-02-15 14:30:10 +08:00
|
|
|
|
|
|
|
/**getSkinBoneCount() * 3 * sizeof(Vec4) */
|
|
|
|
ssize_t getMatrixPaletteSizeInBytes() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-18 17:02:13 +08:00
|
|
|
/**get root bone of the skin*/
|
|
|
|
Bone3D* getRootBone() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS :
|
|
|
|
|
|
|
|
MeshSkin();
|
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
~MeshSkin();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**remove all bones*/
|
2014-06-04 18:17:09 +08:00
|
|
|
void removeAllBones();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**add skin bone*/
|
2014-07-11 10:17:36 +08:00
|
|
|
void addSkinBone(Bone3D* bone);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-20 22:53:24 +08:00
|
|
|
/** get inverse bind pose */
|
|
|
|
const Mat4& getInvBindPose(const Bone3D* bone);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
Vector<Bone3D*> _skinBones; // bones with skin
|
|
|
|
std::vector<Mat4> _invBindPoses; // inverse bind pose of bone
|
2014-06-19 12:01:03 +08:00
|
|
|
|
2014-07-11 10:17:36 +08:00
|
|
|
Bone3D* _rootBone;
|
2021-12-25 10:04:45 +08:00
|
|
|
Skeleton3D* _skeleton; // skeleton the skin referred
|
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
// Pointer to the array of palette matrices.
|
|
|
|
// This array is passed to the vertex shader as a uniform.
|
|
|
|
// Each 4x3 row-wise matrix is represented as 3 Vec4's.
|
2014-06-19 12:01:03 +08:00
|
|
|
// The number of Vec4's is (_skinBones.size() * 3).
|
2019-02-15 14:30:10 +08:00
|
|
|
std::vector<Vec4> _matrixPalette;
|
2014-06-04 18:17:09 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCSKIN_H__
|