2014-06-05 16:36:01 +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-05 16:36:01 +08:00
|
|
|
|
2022-01-04 12:36:20 +08:00
|
|
|
https://adxeproject.github.io/
|
2014-06-05 16:36:01 +08:00
|
|
|
|
|
|
|
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__
|
|
|
|
|
2016-01-15 00:52:12 +08:00
|
|
|
#include "base/CCData.h"
|
2014-06-17 10:49:52 +08:00
|
|
|
#include "3d/CCBundle3DData.h"
|
2014-08-28 17:32:23 +08:00
|
|
|
#include "3d/CCBundleReader.h"
|
2020-05-06 15:42:25 +08:00
|
|
|
#include "rapidjson/document-wrapper.h"
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
NS_CC_BEGIN
|
2015-03-27 14:10:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
class Animation3D;
|
2014-06-19 15:43:02 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
2015-03-27 14:10:41 +08:00
|
|
|
* @brief Defines a bundle file that contains a collection of assets. Mesh, Material, MeshSkin, Animation
|
2014-06-19 14:11:14 +08:00
|
|
|
* There are two types of bundle files, c3t and c3b.
|
|
|
|
* c3t text file
|
|
|
|
* c3b binary file
|
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
|
|
|
*/
|
2014-10-09 09:30:23 +08:00
|
|
|
class CC_DLL Bundle3D
|
2014-06-05 16:36:01 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-20 17:20:22 +08:00
|
|
|
/**
|
|
|
|
* create a new bundle, destroy it when finish using it
|
|
|
|
*/
|
2014-12-19 10:20:44 +08:00
|
|
|
static Bundle3D* createBundle();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-19 10:20:44 +08:00
|
|
|
static void destroyBundle(Bundle3D* bundle);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
virtual void clear();
|
2014-06-20 15:30:08 +08:00
|
|
|
|
2019-01-30 09:35:17 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* get define data type
|
|
|
|
* @param str The type in string
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static backend::VertexFormat parseGLDataType(std::string_view str, int size);
|
2019-01-30 09:35:17 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* get define data type
|
|
|
|
* @param str The type in string
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static backend::SamplerAddressMode parseSamplerAddressMode(std::string_view str);
|
2019-01-30 09:35:17 +08:00
|
|
|
|
2014-06-20 15:30:08 +08:00
|
|
|
/**
|
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-06-20 15:30:08 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual bool load(std::string_view path);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual bool loadSkinData(std::string_view id, SkinData* skindata);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
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
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual bool loadAnimationData(std::string_view id, Animation3DData* animationdata);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// since 3.3, to support reskin
|
2014-08-15 13:03:53 +08:00
|
|
|
virtual bool loadMeshDatas(MeshDatas& meshdatas);
|
2021-12-25 10:04:45 +08:00
|
|
|
// since 3.3, to support reskin
|
2014-08-15 13:03:53 +08:00
|
|
|
virtual bool loadNodes(NodeDatas& nodedatas);
|
2021-12-25 10:04:45 +08:00
|
|
|
// since 3.3, to support reskin
|
2014-08-15 13:03:53 +08:00
|
|
|
virtual bool loadMaterials(MaterialDatas& materialdatas);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-14 10:30:20 +08:00
|
|
|
/**
|
|
|
|
* load triangle list
|
|
|
|
* @param path the file path to load
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static std::vector<Vec3> getTrianglesList(std::string_view path);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// load .obj file
|
|
|
|
static bool loadObj(MeshDatas& meshdatas,
|
|
|
|
MaterialDatas& materialdatas,
|
|
|
|
NodeDatas& nodedatas,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view fullPath,
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* mtl_basepath = nullptr);
|
|
|
|
|
|
|
|
// calculate aabb
|
2014-12-08 10:30:06 +08:00
|
|
|
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
|
2014-06-20 15:30:08 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
protected:
|
2021-12-26 23:26:34 +08:00
|
|
|
bool loadJson(std::string_view path);
|
|
|
|
bool loadBinary(std::string_view 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);
|
2014-08-18 17:31:04 +08:00
|
|
|
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);
|
2014-08-18 17:31:04 +08:00
|
|
|
bool loadMaterialsBinary_0_1(MaterialDatas& materialdatas);
|
|
|
|
bool loadMaterialsBinary_0_2(MaterialDatas& materialdatas);
|
2016-11-16 09:48:37 +08:00
|
|
|
bool loadMeshDataJson(MeshData* meshdata);
|
|
|
|
bool loadMeshDataJson_0_1(MeshData* meshdata);
|
|
|
|
bool loadMeshDataJson_0_2(MeshData* meshdata);
|
2014-06-20 15:30:08 +08:00
|
|
|
bool loadSkinDataJson(SkinData* skindata);
|
2014-10-21 18:44:10 +08:00
|
|
|
bool loadSkinDataBinary(SkinData* skindata);
|
2016-11-16 09:48:37 +08:00
|
|
|
bool loadMaterialDataJson(MaterialData* materialdata);
|
|
|
|
bool loadMaterialDataJson_0_1(MaterialData* materialdata);
|
|
|
|
bool loadMaterialDataJson_0_2(MaterialData* materialdata);
|
2021-12-26 23:26:34 +08:00
|
|
|
bool loadAnimationDataJson(std::string_view id, Animation3DData* animationdata);
|
|
|
|
bool loadAnimationDataBinary(std::string_view id, Animation3DData* animationdata);
|
2014-06-19 15:43:02 +08:00
|
|
|
|
2014-08-16 11:12:26 +08:00
|
|
|
/**
|
|
|
|
* load nodes of json
|
|
|
|
*/
|
|
|
|
bool loadNodesJson(NodeDatas& nodedatas);
|
2015-03-24 17:59:24 +08:00
|
|
|
NodeData* parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bool singleSprite);
|
2014-08-16 11:12:26 +08:00
|
|
|
|
|
|
|
/**
|
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);
|
2015-03-24 17:59:24 +08:00
|
|
|
NodeData* parseNodesRecursivelyBinary(bool& skeleton, bool singleSprite);
|
2014-08-16 11:12:26 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2014-08-16 10:41:42 +08:00
|
|
|
* get define data type
|
|
|
|
* @param str The type in string
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
NTextureData::Usage parseGLTextureType(std::string_view str);
|
2014-08-16 10:41:42 +08:00
|
|
|
|
2014-06-20 15:30:08 +08:00
|
|
|
/**
|
|
|
|
* get vertex attribute type
|
|
|
|
* @param str The type in string
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
shaderinfos::VertexKey parseGLProgramAttribute(std::string_view str);
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-20 15:30:08 +08:00
|
|
|
/*
|
|
|
|
* get model path
|
|
|
|
* @param str Full path of model file
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void getModelRelativePath(std::string_view path);
|
2014-06-16 19:08:43 +08:00
|
|
|
|
2014-06-20 15:30:08 +08:00
|
|
|
/*
|
2014-11-18 16:10:33 +08:00
|
|
|
* set the read position in buffer to the target type
|
|
|
|
* @param The data type
|
|
|
|
* @param The data id
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
Reference* seekToFirstType(unsigned int type, std::string_view id = "");
|
2014-06-19 15:43:02 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS : Bundle3D();
|
2014-08-21 20:02:22 +08:00
|
|
|
virtual ~Bundle3D();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
protected:
|
2014-08-16 11:12:26 +08:00
|
|
|
std::string _modelPath;
|
2014-10-21 18:44:10 +08:00
|
|
|
std::string _path;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string _version; // the c3b or c3t version
|
|
|
|
|
2014-06-25 09:13:24 +08:00
|
|
|
// for json reading
|
2016-01-15 00:52:12 +08:00
|
|
|
std::string _jsonBuffer;
|
2014-06-25 09:13:24 +08:00
|
|
|
rapidjson::Document _jsonReader;
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-25 09:13:24 +08:00
|
|
|
// for binary reading
|
2016-01-15 00:52:12 +08:00
|
|
|
Data _binaryBuffer;
|
2014-06-25 09:13:24 +08:00
|
|
|
BundleReader _binaryReader;
|
2014-06-30 17:10:07 +08:00
|
|
|
unsigned int _referenceCount;
|
2014-06-19 15:43:02 +08:00
|
|
|
Reference* _references;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool _isBinary;
|
2014-06-05 16:36:01 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCBUNDLE3D_H__
|