コード例 #1
0
AlembicFloatController* createFloatController(const std::string& path,
        const std::string& identifier,
        const std::string& prop)
{
    AlembicFloatController* pControl =
        static_cast<AlembicFloatController*>(GetCOREInterface()->CreateInstance(
                    CTRL_FLOAT_CLASS_ID, ALEMBIC_FLOAT_CONTROLLER_CLASSID));

    if (!pControl) {
        return NULL;
    }

    TimeValue zero(0);

    // Set the alembic id
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "path"), zero,
        EC_UTF8_to_TCHAR(path.c_str()));
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "identifier"), zero,
        EC_UTF8_to_TCHAR(identifier.c_str()));
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "property"), zero,
        EC_UTF8_to_TCHAR(prop.c_str()));
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "time"), zero, 0.0f);
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "muted"), zero, FALSE);

    return pControl;
}
コード例 #2
0
void AlembicImport_TimeControl( alembic_importoptions &options ) {

   if(!options.loadTimeControl){
      return;
   }

	// check if an Alembic Time Control already exists in the scene.

	BOOL alreadyExists = ExecuteMAXScriptScript( _T( "select $Alembic_Time_Control" ), TRUE );
	if( alreadyExists != 0 ) {
		if( GetCOREInterface()->GetSelNodeCount() > 0 ) {
			INode *pSelectedNode = GetCOREInterface()->GetSelNode( 0 );
			HelperObject *pSelectedHelper = static_cast<HelperObject*>( pSelectedNode->GetObjectRef() );
			options.pTimeControl = pSelectedHelper;
			return;
		}
	}

	// Create the xform modifier
	HelperObject *pHelper = static_cast<HelperObject*>
		(GetCOREInterface()->CreateInstance(HELPER_CLASS_ID, ALEMBIC_TIME_CONTROL_HELPER_CLASSID));

	TimeValue zero( 0 );

	// Set the alembic id
	pHelper->GetParamBlockByID( 0 )->SetValue( GetParamIdByName( pHelper, 0, "current" ), zero, 0.0f );
	pHelper->GetParamBlockByID( 0 )->SetValue( GetParamIdByName( pHelper, 0, "offset" ), zero, 0.0f );
	pHelper->GetParamBlockByID( 0 )->SetValue( GetParamIdByName( pHelper, 0, "factor" ), zero, 1.0f );

	// Create the object node
	INode *node = GET_MAX_INTERFACE()->CreateObjectNode(pHelper, pHelper->GetObjectName() );

	// Add the new inode to our current scene list
	SceneEntry *pEntry = options.sceneEnumProc.Append(node, pHelper, OBTYPE_CURVES, &std::string( EC_MCHAR_to_UTF8( node->GetName() ) ) ); 
	options.currentSceneList.Append(pEntry);

	//GET_MAX_INTERFACE()->SelectNode( node );

	//std::string nodeName = EC_MCHAR_to_UTF8( node->GetName() );
	//char szBuffer[10000];	
	//sprintf_s( szBuffer, 10000,
	//	"$'%s'.current.controller = float_expression()\n"
	//	"$'%s'.current.controller.setExpression \"S\"\n"
	//	"$'%s'.offset.controller = bezier_float()\n"
	//	"$'%s'.factor.controller = bezier_float()\n"
	//	, nodeName.c_str(), nodeName.c_str(), nodeName.c_str(), nodeName.c_str() );
	//ExecuteMAXScriptScript( EC_UTF8_to_TCHAR( szBuffer ) );

	options.pTimeControl = pHelper;
}
コード例 #3
0
AlembicFloatController* getController(Animatable* pObj,
                                      const std::string& identifier,
                                      const std::string& camProperty, int i,
                                      int j, int k = -1)
{
    if (i >= pObj->NumSubs()) {
        return NULL;
    }

    Animatable* an = pObj->SubAnim(i);

    if (!an || j >= an->NumSubs()) {
        return NULL;
    }

    an = an->SubAnim(j);

    if (k != -1) {
        if (!an || k >= an->NumSubs()) {
            return NULL;
        }
        an = an->SubAnim(k);
    }

    Class_ID cid = an->ClassID();
    if (!an || an->ClassID() != ALEMBIC_FLOAT_CONTROLLER_CLASSID) {
        return NULL;
    }

    AlembicFloatController* pControl = static_cast<AlembicFloatController*>(an);
    TimeValue zero(0);
    std::string contIdentifier =
        EC_MCHAR_to_UTF8(pControl->GetParamBlockByID(0)->GetStr(
                             GetParamIdByName(pControl, 0, "identifier"), zero));
    if (strcmp(contIdentifier.c_str(), identifier.c_str()) != 0) {
        return NULL;
    }

    std::string contCamProperty =
        EC_MCHAR_to_UTF8(pControl->GetParamBlockByID(0)->GetStr(
                             GetParamIdByName(pControl, 0, "property"), zero));
    if (strcmp(contCamProperty.c_str(), camProperty.c_str()) != 0) {
        return NULL;
    }

    return pControl;
}
コード例 #4
0
///////////////////////////////////////////////////////////////////////////////////////////////////
// AlembicImport_vis
///////////////////////////////////////////////////////////////////////////////////////////////////
void AlembicImport_SetupVisControl(std::string const &file,
                                   std::string const &identifier,
                                   AbcG::IObject &obj, INode *pNode,
                                   alembic_importoptions &options)
{
  if (!pNode) {
    return;
  }

  AbcG::IVisibilityProperty visibilityProperty = getAbcVisibilityProperty(obj);

  bool isConstant = true;
  if (visibilityProperty.valid()) {
    isConstant = visibilityProperty.isConstant();
  }

  if (isConstant) {
    Animatable *pAnimatable = pNode->SubAnim(0);

    if (pAnimatable &&
        pAnimatable->ClassID() == ALEMBIC_VISIBILITY_CONTROLLER_CLASSID) {
      pNode->DeleteSubAnim(0);
    }

    alembic_fillvis_options visFillOptions;
    visFillOptions.pIObj = &obj;
    visFillOptions.dTicks = 0;
    visFillOptions.bOldVisibility = true;
    AlembicImport_FillInVis(visFillOptions);
    BOOL bVis = visFillOptions.bVisibility ? TRUE : FALSE;
    float fBool = bVis ? 1.0f : 0.0f;
    pNode->SetVisibility(0, fBool);
  }
  else {
    // Create the xform modifier
    AlembicVisibilityController *pControl =
        static_cast<AlembicVisibilityController *>(
            GetCOREInterface()->CreateInstance(
                CTRL_FLOAT_CLASS_ID, ALEMBIC_VISIBILITY_CONTROLLER_CLASSID));

    // Set the alembic id
    TimeValue t = GET_MAX_INTERFACE()->GetTime();

    TimeValue zero(0);

    // Set the alembic id
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "path"), zero,
        EC_UTF8_to_TCHAR(file.c_str()));
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "identifier"), zero,
        EC_UTF8_to_TCHAR(identifier.c_str()));
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "time"), zero, 0.0f);
    pControl->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pControl, 0, "muted"), zero, FALSE);

    // Add the modifier to the node
    pNode->SetVisController(pControl);

    if (!isConstant) {
      std::stringstream controllerName;
      controllerName << GET_MAXSCRIPT_NODE(pNode);
      controllerName << "mynode2113.visibility.controller.time";
      AlembicImport_ConnectTimeControl(controllerName.str().c_str(), options);
    }
  }
}
コード例 #5
0
int AlembicImport_Camera(const std::string& path, AbcG::IObject& iObj,
                         alembic_importoptions& options, INode** pMaxNode)
{
    const std::string& identifier = iObj.getFullName();

    if (!AbcG::ICamera::matches(iObj.getMetaData())) {
        return alembic_failure;
    }
    AbcG::ICamera objCamera = AbcG::ICamera(iObj, Abc::kWrapExisting);
    if (!objCamera.valid()) {
        return alembic_failure;
    }
    bool isConstant = objCamera.getSchema().isConstant();

    TimeValue zero(0);

    INode* pNode = *pMaxNode;
    CameraObject* pCameraObj = NULL;
    if (!pNode) {
        // Create the camera object and place it in the scene
        GenCamera* pGenCameraObj =
            GET_MAX_INTERFACE()->CreateCameraObject(FREE_CAMERA);
        if (pGenCameraObj == NULL) {
            return alembic_failure;
        }
        pGenCameraObj->Enable(TRUE);
        pGenCameraObj->SetConeState(TRUE);
        pGenCameraObj->SetManualClip(TRUE);

        IMultiPassCameraEffect* pCameraEffect =
            pGenCameraObj->GetIMultiPassCameraEffect();
        const int TARGET_DISTANCE = 0;
        pCameraEffect->GetParamBlockByID(0)->SetValue(TARGET_DISTANCE, zero, FALSE);

        pCameraObj = pGenCameraObj;

        Abc::IObject parent = iObj.getParent();
        std::string name = removeXfoSuffix(parent.getName().c_str());
        pNode = GET_MAX_INTERFACE()->CreateObjectNode(
                    pGenCameraObj, EC_UTF8_to_TCHAR(name.c_str()));
        if (pNode == NULL) {
            return alembic_failure;
        }
        *pMaxNode = pNode;
    }
    else {
        Object* obj = pNode->EvalWorldState(zero).obj;

        if (obj->CanConvertToType(Class_ID(SIMPLE_CAM_CLASS_ID, 0))) {
            pCameraObj = reinterpret_cast<CameraObject*>(
                             obj->ConvertToType(zero, Class_ID(SIMPLE_CAM_CLASS_ID, 0)));
        }
        else if (obj->CanConvertToType(Class_ID(LOOKAT_CAM_CLASS_ID, 0))) {
            pCameraObj = reinterpret_cast<CameraObject*>(
                             obj->ConvertToType(zero, Class_ID(LOOKAT_CAM_CLASS_ID, 0)));
        }
        else {
            return alembic_failure;
        }
    }

    // Fill in the mesh
    //   alembic_fillcamera_options dataFillOptions;
    //   dataFillOptions.pIObj = &iObj;
    //   dataFillOptions.pCameraObj = pCameraObj;
    //   dataFillOptions.dTicks =  GET_MAX_INTERFACE()->GetTime();
    // AlembicImport_FillInCamera(dataFillOptions);

    // printAnimatables(pCameraObj);

    Interval interval = FOREVER;

    AlembicFloatController* pControl = NULL;
    {
        std::string prop("horizontalFOV");
        if (options.attachToExisting) {
            pControl = getController(pCameraObj, identifier, prop, 0, 0);
        }
        if (pControl) {
            pControl->GetParamBlockByID(0)->SetValue(
                GetParamIdByName(pControl, 0, "path"), zero,
                EC_UTF8_to_TCHAR(path.c_str()));
        }
        else if (assignController(createFloatController(path, identifier, prop),
                                  pCameraObj, 0, 0) &&
                 !isConstant) {
            std::stringstream controllerName;
            controllerName << GET_MAXSCRIPT_NODE(pNode);
            controllerName << "mynode2113.FOV.controller.time";
            AlembicImport_ConnectTimeControl(controllerName.str().c_str(), options);
        }
    }
    {
        std::string prop("FocusDistance");
        if (options.attachToExisting) {
            pControl = getController(pCameraObj, identifier, prop, 1, 0, 1);
        }
        if (pControl) {
            pControl->GetParamBlockByID(0)->SetValue(
                GetParamIdByName(pControl, 0, "path"), zero,
                EC_UTF8_to_TCHAR(path.c_str()));
        }
        else if (assignController(createFloatController(path, identifier, prop),
                                  pCameraObj, 1, 0, 1) &&
                 !isConstant) {
            std::stringstream controllerName;
            controllerName << GET_MAXSCRIPT_NODE(pNode);
            controllerName
                    << "mynode2113.MultiPass_Effect.focalDepth.controller.time";
            AlembicImport_ConnectTimeControl(controllerName.str().c_str(), options);
        }
    }
    {
        std::string prop("NearClippingPlane");
        if (options.attachToExisting) {
            pControl = getController(pCameraObj, identifier, prop, 0, 2);
        }
        if (pControl) {
            pControl->GetParamBlockByID(0)->SetValue(
                GetParamIdByName(pControl, 0, "path"), zero,
                EC_UTF8_to_TCHAR(path.c_str()));
        }
        else if (assignController(createFloatController(path, identifier, prop),
                                  pCameraObj, 0, 2) &&
                 !isConstant) {
            std::stringstream controllerName;
            controllerName << GET_MAXSCRIPT_NODE(pNode);
            controllerName << "mynode2113.nearclip.controller.time";
            AlembicImport_ConnectTimeControl(controllerName.str().c_str(), options);
        }
    }
    {
        std::string prop("FarClippingPlane");
        if (options.attachToExisting) {
            pControl = getController(pCameraObj, identifier, prop, 0, 3);
        }
        if (pControl) {
            pControl->GetParamBlockByID(0)->SetValue(
                GetParamIdByName(pControl, 0, "path"), zero,
                EC_UTF8_to_TCHAR(path.c_str()));
        }
        else if (assignController(createFloatController(path, identifier, prop),
                                  pCameraObj, 0, 3) &&
                 !isConstant) {
            std::stringstream controllerName;
            controllerName << GET_MAXSCRIPT_NODE(pNode);
            controllerName << "mynode2113.farclip.controller.time";
            AlembicImport_ConnectTimeControl(controllerName.str().c_str(), options);
        }
    }

    // if(assignControllerToLevel1SubAnim(createFloatController(path, identifier,
    // std::string("FocusDistance")), pCameraObj, 0, 1) && !isConstant){
    //	AlembicImport_ConnectTimeControl( "$.targetDistance.controller.time",
    // options );
    //}

    createCameraModifier(path, identifier, pNode);

    // Add the new inode to our current scene list
    SceneEntry* pEntry = options.sceneEnumProc.Append(
                             pNode, pCameraObj, OBTYPE_CAMERA, &std::string(iObj.getFullName()));
    options.currentSceneList.Append(pEntry);

    // Set the visibility controller
    AlembicImport_SetupVisControl(path, identifier, iObj, pNode, options);

    importMetadata(pNode, iObj);

    return 0;
}
コード例 #6
0
void createCameraModifier(const std::string& path,
                          const std::string& identifier, INode* pNode)
{
    ////Create the Camera modifier
    Modifier* pModifier =
        static_cast<Modifier*>(GET_MAX_INTERFACE()->CreateInstance(
                                   OSM_CLASS_ID, ALEMBIC_CAMERA_MODIFIER_CLASSID));

    TimeValue now = GET_MAX_INTERFACE()->GetTime();

    // Set the alembic id
    pModifier->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pModifier, 0, "path"), now,
        EC_UTF8_to_TCHAR(path.c_str()));
    pModifier->GetParamBlockByID(0)->SetValue(
        GetParamIdByName(pModifier, 0, "identifier"), now,
        EC_UTF8_to_TCHAR(identifier.c_str()));

    // Set the alembic id
    // pModifier->SetCamera(pCameraObj);

    // Add the modifier to the node
    GET_MAX_INTERFACE()->AddModifier(*pNode, *pModifier);

    // AlembicImport_ConnectTimeControl("$.modifiers[\"AlembicCameraProperties\"].time",
    // options );

    // printControllers(pModifier->GetParamBlockByID(0));

    IParamBlock2* pBlock = pModifier->GetParamBlockByID(0);
    if (pBlock) {
        pBlock->AssignController(
            createFloatController(path, identifier, "horizontalFOV"), 0);
        pBlock->AssignController(
            createFloatController(path, identifier, "verticalFOV"), 1);
        pBlock->AssignController(
            createFloatController(path, identifier, "FocalLength"), 2);
        pBlock->AssignController(
            createFloatController(path, identifier, "HorizontalAperture"), 3);
        pBlock->AssignController(
            createFloatController(path, identifier, "VerticalAperture"), 4);
        pBlock->AssignController(
            createFloatController(path, identifier, "HorizontalFilmOffset"), 5);
        pBlock->AssignController(
            createFloatController(path, identifier, "VerticalFilmOffset"), 6);
        pBlock->AssignController(
            createFloatController(path, identifier, "LensSqueezeRatio"), 7);
        pBlock->AssignController(
            createFloatController(path, identifier, "OverScanLeft"), 8);
        pBlock->AssignController(
            createFloatController(path, identifier, "OverScanRight"), 9);
        pBlock->AssignController(
            createFloatController(path, identifier, "OverScanTop"), 10);
        pBlock->AssignController(
            createFloatController(path, identifier, "OverScanBottom"), 11);
        pBlock->AssignController(createFloatController(path, identifier, "FStop"),
                                 12);
        pBlock->AssignController(
            createFloatController(path, identifier, "FocusDistance"), 13);
        pBlock->AssignController(
            createFloatController(path, identifier, "ShutterOpen"), 14);
        pBlock->AssignController(
            createFloatController(path, identifier, "ShutterClose"), 15);
        pBlock->AssignController(
            createFloatController(path, identifier, "NearClippingPlane"), 16);
        pBlock->AssignController(
            createFloatController(path, identifier, "FarClippingPlane"), 17);
    }
}