Example #1
0
void LoadScene(TiXmlElement *element)
{
    for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
        
        if ( COMPARE( child->Value(), "background" ) ) {
            Color c(1,1,1);
            ReadColor( child, c );
            background.SetColor(c);
            printf("Background %f %f %f\n",c.r,c.g,c.b);
            background.SetTexture( ReadTexture(child) );
        } else if ( COMPARE( child->Value(), "environment" ) ) {
            Color c(1,1,1);
            ReadColor( child, c );
            environment.SetColor(c);
            printf("Environment %f %f %f\n",c.r,c.g,c.b);
            environment.SetTexture( ReadTexture(child) );
        } else if ( COMPARE( child->Value(), "object" ) ) {
            LoadNode( &rootNode, child );
        } else if ( COMPARE( child->Value(), "material" ) ) {
            LoadMaterial( child );
        } else if ( COMPARE( child->Value(), "light" ) ) {
            LoadLight( child );
        }
    }
}
Example #2
0
bool CEnvironment::LoadEnvironment (size_t loc, size_t light) {
	if (loc >= locs.size()) loc = 0;
	if (light >= 4) light = 0;
	// remember: with (example) 3 locations and 4 lights there
	// are 12 different environments
	size_t env_id = loc * 100 + light;

	if (env_id == EnvID) {
		Message ("same environment");
		return false;
	}

	// Set directory. The dir is used several times.
	EnvDir = GetDir (loc, light);

	// Load skybox. If the sky can't be loaded for any reason, the
	// texture id's are set to 0 and the sky will not be drawn.
	// There is no error handlung, you see the result on the screen.
	ResetSkybox ();
	LoadSkybox ();

	// Load light conditions.
	ResetFog ();
	ResetLight ();
	LoadLight ();
	return true;
}
Example #3
0
void LoadScene(TiXmlElement *element)
{
    for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
        
        if ( COMPARE( child->Value(), "object" ) ) {
            //cout<<"Object...................";
            LoadNode( &rootNode, child );
        } else if ( COMPARE( child->Value(), "material" ) ) {
            LoadMaterial( child );
        } else if ( COMPARE( child->Value(), "light" ) ) {
            LoadLight( child );
        }
    }
}
Example #4
0
bool SceneLoader::Load(SECore::Scene* scene, const TCHAR* filename)
{
	bool ret = false;
	Json::Value root;
	CHECK(scene);
	CHECK(LoadJsonFromFile(filename, root));

	if (root.isMember("Config"))
	{
		const Json::Value& configRoot = root["Config"];
		if (configRoot.isMember("ShowGizmo"))
			scene->GetConfig()->EnableGizmo(configRoot["ShowGizmo"].asBool());
		if (configRoot.isMember("AmbientColor"))
		{
			scene->GetConfig()->SetAmbientColor(Json2Color(configRoot["AmbientColor"]));
		}
	}

	CHECK(root.isMember("Entities"));
	CHECK(root["Entities"].isArray());

	size_t entityCount = root["Entities"].size();

	for (size_t i = 0; i < entityCount; ++i)
	{
		SECore::Scene::Entity* entity = scene->CreateEntity();
		const Json::Value& entityRoot = root["Entities"][i];

		if (entityRoot.isMember("Prefab"))
		{
			CString filename = MStr2WStr(entityRoot["Prefab"].asCString());
			Json::Value prefab;
			LoadJsonFromFile(filename, prefab);
			LoadEntity(scene->GetCore(), entity, prefab);
		}
		
		LoadEntity(scene->GetCore(), entity, entityRoot);
	}

	size_t lightCount = root["Lights"].size();
	for (size_t i = 0; i < lightCount; i++)
	{
		LoadLight(scene, root["Lights"][i]);
	}

	ret = true;
Exit0:
	return ret;
}
Example #5
0
void SceneBase::InitLights()
{
	const string LIGHT_FILE_PATH = "SONs//Lights.son";

	StopWatch initTimer;
	initTimer.startTimer();

	std::cout << "Loading " << LIGHT_FILE_PATH << "... ";

	vector<Light> lightList = LoadLight(LIGHT_FILE_PATH);

	for (int i = 0; i < m_NUM_LIGHTS && i < lightList.size(); ++i)
	{
		lights[i] = lightList[i];
		lights[i].enabled = true;
	}

	std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
}
Example #6
0
	void FbxUtil::LoadNode(const SceneNode::Ptr &ntNode, FbxNode* fbxNode)
	{
		SceneNode::Ptr childNode = SceneNode::Create(fbxNode->GetName());

		// copy transforms.
		FbxQuaternion fbxQ;
		fbxQ.ComposeSphericalXYZ(fbxNode->LclRotation.Get());
		FbxDouble3 fbxT = fbxNode->LclTranslation.Get();
		FbxDouble3 fbxS = fbxNode->LclScaling.Get();

		Vector4 furyT((float)fbxT.mData[0] * m_ScaleFactor, (float)fbxT.mData[1] * m_ScaleFactor, (float)fbxT.mData[2] * m_ScaleFactor, 1.0f);
		Vector4 furyS((float)fbxS.mData[0] * m_ScaleFactor, (float)fbxS.mData[1] * m_ScaleFactor, (float)fbxS.mData[2] * m_ScaleFactor, 1.0f);
		Quaternion furyR((float)fbxQ.mData[0], (float)fbxQ.mData[1], (float)fbxQ.mData[2], (float)fbxQ.mData[3]);

		childNode->SetLocalPosition(furyT);
		childNode->SetLocalRoattion(furyR);
		childNode->SetLocalScale(furyS);

		// add to scene graph
		ntNode->AddChild(childNode);

		// read Components
		FbxNodeAttribute* fbxNodeAttr = fbxNode->GetNodeAttribute();
		if (fbxNodeAttr != NULL)
		{
			FbxNodeAttribute::EType fbxNodeAttrType = fbxNodeAttr->GetAttributeType();
			if (fbxNodeAttrType == FbxNodeAttribute::eMesh)
			{
				LoadMesh(childNode, fbxNode);
			}
			else if (fbxNodeAttrType == FbxNodeAttribute::eLight)
			{
				LoadLight(childNode, fbxNode);
			}
		}

		// read child nodes.
		for (int i = 0; i < fbxNode->GetChildCount(); i++)
			LoadNode(ntNode, fbxNode->GetChild(i));
	}
Example #7
0
void scene::Init() {
    LoadModel();
    LoadView();
    LoadLight();
}
Example #8
0
bool CAR::LoadGraphics(
	const PTree & cfg,
	const std::string & partspath,
	const std::string & carpath,
	const std::string & carname,
	const std::string & carpaint,
	const MATHVECTOR <float, 3> & carcolor,
	const int anisotropy,
	const float camerabounce,
	const bool damage,
	const bool debugmode,
	ContentManager & content,
	std::ostream & info_output,
	std::ostream & error_output)
{
	//write_inf(cfg, std::cerr);
	cartype = carname;
	LoadDrawable loadDrawable(carpath, anisotropy, content, models, error_output);

	// load body first
	const PTree * cfg_body;
	std::string meshname;
	std::vector<std::string> texname;
	if (!cfg.get("body", cfg_body, error_output))
	{
		error_output << "there is a problem with the .car file" << std::endl;
		return false;
	}
	if (!cfg_body->get("mesh", meshname, error_output)) return false;
	if (!cfg_body->get("texture", texname, error_output)) return false;
	if (carpaint != "default") texname[0] = carpaint;
	if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;

	// load wheels
	const PTree * cfg_wheel;
	if (!cfg.get("wheel", cfg_wheel, error_output)) return false;
	for (PTree::const_iterator i = cfg_wheel->begin(); i != cfg_wheel->end(); ++i)
	{
		if (!LoadWheel(i->second, loadDrawable, topnode, error_output))
		{
			error_output << "Failed to load wheels." << std::endl;
			return false;
		}
	}

	// load drawables
	LoadBody loadBody(topnode, bodynode, loadDrawable);
	for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
	{
		if (i->first != "body" &&
			i->first != "steering" &&
			i->first != "light-brake" &&
			i->first != "light-reverse")
		{
			loadBody(i->second);
		}
	}

	// load steering wheel
	const PTree * cfg_steer;
	if (cfg.get("steering", cfg_steer))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
		{
			error_output << "Failed to load steering wheel." << std::endl;
			return false;
		}
		cfg_steer->get("max-angle", steer_angle_max);
		steer_angle_max = steer_angle_max / 180.0 * M_PI;
		SCENENODE & steernoderef = bodynoderef.GetNode(steernode);
		steer_orientation = steernoderef.GetTransform().GetRotation();
	}

	// load brake/reverse light point light sources (optional)
	int i = 0;
	std::string istr = "0";
	const PTree * cfg_light;
	while (cfg.get("light-brake-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::stringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}
	i = 0;
	istr = "0";
	while (cfg.get("light-reverse-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::stringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}

	// load car brake/reverse graphics (optional)
	if (cfg.get("light-brake", cfg_light))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &brakelights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}
	if (cfg.get("light-reverse", cfg_light))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &reverselights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}

	const PTree * cfg_cams;
	if (!cfg.get("camera", cfg_cams))
	{
		return false;
	}
	if (!cfg_cams->size())
	{
		error_output << "No cameras defined." << std::endl;
		return false;
	}
	cameras.reserve(cfg_cams->size());
	for (PTree::const_iterator i = cfg_cams->begin(); i != cfg_cams->end(); ++i)
	{
		CAMERA * cam = LoadCamera(i->second, camerabounce, error_output);
		if (!cam) return false;
		cameras.push_back(cam);
	}

	SetColor(carcolor[0], carcolor[1], carcolor[2]);

	return true;
}
Example #9
0
bool CarGraphics::Load(
	const PTree & cfg,
	const std::string & carpath,
	const std::string & /*carname*/,
	const std::string & carwheel,
	const std::string & carpaint,
	const Vec3 & carcolor,
	const int anisotropy,
	const float camerabounce,
	ContentManager & content,
	std::ostream & error_output)
{
	assert(!loaded);

	// init drawable load functor
	LoadDrawable loadDrawable(carpath, anisotropy, content, models, textures, error_output);

	// load body first
	const PTree * cfg_body;
	std::string meshname;
	std::vector<std::string> texname;
	if (!cfg.get("body", cfg_body, error_output)) return false;
	if (!cfg_body->get("mesh", meshname, error_output)) return false;
	if (!cfg_body->get("texture", texname, error_output)) return false;
	if (carpaint != "default") texname[0] = carpaint;
	if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;

	// load wheels
	const PTree * cfg_wheels;
	if (!cfg.get("wheel", cfg_wheels, error_output)) return false;

	std::shared_ptr<PTree> sel_wheel;
	if (carwheel != "default" && !content.load(sel_wheel, carpath, carwheel)) return false;

	for (PTree::const_iterator i = cfg_wheels->begin(); i != cfg_wheels->end(); ++i)
	{
		const PTree * cfg_wheel = &i->second;

		// override default wheel with selected, not very efficient, fixme
		PTree opt_wheel;
		if (sel_wheel.get())
		{
			opt_wheel.set(*sel_wheel);
			opt_wheel.merge(*cfg_wheel);
			cfg_wheel = &opt_wheel;
		}

		if (!LoadWheel(*cfg_wheel, loadDrawable, topnode, error_output))
		{
			error_output << "Failed to load wheels." << std::endl;
			return false;
		}
	}

	// load drawables
	LoadBody loadBody(topnode, bodynode, loadDrawable);
	for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
	{
		if (i->first != "body" &&
			i->first != "steering" &&
			i->first != "light-brake" &&
			i->first != "light-reverse")
		{
			loadBody(i->second);
		}
	}

	// load steering wheel
	const PTree * cfg_steer;
	if (cfg.get("steering", cfg_steer))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
		{
			error_output << "Failed to load steering wheel." << std::endl;
			return false;
		}
		cfg_steer->get("max-angle", steer_angle_max);
		steer_angle_max = steer_angle_max / 180.0 * M_PI;
		SceneNode & steernoderef = bodynoderef.GetNode(steernode);
		steer_orientation = steernoderef.GetTransform().GetRotation();
		steer_rotation = steer_orientation;
	}

	// load brake/reverse light point light sources (optional)
	int i = 0;
	std::string istr = "0";
	const PTree * cfg_light;
	while (cfg.get("light-brake-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::ostringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}
	i = 0;
	istr = "0";
	while (cfg.get("light-reverse-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::ostringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}

	// load car brake/reverse graphics (optional)
	if (cfg.get("light-brake", cfg_light))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &brakelights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}
	if (cfg.get("light-reverse", cfg_light))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &reverselights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}

	if (!LoadCameras(cfg, camerabounce, error_output))
	{
		return false;
	}

	SetColor(carcolor[0], carcolor[1], carcolor[2]);
	loaded = true;
	return true;
}
Example #10
0
ge_Scene* geLoadScene_ge_text(const char* file){
	ge_File* fp = NULL;
	if( !(fp = geFileOpen(file, GE_FILE_MODE_READ | GE_FILE_MODE_BINARY))){
		return NULL;
	}
	char path[2048] = "";
	strncpy(path, file, strlen(file));
	if(strstr(path, "/")){
		int A = 0;
		for(A=strlen(path); A>=0; A--){
			if(path[A]=='/')break;
			path[A] = 0x0;
		}
	}
	ge_Scene* scene = (ge_Scene*)geMalloc(sizeof(ge_Scene));
	ge_Fog* fog = (ge_Fog*)geMalloc(sizeof(ge_Fog));
	memset(scene, 0, sizeof(ge_Scene));
	memset(fog, 0, sizeof(ge_Fog));
	scene->fog = fog;

	int i = 0;
	int rgba[4] = { -1 };
	char buffer[2048] = "";
	char tmp[2048] = "";
	int tmp_ivec[4];
	scene->cloudsGenerator = NULL;

	while(geFileGets(fp, buffer, 2048)){
		PASS_COMMENTS;

		if(strstr(buffer, "RENDERER") && !strstr(buffer, "END_RENDERER")){
			scene->nRenderers++;
			continue;
		}

		if(strstr(buffer, "LIGHT") && !strstr(buffer, "END_LIGHT")){
			if(strstr(buffer,"dynamic")){
				scene->nDynamicLights++;
			}else{
				scene->nLights++;
			}
			continue;
		}

		if(geGetParamIntMulti(buffer, "clear_color", rgba, 3)){
			SET_COLOR_RGBAf(scene->clear_color, rgba[0], rgba[1], rgba[2], 1.0);
		}
		if(geGetParamIntMulti(buffer, "material_ambient", rgba, 3)){
			SET_COLOR_RGBAf(scene->material_ambient, rgba[0], rgba[1], rgba[2], 1.0);
		}
		if(geGetParamIntMulti(buffer, "material_diffuse", rgba, 3)){
			SET_COLOR_RGBAf(scene->material_diffuse, rgba[0], rgba[1], rgba[2], 1.0);
		}
		if(geGetParamString(buffer, "skysphere", tmp, 2048)){
			if(tmp[0] != 0x0 && tmp[0] != '\n'){
				gePrintDebug(0x100, "sky : \"%s\"\n", tmp);
				scene->sky.animator = (ge_Animator*)geMalloc(sizeof(char)*2048);
				scene->sky.nVerts = -2;
				if(strstr(tmp, "generic")){
					sprintf(((char*)scene->sky.animator), "default_objects/maps/%s.png", tmp);
				}else{
					sprintf(((char*)scene->sky.animator), "%s%s", path, tmp);
				}
			}
		}else if(geGetParamString(buffer, "sky", tmp, 2048)){
			if(tmp[0] != 0x0 && tmp[0] != '\n'){
				gePrintDebug(0x102, "sky : \"%s\"\n", tmp);
				scene->sky.animator = (ge_Animator*)geMalloc(sizeof(char)*2048);
				if(strstr(tmp, "generic")){
					sprintf(((char*)scene->sky.animator), "default_objects/maps/%s.png", tmp);
				}else{
					sprintf(((char*)scene->sky.animator), "%s%s", path, tmp);
				}
			}
		}

		if(strstr(buffer,"fog"))scene->fogEnabled=true;
		if(strstr(buffer, "fog_mode = ")){
			if(strstr(buffer, "LINEAR"))fog->mode=GE_FOG_LINEAR;
			if(strstr(buffer, "EXP2"))fog->mode=GE_FOG_EXP2;
			if(strstr(buffer, "EXP"))fog->mode=GE_FOG_EXP;
		}
		if(geGetParamIntMulti(buffer, "fog_color", rgba, 3)){
			SET_COLOR_RGBAf(fog->color, rgba[0], rgba[1], rgba[2], 1.0);
		}
		geGetParamFloat(buffer, "fog_density", &fog->density);
		geGetParamFloat(buffer, "fog_start", &fog->start);
		geGetParamFloat(buffer, "fog_end", &fog->end);

		if(strstr(buffer, "CLOUDS_GENERATOR") && !strstr(buffer, "END_CLOUDS_GENERATOR")){
			gePrintDebug(0x100, " LoadRenderer A\n");
			scene->cloudsGenerator = (ge_CloudsGenerator*)geMalloc(sizeof(ge_CloudsGenerator));
			while(geFileGets(fp, buffer, 2048)){
				PASS_COMMENTS;
				if(strstr(buffer, "END_CLOUDS_GENERATOR"))break;
				geGetParamIntMulti(buffer, "map_size", &scene->cloudsGenerator->map_size_x, 2);
				if(strstr(buffer, "CLOUDS_LEVEL")){
					geGetParamString(buffer, "CLOUDS_LEVEL", tmp, 2048);
					int type = -1;
					if(!strcmp(tmp, "high")){
						type = GE_CLOUD_TYPE_HIGH_LEVEL;
					}else
					if(!strcmp(tmp, "mid")){
						type = GE_CLOUD_TYPE_MID_LEVEL;
					}else
					if(!strcmp(tmp, "low")){
						type = GE_CLOUD_TYPE_LOW_LEVEL;
					}else{
						break;
					}
					while(geFileGets(fp, buffer, 2048)){
						PASS_COMMENTS;
						if(strstr(buffer, "END_CLOUDS_LEVEL"))break;
						if(geGetParamIntMulti(buffer, "size_range", tmp_ivec, 2)){
							scene->cloudsGenerator->size_min[type] = tmp_ivec[0];
							scene->cloudsGenerator->size_max[type] = tmp_ivec[1];
						}
						if(geGetParamIntMulti(buffer, "parts_range", tmp_ivec, 2)){
							scene->cloudsGenerator->parts_min[type] = tmp_ivec[0];
							scene->cloudsGenerator->parts_max[type] = tmp_ivec[1];
						}
						geGetParamInt(buffer, "n_clouds", &scene->cloudsGenerator->n_clouds[type]);
					}
				}
			}
		}
	}
	geFileRewind(fp);
	gePrintDebug(0x100, "scene 1\n");

	gePrintDebug(0x100, "scene->nLights %d\n", scene->nLights);
	scene->lights = (ge_Light*)geMalloc(sizeof(ge_Light)*(scene->nLights + 8));
	scene->dynamicLights = scene->lights;
//	scene->dynamicLights = (ge_Light*)geMalloc(sizeof(ge_Light)*scene->nDynamicLights);
	int iS=8, iD=0;
	while(geFileGets(fp, buffer, 1024)){
		PASS_COMMENTS;
		if(strstr(buffer, "LIGHT") && !strstr(buffer, "END_LIGHT")){
			if(strstr(buffer,"dynamic")){
				LoadLight(fp, &scene->lights[iD]);
				scene->lights[iD].isDynamic = true;
				iD++;
			}else{
				LoadLight(fp, &scene->lights[iS]);
				scene->lights[iS].isDynamic = false;
				PrecalculateLight(&scene->lights[iS]);
				iS++;
			}
		}
	}
	gePrintDebug(0x100, "scene 2\n");
	geFileRewind(fp);
	
	scene->renderers = (ge_Renderer*)geMalloc(sizeof(ge_Renderer)*scene->nRenderers);
	gePrintDebug(0x100, "scene 2.1\n");
	i = 0;
	while(geFileGets(fp, buffer, 1024)){
		PASS_COMMENTS;
		if(strstr(buffer, "RENDERER") && !strstr(buffer, "END_RENDERER")){
			memset(&scene->renderers[i], 0, sizeof(ge_Renderer));
			geGetParamString(buffer, "RENDERER", scene->renderers[i].name, 64);
			gePrintDebug(0x100, "scene 2.2.%d.1\n", i);
			LoadRenderer(path, fp, scene, &scene->renderers[i]);
			gePrintDebug(0x100, "scene 2.2.%d.2\n", i);
			i++;
			if(i>scene->nRenderers)break;
		}
	}
	gePrintDebug(0x100, "scene 3\n");

	geFileClose(fp);
	
	return scene;
}