コード例 #1
0
void SetMaxSceneTime(TimeValue ticks)
{
    if (g_currTick != ticks) {
        g_currTick = ticks;
        GET_MAX_INTERFACE()->SetTime(ticks);
    }
}
コード例 #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
///////////////////////////////////////////////////////////////////////////////////////////////////
// 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);
    }
  }
}
コード例 #4
0
int AlembicImport_Light(const std::string &path, AbcG::IObject& iObj, alembic_importoptions &options, INode** pMaxNode)
{
//#define OMNI_LIGHT_CLASS_ID  		0x1011
//#define SPOT_LIGHT_CLASS_ID  		0x1012
//#define DIR_LIGHT_CLASS_ID  		0x1013
//#define FSPOT_LIGHT_CLASS_ID  		0x1014
//#define TDIR_LIGHT_CLASS_ID  		0x1015

//#define OMNI_LIGHT		0	// Omnidirectional
//#define TSPOT_LIGHT		1	// Targeted
//#define DIR_LIGHT		2	// Directional
//#define FSPOT_LIGHT		3	// Free
//#define TDIR_LIGHT		4   // Targeted directional

   if(options.attachToExisting){
      ESS_LOG_WARNING("Attach to existing for lights is not yet supported. Could not attach "<<iObj.getFullName());
      return alembic_success;
   }

   std::vector<matShader> shaders;

   AbcG::ILight objLight = AbcG::ILight(iObj, Alembic::Abc::kWrapExisting);

   std::string identifier = objLight.getFullName();

   //CompoundPropertyReaderPtr propReader = objLight.getProperties();

   Abc::ICompoundProperty props = objLight.getProperties();

   InputLightType::enumt lightType = InputLightType::NUM_INPUT_LIGHT_TYPES;

   for(int i=0; i<props.getNumProperties(); i++){
      Abc::PropertyHeader propHeader = props.getPropertyHeader(i);
      if(AbcM::IMaterialSchema::matches(propHeader)){
         AbcM::IMaterialSchema matSchema(props, propHeader.getName());
   
         //ESS_LOG_WARNING("MaterialSchema present on light.");

         lightType = readShader(matSchema, shaders);
      }

      //ESS_LOG_WARNING("name: "<<propHeader.getName());

      //if( AbcG::ICameraSchema::matches(propHeader) ){
      //   ESS_LOG_WARNING("Found light camera.");
      //   //AbcG::ICameraSchema camSchema(props, propHeader.getName());

      //}
   }



   bool bReplaceExisting = false;
   int nodeRes = alembic_failure;
   if(lightType == InputLightType::AMBIENT_LIGHT){
      nodeRes = createNode(iObj, LIGHT_CLASS_ID, Class_ID(OMNI_LIGHT_CLASS_ID, 0), pMaxNode, bReplaceExisting);

      //Modifier* pModifier = FindModifier(*pMaxNode, Class_ID(OMNI_LIGHT_CLASS_ID, 0));

      //if(pModifier){
      //   ESS_LOG_WARNING("NumParamBlocks: "<<pModifier->NumParamBlocks());
      //}
   
      //printControllers(*pMaxNode);

      //pMaxNode>GetParamBlockByID( 0 )->SetValue( GetParamIdByName( pModifier, 0, "muted" ), zero, FALSE );


      GET_MAX_INTERFACE()->SelectNode(*pMaxNode);

      //set the ambient check box, intensity controller, and light colour controller (not sure how to this in C++)
      std::stringstream evalStream;
      std::string modkey("");

      for(int s=0; s<shaders.size(); s++){
         std::string target = shaders[s].target;
         std::string type = shaders[s].type;

         for(int i=0; i<shaders[s].props.size(); i++){
            std::string propName = shaders[s].props[i].name;
            std::string& val = shaders[s].props[i].displayVal;
            bool& bConstant = shaders[s].props[i].bConstant;

            const AbcA::DataType& datatype = shaders[s].props[i].propHeader.getDataType();
            const AbcA::MetaData& metadata = shaders[s].props[i].propHeader.getMetaData();

            if(datatype.getPod() == AbcA::kFloat32POD){

               std::stringstream propStream;
               propStream<<target<<"."<<type<<"."<<propName;
               if(datatype.getExtent() == 1 && propName.find("intensity") != std::string::npos ){ //intensity property found, so attach controller
                  addFloatController(evalStream, options, modkey, std::string("multiplier"), path, iObj.getFullName(), propStream.str());
               }
               else if(datatype.getExtent() == 3 && propName.find("lightcolor") != std::string::npos ){ //color property found, so attach controller

                  std::stringstream xStream, yStream, zStream;

                  xStream<<propStream.str()<<"."<<metadata.get("interpretation")<<".x";
                  yStream<<propStream.str()<<"."<<metadata.get("interpretation")<<".y";
                  zStream<<propStream.str()<<"."<<metadata.get("interpretation")<<".z";

                  evalStream<<"$.rgb.controller = Color_RGB()\n";

                  addFloatController(evalStream, options, modkey, std::string("rgb.controller.r"), path, iObj.getFullName(), xStream.str());
                  addFloatController(evalStream, options, modkey, std::string("rgb.controller.g"), path, iObj.getFullName(), yStream.str());
                  addFloatController(evalStream, options, modkey, std::string("rgb.controller.b"), path, iObj.getFullName(), zStream.str());
               }
            }
            else{
               
            }
            evalStream<<"\n";
         }
      }

      evalStream<<"$.ambientOnly = true\n";
      ExecuteMAXScriptScript( EC_UTF8_to_TCHAR((char*)evalStream.str().c_str()));
   }
   else{//create a null, if we don't know what type of light this is
      nodeRes = createNode(iObj, HELPER_CLASS_ID, Class_ID(DUMMY_CLASS_ID,0), pMaxNode, bReplaceExisting);
   }

   if(nodeRes == alembic_failure){
      return nodeRes;
   }


   GET_MAX_INTERFACE()->SelectNode(*pMaxNode);

   for(int i=0; i<shaders.size(); i++){

      std::sort(shaders[i].props.begin(), shaders[i].props.end(), sortFunc);

      Modifier* pMod = createDisplayModifier("Shader Properties", shaders[i].name, shaders[i].props);

      std::string target = shaders[i].target;
      std::string type = shaders[i].type;

      addControllersToModifier("Shader Properties", shaders[i].name, shaders[i].props, target, type, path, iObj.getFullName(), options);
   }

   // ----- TODO: add camera modifier
   //createCameraModifier(path, identifier, *pMaxNode);


   // ----- TODO: don't attach controllers for constant parameters


   //TODO: make the spinners read only



   return alembic_success;
}
コード例 #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);
    }
}