Description

This is a basic Entity creator, loads datas from VRML 2.0 / X3D using CyberX3D (basically the only correct open-source C++ VRML 2.0 (X3D) loader I found), this is a very basic loader, but demonstrates the creation of Meshes and Submeshes. Creates custom Manager for VRML files, based on the article: Resources and ResourceManagers.

VRML and X3D

This is a VRML 2.0 loader, uses a lib for X3D format. Basicly, X3D is an extension of VRML 2.0 . More info in wikis: Wikipedia - X3D and Wikipedia - VRML97

Environment

  • MSVC++ 2008 Express
  • Ogre 1.4.9


Anybody want to extend/correct the article is welcome!

(article will be extended when I have more time)

Overview

  • materials have to be created based on transparency (question: if the VRML-material doesn't contain transparency but the related texture is transparent - how should indicate this?)

Limitations

  • can handle only 'normalPerVertex FALSE'
  • triangle based models
  • no hierarchy
  • no scripting
  • no multi-texture

Usage

// register the manager (only once!)
new VrmlFileManager();

// ...

// load the VRML to memory + let CyberX3D to process it
VrmlFilePtr vrml_scene = VrmlFileManager::getSingleton().load(
		EyeWitnessInterfaceConverter::convertResourceUrlRelativeToDirectory(in_file_name, in_base_dir), 
		GlobalSettings::getSingleton().getResourceGroupAct()
	);

// and create an entity from the VRML datas
Ogre::Entity* mp_entity = vrml_scene->createEntity("the-id", GlobalSettings::getSingleton().getSceneManager(), 
		1.0f, Ogre::Vector3::ZERO, Ogre::CULL_NONE);

Header

#ifndef _VRML_FILE_H_
#define _VRML_FILE_H_

//============
// INCLUDES
#include <Base.h>
#include <cybergarage\x3d\CyberX3D.h>

#include <OgreResourceManager.h>
#include <OgreVector3.h>

//============
// USING

//============
// CLASSES

	/// *********** CLASS **************/
	/// <name> XmlFile </name>
	/// <description> - </description>
	/// <remarks> - </remarks>
	/// ********************************/
	class VrmlFile : public Ogre::Resource
	{
	protected:
		// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		// inherited from Resource 
		// -> must implement these from the Ogre::Resource interface
		// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		void loadImpl();
		void unloadImpl();
		size_t calculateSize() const;

	public:
		VrmlFile(Ogre::ResourceManager* creator, const Ogre::String &name, 
			Ogre::ResourceHandle handle, const Ogre::String& group, bool isManual = false, 
			Ogre::ManualResourceLoader* loader = 0);
		virtual ~VrmlFile();

		///----------- FUNCTION ------------
		/// <name> createEntity </name>
		/// <description> - </description>
		/// <parameters> 
		/// @in_base_unique_name := an unique string, the entities/meshes/materials will use this to make unique names (required by Ogre)
		///		-> entities will be named:		base-unique-name/number-of-the-shape-node-in-this-file
		///											or if the shape-node has a name: base-unique-name/name-of-the-shape-node
		///		-> meshes will be named:		base-unique-name/meshes/number-of-the-shape-node-in-this-file
		///											or if the shape-node has a name: base-unique-name/meshes/name-of-the-shape-node (HAVE TO BE UNIQUE!!!)
		///		-> materials will be named:		base-unique-name/materials/texture-file-name
		///											or if it won't hold any textures: base-unique-name/materials/number-of-the-shape-node-in-this-file (the shape-node's number!!!)
		/// Example:
		///		in_base_unique_name example = StaticMeshesFromScene (
		///		first mesh will be: StaticMeshesFromScene/meshes/1
		/// </parameters>
		/// <remarks>
		///		* additionally this will create a scene-node, which is child of the roor-scene-node and
		///			possibly holds the transformations given from the VRML (rotation, scale, translation)
		///	</remarks>
		/// <return> - </return>
		///---------------------------------
		Ogre::Entity* createEntity(const Ogre::String& in_base_unique_name, Ogre::SceneManager* in_scene_manager, 
			const Ogre::Real in_scale_factor = 1.0f, const Ogre::Vector3& in_pos_offset = Ogre::Vector3::ZERO, Ogre::CullingMode in_cull_mode = Ogre::CULL_NONE);

		///----------- FUNCTION ------------
		/// <name> getBackgroundColor </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		Ogre::ColourValue getBackgroundColor();

		///----------- FUNCTION ------------
		/// <name> getContentString </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		const Ogre::String getContentString();

		///----------- FUNCTION ------------
		/// <name> getWorldAmbientColor </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		Ogre::ColourValue getWorldAmbientColor();

		///----------- FUNCTION ------------
		/// <name> getDirectionalLights </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		CyberX3D::DirectionalLightNode* VrmlFile::getDirectionalLights();

		///----------- FUNCTION ------------
		/// <name> getPointLights </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		CyberX3D::PointLightNode* VrmlFile::getPointLights();

	private:
		size_t m_size;
		CyberX3D::SceneGraph* m_x3d_scene_graph;

	private:
		///----------- FUNCTION ------------
		/// <name> loadToMemory </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		void loadToMemory(const Ogre::String& in_xml_file_string);

		///----------- FUNCTION ------------
		/// <name> addSubMesh </name>
		/// <description> adds a SubMesh (from VRML - Shape (node) ) to the reference ManualObject </description>
		/// <parameters>
		///		@in_is_generate_normal_if_needed:  
		/// </parameters>
		/// <return> - </return>
		///---------------------------------
		void addSubMesh(Ogre::ManualObject* ref_manual_object,const Ogre::String& in_base_unique_name, CyberX3D::ShapeNode* inp_shn, 
									Ogre::SceneManager* in_scene_manager, 
									const Ogre::Real in_scale_factor, const Ogre::Vector3& in_pos_offset,
									int in_curr_mesh_num, 
									const bool in_is_flip_texture_vertically = true, const bool in_is_flip_texture_horizontally = true,
									bool in_is_flip_normals = false, bool in_is_generate_normal_if_needed = true, 
									Ogre::CullingMode in_cull_mode = Ogre::CULL_NONE, bool in_is_overlay_to_debug = false);

		///----------- FUNCTION ------------
		/// <name> makeMaterialBase </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		void makeMaterialBase(Ogre::String& ref_mat_name, const Ogre::ColourValue in_diffuse_color,
			const Ogre::ColourValue in_ambient_color, Ogre::CullingMode in_cull_mode = Ogre::CULL_NONE);

		///----------- FUNCTION ------------
		/// <name> makeMaterialTextured </name>
		/// <description> - </description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		void makeMaterialTextured(Ogre::String& ref_material_name, const Ogre::String in_tex_name, 
			const Ogre::ColourValue in_diffuse_color, const Ogre::ColourValue in_ambient_color,
			Ogre::CullingMode in_cull_mode = Ogre::CULL_NONE);
	};

	/// *********** CLASS **************/
	/// <name> XmlFilePtr </name>
	/// <description> - </description>
	/// ********************************/
	class VrmlFilePtr : public Ogre::SharedPtr<VrmlFile> 
	{
	public:
		VrmlFilePtr() : Ogre::SharedPtr<VrmlFile>() {}
		explicit VrmlFilePtr(VrmlFile *rep) : Ogre::SharedPtr<VrmlFile>(rep) {}
		VrmlFilePtr(const VrmlFilePtr &r) : Ogre::SharedPtr<VrmlFile>(r) {} 
		VrmlFilePtr(const Ogre::ResourcePtr &r) : Ogre::SharedPtr<VrmlFile>()
		{
			// lock & copy other mutex pointer
			OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
				OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
				pRep = static_cast<VrmlFile*>(r.getPointer());
			pUseCount = r.useCountPointer();
			if (pUseCount)
			{
				++(*pUseCount);
			}
		}

		/// Operator used to convert a ResourcePtr to a VrmlFilePtr
		VrmlFilePtr& operator=(const Ogre::ResourcePtr& r)
		{
			if (pRep == static_cast<VrmlFile*>(r.getPointer()))
				return *this;
			release();
			// lock & copy other mutex pointer
			OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
				OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
				pRep = static_cast<VrmlFile*>(r.getPointer());
			pUseCount = r.useCountPointer();
			if (pUseCount)
			{
				++(*pUseCount);
			}
			return *this;
		}
	};

#endif // end-of: _VRML_FILE_H_

Source

#include "stdafx.h"

#include "VrmlFile.h"
#include "VrmlFileSerializer.h"
#include <xercesc/framework/MemBufInputSource.hpp>
#include <SearchInResources.h>
#include "MaterialFileConstants.h"
#include <TextureMaterialHelper.h>
#include <EyeWitnessInterfaceConverter.h>

#include <OgreManualObject.h>
#include <OgreMaterial.h>
#include <OgreRenderOperation.h>
#include <OgreEntity.h>
#include <OgrePass.h>
#include <OgreSceneManager.h>
#include <OgreStringConverter.h>
#include <OgreTechnique.h>

using namespace Ayroth;

//---------------------------------------------------------------------------------------------
VrmlFile::VrmlFile(Ogre::ResourceManager* creator, const Ogre::String &name, 
                    Ogre::ResourceHandle handle, const Ogre::String &group, bool isManual, 
                    Ogre::ManualResourceLoader *loader) 
	:	Ogre::Resource(creator, name, handle, group, isManual, loader)
{
    /* If you were storing a pointer to an object, then you would set that pointer to NULL here.
    */

    /* For consistency with StringInterface, but we don't add any parameters here
    That's because the Resource implementation of StringInterface is to
    list all the options that need to be set before loading, of which 
    we have none as such. Full details can be set through scripts.
    */ 
    createParamDictionary("VrmlFile");
}

//---------------------------------------------------------------------------------------------
VrmlFile::~VrmlFile()
{
    unload();
}

//---------------------------------------------------------------------------------------------
void VrmlFile::loadImpl()
{
    //VrmlFileSerializer serializer;
    //Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mName, mGroup, true, this);    
	//loadToMemory(serializer.importFromFile(stream));

	Ogre::String full_url = Ayroth::SearchInResources::GetFullPath(mName, mGroup);
	if( full_url == "0" )
	{
		LOG_CRITICAL( "Cannot load the file: " + mName + " (possibly this is not in the specified resource group: " + mGroup + ")");
		return;
	}

	m_size = 1024;		// TODO: TMP 1MB
	m_x3d_scene_graph = new CyberX3D::SceneGraph();
	LOG_NORMAL("Vrml-file: " + Ogre::String(full_url).c_str());
	bool result = m_x3d_scene_graph->load(Ogre::String(full_url).c_str());
	if (result == false) {
		LOG_CRITICAL(
			"VRML loading failed! Datas: " +
			Ogre::String(m_x3d_scene_graph->getParserErrorMessage()) + 
			" : " + Ogre::StringConverter::toString(m_x3d_scene_graph->getParserErrorLineNumber()) + 
			" | " + Ogre::String(m_x3d_scene_graph->getParserErrorToken())
			);
	}
}

//---------------------------------------------------------------------------------------------
void VrmlFile::unloadImpl()
{
    /* If you were storing a pointer to an object, then you would check the pointer here,
    and if it is not NULL, you would destruct the object and set its pointer to NULL again.
    */
}

//---------------------------------------------------------------------------------------------
void VrmlFile::loadToMemory(const Ogre::String& in_xml_file_string)
{
	m_size = in_xml_file_string.size();

	/*
	MemBufInputSource* memBufIS = new MemBufInputSource((const XMLByte*)in_xml_file_string.c_str(), in_xml_file_string.length(), 
		mName.c_str(), false);
	m_dom_parser->parse(*memBufIS);

	m_xml_doc = m_dom_parser->getDocument();
	m_root_element = m_xml_doc->getDocumentElement();
	*/
}

//---------------------------------------------------------------------------------------------
size_t VrmlFile::calculateSize() const
{
    return m_size;
}

//---------------------------------------------------------------------------------------------
const Ogre::String VrmlFile::getContentString()
{
	return Ogre::String("Need to implement!");
}

//---------------------------------------------------------------------------------------------
Ogre::Entity* VrmlFile::createEntity(const Ogre::String& in_base_unique_name, Ogre::SceneManager* in_scene_manager,
									 const Ogre::Real in_scale_factor, const Ogre::Vector3& in_pos_offset,
									 const Ogre::CullingMode in_cull_mode)
{
	LOG_NORMAL("Start to create entity from VRML - entity ID: " + in_base_unique_name);
	Ogre::Entity* _ret = NULL;

	// 1) start a new ManualObject, to create the mesh on-the-fly
	Ogre::ManualObject* mo = new Ogre::ManualObject("man_obj");

	// 2) traverse through all ShapeNodes 
	// -> each one is a SubMesh/entity, BECAUSE we use it this way; 
	// but VRML could handle hiearchy! (we just don't use it)
	// here: 1 VRML file is 1 Mesh/Entity; Shape's are Sub-Meshes/Entities
	int i = 0;
	CyberX3D::ShapeNode* shn = NULL;
	for( shn = m_x3d_scene_graph->getShapeNodes(), i = 0; shn; shn = shn->next(), i++)
	{
		this->addSubMesh(mo, in_base_unique_name, shn, in_scene_manager, in_scale_factor, in_pos_offset, i, true, true, false, true, in_cull_mode, false);
	}

	if( mo->getNumSections() == 0 )
	{
		LOG_WARNING("The VRML doesn't have any geometry");
		return NULL;
	}

	// set the ManualObject/Entity datas
	mo->setDynamic(false);
	mo->setCastShadows(false);

	Ogre::String mesh_name = in_base_unique_name + "Mesh";
	// convert it to Mesh
	Ogre::MeshPtr pmesh = mo->convertToMesh(mesh_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	pmesh->buildEdgeList(); // build edge-list to shadow-volumes
	// and delete the ManualObject
	delete mo;

	_ret = in_scene_manager->createEntity(
		in_base_unique_name,		// entity's name
		mesh_name
	);
	/*if( inp_shn->hasName() )
	{
		_ret_entity = in_scene_manager->createEntity(
			in_base_unique_name + Ogre::String(inp_shn->getName()),		// entity's name
			mesh_name
			);
	} else {
		_ret_entity = in_scene_manager->createEntity(
			in_base_unique_name + "/meshes/" + Ogre::StringConverter::toString(in_curr_mesh_num),		// entity's name
			mesh_name
			);
	}*/

	_ret->setCastShadows(true);
	Ogre::SceneNode* thisSceneNode = in_scene_manager->getRootSceneNode()->createChildSceneNode();
	//if( in_is_overlay_to_debug )
	//	thisSceneNode->setPosition(0.0f, 0.0f, 20.0f * in_curr_mesh_num);
	thisSceneNode->attachObject(_ret);

	return _ret;
}

//---------------------------------------------------------------------------------------------
void VrmlFile::addSubMesh(Ogre::ManualObject* ref_manual_object, const Ogre::String& in_base_unique_name, CyberX3D::ShapeNode* inp_shn, 
									Ogre::SceneManager* in_scene_manager, 
									const Ogre::Real in_scale_factor, const Ogre::Vector3& in_pos_offset,
									int in_curr_mesh_num, 
									const bool in_is_flip_texture_vertically, const bool in_is_flip_texture_horizontally,
									bool in_is_flip_normals, bool in_is_generate_normal_if_needed, 
									const Ogre::CullingMode in_cull_mode, bool in_is_overlay_to_debug)
{
	bool is_texture_available = true;
	bool is_normal_available = true;
	bool is_transparent = false;

	// :::::::::::::::::::
	// ::Appearance
	Ogre::String texture_name = "";
	Ogre::String material_name = "";
	Ogre::ColourValue diffuse_color = Ogre::ColourValue::White;
	Ogre::ColourValue ambient_color = Ogre::ColourValue::White;
	CyberX3D::AppearanceNode* pappearance_node = inp_shn->getAppearanceNodes();
	if( pappearance_node != NULL )
	{
		float transparency = pappearance_node->getMaterialNodes()->getTransparency();
		if( transparency > 0.0f )
			is_transparent = true;
		float* col = new float[3];
		pappearance_node->getMaterialNodes()->getDiffuseColor(col);
		diffuse_color = Ogre::ColourValue::ColourValue(col[0], col[1], col[2], 1.0f - transparency);
		float amb_int = 1.0f;
		amb_int = pappearance_node->getMaterialNodes()->getAmbientIntensity();
		ambient_color = Ogre::ColourValue::ColourValue(amb_int, amb_int, amb_int, 1.0f);

		CyberX3D::ImageTextureNode* pimage_tex_node = pappearance_node[0].getImageTextureNodes();
		// pimage_tex_node[0].getRepeatS
		// pimage_tex_node[0].getRepeatT
		pimage_tex_node[0].get
		if( pimage_tex_node != NULL )
		{
			texture_name = Ogre::String(pimage_tex_node[0].getUrl(0));
			texture_name = EyeWitnessInterfaceConverter::convertResourceUrlRelativeToFile(texture_name, mName, mGroup);
			//this->getName()
			material_name = in_base_unique_name + "/materials/" + texture_name;
			makeMaterialTextured(material_name, texture_name, diffuse_color, ambient_color, in_cull_mode);
		} else {
			is_texture_available = false;			// disable texture
			material_name = in_base_unique_name + "/materials/" + Ogre::StringConverter::toString(in_curr_mesh_num);
			material_name += Ogre::StringConverter::toString(diffuse_color);
			makeMaterialBase(material_name, diffuse_color, ambient_color, in_cull_mode);
		}
	} else {
		is_texture_available = false;			// disable texture
		material_name = "material/no-material";
		makeMaterialBase(material_name, diffuse_color, ambient_color);
	}

	// :::::::::::::::::::
	// ::Geometry
	//g_CurrAvailableVertexID = 0;
	//g_IndexBufferOffset = 0;

	// :::::::::::::::::::
	// :: 1.) Get datas ::
	Ogre::String mesh_name;
	if( inp_shn->hasName() )
		mesh_name = in_base_unique_name + "/meshes/" + Ogre::String(inp_shn->getName());
	else
		mesh_name = in_base_unique_name + "/meshes/" + Ogre::StringConverter::toString(in_curr_mesh_num);

	//CyberX3D::AppearanceNode* appearance = inp_shn->getAppearanceNodes();
	//CyberX3D::Geometry3DNode* pgeomn = inp_shn->getGeometry3DNode();

	CyberX3D::IndexedFaceSetNode* ifsn = inp_shn->getIndexedFaceSetNodes();
	if( ifsn==NULL )
	{
		LOG_CRITICAL("Cannot get face-set-nodes, probably this type is not supported.");
		return;
	}

	// coord-index
	CyberX3D::MFInt32* pcoord_idx = ifsn->getCoordIndexField();
	// points / coords
	CyberX3D::CoordinateNode* cn = ifsn->getCoordinateNodes();
	if( cn==NULL || pcoord_idx==NULL )
	{
		LOG_CRITICAL("Cannot get coordinates");
		return;
	}
	CyberX3D::MFVec3f* coordinate_points_field = cn[0].getPointField();
	// tex-coords
	CyberX3D::MFInt32* ptex_idx = ifsn->getTexCoordIndexField();
	CyberX3D::TextureCoordinateNode* tn = ifsn->getTextureCoordinateNodes();
	CyberX3D::MFVec2f* texture_coordinates_field = NULL;
	if( ptex_idx!=NULL && tn!=NULL )
	{
		texture_coordinates_field = tn[0].getPointField();
		if( ptex_idx->getSize() != pcoord_idx->getSize() )
		{
			// the only supported type is that:
			// each texCoordIndex attached to a coordIndex
			// -> per-face-vertex texCoordIndex
			// -> every face-vertex has to have a texCoordIndex!
			LOG_CRITICAL("tex-index's num is NOT equal to coord-index's num!");
			return;
		}
	} else {
		LOG_NORMAL("Can't find texture-coordinate datas in: " + mesh_name);	

		is_texture_available = false;			// disable texture
	}
	// normals
	//ifsn->setSolid(true);
	//ifsn->setCCW(true);
	//ifsn->setNormalPerVertex(false);	// -> set to per face
	CyberX3D::NormalNode* nn = ifsn->getNormalNodes();
	if( nn==NULL && in_is_generate_normal_if_needed )
	{
		// cannot find normal-datas
		// so try to generate them
		if( !ifsn->generateNormals() )
		{
			LOG_NORMAL("Cannot generate normals!");
		} else {
			nn = ifsn->getNormalNodes();
		}
	}

	CyberX3D::MFVec3f* normal_field = NULL;
	if( nn!=NULL )
	{
		normal_field = nn[0].getVectorField();
	} else {
			is_normal_available = false;
	}

	// :::::::::::::::::::::::::::::::
	// :: 2.) create the sub-mesh datas ::	
	ref_manual_object->begin(material_name, Ogre::RenderOperation::OT_TRIANGLE_LIST);
		int face_idx = 0;
		int vert_idx = 0;
		for( int i = 0; i < pcoord_idx->getSize(); i++ )
		{
			if( (i+1)%4 != 0 )
			{
				// add position
				Ogre::uint16 coord_idx = pcoord_idx->get1Value(i);
				float* pos = new float[3];
				coordinate_points_field->get1Value(coord_idx, pos);
				ref_manual_object->position(Ogre::Vector3(pos) * in_scale_factor);

				if( is_texture_available )
				{
					// add texture
					Ogre::uint16 tex_idx = ptex_idx->get1Value(i);
					float* tex = new float[2];
					texture_coordinates_field->get1Value(tex_idx, tex);
					Ogre::Vector2 tex_uv = Ogre::Vector2(tex);

					// make the flips (if needed)
					if( in_is_flip_texture_vertically )
					{
						tex_uv.y = 1.0f - tex_uv.y;
					}

					if( in_is_flip_texture_horizontally )
					{
						tex_uv.x = 1.0f - tex_uv.x;
					}

					ref_manual_object->textureCoord(tex_uv);
				} 

				if( is_normal_available )
				{
					// add normal
					Ogre::uint16 normal_idx = face_idx;
					float* norm = new float[3];
					normal_field->get1Value(normal_idx, norm);
					Ogre::Vector3 norm_vec = Ogre::Vector3(norm);
					if( in_is_flip_normals )
						norm_vec *= -1;
					ref_manual_object->normal(norm_vec);
				}

				ref_manual_object->index(vert_idx);
				vert_idx++;
			} else {
				face_idx++;
			}
		}
	ref_manual_object->end();

	//LOG_NORMAL(" VRML-MESH sub-mesh use the material: " + material_name);
	//LOG_NORMAL(" VRML-MESH face cnt: " + Ogre::StringConverter::toString(face_idx));
	//LOG_NORMAL(" VRML-MESH vert cnt: " + Ogre::StringConverter::toString(vert_idx));
}

//---------------------------------------------------------------------------------------------
void VrmlFile::makeMaterialBase(Ogre::String& ref_material_name, const Ogre::ColourValue in_diffuse_color, 
								const Ogre::ColourValue in_ambient_color, const Ogre::CullingMode in_cull_mode)
{
	Ogre::String base_mat = MaterialFileConstants::getMaterialNameNoTextureSimple();
	if( in_diffuse_color.a != 1.0f )
	{
		base_mat = MaterialFileConstants::getMaterialNameNoTextureAlphaBlend();
	}

	Ogre::MaterialPtr material;
	if( TextureMaterialHelper::cloneMaterialSafely(base_mat, material,
			ref_material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME) )
	{
		// OK
		Ogre::Material::TechniqueIterator tech_it =  material->getTechniqueIterator();
		// change all technique's first pass's texture
		//LOG_TRACE();
		while( tech_it.hasMoreElements() )
		{
			Ogre::Technique* ct = tech_it.getNext();
			Ogre::String desired_pass = MaterialFileConstants::getMaterialPassName_GenericMainPass();
			Ogre::Pass* pass = ct->getPass(desired_pass);
			if( pass == NULL )
			{
				LOG_CRITICAL("Pass (" + desired_pass + ") not found in technique: " + ct->getName());
			} else {
				pass->setAmbient(in_ambient_color);
				//LOG_NORMAL("Ambient: " + Ogre::StringConverter::toString(in_ambient_color));
				pass->setDiffuse(in_diffuse_color);
				//LOG_NORMAL("Diffuse: " + Ogre::StringConverter::toString(in_diffuse_color));
				//pass->setCullingMode(in_cull_mode);
			} 
		}
	}

	/*if( Ogre::MaterialManager::getSingleton().getByName(in_material_name).isNull() )
	{
		Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
			in_material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		if( material.isNull() )
		{
			LOG_NORMAL("Error: material cannot be created! Maybe name duplication/material is already exists? " + in_material_name);	
		} else {
			if( in_diffuse_color.a < 1.0f )
			{
				material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
				material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SceneBlendType::SBT_TRANSPARENT_ALPHA);
			}
			else
			{
				material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
			}
			material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);

			material->getTechnique(0)->getPass(0)->setDiffuse(in_diffuse_color);
			material->getTechnique(0)->getPass(0)->setAmbient(in_ambient_color);
			material->getTechnique(0)->getPass(0)->setCullingMode(in_cull_mode);
		}
	}*/
}

/*void VrmlFile::setToAllTechnique(Ogre::MaterialPtr in_material, Ogre::uint16 in_pass_idx, Ogre::ColourValue in_color)
{
	// try to get the material
	if( !in_material.isNull() )
	{
		// material is existing

		Ogre::Material::TechniqueIterator tech_it =  in_material->getTechniqueIterator();
		// change all technique's first pass's texture
		while( tech_it.hasMoreElements() )
		{
			Ogre::Pass* pass = tech_it.getNext()->getPass(in_pass_idx);
			pass->
		}
	} else {
		LOG_NORMAL("Error: material does not exist " + in_material->getName());
		return false;
	}
}*/

//---------------------------------------------------------------------------------------------
void VrmlFile::makeMaterialTextured(Ogre::String& ref_material_name, const Ogre::String in_tex_name, 
									const Ogre::ColourValue in_diffuse_color, const Ogre::ColourValue in_ambient_color, 
									const Ogre::CullingMode in_cull_mode)
{
	Ogre::String material_name = MaterialFileConstants::getMaterialNameTextureAmbientDiffuse();

	Ogre::MaterialPtr material;
	if( TextureMaterialHelper::cloneMaterialSafely(material_name, material,
			ref_material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME) )
	{
		if( TextureMaterialHelper::setTextureToAllTextureUnitThisName(material, 
				in_tex_name, MaterialFileConstants::getTextureUnitNameDiffuseTexture(), 0) )
		{
			// OK
			Ogre::Material::TechniqueIterator tech_it =  material->getTechniqueIterator();
			// change all technique's first pass's texture
			while( tech_it.hasMoreElements() )
			{
				Ogre::Technique* ct = tech_it.getNext();
				Ogre::String desired_pass = MaterialFileConstants::getMaterialPassName_GenericMainPass();
				Ogre::Pass* pass = ct->getPass(desired_pass);
				if( pass == NULL )
				{
					LOG_CRITICAL("Pass (" + desired_pass + ") not found in technique: " + ct->getName());
				} else {
					pass->setAmbient(in_ambient_color);
					pass->setDiffuse(in_diffuse_color);
					pass->setCullingMode(in_cull_mode);
				}
			}
		}
	}

	/*if( Ogre::MaterialManager::getSingleton().getByName(in_material_name).isNull() )
	{
		if( Ogre::TextureManager::getSingleton().getByName(in_tex_name).isNull() )
		{
			if( Ogre::TextureManager::getSingleton().load(in_tex_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).isNull() )
			{
				LOG_NORMAL("Error: texture cannot be loaded! " + in_tex_name);
			}
		}

		// 1) create an empty material
		Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
			in_material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		if( material.isNull() )
		{
			LOG_NORMAL("Error: material cannot be created! Maybe name duplication problem or the material is already exists? " + in_material_name);	
		} else {
			// 2) if succeeded -> get the basic material (from a .material file! -> support both shader and ffp)
			//		[%%%] mostly the material has some remarks, see it in the material file!!!
			Ogre::MaterialPtr base_mat = Ogre::MaterialManager::getSingleton().load( MaterialFileConstants::getMaterialNameTextureAmbientDiffuse(), 
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

			// 3) then copy the base material to our (empty) material
			base_mat->copyDetailsTo(material);
			// 4) and change the parameters, we need
			Ogre::Material::TechniqueIterator tech_it =  material->getTechniqueIterator();
			// change all technique's first pass's texture
			while( tech_it.hasMoreElements() )
			{
				//Ogre::Technique::PassIterator pass_it = tech_it.getNext()->getPassIterator();
				Ogre::Pass* pass = tech_it.getNext()->getPass(0);
				pass->getTextureUnitState( MaterialFileConstants::getTextureUnitNameDiffuseTexture() )->setTextureName(in_tex_name);
				pass->setDiffuse(in_diffuse_color);

				while( pass_it.hasMoreElements() )
				{
					std::vector<Ogre::Pass*>::value_type pass_v = pass_it.getNext();
					pass_v->getTextureUnitState("color_texture")->setTextureName(in_tex_name);
					pass_v->setDiffuse(in_diffuse_color);
				}
			}

			if( in_diffuse_color.a < 1.0f )
			{
				material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
			}
			else
			{
				material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
			}

			// [iii]
			// info on multiple semi-transparency: 
			// http://www.ogre3d.org/phpBB2/viewtopic.php?t=12694&view=next&sid=ce193664e1d3d7c4af509e6f4e2718c6

			material->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER, 128);
			material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
			material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SceneBlendType::SBT_TRANSPARENT_ALPHA);
			material->getTechnique(0)->getPass(0)->setDiffuse(in_diffuse_color);
			material->getTechnique(0)->getPass(0)->setCullingMode(in_cull_mode);
		}
	} else {
		// don't do anything, the material is already exist!
	}*/
}

//---------------------------------------------------------------------------------------------
Ogre::ColourValue VrmlFile::getBackgroundColor()
{
	float* vec3 = new float[3];
	vec3[0] = 1; vec3[1] = 1; vec3[2] = 1;
	if( m_x3d_scene_graph->getBackgroundNode() != NULL )
	{
		m_x3d_scene_graph->getBackgroundNode()->getSkyColor(0, vec3);
	}

	//mViewport->setBackgroundColour(
	//	Ogre::ColourValue::ColourValue(vec3[0], vec3[1], vec3[2], 1));

	return Ogre::ColourValue::ColourValue(vec3[0], vec3[1], vec3[2], 1);
}

//---------------------------------------------------------------------------------------------
CyberX3D::DirectionalLightNode* VrmlFile::getDirectionalLights()
{
	return m_x3d_scene_graph->getDirectionalLightNodes();
}

//---------------------------------------------------------------------------------------------
CyberX3D::PointLightNode* VrmlFile::getPointLights()
{
	return m_x3d_scene_graph->getPointLightNodes();
}

//---------------------------------------------------------------------------------------------
Ogre::ColourValue VrmlFile::getWorldAmbientColor()
{
	float* vec3 = new float[3];
	CyberX3D::DirectionalLightNode* dir_ln = m_x3d_scene_graph->getDirectionalLightNodes();
	dir_ln->getAmbientColor(vec3);
	//dir_ln->getAmbientIntensity();

	//mViewport->setBackgroundColour(
	//	Ogre::ColourValue::ColourValue(vec3[0], vec3[1], vec3[2], 1));

	return Ogre::ColourValue::ColourValue(vec3[0], vec3[1], vec3[2], 1) * dir_ln->getAmbientIntensity();
	//return Ogre::ColourValue::White;
}

Manager

Header

//================================
// VrmlFileManager.h
//--------------------------------
// copyright: -
// based on: http://www.ogre3d.org/wiki/index.php/Advanced_Tutorial_1
// description: -
//================================

#ifndef _VRML_FILE_MANAGER_H_
#define _VRML_FILE_MANAGER_H_

//============
// INCLUDES
#include <OgreResourceManager.h>
#include "VrmlFile.h"


//============
// CLASSES

	class VrmlFileManager : public Ogre::ResourceManager, public Ogre::Singleton<VrmlFileManager>
	{
	protected:

		// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		// must implement this from ResourceManager's interface
		// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		Ogre::Resource *createImpl(const Ogre::String &name, Ogre::ResourceHandle handle, 
			const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader, 
			const Ogre::NameValuePairList *createParams);

	public:
		VrmlFileManager();
		virtual ~VrmlFileManager();
		static VrmlFileManager &getSingleton();
		static VrmlFileManager *getSingletonPtr();

	public:
		virtual VrmlFilePtr load(const Ogre::String &name, const Ogre::String &group);

		///----------- FUNCTION ------------
		/// <name> getTypeName </name>
		/// <description> 
		///		-
		///	</description>
		/// <parameters> - </parameters>
		/// <return> - </return>
		///---------------------------------
		std::string getTypeName();
	};

#endif // end-of: _VRML_FILE_MANAGER_H_


Source

#include "stdafx.h"

#include "VrmlFileManager.h"

#include <OgreStringConverter.h>


//---------------------------------------------------------------------------------------------
template<> VrmlFileManager* Ogre::Singleton<VrmlFileManager>::ms_Singleton = 0;

//---------------------------------------------------------------------------------------------
VrmlFileManager* VrmlFileManager::getSingletonPtr()
{
    return ms_Singleton;
}

//---------------------------------------------------------------------------------------------
VrmlFileManager& VrmlFileManager::getSingleton()
{  
    assert(ms_Singleton);  
    return(*ms_Singleton);
}

//---------------------------------------------------------------------------------------------
VrmlFileManager::VrmlFileManager()
{
    mResourceType = "VrmlFile";

    // low, because it will likely reference other resources
    mLoadOrder = 30.0f;

    // this is how we register the ResourceManager with OGRE
    Ogre::ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
}

//---------------------------------------------------------------------------------------------
VrmlFileManager::~VrmlFileManager()
{
    // and this is how we unregister it
    Ogre::ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
}

//---------------------------------------------------------------------------------------------
VrmlFilePtr VrmlFileManager::load(const Ogre::String& name, const Ogre::String &group)
{
	LOG_NORMAL("Start to load VRML: " + name);
    VrmlFilePtr file = getByName(name);

    if (file.isNull())
        file = create(name, group);

    file->load();
    return file;
}

//---------------------------------------------------------------------------------------------
Ogre::Resource* VrmlFileManager::createImpl(const Ogre::String& name, Ogre::ResourceHandle handle, 
                                            const Ogre::String& group, bool isManual, Ogre::ManualResourceLoader* loader, 
                                            const Ogre::NameValuePairList* createParams)
{
    return new VrmlFile(this, name, handle, group, isManual, loader);
}

//---------------------------------------------------------------------------------------------
std::string VrmlFileManager::getTypeName()
{
	return "VrmlFileManager";
}

Serializer

Header

//================================
// VrmlFileSerializer.h
//--------------------------------
// copyright: -
// based on: http://www.ogre3d.org/wiki/index.php/Advanced_Tutorial_1
// description: -
//================================

#ifndef _VRML_FILE_SERIALIZER_H_
#define _VRML_FILE_SERIALIZER_H_

//============
// INCLUDES
#include <OgreSerializer.h>

//============
// CLASSES

	class VrmlFile; // forward declaration

	class VrmlFileSerializer : public Ogre::Serializer
	{
	public:
		VrmlFileSerializer();
		virtual ~VrmlFileSerializer();

		void exportToFile(VrmlFile* in_vrml_file, const Ogre::String& file_name);
		Ogre::String importFromFile(Ogre::DataStreamPtr& in_stream);
	};


#endif // end-of: _VRML_FILE_SERIALIZER_H_


Source

#include "stdafx.h"

#include "VrmlFileSerializer.h"
#include "VrmlFile.h"

//---------------------------------------------------------------------------------------------
VrmlFileSerializer::VrmlFileSerializer()
{
}

//---------------------------------------------------------------------------------------------
VrmlFileSerializer::~VrmlFileSerializer()
{
}

//---------------------------------------------------------------------------------------------
void VrmlFileSerializer::exportToFile(VrmlFile* in_vrml_file, const Ogre::String& in_file_name)
{
    std::ofstream outFile;
    outFile.open(in_file_name.c_str(), std::ios::out);
    outFile << in_vrml_file->getContentString();
    outFile.close();
}

//---------------------------------------------------------------------------------------------
Ogre::String VrmlFileSerializer::importFromFile(Ogre::DataStreamPtr& in_stream)
{
    return in_stream->getAsString();
}


Alias: Loading from VRML 2.0 / X3D

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.