Пример #1
0
inline void Model::loadNodes(
   aiNode* node,
   const aiScene* scene,
   Engine* engine,
   Entity* entity,
   core::Texture2D* diffuseMap,
   core::Texture2D* normalMap,
   core::Texture2D* specularMap,
   const Material& material) {

	/* Set this node transformations */

	loadNodeTransformations(node, entity);

	for (GLuint i = 0; i < node->mNumMeshes; i++) {
		const aiMesh* aMesh = scene->mMeshes[i];
		entity->attach(loadMesh(aMesh, material, diffuseMap,
		                        normalMap, specularMap,
		                        engine));
	}

	/* Evaluate children */
	for (GLuint i = 0; i < node->mNumChildren; i++) {
		puEntity newEntity = buildHinge();
		loadNodes(node->mChildren[i], scene, engine, newEntity.get(), diffuseMap,
		          normalMap, specularMap, material);
		entity->attach(std::move(newEntity));
	}
}
Пример #2
0
inline void Model::loadNodes(
   aiNode* node,
   const aiScene* scene,
   Engine* engine,
   Entity* entity,
   const std::string& diffuseMapPath,
   const std::string& normalMapPath,
   const std::string& specularMapPath) {

	/* Set this node transformations */

	loadNodeTransformations(node, entity);

	for (GLuint i = 0; i < node->mNumMeshes; i++) {
		const aiMesh* aMesh = scene->mMeshes[node->mMeshes[i]];
		const aiMaterial* aMaterial = scene->mMaterials[aMesh->mMaterialIndex];

		entity->attach(
		   loadMesh(aMesh, Material(aMaterial),
		            engine->storeTexture(diffuseMapPath.c_str()),
		            engine->storeTexture(normalMapPath.c_str()),
		            engine->storeTexture(specularMapPath.c_str()),
		            engine));
	}

	/* Evaluate children */
	for (GLuint i = 0; i < node->mNumChildren; i++) {
		puEntity newEntity = buildHinge();
		loadNodes(node->mChildren[i], scene, engine, newEntity.get(),
		          diffuseMapPath, normalMapPath, specularMapPath);
		entity->attach(std::move(newEntity));
	}
}
Пример #3
0
bool Sprite3D::loadFromC3x(const std::string& path)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);

    //load from .c3b or .c3t
    auto bundle = Bundle3D::getInstance();
    if (!bundle->load(fullPath))
        return false;
    
    MeshDatas meshdatas;
    MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas();
    NodeDatas*   nodeDatas = new (std::nothrow) NodeDatas();
    if (bundle->loadMeshDatas(meshdatas)
        && bundle->loadMaterials(*materialdatas)
        && bundle->loadNodes(*nodeDatas)
        && initFrom(*nodeDatas, meshdatas, *materialdatas))
    {
        //add to cache
        auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
        data->materialdatas = materialdatas;
        data->nodedatas = nodeDatas;
        data->meshVertexDatas = _meshVertexDatas;
        for (const auto mesh : _meshes) {
            data->glProgramStates.pushBack(mesh->getGLProgramState());
        }
        Sprite3DCache::getInstance()->addSprite3DData(path, data);
        return true;
    }
    
    delete materialdatas;
    delete nodeDatas;
    
    return false;
}
Пример #4
0
bool Sprite3D::loadFromFile(const std::string& path, NodeDatas* nodedatas, MeshDatas* meshdatas,  MaterialDatas* materialdatas)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
    
    std::string ext = path.substr(path.length() - 4, 4);
    std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
    if (ext == ".obj")
    {
        return Bundle3D::loadObj(*meshdatas, *materialdatas, *nodedatas, fullPath);
    }
    else if (ext == ".c3b" || ext == ".c3t")
    {
        //load from .c3b or .c3t
        auto bundle = Bundle3D::createBundle();
        if (!bundle->load(fullPath))
        {
            Bundle3D::destroyBundle(bundle);
            return false;
        }
        
        auto ret = bundle->loadMeshDatas(*meshdatas)
            && bundle->loadMaterials(*materialdatas) && bundle->loadNodes(*nodedatas);
        Bundle3D::destroyBundle(bundle);
        
        return ret;
    }
    return false;
}
Пример #5
0
Problem ProblemLoader::load() {
  content = readContent();

  loadCriteria();
  loadNodes();
  p.analyze();
  return p;
}
Пример #6
0
Model::Model(Engine* engine, core::Program* program,
             const std::string& shapePath) :
	IFocusable(engine),
	Programmable(program),
#ifdef FILLWAVE_MODEL_LOADER_ASSIMP
	mAnimator(nullptr),
	mActiveAnimation(FILLWAVE_DO_NOT_ANIMATE),
#endif /* FILLWAVE_MODEL_LOADER_ASSIMP */
	mLights(engine->getLightSystem()) {

#ifdef FILLWAVE_MODEL_LOADER_ASSIMP
	const aiScene* scene = engine->getModelFromFile(shapePath);

	if (scene) {
		initAnimations(scene);
		initShadowing(engine);
		initUniformsCache();
		loadNodes(scene->mRootNode, scene, engine, this);
	} else {
		FLOG_FATAL("Model: %s could not be read", shapePath.c_str());
	}
#else
	std::vector<tinyobj::shape_t> shapes;
	std::vector<tinyobj::material_t> materials;
	tinyobj::attrib_t attrib;
	std::string err;
	if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, shapePath.c_str())) {
		FLOG_FATAL("Model: %s could not be read", shapePath.c_str());
	}
	if (!err.empty()) { // `err` may contain warning message.
		FLOG_WARNING("%s", err.c_str());
	}

	initShadowing(engine);
	for (GLuint i = 0; i < shapes.size(); i++) {
		if (shapes[i].mesh.material_ids.empty()) {
			FLOG_FATAL("No materials available");
		}

		int materialId = shapes[i].mesh.material_ids[0];
		if (materialId != -1) {
			attach(loadMesh(shapes[i], attrib,
			                Material(materials[materialId]),
			                engine->storeTexture(materials[materialId].diffuse_texname),
			                engine->storeTexture(materials[materialId].bump_texname),
			                engine->storeTexture(materials[materialId].specular_texname),
			                engine));
			continue;
		}
		attach(loadMesh(shapes[i], attrib,
		                Material(),
		                nullptr,
		                nullptr,
		                nullptr,
		                engine));
	}
#endif
}
Пример #7
0
Map::Map(char *nodesFile, char *buildingsFile)
:Object3d(Point()), topLeftMapPoint(Point(+1000000, 0, +1000000)), bottomRightPoint(Point(-1000000, 0, -100000))
{
	currentWayName = NULL;
	loadNodes(nodesFile);
	loadBuildings(buildingsFile);
	initQuadTree();
	initMinimap();
}
Пример #8
0
inline void Model::loadNodes(
   aiNode* node,
   const aiScene* scene,
   Engine* engine,
   Entity* entity) {

	/* Set this node transformations */

	loadNodeTransformations(node, entity);

	for (GLuint i = 0; i < node->mNumMeshes; i++) {
		const aiMesh* aMesh = scene->mMeshes[node->mMeshes[i]];
		const aiMaterial* aMaterial = scene->mMaterials[aMesh->mMaterialIndex];

		aiString diffuseMapPathAssimp, normalMapPathAssimp, specularMapPathAssimp;
		std::string diffuseMapPath, normalMapPath, specularMapPath;

		diffuseMapPath =
		   (aMaterial->GetTexture(
		       aiTextureType_DIFFUSE, 0, &diffuseMapPathAssimp, nullptr,
		       nullptr, nullptr, nullptr, nullptr) == AI_SUCCESS) ?
		   diffuseMapPathAssimp.data : "255_255_255.color";

		normalMapPath =
		   (aMaterial->GetTexture(
		       aiTextureType_NORMALS, 0, &normalMapPathAssimp, nullptr,
		       nullptr, nullptr, nullptr, nullptr) == AI_SUCCESS) ?
		   normalMapPathAssimp.data : "128_128_255.color";

		specularMapPath =
		   (aMaterial->GetTexture(
		       aiTextureType_SPECULAR, 0, &specularMapPathAssimp, nullptr,
		       nullptr, nullptr, nullptr, nullptr) == AI_SUCCESS) ?
		   specularMapPathAssimp.data : "";

		entity->attach(
		   loadMesh(aMesh, Material(aMaterial),
		            engine->storeTexture(diffuseMapPath.c_str()),
		            engine->storeTexture(normalMapPath.c_str()),
		            engine->storeTexture(specularMapPath.c_str()),
		            engine));
	}

	/* Evaluate children */
	for (GLuint i = 0; i < node->mNumChildren; i++) {
		puEntity newEntity = buildHinge();
		loadNodes(node->mChildren[i], scene, engine, newEntity.get());
		entity->attach(std::move(newEntity));
	}
}
Пример #9
0
void House::parse(INIFile* file)
{
	INISection* houseSection = file->getSection(ID);
	if (!houseSection) return;

	houseSection->readStringValue("Country", Country);
	houseSection->readIntValue("TechLevel", TechLevel);
	houseSection->readIntValue("Credits", Credits);
	houseSection->readIntValue("IQ", IQ);
	houseSection->readStringValue("Edge", Edge);
	houseSection->readBoolValue("PlayerControl", PlayerControl);
	houseSection->readStringValue("Color", Color);
	houseSection->readIntValue("PercentBuilt", PercentBuilt);
	houseSection->readIntValue("NodeCount", NodeCount);

	std::string allies_List;
	houseSection->readStringValue("Allies", allies_List);

	loadAllies(allies_List);
	loadNodes(houseSection);
}
Пример #10
0
/***
	loadCfg: This function loads cfg file to RAM memory using libxml API functions
	xmlfile: Cfg's file name
*/
void loadCfg(char *xmlfile)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;

    LIBXML_TEST_VERSION

    doc = xmlParseFile(xmlfile);

    if (doc == NULL) {
        printf("error: could not parse file file.xml\n");
	exit(1);
    }

    root_element = xmlDocGetRootElement(doc);

	puts("carregando nodos\n");
    loadNodes(getElement(root_element, "nodes"));
	puts("construindo arestas\n");
    buildGraphFromEdges(getElement(root_element, "edges"));

    xmlFreeDoc(doc);
    xmlCleanupParser();
}
Пример #11
0
 qlib::uid_t loadNodes(LDom2Node *pRoot, qlib::uid_t scope) {
   return loadNodes(pRoot, scope, LString(), LString());
 }
Пример #12
0
 qlib::uid_t loadNodes(LDom2Node *pRoot, qlib::uid_t scope, const LString &src) {
   return loadNodes(pRoot, scope, src, LString());
 }