void DotSceneLoader::processLight(rapidxml::xml_node<>* XMLNode, Ogre::SceneNode *pParent)
{
	// Process attributes
	Ogre::String name = getAttrib(XMLNode, "name");
	Ogre::String id = getAttrib(XMLNode, "id");

	// Create the light
	Ogre::Light *pLight = mSceneMgr->createLight(name);
	if (pParent)
		pParent->attachObject(pLight);

	Ogre::String sValue = getAttrib(XMLNode, "type");
	if (sValue == "point")
		pLight->setType(Ogre::Light::LT_POINT);
	else if (sValue == "directional")
		pLight->setType(Ogre::Light::LT_DIRECTIONAL);
	else if (sValue == "spot")
		pLight->setType(Ogre::Light::LT_SPOTLIGHT);
	else if (sValue == "radPoint")
		pLight->setType(Ogre::Light::LT_POINT);

	pLight->setVisible(getAttribBool(XMLNode, "visible", true));
	pLight->setCastShadows(getAttribBool(XMLNode, "castShadows", true));

	rapidxml::xml_node<>* pElement;

	// Process position (?)
	pElement = XMLNode->first_node("position");
	if (pElement)
		pLight->setPosition(parseVector3(pElement));

	// Process normal (?)
	pElement = XMLNode->first_node("normal");
	if (pElement)
		pLight->setDirection(parseVector3(pElement));

	pElement = XMLNode->first_node("directionVector");
	if (pElement)
	{
		pLight->setDirection(parseVector3(pElement));
		mLightDirection = parseVector3(pElement);
	}

	// Process colourDiffuse (?)
	pElement = XMLNode->first_node("colourDiffuse");
	if (pElement)
		pLight->setDiffuseColour(parseColour(pElement));

	// Process colourSpecular (?)
	pElement = XMLNode->first_node("colourSpecular");
	if (pElement)
		pLight->setSpecularColour(parseColour(pElement));

	if (sValue != "directional")
	{
		// Process lightRange (?)
		pElement = XMLNode->first_node("lightRange");
		if (pElement)
			processLightRange(pElement, pLight);

		// Process lightAttenuation (?)
		pElement = XMLNode->first_node("lightAttenuation");
		if (pElement)
			processLightAttenuation(pElement, pLight);
	}
	// Process userDataReference (?)
	pElement = XMLNode->first_node("userDataReference");
	if (pElement)
		;//processUserDataReference(pElement, pLight);
}
Esempio n. 2
0
void DotSceneLoader::processLight(TiXmlElement *xmlNode, Node *pParent) {
	// Process attributes
	std::string name = getAttrib(xmlNode, "name");
	std::string id = getAttrib(xmlNode, "id");
	std::string sValue = getAttrib(xmlNode, "type");

	Light* light = 0;

	if(sValue == "point") {
		light = scene->createPointLight();
	}
	//	else if(sValue == "directional")
	//		pLight->setType(Light::LT_DIRECTIONAL);
	//	else if(sValue == "spot")
	//		pLight->setType(Light::LT_SPOTLIGHT);
	//	else if(sValue == "radPoint")
	//		pLight->setType(Light::LT_POINT);

	// Create the light
	if(pParent) {
		//lightEntity->addComponent(new NodeAdapter(pParent));
	}

	//light->setVisible(getAttribBool(xmlNode, "visible", true));
	light->castShadow(getAttribBool(xmlNode, "castShadows", true));

	TiXmlElement *pElement;

	// Process position (?)
	pElement = xmlNode->FirstChildElement("position");
	if(pElement)
		light->setPosition(parseVector3(pElement));

	// Process normal (?)
	pElement = xmlNode->FirstChildElement("normal");
	if(pElement)
		light->setDirection(parseVector3(pElement));

	// Process colourDiffuse (?)
	pElement = xmlNode->FirstChildElement("colourDiffuse");
	if(pElement)
		light->setDiffuse(parseColour(pElement));

	// Process colourSpecular (?)
	pElement = xmlNode->FirstChildElement("colourSpecular");
	if(pElement)
		light->setSpecular(parseColour(pElement));

	// Process lightRange (?)
	pElement = xmlNode->FirstChildElement("lightRange");
	if(pElement)
		processLightRange(pElement, light);

	// Process lightAttenuation (?)
	pElement = xmlNode->FirstChildElement("lightAttenuation");
	if(pElement)
		processLightAttenuation(pElement, light);

	// Process userDataReference (?)
	pElement = xmlNode->FirstChildElement("userDataReference");
	if(pElement)
		; //processUserDataReference(pElement, pLight);

	//light->setAmbient(math::Vector3(0.5, 0.5, 0.5));
	//light->setDiffuse(math::Vector3(1.0, 1.0, 1.0));
	//light->setSpecular(math::Vector3(0.5, 0.5, 0.5));
	//light->setPosition(math::Vector3(0.0, 10.0, 0.0));
	//light->setAttenuations(math::Vector3(100.0, 1.0, 1.0));
	light->setDirection(math::Vector3(0.5, -1.0, 0.0).normalize());
	light->castShadow(true);
}