50 #define ADDMD5PREFIX(x) StringHelper::addPrefix(m_md5, x)
60 m_nodesId =
new std::vector<std::string>();
78 std::string((
const char*)filename),
80 m_md5 =
md5(relative_path);
81 unsigned int size = m_md5.size();
82 unsigned int index = size - k_CLScene_MD5MaxCharactersCount;
83 m_md5 = m_md5.substr(index, k_CLScene_MD5MaxCharactersCount).append(
"_");
98 std::vector<std::string> nodes_list;
100 auto it = m_nodes->begin();
102 for (; it != m_nodes->end(); it++) {
103 nodes_list.push_back(it->first);
112 return (m_nodes->count(node_id) == 0 ? NULL : m_nodes->at(node_id));
118 return (m_materials->count(material_id) == 0 ? NULL : m_materials->at(material_id));
124 return (m_effects->count(effect_id) == 0 ? NULL : m_effects->at(effect_id));
130 return (m_images->count(image_id) == 0 ? NULL : m_images->at(image_id));
136 return (m_geometries->count(geometry_obj_id) == 0 ? NULL : m_geometries->at(geometry_obj_id));
172 std::string image_id = image_node->
Attribute(
"id");
174 LOG(
"Loading image with id: %s", image_id.c_str());
176 std::string image_name = image_node->
Attribute(
"name");
181 image_detail->
filename = image_filename;
192 std::string material_id = material_node->
Attribute(
"id");
193 LOG(
"Loading material with id: %s", material_id.c_str());
195 std::string material_name =
"";
198 material_id = material_node->
Attribute(
"id");
202 material_name = material_node->
Attribute(
"name");
215 std::string node_id = node->
Attribute(
"id");
217 LOG(
"Loading node: %s", node_id.c_str());
221 std::vector<CLInstanceGeometry>* instance_geometries_vector =
new std::vector<CLInstanceGeometry>();
224 while (instance_geometry_node) {
226 instance_geometries_vector->push_back(instance_geometry);
227 instance_geometry_node = instance_geometry_node->
NextSiblingElement(
"instance_geometry");
233 std::string scale = (scale_node ? scale_node->
GetText() :
"1 1 1");
236 cl_node->transform().setLocalScale(btVector3(scale_array->at(0), scale_array->at(1), scale_array->at(2)));
237 scale_array->clear();
241 std::string location = (location_node ? location_node->
GetText() :
"0 0 0");
243 cl_node->transform().setLocalPosition(btVector3(location_array->at(0), location_array->at(1), location_array->at(2)));
246 cl_node->transform().setLocalRotation(btQuaternion(0, 0, 0));
247 cl_node->setId(node_id);
251 m_nodesId =
new std::vector<std::string>();
254 m_nodesId->push_back(node_id);
264 while (current_node) {
282 const char* sid = tc_node->
Attribute(
"sid");
283 if (strcmp(sid,
"common") == 0) {
319 while (newparam_node) {
320 std::string alternative = sampler_str;
321 alternative = alternative.append(
"-sampler");
322 if (strcmp(newparam_node->
Attribute(
"sid"), sampler_str) == 0 ||
323 strcmp(newparam_node->
Attribute(
"sid"), alternative.c_str()) == 0) {
327 while (inner_newparam_node) {
328 if (strcmp(inner_newparam_node->
Attribute(
"sid"), source_str) == 0) {
400 if (!materials_node) {
406 while (current_material) {
431 while (current_image) {
451 while (current_node) {
476 while (effect_node) {
496 while (current_geometry) {
497 loadGeometry(current_geometry);
506 MaterialsMapType::const_iterator it = m_materials->begin();
508 for (; it != m_materials->end(); it++) {
510 if (material_obj->
name() == material_name ||
511 material_obj->
id() == material_name) {
520 bool CLScene::loadGeometry(
TiXmlElement* geometry_node) {
521 const char *geometry_id = geometry_node->
Attribute(
"id");
526 std::string str_positions = geometry_id;
527 std::string str_normals = geometry_id;
528 std::string str_map_array = geometry_id;
529 std::string str_map_array_alt1 = geometry_id;
531 str_positions +=
"-positions";
532 str_normals +=
"-normals";
533 str_map_array +=
"-map-0";
534 str_map_array_alt1 +=
"-map";
536 const char* obj_id = NULL;
538 while (source_node) {
542 if (strcmp(obj_id, str_positions.c_str()) == 0) {
545 else if (strcmp(obj_id, str_normals.c_str()) == 0) {
546 geometry_object->
getMesh()->
setNormals(getFloatCArrayFromSourceNode(source_node));
548 else if (strcmp(obj_id, str_map_array.c_str()) == 0 ||
549 strcmp(obj_id, str_map_array_alt1.c_str()) == 0) {
558 std::vector<CLTriangles>* triangles_vector =
new std::vector<CLTriangles>();
559 std::vector<int> vertices_indices;
560 std::vector<int> normals_indices;
561 std::vector<int> textcoords_indices;
563 while (triangles_node) {
564 vertices_indices = std::vector<int>();
565 normals_indices = std::vector<int>();
566 textcoords_indices = std::vector<int>();
568 int input_nodes_count = 0, vertices_offset = 0, normals_offset = 0, texture_coords_offset = 0;
572 if (strcmp(input_node->
Attribute(
"semantic"),
"VERTEX") == 0) {
573 vertices_offset = atoi(input_node->
Attribute(
"offset"));
574 }
else if (strcmp(input_node->
Attribute(
"semantic"),
"NORMAL") == 0) {
575 normals_offset = atoi(input_node->
Attribute(
"offset"));
576 }
else if (strcmp(input_node->
Attribute(
"semantic"),
"TEXCOORD") == 0) {
577 texture_coords_offset = atoi(input_node->
Attribute(
"offset"));
589 for (
unsigned int i = vertices_offset; i < indices->size(); i += input_nodes_count) {
590 vertices_indices.push_back(indices->at(i));
593 for (
unsigned int i = normals_offset; i < indices->size(); i += input_nodes_count) {
594 normals_indices.push_back(indices->at(i));
597 for (
unsigned int i = texture_coords_offset; i < indices->size(); i += input_nodes_count) {
598 textcoords_indices.push_back(indices->at(i));
601 const char* material_id_cstr = triangles_node->
Attribute(
"material");
602 std::string material_id = (material_id_cstr ? material_id_cstr :
"");
611 triangles_vector->push_back(triangles_obj);
616 triangles_vector->clear();
621 int len = strlen(geometry_id) + 1;
622 char *tmp =
new char[len];
623 strncpy_s(tmp, len, geometry_id, len);
632 void CLScene::getFloatStdVecFromSourceNode(
TiXmlElement* source_node, std::vector<btVector3*>* vector_dest) {
635 std::vector<GLfloat>* position_array =
new std::vector<GLfloat>();
637 char *tmp =
new char[strlen(float_array_as_string)];
638 strcpy_s(tmp, strlen(float_array_as_string)+1, float_array_as_string);
641 char* context = NULL;
643 pch = strtok_s (tmp,
" ", &context);
645 while (pch != NULL) {
646 position_array->push_back((
float)atof(pch));
648 if (position_array->size() == 3) {
649 btVector3* new_point =
new btVector3(position_array->at(0), position_array->at(1), position_array->at(2));
650 vector_dest->push_back(new_point);
653 position_array =
new std::vector<GLfloat>();
655 pch = strtok_s (NULL,
" ", &context);
666 std::vector<GLfloat> position_array;
668 int len = strlen(float_array_as_string) + 1;
669 char *tmp =
new char[len];
670 strncpy_s(tmp, len, float_array_as_string, len);
673 char* context = NULL;
675 pch = strtok_s (tmp,
" ", &context);
677 btAlignedObjectArray<btVector3>* vector_dest =
new btAlignedObjectArray<btVector3>();
679 while (pch != NULL) {
680 position_array.push_back((
float)atof(pch));
682 if (position_array.size() == 3) {
683 btVector3 new_point = btVector3(position_array.at(0), position_array.at(1), position_array.at(2));
684 vector_dest->push_back(new_point);
685 position_array = std::vector<GLfloat>();
687 pch = strtok_s (NULL,
" ", &context);
693 vector_dest->clear();
703 std::vector<GLfloat> position_array;
705 int len = strlen(float_array_as_string) + 1;
706 char* tmp =
new char[len];
707 strncpy_s(tmp, len, float_array_as_string, len);
710 char* context = NULL;
712 pch = strtok_s (tmp,
" ", &context);
714 std::vector<TextureCoord>* vector_dest =
new std::vector<TextureCoord>();
716 while (pch != NULL) {
717 position_array.push_back((
float)atof(pch));
719 if (position_array.size() == 2) {
721 new_texcoord.
s = position_array.at(0);
722 new_texcoord.
t = 1.0f - position_array.at(1);
723 vector_dest->push_back(new_texcoord);
725 position_array = std::vector<GLfloat>();
727 pch = strtok_s (NULL,
" ", &context);
743 std::vector<CLInstanceMaterial> instance_materials_vec = std::vector<CLInstanceMaterial>();
745 if (bind_material_node) {
748 std::vector<CLBindVertexInput>* bindvertexinput_array = NULL;
750 while (material_node) {
758 bindvertexinput_array =
new std::vector<CLBindVertexInput>();
760 while (bind_vertex_node) {
761 std::string semantic = bind_vertex_node->
Attribute(
"semantic");
762 std::string input_semantic = bind_vertex_node->
Attribute(
"input_semantic");
763 std::string input_set_as_string =
"0";
765 if (bind_vertex_node->
Attribute(
"input_set")) {
766 input_set_as_string = bind_vertex_node->
Attribute(
"input_set");
769 int input_set = atoi(input_set_as_string.c_str());
772 bindvertexinput_array->push_back(bind_vertex);
776 if (bindvertexinput_array->size() > 0) {
779 material_instance.setBindVertexInputList(NULL);
783 instance_materials_vec.push_back(material_instance);
788 instance_materials_vec.clear();
790 return instance_geometry;
803 Color* color =
new Color(colorArray->at(0), colorArray->at(1), colorArray->at(2));
807 }
else if (texture_node) {
809 }
else if (float_node) {
810 float val = (float)atof(float_node->
GetText());
const CLImageDetails * imageDetails() const
const GeometriesMapType * geometries() const
static void deleteMap(std::map< TKey, TVal * > *map)
void setMeshURL(const std::string &url)
void setMaterialId(const std::string &material_id)
static std::string & removeOccurrencesOfString(std::string &original_str, std::string &str_to_remove)
const EffectsMapType * effects() const
std::pair< std::string, CLGeometry * > GeometryPairType
void setValue(void *value, PhongChildType value_type)
bool loadEffect(TiXmlElement *effect_node)
CLPhongChild * getPhongChildFromNode(TiXmlElement *node)
const ImagesMapType * images() const
bool loadScene(TiXmlElement *scene_node)
void setShininess(CLPhongChild *shininess)
static CArray * fromBtAlignedObjectArray(btAlignedObjectArray< T > *vec)
bool loadNode(TiXmlElement *node)
std::pair< std::string, CLNode * > NodePairType
std::map< std::string, CLEffect * > EffectsMapType
void insertImagePair(const std::string &image_id, CLImageDetails *image_details)
void setDiffuse(CLPhongChild *diffuse)
void insertMaterialPair(const std::string &material_id, CLMaterial *material)
void setTriangles(CArray< CLTriangles > *triangles_array)
void setAmbient(CLPhongChild *ambient)
std::map< std::string, CLImageDetails * > ImagesMapType
PhongChildType getValueType() const
void setNormals(CArray< btVector3 > *normals)
CLMaterial * getMaterialHavingName(const std::string &material_name)
void insertNodesPair(const std::string &node_id, CLNode *node)
void setSpecular(CLPhongChild *specular)
const MaterialsMapType * materials() const
void setMapArray(CArray< TextureCoord > *map_array)
void setVerticesIndices(CArray< int > *indices)
std::map< std::string, CLGeometry * > GeometriesMapType
std::pair< std::string, CLMaterial * > MaterialPairType
void Clear()
Delete all the children of this node. Does not affect 'this'.
bool loadImage(TiXmlElement *image_node)
void setPositions(CArray< btVector3 > *positions)
void setEmission(CLPhongChild *emission)
const TiXmlElement * NextSiblingElement() const
std::pair< std::string, CLImageDetails * > ImagePairType
bool loadMaterial(TiXmlElement *material_node)
const std::string & id() const
CArray< CLPolygon > * getPolygonsArray()
std::map< std::string, CLMaterial * > MaterialsMapType
const char * Attribute(const char *name) const
CLGeometry * getGeometryObjHavingId(const std::string &geometry_obj_id)
CLNode * getNodeHavingId(const std::string &node_id)
CLEffect * getEffectHavingId(const std::string &effect_id)
void setImageId(const std::string &image_id)
CLMaterial * getMaterialHavingId(const std::string &material_id)
static void * getVectorFromString(const char *p_as_str, VectorType type)
static std::string getProjectDirectory()
CLPhongChild * getDiffuse() const
std::vector< std::string > getNodeIdList()
const char * GetText() const
std::pair< std::string, CLEffect * > EffectPairType
#define SAFE_RELEASE_ARRAY(x)
void setIndexOfRefraction(CLPhongChild *index_of_refraction)
void setNormalsIndices(CArray< int > *indices)
std::string md5(const std::string str)
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
std::map< std::string, CLNode * > NodesMapType
void insertGeometryPair(const std::string &geometry_id, CLGeometry *geometry)
void setInstanceMaterials(CArray< CLInstanceMaterial > *instance_materials)
void insertEffectPair(const std::string &effect_id, CLEffect *effect)
void setPolygons(CArray< CLPolygon > *)
static CArray * fromStdVector(std::vector< T > *vec)
const std::string & name() const
CLInstanceGeometry getInstanceGeometryFromNode(TiXmlElement *instance_geometry_node)
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const NodesMapType * nodes() const
CLImageDetails * getImageDetailsHavingId(const std::string &image_id)
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
void setTextureCoordsIndices(CArray< int > *indices)
void setPhong(CLPhong *phong)