示例#1
0
	void Renderer::RenderablesAcquire(const Variant& entities_variant)
	{
		TIME_BLOCK_START_CPU(m_profiler);

		// Clear previous state
		m_entities.clear();
		m_camera = nullptr;
		m_skybox = nullptr;
		
		auto entities_vec = entities_variant.Get<vector<shared_ptr<Entity>>>();
		for (const auto& entitieshared : entities_vec)
		{
			auto entity = entitieshared.get();
			if (!entity)
				continue;

			// Get all the components we are interested in
			auto renderable = entity->GetComponent<Renderable>();
			auto light		= entity->GetComponent<Light>();
			auto skybox		= entity->GetComponent<Skybox>();
			auto camera		= entity->GetComponent<Camera>();

			if (renderable)
			{
				const auto is_transparent = !renderable->MaterialExists() ? false : renderable->MaterialPtr()->GetColorAlbedo().w < 1.0f;
				if (!skybox) // Ignore skybox
				{
					m_entities[is_transparent ? Renderable_ObjectTransparent : Renderable_ObjectOpaque].emplace_back(entity);
				}
			}

			if (light)
			{
				m_entities[Renderable_Light].emplace_back(entity);
			}

			if (skybox)
			{
				m_skybox = skybox;
			}

			if (camera)
			{
				m_entities[Renderable_Camera].emplace_back(entity);
				m_camera = camera;
			}
		}

		RenderablesSort(&m_entities[Renderable_ObjectOpaque]);
		RenderablesSort(&m_entities[Renderable_ObjectTransparent]);

		TIME_BLOCK_END(m_profiler);
	}
	//	Description:
	//		Create in_MaterialName 
	//
	//	Pre-Conditions:
	//		in_Part must be a model retrieved into memory.
	//		in_MaterialName length < 32 chars
	//
	//	Post-Conditions
	//		if in_MaterialName already exist
	//			return; //no action required
	//		else
	//			create in_MaterialName material
	void CreateMaterial( ProSolid in_part, const std::string &in_MaterialName ) 
													throw (isis::application_exception)
	{
		// Check if material exist
		if ( MaterialExists(in_part, in_MaterialName) )
		{
			return;
		}

		// Create new material
		ProMaterial newMaterial;
		ProName  materialName_wchar;
		ProStringToWstring(materialName_wchar, (char *)in_MaterialName.c_str() );
		isis::isis_ProMaterialCreate ( in_part, materialName_wchar, NULL, &newMaterial  );

	}
	void SetMaterial_to_CurrentMaterial( ProSolid in_part, const std::string &in_MaterialName ) 
													throw (isis::application_exception)
	{
		// Check if material exists
		if ( !MaterialExists(in_part, in_MaterialName) )
		{
			std::string TempError = "Function SetMaterial_to_CurrentMaterial(...) was passed a material name that does not exist in the model (i.e. argument in_part).  in_MaterialName: " +
				in_MaterialName;
			throw isis::application_exception(TempError.c_str());
		}

		ProMaterial material;
		ProName  materialName_wchar;
		ProStringToWstring(material.matl_name, (char *)in_MaterialName.c_str() );
		material.part = in_part;

		// Set material as the current material
		ProMaterialCurrentSet(&material);

	}
	//	Description:
	//		Set in_MaterialName material properties to be the same as the current material (i.e. material that
	//		is set to current in the Creo Model)
	//
	//	Pre-Conditions:
	//		in_Part must be a model retrieved into memory.
	//		in_MaterialName length < 32 chars
	//
	//	Post-Conditions
	//		if in_MaterialName is already the current material
	//			return; // no action required.
	//		else
	//			if in_MaterialName material does not exist
	//				throw isis::application_exception
	//			else
	//				set in_MaterialName properties to be equal to the current material properties
	////////////////////////////////////////////////////////////////////////////////////////////////////////
	void SetMaterialPropertiesToBeTheSameAsCurrentMaterial(ProSolid in_part, const std::string &in_MaterialName ) 
													throw (isis::application_exception)
	{

		// Check if material exist
		if ( !MaterialExists(in_part, in_MaterialName) )
		{
			std::string TempError = "Function SetMaterialPropertiesToBeTheSameAsCurrentMaterial(...) was passed a material name that does not exist in the model (i.e. argument in_part).  in_MaterialName: " +
				in_MaterialName;
			throw isis::application_exception(TempError.c_str());
		}


		// Get current material
		ProMaterial currentMaterial;
		isis::isis_ProMaterialCurrentGet( in_part, &currentMaterial );
		ProModelitem  currentMaterialModelItem;
		isis_ProModelitemByNameInit ( in_part, PRO_RP_MATERIAL, currentMaterial.matl_name, &currentMaterialModelItem );

		// Check if in_MaterialName is the current material, if so, no action required.
		char stringBuffer[PRO_NAME_SIZE];  // PRO_NAME_SIZE = 32
		ProWstringToString(stringBuffer, currentMaterial.matl_name);
		std::string tempString = isis::ConvertToUpperCase(in_MaterialName);
		if ( strcmp(tempString.c_str(), _strupr(stringBuffer ))  == 0  )
		{
			// The current material is in_MaterialName. No action needed.
			return;
		}

		// Destination material
		ProMaterial destinationMaterial;
		ProName  materialName_wchar;
		ProStringToWstring(materialName_wchar, (char *)in_MaterialName.c_str() );
		ProModelitem  destinationMaterialModelItem;
		isis_ProModelitemByNameInit ( in_part, PRO_RP_MATERIAL, materialName_wchar, &destinationMaterialModelItem );

		// Copy the material properties from the current to destination material property
		ProParamvalue materialValue;
		ProUnititem   materialUnit;

		// Density
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem,		  PRO_MATPROP_MASS_DENSITY, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_MASS_DENSITY, &materialValue, &materialUnit );

		// Poisson' Ratio
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem,		  PRO_MATPROP_POISSON_RATIO, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_POISSON_RATIO, &materialValue, &materialUnit );

		// Young's Modulus
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem,		  PRO_MATPROP_YOUNG_MODULUS, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_YOUNG_MODULUS, &materialValue, &materialUnit );
		
		// Coeef. of Thermal Expansion
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem,		  PRO_MATPROP_THERMAL_EXPANSION_COEFFICIENT, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_THERMAL_EXPANSION_COEFFICIENT, &materialValue, &materialUnit );

		// Stress-Strain Response e.g. Linear, Hyperelastic, Elastroplastic
		// Couldn't find the enum entry
		
		// Specific Heat Capicity
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem, PRO_MATPROP_SPECIFIC_HEAT, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_SPECIFIC_HEAT, &materialValue, &materialUnit );

		// Thermal Conductivity
		isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem, PRO_MATPROP_THERMAL_CONDUCTIVITY, &materialValue, &materialUnit );
		isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_THERMAL_CONDUCTIVITY, &materialValue, &materialUnit );

		// Symmetry e.g. isotropic
		// Could not find the enum entry

		try 
		{  // Don't fail if this doesnt't exist.
		// Initial Bend Y-Factor
			isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem, PRO_MATPROP_INITIAL_BEND_Y_FACTOR, &materialValue, &materialUnit );
			isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_INITIAL_BEND_Y_FACTOR, &materialValue, &materialUnit );
		}
		catch (...)
		{
		}

		// Bend Table, skip this 
		//isis::isis_ProMaterialPropertyGet( &currentMaterialModelItem, PRO_MATPROP_BEND_TABLE, &materialValue, &materialUnit );
		//isis::isis_ProMaterialPropertySet( &destinationMaterialModelItem,	  PRO_MATPROP_BEND_TABLE, &materialValue, &materialUnit );

		// Cross Hatching
		// Could not find the enum entry

	}