123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- /****************************************************************************
- Copyright (c) 2014-2017 Chukong Technologies Inc.
- 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 __CCBUNDLE3D_H__
- #define __CCBUNDLE3D_H__
- #include "base/CCData.h"
- #include "3d/CCBundle3DData.h"
- #include "3d/CCBundleReader.h"
- #include "json/document-wrapper.h"
- NS_CC_BEGIN
- /**
- * @addtogroup _3d
- * @{
- */
- class Animation3D;
- /**
- * @brief Defines a bundle file that contains a collection of assets. Mesh, Material, MeshSkin, Animation
- * There are two types of bundle files, c3t and c3b.
- * c3t text file
- * c3b binary file
- * @js NA
- * @lua NA
- */
- class CC_DLL Bundle3D
- {
- public:
- /**
- * create a new bundle, destroy it when finish using it
- */
- static Bundle3D* createBundle();
-
- static void destroyBundle(Bundle3D* bundle);
-
- virtual void clear();
- /**
- * load a file. You must load a file first, then call loadMeshData, loadSkinData, and so on
- * @param path File to be loaded
- * @return result of load
- */
- virtual bool load(const std::string& path);
-
- /**
- * load skin data from bundle
- * @param id The ID of the skin, load the first Skin in the bundle if it is empty
- */
- virtual bool loadSkinData(const std::string& id, SkinData* skindata);
-
- /**
- * load material data from bundle
- * @param id The ID of the animation, load the first animation in the bundle if it is empty
- */
- virtual bool loadAnimationData(const std::string& id, Animation3DData* animationdata);
-
- //since 3.3, to support reskin
- virtual bool loadMeshDatas(MeshDatas& meshdatas);
- //since 3.3, to support reskin
- virtual bool loadNodes(NodeDatas& nodedatas);
- //since 3.3, to support reskin
- virtual bool loadMaterials(MaterialDatas& materialdatas);
-
- /**
- * load triangle list
- * @param path the file path to load
- */
- static std::vector<Vec3> getTrianglesList(const std::string& path);
-
- //load .obj file
- static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
-
- //calculate aabb
- static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
-
- protected:
- bool loadJson(const std::string& path);
- bool loadBinary(const std::string& path);
- bool loadMeshDatasJson(MeshDatas& meshdatas);
- bool loadMeshDataJson_0_1(MeshDatas& meshdatas);
- bool loadMeshDataJson_0_2(MeshDatas& meshdatas);
- bool loadMeshDatasBinary(MeshDatas& meshdatas);
- bool loadMeshDatasBinary_0_1(MeshDatas& meshdatas);
- bool loadMeshDatasBinary_0_2(MeshDatas& meshdatas);
- bool loadMaterialsJson(MaterialDatas& materialdatas);
- bool loadMaterialDataJson_0_1(MaterialDatas& materialdatas);
- bool loadMaterialDataJson_0_2(MaterialDatas& materialdatas);
- bool loadMaterialsBinary(MaterialDatas& materialdatas);
- bool loadMaterialsBinary_0_1(MaterialDatas& materialdatas);
- bool loadMaterialsBinary_0_2(MaterialDatas& materialdatas);
- bool loadMeshDataJson(MeshData* meshdata);
- bool loadMeshDataJson_0_1(MeshData* meshdata);
- bool loadMeshDataJson_0_2(MeshData* meshdata);
- bool loadSkinDataJson(SkinData* skindata);
- bool loadSkinDataBinary(SkinData* skindata);
- bool loadMaterialDataJson(MaterialData* materialdata);
- bool loadMaterialDataJson_0_1(MaterialData* materialdata);
- bool loadMaterialDataJson_0_2(MaterialData* materialdata);
- bool loadAnimationDataJson(const std::string& id,Animation3DData* animationdata);
- bool loadAnimationDataBinary(const std::string& id,Animation3DData* animationdata);
- /**
- * load nodes of json
- */
- bool loadNodesJson(NodeDatas& nodedatas);
- NodeData* parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bool singleSprite);
- /**
- * load nodes of binary
- */
- bool loadNodesBinary(NodeDatas& nodedatas);
- NodeData* parseNodesRecursivelyBinary(bool& skeleton, bool singleSprite);
- /**
- * get define data type
- * @param str The type in string
- */
- GLenum parseGLType(const std::string& str);
- /**
- * get define data type
- * @param str The type in string
- */
- NTextureData::Usage parseGLTextureType(const std::string& str);
- /**
- * get vertex attribute type
- * @param str The type in string
- */
- unsigned int parseGLProgramAttribute(const std::string& str);
- /*
- * get model path
- * @param str Full path of model file
- */
- void getModelRelativePath(const std::string& path);
- /*
- * set the read position in buffer to the target type
- * @param The data type
- * @param The data id
- */
- Reference* seekToFirstType(unsigned int type, const std::string& id = "");
- CC_CONSTRUCTOR_ACCESS:
- Bundle3D();
- virtual ~Bundle3D();
-
- protected:
- std::string _modelPath;
- std::string _path;
- std::string _version;// the c3b or c3t version
-
- // for json reading
- std::string _jsonBuffer;
- rapidjson::Document _jsonReader;
- // for binary reading
- Data _binaryBuffer;
- BundleReader _binaryReader;
- unsigned int _referenceCount;
- Reference* _references;
- bool _isBinary;
- };
- // end of 3d group
- /// @}
- NS_CC_END
- #endif // __CCBUNDLE3D_H__
|