Пример #1
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);
	}
}
Пример #2
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);
}