예제 #1
0
void AlembicImport_ConnectTimeControl( const char* szControllerName, alembic_importoptions &options ) 
{
   char szBuffer[10000];
   if(options.loadTimeControl && options.pTimeControl){

	std::string objectNameName = EC_MCHAR_to_UTF8( options.pTimeControl->GetObjectName() );
		
	sprintf_s( szBuffer, 10000, 
		"%s.controller = float_expression()\n"
		"%s.controller.AddScalarTarget \"current\" $'%s'.time.controller\n"
		"%s.controller.setExpression \"current\"\n",
		szControllerName,
		szControllerName, objectNameName.c_str(),
		szControllerName, objectNameName.c_str(),
		szControllerName, objectNameName.c_str(),
		szControllerName );

   }
   else{
	sprintf_s( szBuffer, 10000,
		"%s.controller = float_expression()\n"
		"%s.controller.setExpression \"S\"\n"
		, szControllerName, szControllerName, szControllerName, szControllerName );
   }
   ExecuteMAXScriptScript( EC_UTF8_to_TCHAR( szBuffer ) );
}
void addControllersToModifierV2(const std::string& modkey, const std::string& modname, std::vector<AbcProp>& props, 
                              const std::string& file, const std::string& identifier, const std::string& category, alembic_importoptions &options, INode* pNode)
{
   ESS_PROFILE_FUNC();

   std::stringstream evalStream;
   std::string nodeName("$");
   if(pNode){
      evalStream<<GET_MAXSCRIPT_NODE(pNode);
      nodeName = std::string("mynode2113");
   }

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

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

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

         std::stringstream propStream;
         propStream<<propName;
         if(datatype.getExtent() == 1){
            addFloatControllerV2(evalStream, options, nodeName, modkey, propName, file, identifier, category, propStream.str());
         }
         else if(datatype.getExtent() == 3){

            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";

            addFloatControllerV2(evalStream, options, nodeName, modkey, propName + std::string("x"), file, identifier, category, xStream.str());
            addFloatControllerV2(evalStream, options, nodeName, modkey, propName + std::string("y"), file, identifier, category, yStream.str());
            addFloatControllerV2(evalStream, options, nodeName, modkey, propName + std::string("z"), file, identifier, category, zStream.str());
         }
      }
      else if(datatype.getPod() == AbcA::kInt32POD){
         std::stringstream propStream;
         propStream<<propName;
         if(datatype.getExtent() == 1){
            addFloatControllerV2(evalStream, options, nodeName, modkey, propName, file, identifier, category, propStream.str());
         }
      }
      else{
         
      }
      evalStream<<"\n";
   }

  
   //ESS_LOG_WARNING(evalStream.str());

   ExecuteMAXScriptScript( EC_UTF8_to_TCHAR((char*)evalStream.str().c_str()));
}
예제 #3
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;
}
void addControllersToModifier(const std::string& modkey, const std::string& modname, std::vector<AbcProp>& props, 
                              const std::string& target, const std::string& type,
                              const std::string& file, const std::string& identifier, alembic_importoptions &options)
{
   ESS_PROFILE_FUNC();

   //the script assumes a single object is selected

   std::stringstream evalStream;

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

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

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

         std::stringstream propStream;
         propStream<<target<<"."<<type<<"."<<propName;
         if(datatype.getExtent() == 1){
            addFloatController(evalStream, options, modkey, propName, file, identifier, propStream.str());
         }
         else if(datatype.getExtent() == 3){

            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";

            addFloatController(evalStream, options, modkey, propName + std::string("x"), file, identifier, xStream.str());
            addFloatController(evalStream, options, modkey, propName + std::string("y"), file, identifier, yStream.str());
            addFloatController(evalStream, options, modkey, propName + std::string("z"), file, identifier, zStream.str());
         }
      }
      else{
         
      }
      evalStream<<"\n";
   }

  
   //ESS_LOG_WARNING(evalStream.str());

   ExecuteMAXScriptScript( EC_UTF8_to_TCHAR((char*)evalStream.str().c_str()));
}
void createStringPropertyDisplayModifier(std::string modname, std::vector<std::pair<std::string, std::string>>& nameValuePairs)
{
   //Example usage:
   //
   //std::vector<std::pair<std::string, std::string>> nameValuePairs;
   //nameValuePairs.push_back(std::pair<std::string, std::string>("Prop1", "Prop1Val"));
   //nameValuePairs.push_back(std::pair<std::string, std::string>("Prop2", "Prop2Val"));
   //nameValuePairs.push_back(std::pair<std::string, std::string>("Prop3", "Prop3Val"));
   //nameValuePairs.push_back(std::pair<std::string, std::string>("Prop4", "Prop4Val"));
   //createPropertiesDisplayModifier(std::string("My Properties"), nameValuePairs);

   //the script assumes a single object is selected

   std::stringstream evalStream;
   evalStream<<"propModifier = EmptyModifier()"<<"\n";
   evalStream<<"propModifier.name = \""<<modname<<"\""<<"\n";
   evalStream<<"modCount = $.modifiers.count"<<"\n";
   evalStream<<"addmodifier $ propModifier before:modCount"<<"\n";
   evalStream<<"$.modifiers[\""<<modname<<"\"].enabled = false"<<"\n";

   evalStream<<"propAttribute = attributes propAttribute"<<"\n";
   evalStream<<"("<<"\n";

   evalStream<<"parameters propAttributePRM1 rollout:propAttributeRLT1"<<"\n";
   evalStream<<"("<<"\n";
   for(int i=0; i<nameValuePairs.size(); i++){
      std::string& name = nameValuePairs[i].first;
      std::string& val = nameValuePairs[i].second;
      evalStream<<name<<" type:#string ui:e"<<name<<" default:\""<<val<<"\""<<"\n";
   }
   evalStream<<")"<<"\n";
   
   evalStream<<"rollout propAttributeRLT1 \""<<modname<<"\""<<"\n";
   evalStream<<"("<<"\n";
   for(int i=0; i<nameValuePairs.size(); i++){
      std::string& name = nameValuePairs[i].first;
      //std::string& val = nameValuePairs[i].second;
      evalStream<<"edittext e"<<name<<" \""<<name<<"\" fieldWidth:140 labelOnTop:true"<<"\n";
   }
   evalStream<<")"<<"\n";
   evalStream<<")"<<"\n";


   evalStream<<"custattributes.add $.modifiers[\""<<modname<<"\"] propAttribute baseobject:false"<<"\n";

   ExecuteMAXScriptScript( EC_UTF8_to_TCHAR((char*)evalStream.str().c_str()) );
}
void importMetadata(INode* pNode, AbcG::IObject& iObj)
{
  ESS_PROFILE_FUNC();

  AbcG::IObject* metadataChild = NULL;

  if (getCompoundFromObject(iObj).getPropertyHeader(".metadata") == NULL) {
    return;
  }

  Abc::IStringArrayProperty metaDataProp =
      Abc::IStringArrayProperty(getCompoundFromObject(iObj), ".metadata");
  Abc::StringArraySamplePtr ptr = metaDataProp.getValue(0);
  // for(unsigned int i=0;i<ptr->size();i++){
  //	const char* name = ptr->get()[i].c_str();
  //	Abc::StringArraySamplePtr ptr = metaDataProp.getValue(0);
  //
  //}

  std::stringstream exeBuffer;

  exeBuffer << GET_MAXSCRIPT_NODE(pNode);
  exeBuffer << "ImportMetadata mynode2113";

  exeBuffer << "#(";

  for (int i = 0; i < ptr->size() - 1; i++) {
    exeBuffer << "\"";
    exeBuffer << ptr->get()[i];
    exeBuffer << "\", ";
  }
  exeBuffer << "\"";
  exeBuffer << ptr->get()[ptr->size() - 1];
  exeBuffer << "\")";

  exeBuffer << " \n";

  ExecuteMAXScriptScript(EC_UTF8_to_TCHAR((char*)exeBuffer.str().c_str()));

  // delete[] szBuffer;
}
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;
}
Modifier* createDisplayModifier(std::string modkey, std::string modname, std::vector<AbcProp>& props, INode* pNode)
{
   ESS_PROFILE_FUNC();

   //the script assumes a single object is selected
   std::stringstream evalStream;
   std::string nodeName("$");
   if(pNode){
      evalStream<<GET_MAXSCRIPT_NODE(pNode);
      nodeName = std::string("mynode2113");
   }
   evalStream<<"propModifier = EmptyModifier()"<<"\n";
   evalStream<<"propModifier.name = \""<<modkey<<"\""<<"\n";
   evalStream<<"modCount = "<<nodeName<<".modifiers.count"<<"\n";
   evalStream<<"addmodifier "<<nodeName<<" propModifier before:modCount"<<"\n";
   evalStream<<nodeName<<".modifiers[\""<<modkey<<"\"].enabled = false"<<"\n";

   evalStream<<"propAttribute = attributes propAttribute"<<"\n";
   evalStream<<"("<<"\n";

   evalStream<<"parameters propAttributePRM1 rollout:propAttributeRLT1"<<"\n";
   evalStream<<"("<<"\n";
   for(int i=0; i<props.size(); i++){
      std::string& name = props[i].name;
      std::string& val = props[i].displayVal;
      bool& bConstant = props[i].bConstant;

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

      if(datatype.getPod() == AbcA::kInt32POD && datatype.getExtent() == 1){
         evalStream<<name<<" type:#integer animatable:true ui:e"<<name<<" default:"<<val;
      }
      else if(datatype.getPod() == AbcA::kFloat32POD && datatype.getExtent() == 1){
         evalStream<<name<<" type:#float animatable:true ui:e"<<name<<" default:"<<val;
      }
      else if(datatype.getPod() == AbcA::kFloat32POD && datatype.getExtent() == 3){
         //if(metadata.get("interpretation") == std::string("rgb")){
         //   evalStream<<name<<" type:#color animatable:false ui:e"<<name<<" default:(["<<val<<"] as color)"; 
         //}
         //else{
            //evalStream<<name<<" type:#point3 animatable:false ui:e"<<name<<" ["<<val<<"]"; 
            evalStream<<name<<"x type:#float animatable:true ui:e"<<name<<"x default:300\n";
            evalStream<<name<<"y type:#float animatable:true ui:e"<<name<<"y default:300\n";
            evalStream<<name<<"z type:#float animatable:true ui:e"<<name<<"z default:300\n";
         //}
      }
      else{
         evalStream<<name<<" type:#string animatable:false ui:e"<<name<<" default:\""<<val<<"\"";
      }
      evalStream<<"\n";
   }
   evalStream<<")"<<"\n";
   
   evalStream<<"rollout propAttributeRLT1 \""<<modname<<"\""<<"\n";
   evalStream<<"("<<"\n";

   for(int i=0; i<props.size(); i++){
      std::string& name = props[i].name;
      bool& bConstant = props[i].bConstant;
      const AbcA::DataType& datatype = props[i].propHeader.getDataType();
      const AbcA::MetaData& metadata = props[i].propHeader.getMetaData();
      const int nSize = (const int) props[i].displayVal.size();

      if(datatype.getPod() == AbcA::kInt32POD && datatype.getExtent() == 1){
         evalStream<<"label lbl"<<name<<" \""<<name<<"\" align:#left fieldWidth:140\n";
         evalStream<<"spinner e"<<name<<" \"\" type:#integer range:[-9999999,9999999,0] align:#left labelOnTop:true\n";
      }
      else if(datatype.getPod() == AbcA::kFloat32POD && datatype.getExtent() == 1){
         evalStream<<"label lbl"<<name<<" \""<<name<<"\" align:#left fieldWidth:140\n";
         evalStream<<"spinner e"<<name<<" \"\" type:#float range:[-9999999,9999999,0]align:#left labelOnTop:true\n";
      }
      else if(datatype.getPod() == AbcA::kFloat32POD && datatype.getExtent() == 3){

         evalStream<<"label lbl"<<name<<" \""<<name<<"\" align:#left fieldWidth:140\n";
         evalStream<<"spinner e"<<name<<"x\"\" across:3 type:#float range:[-9999999,9999999,0] fieldWidth:39 readOnly:true\n";
         evalStream<<"spinner e"<<name<<"y\"\" type:#float range:[-9999999,9999999,0] fieldWidth:39\n";
         evalStream<<"spinner e"<<name<<"z\"\" type:#float range:[-9999999,9999999,0] fieldWidth:39\n";
      }
      else{
         //TODO: better fit for large strings
         evalStream<<"edittext e"<<name<<" \" "<<name<<"\" fieldWidth:140 ";
         if(nSize > 140){
            evalStream<<"height:54";
         }
         evalStream<<" labelOnTop:true";
         if(bConstant) evalStream<<" readOnly:true";
      }

      evalStream<<"\n";
   }

   //evalStream<<"on propAttributePRM1 changed do\n";
   //evalStream<<"("<<"\n";

   //for(int i=0; i<props.size(); i++){
   //   std::string& name = props[i].name;

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

   //   evalStream<<"e"<<name<<".text = "<<name<<" as string";
   //   evalStream<<"\n";
   //}

   //evalStream<<")"<<"\n";
   evalStream<<")"<<"\n";
   evalStream<<")"<<"\n";


   evalStream<<"custattributes.add "<<nodeName<<".modifiers[\""<<modkey<<"\"] propAttribute baseobject:false"<<"\n";

   

   //ESS_LOG_WARNING(evalStream.str());

   evalStream<<nodeName<<".modifiers[\""<<modkey<<"\"]\n";
   FPValue fpVal;
   ExecuteMAXScriptScript( EC_UTF8_to_TCHAR((char*)evalStream.str().c_str()), 0, &fpVal);
   Modifier* pMod = (Modifier*)fpVal.r;
   return pMod;
}