コード例 #1
0
	//bool MaterialExporter::streamPass(std::ostream &of, Mtl *mtl) {
	bool MaterialExporter::streamPass(std::ostream &of, IGameMaterial *mtl) {
		of << "\t\tpass" << std::endl;
		of << "\t\t{" << std::endl;

		int subMtlCt = mtl->GetSubMaterialCount();

		Point4 val4;
		Point3 val3;
		PropType pt;
		IGameProperty* p = mtl->GetAmbientData();

		if (p) {
			pt = p->GetType();

			if (pt == IGAME_POINT3_PROP) {
				p->GetPropertyValue(val3);
				of << "\t\t\tambient " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl;
			}

			if (pt == IGAME_POINT4_PROP) {
				p->GetPropertyValue(val4);
				of << "\t\t\tambient " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl;
			}
		}

		p = mtl->GetDiffuseData();
		if (p) {
			pt = p->GetType();

			if (pt == IGAME_POINT3_PROP) {
				p->GetPropertyValue(val3);
				of << "\t\t\tdiffuse " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl;
			}

			if (pt == IGAME_POINT4_PROP) {
				p->GetPropertyValue(val4);
				of << "\t\t\tdiffuse " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl;
			}
		}

		p = mtl->GetSpecularData();
		if (p) {
			pt = p->GetType();

			if (pt == IGAME_POINT3_PROP) {
				p->GetPropertyValue(val3);
				of << "\t\t\tspecular " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl;
			}

			if (pt == IGAME_POINT4_PROP) {
				p->GetPropertyValue(val4);
				of << "\t\t\tspecular " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl;
			}
		}

		p = mtl->GetEmissiveData();
		if (p) {
			pt = p->GetType();

			if (pt == IGAME_POINT3_PROP) {
				p->GetPropertyValue(val3);
				of << "\t\t\temissive " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl;
			}

			if (pt == IGAME_POINT4_PROP) {
				p->GetPropertyValue(val4);
				of << "\t\t\temissive " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl;
			}
		}

		int numTexMaps = mtl->GetNumberOfTextureMaps();
		if (numTexMaps > 0) {

			for (int texMapIdx = 0; texMapIdx < numTexMaps; texMapIdx++) {
				IGameTextureMap* tmap = mtl->GetIGameTextureMap(texMapIdx);
				if (tmap) {
					of << "\n\t\t\ttexture_unit " << std::endl;
					of << "\t\t\t{" << std::endl;

					std::string bmap(tmap->GetBitmapFileName());
					bmap = bmap.substr(bmap.find_last_of('\\') + 1);
					of << "\t\t\t\ttexture " << bmap << std::endl;
					of << "\t\t\t}" << std::endl;
				}
			}
		}

		of << "\t\t}" << std::endl;

		return true;
	}
コード例 #2
0
void SGMExporter::CollectProperties(Scene3DMesh *mesh, IGameMesh *gMesh)
{
	IPropertyContainer *propsContainer = gMesh->GetIPropertyContainer();
	if (propsContainer == NULL || propsContainer->GetNumberOfProperties() == 0)
	{
		Log::LogT("Mesh %s has no properties", mesh->name.c_str());
		return;
	}
	
	Log::LogT("properties count: %d", propsContainer->GetNumberOfProperties());

	for (int i = 0; i < propsContainer->GetNumberOfProperties(); i++)
	{
		IGameProperty *gProp = propsContainer->GetProperty(i);
		if (gProp == NULL)
			continue;

		int propType = gProp->GetType();
		std::string propName = StringUtils::ToNarrow(gProp->GetName());

		Log::LogT("eporting %s with type %d", propName.c_str(), propType);

		if (propType == IGAME_UNKNOWN_PROP)
		{
			Log::LogT("property %s has unknown type", propName.c_str());
			continue;
		}

		Property::AnimationType propAnimType = Property::AnimationType_None;

		Property *prop = NULL; 

		if (!gProp->IsPropAnimated())
		{
			Log::LogT("property %s has no animation", propName.c_str());

			prop = new Property(propName, PropTypeConv(propType), Property::AnimationType_None);
			switch (propType)
			{
			case IGAME_FLOAT_PROP:
				{
					float val;	
					gProp->GetPropertyValue(val);
					prop->SetValue(val);
				}
				break;

			case IGAME_INT_PROP:
				{
					int val;
					gProp->GetPropertyValue(val);
					prop->SetValue(val);
				}
				break;

			case IGAME_POINT3_PROP:
				{
					Point3 val;
					gProp->GetPropertyValue(val);
					prop->SetValue(sm::Vec3(val.x, val.y, val.z));
				}
				break;
			}
		}
		else
		{
			IGameControl *ctrl = gProp->GetIGameControl();

			if (ctrl == NULL)
			{
				Log::LogT("%s IGameControl is NULL", propName.c_str());
				continue;
			}

			switch (propType)
			{
			case IGAME_FLOAT_PROP:
				{
					Control *maxControl = ctrl->GetMaxControl(IGAME_FLOAT);
					if (maxControl != NULL && maxControl->IsAnimated())
					{
						if (maxControl->ClassID() == Class_ID(LININTERP_FLOAT_CLASS_ID, 0))
						{	
							Log::LogT("%s float liniowe scierwo", propName.c_str());
							prop = new Property(propName, Property::PropertyType_Float, Property::AnimationType_Linear);
							IGameKeyTab keys;
							if (ctrl->GetLinearKeys(keys, IGAME_FLOAT))
							{
								for (int j = 0; j < keys.Count(); j++)
								{
									prop->SetValue(keys[j].linearKey.fval, TicksToSec(keys[j].t));
								}
							}
						}
						if (maxControl->ClassID() == Class_ID(TCBINTERP_FLOAT_CLASS_ID, 0))
						{
							Log::LogT("%s float tcb scierwo", propName.c_str());
							prop = new Property(propName, Property::PropertyType_Float, Property::AnimationType_TCB);
							IGameKeyTab keys;
							if (ctrl->GetTCBKeys(keys, IGAME_FLOAT))
							{
								for (int j = 0; j < keys.Count(); j++)
								{
									prop->SetValue(keys[j].tcbKey.fval, TicksToSec(keys[j].t));
								}
							}
						}
					}
				}

				break;

			case IGAME_INT_PROP:
				{
					Control *maxControl = ctrl->GetMaxControl(IGAME_FLOAT);
					if (maxControl != NULL && maxControl->IsAnimated())
					{
						if (maxControl->ClassID() == Class_ID(LININTERP_FLOAT_CLASS_ID, 0))
						{
							Log::LogT("%s int liniowe scierwo", propName.c_str());
							//prop = new Property(propName, Property::PropertyType_Int, Property::AnimationType_Linear);
							// it should be always state interpolator for int
							prop = new Property(propName, Property::PropertyType_Int, Property::AnimationType_State);
							IGameKeyTab keys;
							if (ctrl->GetLinearKeys(keys, IGAME_FLOAT))
							{
								Log::LogT("eksportowanie %d keyframow", keys.Count());
								for (int j = 0; j < keys.Count(); j++)
								{
									prop->SetValue((int)keys[j].linearKey.fval, TicksToSec(keys[j].t));
								}
							}
						}
						if (maxControl->ClassID() == Class_ID(TCBINTERP_FLOAT_CLASS_ID, 0))
						{
							Log::LogT("%s int tcb scierwo", propName.c_str());
							//prop = new Property(propName, Property::PropertyType_Int, Property::AnimationType_TCB);
							// it should be always state interpolator for int
							prop = new Property(propName, Property::PropertyType_Int, Property::AnimationType_State);
							IGameKeyTab keys;
							if (ctrl->GetTCBKeys(keys, IGAME_FLOAT))
							{
								for (int j = 0; j < keys.Count(); j++)
								{
									prop->SetValue((int)keys[j].linearKey.fval, TicksToSec(keys[j].t));
								}
							}
						}
					}
					else
					{
					}
				}

				break;
			}
		}

		if (prop != NULL)
			mesh->properties.push_back(prop);
	}
}
コード例 #3
0
void SGMExporter::ExportCam(IGameNode *node, BinaryWriter *bw)
{
	IGameObject *gameObject = node ->GetIGameObject();
	assert(gameObject != NULL);

	if (gameObject ->GetIGameType() == IGameObject::IGAME_CAMERA)
	{
		camsCount++;
		IGameCamera *gameCam = (IGameCamera*)gameObject;
		bw->Write((int)node->GetNodeID());
		bw->Write(StringUtils::ToNarrow(node->GetName()));
		GMatrix viewMatrix = gameCam->GetIGameObjectTM().Inverse();
		SaveMatrix(bw, viewMatrix);
		
		IGameProperty *fov = gameCam->GetCameraFOV();
		IGameProperty *trgDist = gameCam->GetCameraTargetDist();
		IGameProperty *nearClip = gameCam->GetCameraNearClip();
		IGameProperty *farClip = gameCam->GetCameraFarClip();

		// FOV
		if (fov != NULL && fov->IsPropAnimated())
		{
			IGameControl *gameCtrl = fov->GetIGameControl();

			IGameKeyTab keys;
			if (gameCtrl->GetTCBKeys(keys, IGAME_FLOAT))
			{
				bw->Write((bool)true);
				bw->Write(keys.Count());
				for (int i = 0; i < keys.Count(); i++)
				{
					bw->Write(TicksToSec(keys[i].t));
					bw->Write(keys[i].tcbKey.fval);
				}
			}
			else
			{
				Log::LogT("warning: node '%s' doesn't have TCB controller for FOV, animation won't be exported", StringUtils::ToNarrow(node->GetName()).c_str());

				bw->Write((bool)false);
				float fovVal;
				fov->GetPropertyValue(fovVal);
				bw->Write(fovVal);
			}
		}
		else
		{
			bw->Write((bool)false);
			float fovVal;
			fov->GetPropertyValue(fovVal);
			bw->Write(fovVal);
		}

		///////DISTANCE
		if (trgDist != NULL && trgDist->IsPropAnimated())
		{
			IGameControl *gameCtrl = trgDist->GetIGameControl();

			IGameKeyTab keys;
			if (gameCtrl->GetTCBKeys(keys, IGAME_FLOAT))
			{
				bw->Write((bool)true);
				bw->Write(keys.Count());
				for (int i = 0; i < keys.Count(); i++)
				{
					bw->Write(TicksToSec(keys[i].t));
					bw->Write(keys[i].tcbKey.fval);
				}
			}
			else
			{
				Log::LogT("warning: node '%s' doesn't have TCB controller for target distance, animation won't be exported", StringUtils::ToNarrow(node->GetName()).c_str());

				bw->Write((bool)false);
				float val;
				trgDist->GetPropertyValue(val);
				bw->Write(val);
			}
		}
		else
		{
			bw->Write((bool)false);
			float fovVal;
			//trgDist->GetPropertyValue(fovVal);
			bw->Write(10.0f);
		}

		float nearClipValue;
		if (nearClip != NULL)
			nearClip->GetPropertyValue(nearClipValue);
		else nearClipValue = 0.1f;

		float farClipValue;
		if (farClip != NULL)
			farClip->GetPropertyValue(farClipValue);
		else farClipValue = 0.1f;

		bw->Write(nearClipValue);
		bw->Write(farClipValue);
	}

	node ->ReleaseIGameObject();

	for (int i = 0; i < node ->GetChildCount(); i++)
		ExportCam(node ->GetNodeChild(i), bw);
}
コード例 #4
0
ファイル: ExporterF3D.cpp プロジェクト: fedoriusv/V3DEngine
bool ExporterF3D::ExportMaterial(IGameMaterial* gameMaterial, MaterialPtr& material, STileUV& tile)
{
    if (!m_settings->isExportMaterials())
    {
        return true;
    }

    if (!gameMaterial)
    {
        LOG_WARNING("Material don't apply for this Node. Skipping Export Material");
        return true; //maybe need false
    }

    std::string materialName = TCHARToString(gameMaterial->GetMaterialName());
    std::string materialClass = TCHARToString(gameMaterial->GetMaterialClass());

    auto predMaterialExist = [&materialName](const MaterialPtr& material) -> bool
    {
        return material->getResourseName() == materialName;
    };

    const std::vector<MaterialPtr>& materials = m_scene->getMaterialList();
    std::vector<MaterialPtr>::const_iterator iter = std::find_if(materials.begin(), materials.end(), predMaterialExist);
    if (iter != materials.end())
    {
        material = (*iter);
        return true;
    }

    LOG_INFO("ExportMaterial : %s, class: %s", materialName.c_str(), materialClass.c_str());
    if (gameMaterial->IsMultiType())
    {
        LOG_DEBUG("ExportMaterial Export muliType");
        s32 countSubMaterial = gameMaterial->GetSubMaterialCount();
        LOG_INFO("Num Sub Materials : %d", countSubMaterial);
        for (u32 i = 0; i < countSubMaterial; ++i)
        {
            if (i == 0) //Use only first
            {
                IGameMaterial* subGameMaterial = gameMaterial->GetSubMaterial(i);

                s32 materialId = gameMaterial->GetMaterialID(i);
                LOG_INFO("Material ID : %d", materialId);

                return ExporterF3D::ExportMaterial(subGameMaterial, material, tile);
            }
        }
    }
    else
    {
        LOG_DEBUG("ExportMaterial Export singleType");
        material->setResourseName(materialName);

        //Texture
        for (u32 i = 0; i < gameMaterial->GetNumberOfTextureMaps(); ++i)
        {
            LOG_DEBUG("ExportMaterial Textures");
            IGameTextureMap* textureMap = gameMaterial->GetIGameTextureMap(i);

            std::string textureName = TCHARToString(textureMap->GetTextureName());
            LOG_INFO("Texture Name[%d] : %s", i, textureName.c_str());

            s32 textureType = textureMap->GetStdMapSlot();
            switch (textureType)
            {
            case ID_DI:
            {
                std::string diffuseMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName()));
                LOG_INFO("DiffuseMap Texture File : %s", diffuseMapName.c_str());

                CImage* texture = new CImage();
                texture->setResourseName(diffuseMapName);

                //material->setTexture(i, texture);
                m_scene->addTexture(material, texture);

                IGameUVGen* uvGen = textureMap->GetIGameUVGen();
                if (uvGen)
                {
                    IGameProperty* u = uvGen->GetUTilingData();
                    IGameProperty* v = uvGen->GetVTilingData();

                    if (u->GetType() == IGAME_FLOAT_PROP)
                    {
                        u->GetPropertyValue(tile._u);
                    }

                    if (v->GetType() == IGAME_FLOAT_PROP)
                    {
                        v->GetPropertyValue(tile._v);
                    }
                }
            }
                break;

            case ID_DP:
            {
                std::string heightMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName()));
                LOG_INFO("HeightMap Texture File : %s", heightMapName.c_str());

                CImage* texture = new CImage();
                texture->setResourseName(heightMapName);

               // material->setTexture(i, texture);
                m_scene->addTexture(material, texture);

            }
                break;


            case ID_BU:
            {
                std::string normalMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName()));
                LOG_INFO("NormalMap Texture File : %s", normalMapName.c_str());

                CImage* texture = new CImage();
                texture->setResourseName(normalMapName);

                //material->setTexture(i, texture);
                m_scene->addTexture(material, texture);

            }
                break;

            case ID_SP:
            case ID_OP:
            default:
                break;
            }
        }

        LOG_DEBUG("ExportMaterial Props");

        //Diffuse Color
        IGameProperty* propertyDiffuseColor = gameMaterial->GetDiffuseData();
        if (propertyDiffuseColor && propertyDiffuseColor->GetType() == IGAME_POINT3_PROP)
        {
            Point3 color;
            propertyDiffuseColor->GetPropertyValue(color);
            LOG_DEBUG("add DiffuseColor : (%f, %f, %f)", color.x, color.y, color.z);
            material->setDiffuseColor(convertPointToVector3(color));
        }

        //Ambient Color
        IGameProperty* propertyAmbientColor = gameMaterial->GetAmbientData();
        if (propertyAmbientColor && propertyAmbientColor->GetType() == IGAME_POINT3_PROP)
        {
            Point3 color;
            propertyAmbientColor->GetPropertyValue(color);
            LOG_DEBUG("add AmbientColor : (%f, %f, %f)", color.x, color.y, color.z);
            material->setAmbientColor(convertPointToVector3(color));
        }

        //Specular Color
        IGameProperty* propertySpecularColor = gameMaterial->GetSpecularData();
        if (propertySpecularColor && propertySpecularColor->GetType() == IGAME_POINT3_PROP)
        {
            Point3 color;
            propertySpecularColor->GetPropertyValue(color);
            LOG_DEBUG("add SpecularColor : (%f, %f, %f)", color.x, color.y, color.z);
            material->setSpecularColor(convertPointToVector3(color));
        }

        //Emission Color
        IGameProperty* propertyEmissionColor = gameMaterial->GetEmissiveData();
        if (propertyEmissionColor && propertyEmissionColor->GetType() == IGAME_POINT3_PROP)
        {
            Point3 color;
            propertyEmissionColor->GetPropertyValue(color);
            LOG_DEBUG("add EmissionColor : (%f, %f, %f)", color.x, color.y, color.z);
            material->setEmissionColor(convertPointToVector3(color));
        }

        //Opacity Color
        IGameProperty* propertyOpacity = gameMaterial->GetOpacityData();
        if (propertyOpacity && propertyOpacity->GetType() == IGAME_FLOAT_PROP)
        {
            f32 opacity;
            propertyOpacity->GetPropertyValue(opacity);
            LOG_DEBUG("add Transparency : %f", opacity);
            material->setTransparency(opacity);
        }

        //Specular Level
        IGameProperty* propertySpecularLevel = gameMaterial->GetSpecularLevelData();
        if (propertySpecularLevel && propertySpecularLevel->GetType() == IGAME_FLOAT_PROP)
        {
            f32 level;
            propertySpecularLevel->GetPropertyValue(level);
            LOG_DEBUG("add SpecularLevel : %f", level);
            material->setShininess(level);
        }

        //Glossiness
        IGameProperty* propertyGlossiness = gameMaterial->GetGlossinessData();
        if (propertyGlossiness && propertyGlossiness->GetType() == IGAME_FLOAT_PROP)
        {
            f32 glossiness;
            propertyGlossiness->GetPropertyValue(glossiness);
            LOG_DEBUG("add Glossiness : %f", glossiness);
            material->setGlossiness(glossiness);
        }
    }

    m_scene->addMaterial(material);

    return true;
}
コード例 #5
0
ファイル: MeshExporter.cpp プロジェクト: MSoft1115/Rad3D
void MeshExporter::_dumpMaterial(Rad::Material * m, IGameMaterial * mtl)
{
	Point4 val4;
	Point3 val3;
	PropType pt;
	IGameProperty* p = NULL;

	p = mtl->GetAmbientData();
	if (p)
	{
		pt = p->GetType();
		if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3)) 
		{
			m->ambient = Float3(val3.x, val3.y, val3.z);
		}
	}

	p = mtl->GetDiffuseData();
	if (p)
	{
		pt = p->GetType();
		if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3))
		{
			m->diffuse = Float3(val3.x, val3.y, val3.z);
		}
	}

	p = mtl->GetSpecularData();
	if (p)
	{
		pt = p->GetType();
		if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3))
		{
			m->specular = Float3(val3.x, val3.y, val3.z);
		}
	}

	p = mtl->GetSpecularLevelData();
	if (p)
	{
		float specularPower;
		if (p->GetPropertyValue(specularPower))
		{
			m->shininess = specularPower;
		}
	}

	p = mtl->GetEmissiveData();
	if (p)
	{
		pt = p->GetType();
		if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3))
		{
			m->emissive = Float3(val3.x, val3.y, val3.z);
		}
	}

	Mtl * maxMtl = mtl->GetMaxMaterial();

	ULONG flag = maxMtl->Requirements(0);

	if (flag & MTLREQ_2SIDE)
	{
		m->cullMode = eCullMode::NONE;
	}

	d_assert (!mtl->IsMultiType());

	int numTextures = mtl->GetNumberOfTextureMaps();

	for ( int index = 0; index < numTextures; ++index )
	{
		IGameTextureMap * pMap = mtl->GetIGameTextureMap(index);

		if (!pMap)
			continue;

		const int type = pMap->GetStdMapSlot();
		const char * tex = pMap->GetBitmapFileName();
		const char * ttt = pMap->GetTextureName();
		std::string bmap = tex;
		bmap = bmap.substr(bmap.find_last_of('\\') + 1);

		if (type == ID_DI)
			m->maps[eMapType::DIFFUSE] = HWBufferManager::Instance()->LoadTexture(bmap.c_str());
		else if (type == ID_BU)
			m->maps[eMapType::NORMAL] = HWBufferManager::Instance()->LoadTexture(bmap.c_str());
		else if (type == ID_SP)
			m->maps[eMapType::SPECULAR] = HWBufferManager::Instance()->LoadTexture(bmap.c_str());
		else if (type == ID_SI)
			m->maps[eMapType::EMISSIVE] = HWBufferManager::Instance()->LoadTexture(bmap.c_str());

		if (type == ID_OP)
			m->blendMode = eBlendMode::ALPHA_TEST;

		TextureExporter::Instance()->Push(pMap->GetBitmapFileName());
	}
}