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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-17 10:49:52 +08:00
|
|
|
#include "3d/CCBundle3D.h"
|
2014-06-05 16:36:01 +08:00
|
|
|
|
|
|
|
#include "base/ccMacros.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
|
2014-06-17 10:49:52 +08:00
|
|
|
|
2014-06-12 16:28:36 +08:00
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, const rapidjson::Value& val)
|
2014-06-12 10:01:54 +08:00
|
|
|
{
|
2014-06-12 15:53:41 +08:00
|
|
|
if (!skinData)
|
|
|
|
return;
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
if (!val.HasMember("children"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string parent_name = val["id"].GetString();
|
|
|
|
int parent_name_index = skinData->getBoneNameIndex(parent_name);
|
|
|
|
|
|
|
|
const rapidjson::Value& children = val["children"];
|
|
|
|
for (rapidjson::SizeType i = 0; i < children.Size(); i++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& child = children[i];
|
|
|
|
std::string child_name = child["id"].GetString();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
int child_name_index = skinData->getBoneNameIndex(child_name);
|
|
|
|
if (child_name_index >= 0)
|
|
|
|
{
|
2014-06-12 18:26:42 +08:00
|
|
|
map[parent_name_index].push_back(child_name_index);
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
getChildMap(map, skinData, child);
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
void getChildMapT(std::map<std::string, std::vector<std::string> >& map, const SkinData* skinData, const rapidjson::Value& val)
|
|
|
|
{
|
|
|
|
if (!skinData)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!val.HasMember("children"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string parent_name = val["id"].GetString();
|
|
|
|
const rapidjson::Value& children = val["children"];
|
|
|
|
for (rapidjson::SizeType i = 0; i < children.Size(); i++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& child = children[i];
|
|
|
|
std::string child_name = child["id"].GetString();
|
|
|
|
|
|
|
|
map[parent_name].push_back(child_name);
|
|
|
|
|
|
|
|
getChildMapT(map, skinData, child);
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 15:53:41 +08:00
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
Bundle3D* Bundle3D::_instance = nullptr;
|
2014-06-06 19:12:08 +08:00
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
Bundle3D* Bundle3D::getInstance()
|
|
|
|
{
|
|
|
|
if (_instance == nullptr)
|
|
|
|
_instance = new Bundle3D();
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bundle3D::purgeBundle3D()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Bundle3D::load(const std::string& path)
|
|
|
|
{
|
2014-06-17 13:59:03 +08:00
|
|
|
if (_path == path)
|
|
|
|
return true;
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-17 13:59:03 +08:00
|
|
|
getModelPath(path);
|
2014-06-12 10:01:54 +08:00
|
|
|
std::string strFileString = FileUtils::getInstance()->getStringFromFile(path);
|
2014-06-16 19:30:45 +08:00
|
|
|
ssize_t size = strFileString.length();
|
2014-06-12 10:01:54 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(_documentBuffer);
|
|
|
|
_documentBuffer = new char[size + 1];
|
2014-06-16 19:30:45 +08:00
|
|
|
memcpy(_documentBuffer, strFileString.c_str(), size);
|
2014-06-12 10:01:54 +08:00
|
|
|
_documentBuffer[size] = '\0';
|
2014-06-16 19:08:43 +08:00
|
|
|
if (_document.ParseInsitu<0>(_documentBuffer).HasParseError())
|
2014-06-13 19:26:46 +08:00
|
|
|
{
|
2014-06-17 13:59:03 +08:00
|
|
|
assert(0);
|
|
|
|
CC_SAFE_DELETE_ARRAY(_documentBuffer);
|
|
|
|
_path = "";
|
|
|
|
return false;
|
2014-06-13 19:26:46 +08:00
|
|
|
}
|
2014-06-17 13:59:03 +08:00
|
|
|
_path = path;
|
2014-06-05 16:36:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-05 18:21:25 +08:00
|
|
|
/**
|
|
|
|
* load mesh data from bundle
|
|
|
|
* @param id The ID of the mesh, load the first Mesh in the bundle if it is empty
|
|
|
|
*/
|
|
|
|
bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
|
|
|
|
{
|
2014-06-06 19:12:08 +08:00
|
|
|
meshdata->resetData();
|
2014-06-09 18:37:58 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
assert(_document.HasMember("mesh"));
|
|
|
|
const rapidjson::Value& mash_data_array = _document["mesh"];
|
2014-06-16 14:09:41 +08:00
|
|
|
|
2014-06-16 15:38:03 +08:00
|
|
|
assert(mash_data_array.IsArray());
|
|
|
|
const rapidjson::Value& mash_data_val = mash_data_array[(rapidjson::SizeType)0];
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
assert(mash_data_val.HasMember("body"));
|
|
|
|
const rapidjson::Value& mesh_data_body_array = mash_data_val["body"];
|
|
|
|
|
|
|
|
assert(mesh_data_body_array.IsArray());
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& mesh_data_body_array_0 = mesh_data_body_array[(rapidjson::SizeType)0];
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
// vertex_size
|
2014-06-16 19:08:43 +08:00
|
|
|
assert(mesh_data_body_array_0.HasMember("vertexsize"));
|
|
|
|
meshdata->vertexSizeInFloat = mesh_data_body_array_0["vertexsize"].GetInt();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
// vertices
|
2014-06-16 00:01:38 +08:00
|
|
|
meshdata->vertex.resize(meshdata->vertexSizeInFloat);
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& mesh_data_body_vertices = mesh_data_body_array_0["vertices"];
|
|
|
|
for (rapidjson::SizeType i = 0; i < mesh_data_body_vertices.Size(); i++)
|
|
|
|
meshdata->vertex[i] = mesh_data_body_vertices[i].GetDouble();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
// index_number
|
2014-06-16 19:08:43 +08:00
|
|
|
meshdata->numIndex = mesh_data_body_array_0["indexnum"].GetUint();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
// indices
|
2014-06-16 00:01:38 +08:00
|
|
|
meshdata->indices.resize(meshdata->numIndex);
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& mesh_data_body_indices_val = mesh_data_body_array_0["indices"];
|
2014-06-12 10:01:54 +08:00
|
|
|
for (rapidjson::SizeType i = 0; i < mesh_data_body_indices_val.Size(); i++)
|
|
|
|
meshdata->indices[i] = (unsigned short)mesh_data_body_indices_val[i].GetUint();
|
|
|
|
|
|
|
|
// mesh_vertex_attribute
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& mesh_vertex_attribute = mash_data_val["attributes"];
|
2014-06-12 10:01:54 +08:00
|
|
|
meshdata->attribCount = mesh_vertex_attribute.Size();
|
2014-06-16 00:01:38 +08:00
|
|
|
meshdata->attribs.resize(meshdata->attribCount);
|
2014-06-12 10:01:54 +08:00
|
|
|
for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i];
|
|
|
|
|
|
|
|
meshdata->attribs[i].size = mesh_vertex_attribute_val["size"].GetUint();
|
2014-06-12 18:26:42 +08:00
|
|
|
meshdata->attribs[i].attribSizeBytes = meshdata->attribs[i].size * parseGLTypeSize(mesh_vertex_attribute_val["type"].GetString());
|
2014-06-12 10:01:54 +08:00
|
|
|
meshdata->attribs[i].type = parseGLType(mesh_vertex_attribute_val["type"].GetString());
|
2014-06-16 19:08:43 +08:00
|
|
|
meshdata->attribs[i].vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val["attribute"].GetString());
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
|
2014-06-05 18:21:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
/**
|
|
|
|
* load skin data from bundle
|
|
|
|
* @param id The ID of the skin, load the first Skin in the bundle if it is empty
|
|
|
|
*/
|
|
|
|
bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
|
|
|
|
{
|
2014-06-16 19:08:43 +08:00
|
|
|
if (!_document.HasMember("skin")) return false;
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
skindata->resetData();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& skin_data_array = _document["skin"];
|
2014-06-16 15:38:03 +08:00
|
|
|
|
2014-06-12 10:01:54 +08:00
|
|
|
assert(skin_data_array.IsArray());
|
|
|
|
const rapidjson::Value& skin_data_array_val_0 = skin_data_array[(rapidjson::SizeType)0];
|
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
if (!skin_data_array_val_0.HasMember("bones"))
|
|
|
|
return false;
|
|
|
|
|
2014-06-12 10:01:54 +08:00
|
|
|
const rapidjson::Value& skin_data_bones = skin_data_array_val_0["bones"];
|
|
|
|
for (rapidjson::SizeType i = 0; i < skin_data_bones.Size(); i++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& skin_data_bone = skin_data_bones[i];
|
|
|
|
std::string name = skin_data_bone["node"].GetString();
|
|
|
|
skindata->boneNames.push_back(name);
|
2014-06-16 19:08:43 +08:00
|
|
|
|
2014-06-12 10:01:54 +08:00
|
|
|
Mat4 mat_bind_pos;
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& bind_pos = skin_data_bone["bindshape"];
|
2014-06-12 10:01:54 +08:00
|
|
|
for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
|
|
|
|
{
|
|
|
|
mat_bind_pos.m[j] = bind_pos[j].GetDouble();
|
|
|
|
}
|
2014-06-16 15:38:03 +08:00
|
|
|
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos);
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& skin_data_1 = skin_data_array[1];
|
|
|
|
const rapidjson::Value& bone_array_0 = skin_data_1["children"][(rapidjson::SizeType)0];
|
|
|
|
skindata->rootBoneIndex = skindata->getBoneNameIndex(bone_array_0["id"].GetString());
|
|
|
|
getChildMap(skindata->boneChild, skindata, bone_array_0);
|
2014-06-05 18:21:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* load material data from bundle
|
|
|
|
* @param id The ID of the material, load the first Material in the bundle if it is empty
|
|
|
|
*/
|
|
|
|
bool Bundle3D::loadMaterialData(const std::string& id, MaterialData* materialdata)
|
|
|
|
{
|
2014-06-16 19:08:43 +08:00
|
|
|
if (!_document.HasMember("material"))
|
2014-06-13 19:26:46 +08:00
|
|
|
return false;
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& material_data_array = _document["material"];
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& material_data_array_0 = material_data_array[(rapidjson::SizeType)0];
|
|
|
|
|
|
|
|
const rapidjson::Value& material_data_base_array = material_data_array_0["base"];
|
|
|
|
|
|
|
|
const rapidjson::Value& material_data_base_array_0 = material_data_base_array[(rapidjson::SizeType)0];
|
|
|
|
|
|
|
|
materialdata->texturePath = _modelRelativePath + material_data_base_array_0["filename"].GetString();
|
2014-06-13 19:26:46 +08:00
|
|
|
|
2014-06-05 18:21:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* load material data from bundle
|
|
|
|
* @param id The ID of the animation, load the first animation in the bundle if it is empty
|
|
|
|
*/
|
|
|
|
bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animationdata)
|
|
|
|
{
|
2014-06-16 19:08:43 +08:00
|
|
|
if (!_document.HasMember("animation")) return false;
|
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
animationdata->_rotationKeys.clear();
|
|
|
|
animationdata->_scaleKeys.clear();
|
|
|
|
animationdata->_translationKeys.clear();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& animation_data_array = _document["animation"];
|
|
|
|
if (animation_data_array.Size()==0) return false;
|
2014-06-12 16:28:36 +08:00
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
const rapidjson::Value& animation_data_array_val_0 = animation_data_array[(rapidjson::SizeType)0];
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-16 15:38:03 +08:00
|
|
|
animationdata->_totalTime = animation_data_array_val_0["length"].GetDouble();
|
|
|
|
|
2014-06-12 10:01:54 +08:00
|
|
|
const rapidjson::Value& bones = animation_data_array_val_0["bones"];
|
2014-06-16 19:08:43 +08:00
|
|
|
for (rapidjson::SizeType i = 0; i < bones.Size(); i++)
|
2014-06-12 10:01:54 +08:00
|
|
|
{
|
|
|
|
const rapidjson::Value& bone = bones[i];
|
2014-06-13 19:26:46 +08:00
|
|
|
std::string bone_name = bone["boneId"].GetString();
|
2014-06-12 10:01:54 +08:00
|
|
|
|
|
|
|
if ( bone.HasMember("keyframes"))
|
|
|
|
{
|
|
|
|
const rapidjson::Value& bone_keyframes = bone["keyframes"];
|
2014-06-13 19:26:46 +08:00
|
|
|
rapidjson::SizeType keyframe_size = bone_keyframes.Size();
|
2014-06-12 10:01:54 +08:00
|
|
|
for (rapidjson::SizeType j = 0; j < bone_keyframes.Size(); j++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& bone_keyframe = bone_keyframes[j];
|
2014-06-12 16:28:36 +08:00
|
|
|
|
2014-06-13 19:26:46 +08:00
|
|
|
if ( bone_keyframe.HasMember("translation"))
|
|
|
|
{
|
|
|
|
const rapidjson::Value& bone_keyframe_translation = bone_keyframe["translation"];
|
2014-06-16 14:09:41 +08:00
|
|
|
float keytime = bone_keyframe["keytime"].GetDouble();
|
2014-06-13 19:26:46 +08:00
|
|
|
Vec3 val = Vec3(bone_keyframe_translation[(rapidjson::SizeType)0].GetDouble(), bone_keyframe_translation[1].GetDouble(), bone_keyframe_translation[2].GetDouble());
|
|
|
|
animationdata->_translationKeys[bone_name].push_back(Animation3DData::Vec3Key(keytime,val));
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bone_keyframe.HasMember("rotation"))
|
|
|
|
{
|
2014-06-13 19:26:46 +08:00
|
|
|
const rapidjson::Value& bone_keyframe_rotation = bone_keyframe["rotation"];
|
2014-06-16 14:09:41 +08:00
|
|
|
float keytime = bone_keyframe["keytime"].GetDouble();
|
2014-06-13 19:26:46 +08:00
|
|
|
Quaternion val = Quaternion(bone_keyframe_rotation[(rapidjson::SizeType)0].GetDouble(),bone_keyframe_rotation[1].GetDouble(),bone_keyframe_rotation[2].GetDouble(),bone_keyframe_rotation[3].GetDouble());
|
|
|
|
animationdata->_rotationKeys[bone_name].push_back(Animation3DData::QuatKey(keytime,val));
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bone_keyframe.HasMember("scale"))
|
|
|
|
{
|
2014-06-13 19:26:46 +08:00
|
|
|
const rapidjson::Value& bone_keyframe_scale = bone_keyframe["scale"];
|
2014-06-16 14:09:41 +08:00
|
|
|
float keytime = bone_keyframe["keytime"].GetDouble();
|
2014-06-13 19:26:46 +08:00
|
|
|
Vec3 val = Vec3(bone_keyframe_scale[(rapidjson::SizeType)0].GetDouble(), bone_keyframe_scale[1].GetDouble(), bone_keyframe_scale[2].GetDouble());
|
|
|
|
animationdata->_scaleKeys[bone_name].push_back(Animation3DData::Vec3Key(keytime,val));
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-15 22:45:56 +08:00
|
|
|
|
2014-06-05 18:21:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-12 15:53:41 +08:00
|
|
|
GLenum Bundle3D::parseGLType(const std::string& str)
|
2014-06-12 10:01:54 +08:00
|
|
|
{
|
|
|
|
if (str == "GL_FLOAT")
|
|
|
|
{
|
2014-06-12 15:53:41 +08:00
|
|
|
return GL_FLOAT;
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
else if (str == "GL_UNSIGNED_INT")
|
|
|
|
{
|
2014-06-12 15:53:41 +08:00
|
|
|
return GL_UNSIGNED_INT;
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(0);
|
2014-06-12 15:53:41 +08:00
|
|
|
return 0;
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-12 15:53:41 +08:00
|
|
|
unsigned int Bundle3D::parseGLTypeSize(const std::string& str)
|
2014-06-12 10:01:54 +08:00
|
|
|
{
|
|
|
|
if (str == "GL_FLOAT")
|
|
|
|
{
|
2014-06-12 15:53:41 +08:00
|
|
|
return sizeof(float);
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
else if (str == "GL_UNSIGNED_INT")
|
|
|
|
{
|
2014-06-12 15:53:41 +08:00
|
|
|
return sizeof(unsigned int);
|
2014-06-12 10:01:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str)
|
|
|
|
{
|
|
|
|
if (str == "VERTEX_ATTRIB_POSITION")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_POSITION;
|
|
|
|
}
|
|
|
|
else if (str == "VERTEX_ATTRIB_COLOR")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_COLOR;
|
|
|
|
}
|
|
|
|
else if (str == "VERTEX_ATTRIB_TEX_COORD")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_TEX_COORD;
|
|
|
|
}
|
|
|
|
else if (str == "VERTEX_ATTRIB_NORMAL")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_NORMAL;
|
|
|
|
}
|
|
|
|
else if (str == "VERTEX_ATTRIB_BLEND_WEIGHT")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT;
|
|
|
|
}
|
|
|
|
else if (str == "VERTEX_ATTRIB_BLEND_INDEX")
|
|
|
|
{
|
|
|
|
return GLProgram::VERTEX_ATTRIB_BLEND_INDEX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 19:08:43 +08:00
|
|
|
void Bundle3D::getModelPath(const std::string& path)
|
|
|
|
{
|
|
|
|
int index = path.find_last_of('/');
|
|
|
|
std::string fullModelPath;
|
|
|
|
fullModelPath = path.substr(0, index + 1);
|
|
|
|
|
|
|
|
auto list = FileUtils::getInstance()->getSearchPaths();
|
|
|
|
for( const auto &item : list )
|
|
|
|
{
|
|
|
|
if ( fullModelPath.find(item) != std::string::npos )
|
|
|
|
{
|
|
|
|
_modelRelativePath = fullModelPath.substr(item.length(), fullModelPath.length() + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
Bundle3D::Bundle3D()
|
2014-06-17 13:59:03 +08:00
|
|
|
:_isBinary(false),_modelRelativePath(""),_documentBuffer(NULL),_path("")
|
2014-06-05 16:36:01 +08:00
|
|
|
{
|
2014-06-12 10:01:54 +08:00
|
|
|
|
2014-06-05 16:36:01 +08:00
|
|
|
}
|
|
|
|
Bundle3D::~Bundle3D()
|
|
|
|
{
|
2014-06-12 10:01:54 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(_documentBuffer);
|
2014-06-05 16:36:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_CC_END
|