axmol/cocos/3d/CCBundle3D.h

223 lines
7.2 KiB
C
Raw Normal View History

2014-06-05 16:36:01 +08:00
/****************************************************************************
Copyright (c) 2014 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__
2014-06-17 10:49:52 +08:00
#include "3d/CCBundle3DData.h"
#include "3d/3dExport.h"
2014-08-28 17:32:23 +08:00
#include "3d/CCBundleReader.h"
#include "json/document.h"
2014-06-12 10:01:54 +08:00
2014-06-05 16:36:01 +08:00
NS_CC_BEGIN
class Animation3D;
2014-06-19 15:43:02 +08:00
class Data;
2014-06-19 14:11:14 +08:00
/**
* 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
*/
class CC_3D_DLL Bundle3D
2014-06-05 16:36:01 +08:00
{
public:
2014-07-30 18:32:34 +08:00
/**you can define yourself bundle and set it, use default bundle otherwise*/
static void setBundleInstance(Bundle3D* bundleInstance);
2014-06-05 16:36:01 +08:00
static Bundle3D* getInstance();
2014-06-17 19:18:56 +08:00
static void destroyInstance();
2014-06-05 16:36:01 +08:00
2014-07-30 18:32:34 +08:00
virtual void clear();
/**
2014-06-19 14:11:14 +08:00
* 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
*/
2014-07-30 18:32:34 +08:00
virtual bool load(const std::string& path);
2014-06-05 16:36:01 +08:00
/**
* load mesh data from bundle
2014-06-05 16:47:03 +08:00
* @param id The ID of the mesh, load the first Mesh in the bundle if it is empty
2014-06-05 16:36:01 +08:00
*/
2014-07-30 18:32:34 +08:00
virtual bool loadMeshData(const std::string& id, MeshData* meshdata);
2014-06-05 16:36:01 +08:00
/**
* load skin data from bundle
2014-06-05 16:47:03 +08:00
* @param id The ID of the skin, load the first Skin in the bundle if it is empty
2014-06-05 16:36:01 +08:00
*/
2014-07-30 18:32:34 +08:00
virtual bool loadSkinData(const std::string& id, SkinData* skindata);
2014-06-05 16:36:01 +08:00
/**
* load material data from bundle
2014-06-05 16:47:03 +08:00
* @param id The ID of the material, load the first Material in the bundle if it is empty
2014-06-05 16:36:01 +08:00
*/
2014-07-30 18:32:34 +08:00
virtual bool loadMaterialData(const std::string& id, MaterialData* materialdata);
2014-06-05 16:36:01 +08:00
/**
* load material data from bundle
2014-06-05 16:47:03 +08:00
* @param id The ID of the animation, load the first animation in the bundle if it is empty
2014-06-05 16:36:01 +08:00
*/
2014-07-30 18:32:34 +08:00
virtual bool loadAnimationData(const std::string& id, Animation3DData* animationdata);
2014-08-15 13:03:53 +08:00
//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);
2014-08-17 22:49:53 +08:00
//load .obj file
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
2014-08-16 14:14:37 +08:00
protected:
bool loadJson(const std::string& path);
2014-08-16 14:14:37 +08:00
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);
2014-08-16 14:14:37 +08:00
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){return true;}
bool loadMeshDataJson_0_1(MeshData* meshdata){return true;}
bool loadMeshDataJson_0_2(MeshData* meshdata){return true;}
bool loadSkinDataJson(SkinData* skindata);
bool loadMaterialDataJson(MaterialData* materialdata){return true;}
bool loadMaterialDataJson_0_1(MaterialData* materialdata){return true;}
bool loadMaterialDataJson_0_2(MaterialData* materialdata){return true;}
bool loadAnimationDataJson(Animation3DData* animationdata);
/**
* load data in binary
* @param path The c3b file path
*/
2014-06-19 15:43:02 +08:00
bool loadBinary(const std::string& path);
/**
* load mesh data in binary
* @param meshdata The mesh data pointer
*/
2014-06-19 15:43:02 +08:00
bool loadMeshDataBinary(MeshData* meshdata);
2014-07-29 10:49:06 +08:00
bool loadMeshDataBinary_0_1(MeshData* meshdata);
bool loadMeshDataBinary_0_2(MeshData* meshdata);
2014-06-19 15:43:02 +08:00
/**
* load skin data in binary
* @param skindata The skin data pointer
*/
bool loadSkinDataBinary(SkinData* skindata);
/**
* load material data in binary
* @param materialdata The material pointer
*/
bool loadMaterialDataBinary(MaterialData* materialdata);
/**
* load animation data in binary
* @param animationdata The animation data pointer
*/
bool loadAnimationDataBinary(Animation3DData* animationdata);
2014-06-19 15:43:02 +08:00
2014-08-16 11:12:26 +08:00
bool checkIsBone(const std::string& name);
/**
* load nodes of json
*/
bool loadNodesJson(NodeDatas& nodedatas);
NodeData* parseNodesRecursivelyJson(const rapidjson::Value& jvalue);
/**
2014-08-16 14:28:15 +08:00
* load nodes of binary
2014-08-16 11:12:26 +08:00
*/
2014-08-16 14:28:15 +08:00
bool loadNodesBinary(NodeDatas& nodedatas);
NodeData* parseNodesRecursivelyBinary(bool& skeleton);
2014-08-16 11:12:26 +08:00
/**
* get define data type
* @param str The type in string
*/
GLenum parseGLType(const std::string& str);
2014-08-16 10:41:42 +08:00
/**
* 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);
2014-06-12 10:01:54 +08:00
/*
* get model path
* @param str Full path of model file
*/
void getModelRelativePath(const std::string& path);
2014-06-16 19:08:43 +08:00
/*
* set the read position in buffer to the target type
* @param The data type
*/
2014-06-19 15:43:02 +08:00
Reference* seekToFirstType(unsigned int type);
2014-06-17 19:18:56 +08:00
CC_CONSTRUCTOR_ACCESS:
2014-06-05 16:36:01 +08:00
Bundle3D();
2014-08-21 20:02:22 +08:00
virtual ~Bundle3D();
2014-06-05 16:36:01 +08:00
2014-06-17 19:18:56 +08:00
protected:
2014-06-05 16:36:01 +08:00
static Bundle3D* _instance;
2014-08-16 11:12:26 +08:00
std::string _modelPath;
2014-06-17 13:59:03 +08:00
std::string _path;
2014-06-25 09:13:24 +08:00
2014-07-29 10:49:06 +08:00
std::string _version;// the c3b or c3t version
2014-06-25 09:13:24 +08:00
// for json reading
char* _jsonBuffer;
rapidjson::Document _jsonReader;
2014-06-12 10:01:54 +08:00
2014-06-25 09:13:24 +08:00
// for binary reading
Data* _binaryBuffer;
BundleReader _binaryReader;
2014-06-30 17:10:07 +08:00
unsigned int _referenceCount;
2014-06-19 15:43:02 +08:00
Reference* _references;
2014-06-05 16:36:01 +08:00
bool _isBinary;
};
NS_CC_END
2014-07-31 10:28:39 +08:00
#endif // __CCBUNDLE3D_H__