Ejemplo n.º 1
0
bool SGMExporter::ExportPositionKeys(IGameNode *gNode, IGameControl *gControl, BinaryWriter *bw)
{
	if (!gControl ->IsAnimated(IGAME_POS))
	{
		bw ->Write((int)0);
		return false;
	}

	IGameControl::MaxControlType controlType =
		gControl ->GetControlType(IGAME_POS);

	IGameKeyTab keys;
	if (controlType == IGameControl::IGAME_MAXSTD &&
		gControl ->GetTCBKeys(keys, IGAME_POS))
	{
		bw ->Write(keys.Count());
		for (int i = 0; i < keys.Count(); i++)
		{
			bw ->Write(TicksToSec(keys[i].t));
			bw ->Write(keys[i].tcbKey.pval.x);
			bw ->Write(keys[i].tcbKey.pval.y);
			bw ->Write(keys[i].tcbKey.pval.z);
		}

		return keys.Count() > 0;
	}
	else
	{
		/*log ->AddLog(sb() + "warning: node '" + gNode ->GetName() + 
			"' doesn't have TCB controller for position, animation won't be exported");*/
		bw ->Write((int)0);
		return false;
	}
}
Ejemplo n.º 2
0
void MeshExporter::_dumpAnimation(IGameControl * pGameControl, int boneId)
{
	int start = ExportConfig::Instance()->GetFrameRange().x;
	int end = ExportConfig::Instance()->GetFrameRange().y;
	start *= GetTicksPerFrame();
	end *= GetTicksPerFrame();

	if ((pGameControl->IsAnimated(IGAME_POS)) || pGameControl->IsAnimated(IGAME_ROT) || pGameControl->IsAnimated(IGAME_SCALE))
	{
		IGameKeyTab Key;
		if(pGameControl->GetFullSampledKeys(Key, 1, IGAME_TM, true) )
		{
			SkeletonAnimation * skelAnim = new SkeletonAnimation(boneId);

			int count = Key.Count();
			for(int i=0;i<count;i++)
			{
				if (Key[i].t >= start && Key[i].t <= end)
				{
					float time = (float)Key[i].t / (float)GetTicksPerFrame() / (float)GetFrameRate();
					SkeletonAnimation::KeyFrame * kf = skelAnim->CreateKeyFrame(time);

					kf->position = Utility::ToFloat3(Key[i].sampleKey.gval.Translation());
					kf->rotation = Utility::ToQuat(Key[i].sampleKey.gval.Rotation());
					kf->scale = Utility::ToFloat3(Key[i].sampleKey.gval.Scaling());
				}
			}

			skelAnim->Optimize();
			_getAnimation()->AddSkeletonAnimation(skelAnim);
		}
	}
}
Ejemplo n.º 3
0
int	maxProject2::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)
{
	//TODO: Implement the actual file Export here and 
	//		return TRUE If the file is exported properly

	AllocConsole();
	 _cprintf( "Export Begin\n" );//¼ÇµÃ#include <conio.h>
	IGameConversionManager * cm = GetConversionManager();
	cm->SetCoordSystem( IGameConversionManager::IGAME_D3D );
	
	IGameScene* pSce=GetIGameInterface();

	pSce->InitialiseIGame(false);
	pSce->SetStaticFrame(0);

	int num=pSce->GetTopLevelNodeCount();
//	_cprintf("node count %d \n",num);
//	_cprintf("%s \n",name);

	TSTR outBuf;
	int matCount = pSce->GetRootMaterialCount();
//	_cprintf("MaterialCount count %d \n",matCount);
	FILE* file=freopen(name, "w", stdout);

	if(!file)
	{
		return FALSE;
	}
	/*cout<<"MatreialRootList Num: "<<matCount<<endl;
	
	for(int j =0;j<matCount;j++){	
		IGameMaterial* rootmat=pSce->GetRootMaterial(j);
		int num=rootmat->GetSubMaterialCount();
		TCHAR* name= rootmat->GetMaterialName();
		cout<<"\tMatrial mutiType :"<<rootmat->IsMultiType()<<endl;
		cout<<"\ttMatreialRoot name : "<<name<<endl;
		cout<<"\t\tMatreialRoot #"<<j<<" ----SubMatNum : "<<num<<endl;
		for(int i=0;i<num;i++){
			IGameMaterial* submat=rootmat->GetSubMaterial(i);
			cout<<"\t\tMatrial mutiType"<<submat->IsMultiType()<<endl;
			cout<<"\t\tSubMatName : "<<submat->GetMaterialName()<<endl;
			cout<<"\t\tSubMatSubNum : "<<submat->GetSubMaterialCount()<<endl;
		}
	}*/
	int nodecount=pSce->GetTopLevelNodeCount();
	int frame=pSce->GetSceneStartTime();
/*	cout<<pSce->GetSceneStartTime()<<endl;
	cout<<pSce->GetSceneEndTime()<<endl;
	cout<<GetFrameRate()<<endl;*/
//	cout<<"top level node count:"<<nodecount<<endl;
	for(int i=0;i<nodecount;i++)
	{
		IGameNode* topnode=pSce->GetTopLevelNode(i);
		IGameObject* obj=topnode->GetIGameObject();
//		cout<<"\tnode #:"<<i<<endl;
		if(obj->GetIGameType()==IGameObject::IGAME_BONE)
		{
/*	
			cout<<"\t\t bone"<<endl;
			
			IGameSupportObject * hO = (IGameSupportObject*)obj;
			IGameMesh * hm = hO->GetMeshObject();
			if(hm->InitializeData())
			{
				int num = hm->GetNumberOfVerts();
				cout<<"\t\t number of vertex : "<<num<<endl;
				cout<<"\t\t number of texcoord : "<<hm->GetNumberOfTexVerts()<<endl;
				cout<<"\t\t number of normals : "<<hm->GetNumberOfNormals()<<endl;
			}
			if(obj->GetIGameSkin()){
				cout<<"\t\tHAS SKIN"<<endl;
			}
*/
			IGameControl* con=topnode->GetIGameControl();

			IGameKeyTab keys;
			con->get
			con->GetFullSampledKeys(keys,GetFrameRate(),IGAME_ROT);
			int num=keys.Count();

			_cprintf( "keys count %d \n",keys.Count());//¼ÇµÃ#include <conio.h>
	//		if(num>1)
			//	num=1;
			for(int i=0;i<num;i++){
				Matrix3 t=keys[i].sampleKey.gval.ExtractMatrix3();

				_cprintf("\tkey frame time : %d\n",keys[i].t);
				_cprintf("\tkey frame pos : %d\n",keys[i].t/pSce->GetSceneTicks());
				AffineParts ap;
				
				float rotAngle;
				Point3 rotAxis;
				float scaleAxAngle;	
				Point3 scaleAxis;

				decomp_affine(t, &ap);

				
					// Quaternions are dumped as angle axis.
				AngAxisFromQ(ap.q, &rotAngle, rotAxis);
				AngAxisFromQ(ap.u, &scaleAxAngle, scaleAxis);

				/*_cprintf("\ttrans%f %f %f\n",ap.t.x,ap.t.y,ap.t.z);			
				_cprintf("\trot%f %f %f %f\n",rotAxis.x, rotAxis.y, rotAxis.z, rotAngle);
				_cprintf("%f %f %f %f %f %f %f\n", ap.k.x, ap.k.y, ap.k.z, scaleAxis.x,scaleAxis.y,scaleAxis.z, scaleAxAngle);*/

			}


		}else if(obj->GetIGameType()==IGameObject::IGAME_MESH){
		//	cout<<"\t\t mesh"<<endl;
			
			IGameMesh * hm = (IGameMesh*)obj;


			IGameSkin* skin=obj->GetIGameSkin();
		/*	if(skin){
				cout<<"\t\tHAS SKIN"<<endl;

				if(skin->GetSkinType()== IGameSkin::IGAME_PHYSIQUE)
					cout<<"\t\t\tPhysique"<<endl;
				else
					cout<<"\t\t\tmaxskin"<<endl;
				int bn=skin->GetNumberOfBones(0);
				cout<<"\t\t\t number of bones for 0 :"<<skin->GetNumberOfBones(0)<<endl;
				for(int i=0;i<bn;i++){
					cout<<"\t\t\t"<<skin->GetBone(0,i)->GetName()<<endl;
					cout<<"\t\t\t"<<skin->GetWeight(0,i)<<endl;
				}

				cout<<"\t\t\t total number of bones :"<<skin->GetTotalBoneCount()<<endl;

			}*/
			if(hm->InitializeData())
			{
				cout<<"m"<<endl;
				int num = hm->GetNumberOfVerts();
			/*	cout<<"\t\t number of vertex : "<<num<<endl;
				cout<<"\t\t number of texcoord : "<<hm->GetNumberOfTexVerts()<<endl;
				cout<<"\t\t number of normals : "<<hm->GetNumberOfNormals()<<endl;*/
				for(int iv=0;iv<num;iv++){
					Point3 v=hm->GetVertex(iv);
					cout<<"v "<<v.x<<" "<<v.y<<" "<<v.z<<endl;
					if(skin)
					{
						int bonenum=skin->GetNumberOfBones(iv);
						for(int bi=0;bi<bonenum;bi++)
						{
							INode* bone=skin->GetBone(iv,bi);
							int boneid=skin->GetBoneID(iv,bi);
							bone->GetNodeTM(0);
							cout<<"\t bone ID : "<<boneid<<" bone weight : "<<skin->GetWeight(iv,bi)<<endl;
						}
					}
				}
				cout<<"mi"<<endl;
				int tn=hm->GetNumberOfFaces();
				for(int tv=0;tv<tn;tv++){
					FaceEx* f=hm->GetFace(tv);
					cout<<"i "<<f->vert[0]<<" "<<f->vert[1]<<" "<<f->vert[2]<<endl;
				}
			}
		}else{
//			cout<<"\t\t else"<<endl;
		}

	}


	/*if(!suppressPrompts)
		DialogBoxParam(hInstance, 
				MAKEINTRESOURCE(IDD_PANEL), 
				GetActiveWindow(), 
				maxProject2OptionsDlgProc, (LPARAM)this);*/
	fclose(file);
	return TRUE;
}
Ejemplo n.º 4
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);
	}
}
Ejemplo n.º 5
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);
}