void U2MaxCameraExport::Export(Interface* pIf, INode *pMaxNode, Object *obj)
{

	CameraObject* camObj = (CameraObject*)obj;

	// get camera state
	Interval interval;
	CameraState camState;
	camObj->EvalCameraState(m_animStart, interval, &camState);

	bool bFixedCam = false;
	if(camObj->GetManualClip())
		bFixedCam = true;

	float fFov = camState.fov;
	BOOL bIsOrtho = camState.isOrtho;

	float fInvAspectRatio = 1.0f / pIf->GetRendImageAspect();

	if(bIsOrtho)
	{
		float fWidth = 640.0f / 4.0f;
		float fHeight = 480.0f / 4.0f;
		float fScalar = camObj->GetTDist(0) / 200.0f;
	}
	else 
	{
		// add
	}

	if(bFixedCam)
	{
		float fNearPlane = camState.hither;
		float farPlane = camState.yon;
	}
	else 
	{
		float nearPlane = 1.0f;
		float farPlane = 6000.0f;
	}

	ViewExp* viewport = pIf->GetActiveViewport();
	if(viewport)
	{
		INode* pMaxViewCam = viewport->GetViewCamera();

		if(pMaxNode == pMaxViewCam)
		{
			; 
		}

		pIf->ReleaseViewport(viewport);
	}
	else 
	{
		;
	}
}
Beispiel #2
0
void Exporter::ExportCameraObject(INode* node, int indentLevel)
{
	RSCameraObject *pCO=new RSCameraObject;
	pCO->name=new char[strlen(node->GetName())+1];
	strcpy(pCO->name,node->GetName());

	INode* target = node->GetTarget();
	ExportNodeTM(node, indentLevel,&pCO->tm);

	CameraState cs;
	TimeValue t = GetStaticFrame();
	Interval valid = FOREVER;
	// Get animation range
	Interval animRange = ip->GetAnimRange();
	
	ObjectState os = node->EvalWorldState(t);
	CameraObject *cam = (CameraObject *)os.obj;
	
	cam->EvalCameraState(t,valid,&cs);
	pCO->fov=cs.fov;

#define TARGETFPS	60

	TimeValue start = ip->GetAnimRange().Start();
	TimeValue end = ip->GetAnimRange().End();
	int delta = GetTicksPerFrame() * GetFrameRate() / TARGETFPS;
	Matrix3 tm;

	rsm->m_nCameraFrame=(end-start)/delta+1;
	Matrix3 *m=pCO->am=new Matrix3[rsm->m_nCameraFrame];
	for (t=start; t<=end; t+=delta) {
		tm = node->GetNodeTM(t) * Inverse(node->GetParentTM(t));
		*m=tm;
		m++;
	}
	
	rsm->m_CameraList.Add(pCO);

}
Beispiel #3
0
void RBExport::ProcessCamera( INode* node )
{
    if (m_pConfig->m_bExportCameras == false)
    {
        return;
    }

    ObjectState os = node->EvalWorldState( m_CurTime );
    Object* pCurObject = os.obj;
    if (!pCurObject) return;

    CameraObject* camObj = (CameraObject*)pCurObject;
    Interval validIvl;
    CameraState cs;

    RefResult res = camObj->EvalCameraState( m_CurTime, validIvl, &cs );
    if ( res != REF_SUCCEED)
    {
        Err( "Error processing camera <%s>", node->GetName() );
        return;
    }

    Info( "Processing camera <%s>", node->GetName() );

    Matrix3 camTM = c_CamFlipTM*node->GetNodeTM( m_CurTime );

    Matrix3 parentTM;
    INode* pParent = node->GetParentNode();
    if (pParent && !pParent->IsRootNode())
    {
        parentTM = pParent->GetNodeTM( m_CurTime );
    }
    else
    {
        parentTM = c_IdentityTM;
    }
    parentTM = c_FlipTM*parentTM;
    camTM = camTM*Inverse( parentTM );

    JCamera* pCamera = new JCamera();
    pCamera->SetWorldTM( Convert( camTM ) );

    float aspect = ((float)m_pInterface->GetRendWidth())/((float)m_pInterface->GetRendHeight());
    float zn     = cs.nearRange;
    float zf     = cs.farRange;
    float fov    = cs.fov;
    if (zn < c_FltEpsilon) zn = 1.0f;

    pCamera->SetOrtho  ( cs.isOrtho == TRUE );
    pCamera->SetZNear  ( zn );
    pCamera->SetZFar   ( zf );
    pCamera->SetAspect ( aspect ); 

    if (cs.isOrtho)
    {
        float vVol = 2.0f * cs.tdist * tan( cs.fov * 0.5f );
        pCamera->SetFOVx( vVol );
    }
    else
    {
        pCamera->SetFOVx( RadToDeg( fov ) );
    }

    pCamera->SetName( node->GetName() );

    //  insert camera as the first node in the model
    m_pModel->AddChild( pCamera, 0 );
} // RBExport::ProcessCamera
Beispiel #4
0
void SkeletonExporter::export_camera(INode *node)
{
  Control *c;
  int size_key;
  float camera_znear, camera_zfar;
  CameraState cs;
//  Interval valid = FOREVER;
  ObjectState os;
  CameraObject *cam;
  GenCamera *gencam;
  float roll0;
  Matrix3 mat;
  Point3 row;

  os = node->EvalWorldState(0);
  cam = (CameraObject *)os.obj;
  gencam = (GenCamera *)os.obj;
  if (gencam->Type() != TARGETED_CAMERA)
  {
	 fprintf(fTXT, "Only targeted camera are supported!\n\n");
	 return;
  }

  fprintf(fTXT, "Targeted camera found\n");
  write_chunk_header(fA3D, TARGETED_CAMERA_ID, node->GetName(), 40);
  if (makeRAY) write_chunk_header(fRAY, TARGETED_CAMERA_ID, node->GetName(), 40);

  INode* target = node->GetTarget();
  fprintf(fTXT, "Name : %s\n", node->GetName());
  cam->EvalCameraState(0, FOREVER, &cs);

  // ------------------  salviamo znear e zfar  ----------------------
  camera_znear=2;
  camera_zfar=2000;
  if (cs.manualClip)
  {
	camera_znear=cs.hither;
	camera_zfar=cs.yon;
  }
  fprintf(fTXT, "Znear = %f \n", camera_znear);
  fwrite(&camera_znear, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&camera_znear, sizeof(float), 1, fRAY);
  fprintf(fTXT, "Zfar = %f \n", camera_zfar);
  fwrite(&camera_zfar, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&camera_zfar, sizeof(float), 1, fRAY);

  // -----------------  salviamo l'angolo di FOV  --------------------
  fprintf(fTXT, "FOV (rad) = %f \n", cs.fov);
  fwrite(&cs.fov, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&cs.fov, sizeof(float), 1, fRAY);

  // ------------------  salviamo l'angolo di roll  ------------------
  c=node->GetTMController()->GetRollController();
  c->GetValue(0, &roll0, FOREVER);	
  fprintf(fTXT, "Roll (rad) = %f \n", roll0);
  fwrite(&roll0, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&roll0, sizeof(float), 1, fRAY);

  // salviamo la posizione nel mondo
  mat = node->GetNodeTM(0);
  row = mat.GetRow(3);
  fprintf(fTXT, "Camera world position : x=%f, y=%f, z=%f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);
  if (makeRAY) write_point3(&row, fRAY);

  // ---------  salviamo la posizione del target nel mondo  ----------
  if (target)
  {
    mat = target->GetNodeTM(0);
    row = mat.GetRow(3);
    fprintf(fTXT, "Target world position : x=%f, y=%f, z=%f\n", row.x, row.y, row.z);
    write_point3(&row, fA3D);
    if (makeRAY) write_point3(&row, fRAY);
  }

  
  // esportiamo l'animazione della posizione della camera
  // se ci sono un numero di key > 0
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Camera position track present.");
     write_chunk_header(fA3D, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_point3_track(c, 1, fA3D);
     if (makeRAY) write_chunk_header(fRAY, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_point3_track(c, 1, fRAY);
  }

  // -----  esportiamo l'animazione della posizione del target  ------
  if (target)
  {
    c=target->GetTMController()->GetPositionController();
    if ((c) && (c->NumKeys()>0))
	{
	  if (IsTCBControl(c)) size_key=36;
	  else
	  if (IsBezierControl(c)) size_key=40;
	  else size_key=16;
	  fprintf(fTXT, "Target position track present.");
	  write_chunk_header(fA3D, CAMERA_TARGET_TRACK_ID,
		                 node->GetName(), 1+2+4+c->NumKeys()*size_key);
	  export_point3_track(c, 1, fA3D);

	  if (makeRAY) write_chunk_header(fRAY, CAMERA_TARGET_TRACK_ID,
		                 node->GetName(), 1+2+4+c->NumKeys()*size_key);
	  if (makeRAY) export_point3_track(c, 1, fRAY);
	}
  }

  // ---------------  esportiamo le tracce di FOV  -------------------
  c=gencam->GetFOVControl();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Camera FOV track present.");
     write_chunk_header(fA3D, CAMERA_FOV_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);  // radianti
     if (makeRAY) write_chunk_header(fRAY, CAMERA_FOV_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_float_track(c, 1, fRAY);  // radianti
  }


  // ---------------  esportiamo le tracce di roll  ------------------
  c=node->GetTMController()->GetRollController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Camera roll track present.");
     write_chunk_header(fA3D, CAMERA_ROLL_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D); // radianti

     if (makeRAY) write_chunk_header(fRAY, CAMERA_ROLL_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_float_track(c, 1, fRAY); // radianti
  }
  fprintf(fTXT, "\n\n--------------------------------------------------\n");
}
bool AlembicCamera::Save(double time, bool bLastFrame)
{
    TimeValue ticks = GetTimeValueFromFrame(time);

    Object *obj = mMaxNode->EvalWorldState(ticks).obj;
    if (mNumSamples == 0) {
        bForever = CheckIfObjIsValidForever(obj, ticks);
    }
    else {
        bool bNewForever = CheckIfObjIsValidForever(obj, ticks);
        if (bForever && bNewForever != bForever) {
            ESS_LOG_INFO("bForever has changed");
        }
    }
    bForever = false;

    SaveMetaData(mMaxNode, this);

    // Set the xform sample
    Matrix3 wm = mMaxNode->GetObjTMAfterWSM(ticks);
    if (mJob) {
        Point3 worldMaxPoint = wm.GetTrans();
        Abc::V3f alembicWorldPoint = ConvertMaxPointToAlembicPoint(worldMaxPoint);
        mJob->GetArchiveBBox().extendBy(alembicWorldPoint);
    }

    // check if the camera is animated
    if (mNumSamples > 0) {
        if (bForever) {
            return true;
        }
    }

    // Return a pointer to a Camera given an INode or return false if the node
    // cannot be converted to a Camera

    CameraObject *cam = NULL;

    if (obj->CanConvertToType(Class_ID(SIMPLE_CAM_CLASS_ID, 0))) {
        cam = reinterpret_cast<CameraObject *>(
                  obj->ConvertToType(ticks, Class_ID(SIMPLE_CAM_CLASS_ID, 0)));
    }
    else if (obj->CanConvertToType(Class_ID(LOOKAT_CAM_CLASS_ID, 0))) {
        cam = reinterpret_cast<CameraObject *>(
                  obj->ConvertToType(ticks, Class_ID(LOOKAT_CAM_CLASS_ID, 0)));
    }
    else {
        return false;
    }

    CameraState cs;
    Interval valid = FOREVER;
    cam->EvalCameraState(ticks, valid, &cs);
    float tDist = cam->GetTDist(ticks);
    float ratio = GetCOREInterface()->GetRendImageAspect();
    float aperatureWidth =
        GetCOREInterface()->GetRendApertureWidth();  // this may differ from the
    // imported value
    // unfortunately
    float focalLength =
        (float)((aperatureWidth / 2.0) /
                tan(cs.fov / 2.0));  // alembic wants this one in millimeters
    aperatureWidth /= 10.0f;         // convert to centimeters

    IMultiPassCameraEffect *pCameraEffect = cam->GetIMultiPassCameraEffect();

    Interval interval = FOREVER;

    BOOL bUseTargetDistance = FALSE;
    const int TARGET_DISTANCE = 0;
    pCameraEffect->GetParamBlockByID(0)->GetValue(TARGET_DISTANCE, ticks,
            bUseTargetDistance, interval);
    float fFocalDepth = 0.0f;
    const int FOCAL_DEPTH = 1;
    pCameraEffect->GetParamBlockByID(0)->GetValue(FOCAL_DEPTH, ticks, fFocalDepth,
            interval);

    // store the camera data
    mCameraSample.setNearClippingPlane(cs.hither);
    mCameraSample.setFarClippingPlane(cs.yon);
    // mCameraSample.setLensSqueezeRatio(ratio);

    // should set to 1.0 according the article "Maya to Softimage: Camera
    // Interoperability"
    mCameraSample.setLensSqueezeRatio(1.0);

    mCameraSample.setFocalLength(focalLength);
    mCameraSample.setHorizontalAperture(aperatureWidth);
    mCameraSample.setVerticalAperture(aperatureWidth / ratio);
    if (bUseTargetDistance) {
        mCameraSample.setFocusDistance(tDist);
    }
    else {
        mCameraSample.setFocusDistance(fFocalDepth);
    }

    // save the samples
    mCameraSchema.set(mCameraSample);

    mNumSamples++;

    // Note that the CamObject should only be deleted if the pointer to it is not
    // equal to the object pointer that called ConvertToType()
    if (cam != NULL && obj != cam) {
        delete cam;
        cam = NULL;
        return false;
    }

    return true;
}