<commit_before>#include "stdafx.h"
#include "Alembic.h"
#include "AlembicArchiveStorage.h"
#include "AlembicDefinitions.h"
#include "AlembicFloatController.h"
#include "Utility.h"
#include "AlembicNames.h"
#include "resource.h"
#include "AlembicMAXScript.h"
#include "AlembicCameraUtilities.h"

// This function returns a pointer to a class descriptor for our Utility
// This is the function that informs max that our plug-in exists and is 
// available to use
static AlembicFloatControllerClassDesc sAlembicFloatControllerClassDesc;
ClassDesc2* GetAlembicFloatControllerClassDesc()
{
	return &sAlembicFloatControllerClassDesc;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// Alembic_vis_Ctrl_Param_Blk
///////////////////////////////////////////////////////////////////////////////////////////////////

static ParamBlockDesc2 AlembicFloatControllerParams(
	0,
	_T(ALEMBIC_FLOAT_CONTROLLER_SCRIPTNAME),
	0,
	GetAlembicFloatControllerClassDesc(),
	P_AUTO_CONSTRUCT | P_AUTO_UI,
	0,

	// rollout description 
	IDD_ALEMBIC_FLOAT_CTRL_PARAMS, IDS_ALEMBIC, 0, 0, NULL,

    // params
	AlembicFloatController::ID_PATH, _T("path"), TYPE_FILENAME, P_RESET_DEFAULT, IDS_PATH,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_PATH_EDIT,
		p_assetTypeID,	AssetManagement::kExternalLink,
	 	p_end,
        
	AlembicFloatController::ID_IDENTIFIER, _T("identifier"), TYPE_STRING, P_RESET_DEFAULT, IDS_IDENTIFIER,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_IDENTIFIER_EDIT,
	 	p_end,

	AlembicFloatController::ID_PROPERTY, _T("property"), TYPE_STRING, P_RESET_DEFAULT, IDC_PROPERTY_EDIT,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_PROPERTY_EDIT,
		p_end,

	AlembicFloatController::ID_TIME, _T("time"), TYPE_FLOAT, P_ANIMATABLE, IDS_TIME,
		p_default,       0.0f,
		p_range,         0.0f, 1000.0f,
		p_ui,            TYPE_SPINNER,       EDITTYPE_FLOAT, IDC_TIME_EDIT,    IDC_TIME_SPIN, 0.01f,
		p_end,

	AlembicFloatController::ID_MUTED, _T("muted"), TYPE_BOOL, P_ANIMATABLE, IDS_MUTED,
		p_default,       FALSE,
		p_ui,            TYPE_SINGLECHEKBOX,  IDC_MUTED_CHECKBOX,
		p_end,

	p_end
);

///////////////////////////////////////////////////////////////////////////////////////////////////
// AlembicFloatController Methods
///////////////////////////////////////////////////////////////////////////////////////////////////
IObjParam *AlembicFloatController::ip = NULL;
AlembicFloatController *AlembicFloatController::editMod = NULL;

void AlembicFloatController::GetValueLocalTime(TimeValue t, void *ptr, Interval &valid, GetSetMethod method)
{
 	ESS_CPP_EXCEPTION_REPORTING_START

	Interval interval = FOREVER;

   MCHAR const* strPath = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_PATH, t, strPath, interval);

	MCHAR const* strIdentifier = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_IDENTIFIER, t, strIdentifier, interval);
 
	MCHAR const* strProperty = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_PROPERTY, t, strProperty, interval);

	float fTime;
	this->pblock->GetValue( AlembicFloatController::ID_TIME, t, fTime, interval);

	BOOL bMuted;
	this->pblock->GetValue( AlembicFloatController::ID_MUTED, t, bMuted, interval);

	extern bool g_bVerboseLogging;

	if(g_bVerboseLogging){
		ESS_LOG_INFO("Param block at tick "<<t<<"-----------------------");
		ESS_LOG_INFO("PATH: "<<strPath);
		ESS_LOG_INFO("IDENTIFIER: "<<strIdentifier);
		ESS_LOG_INFO("PROPERTY: "<<strProperty);
		ESS_LOG_INFO("TIME: "<<fTime);
		ESS_LOG_INFO("MUTED: "<<bMuted);
		ESS_LOG_INFO("Param block end -------------");
	}

   if (bMuted || !strProperty){
      return;
   }
	
	std::string szPath = EC_MCHAR_to_UTF8( strPath );
	std::string szIdentifier = EC_MCHAR_to_UTF8( strIdentifier );
	std::string szProperty = EC_MCHAR_to_UTF8( strProperty );	

	if( szProperty.size() == 0 ) {
	   ESS_LOG_ERROR( "No property specified." );
	   return;
	}


	AbcG::IObject iObj = getObjectFromArchive(szPath, szIdentifier);
    
	if(!iObj.valid() || !AbcG::ICamera::matches(iObj.getMetaData())) {
        return;
	}

	if(g_bVerboseLogging){
		ESS_LOG_INFO("Camera object found.");
	}

   AbcG::ICamera objCamera = AbcG::ICamera(iObj, Abc::kWrapExisting);

	TimeValue dTicks = GetTimeValueFromSeconds( fTime );
   double sampleTime = GetSecondsFromTimeValue(dTicks);

	SampleInfo sampleInfo = getSampleInfo(sampleTime,
                                          objCamera.getSchema().getTimeSampling(),
                                          objCamera.getSchema().getNumSamples());
   AbcG::CameraSample sample;
   objCamera.getSchema().get(sample, sampleInfo.floorIndex);

	if(g_bVerboseLogging){
		ESS_LOG_INFO("dTicks: "<<dTicks<<" sampleTime: "<<sampleTime);
		ESS_LOG_INFO("SampleInfo.alpha: "<<sampleInfo.alpha<< "SampleInfo(fi, ci): "<<sampleInfo.floorIndex<<", "<<sampleInfo.ceilIndex);
	}

	double sampleVal = 0.0;
	if(!getCameraSampleVal(objCamera, sampleInfo, sample, szProperty.c_str(), sampleVal)){
		return;
	}

   // Blend the camera values, if necessary
   if (sampleInfo.alpha != 0.0)
   {
      objCamera.getSchema().get(sample, sampleInfo.ceilIndex);
      double sampleVal2 = 0.0;
      if(getCameraSampleVal(objCamera, sampleInfo, sample, szProperty.c_str(), sampleVal2)){
         sampleVal = (1.0 - sampleInfo.alpha) * sampleVal + sampleInfo.alpha * sampleVal2;
      }
   }

	const float fSampleVal = (float)sampleVal;

	if(g_bVerboseLogging){
		ESS_LOG_INFO("Property "<<strProperty<<": "<<fSampleVal);
		
	}

	valid = interval;

	if (method == CTRL_ABSOLUTE)
	{
		float* fInVal = (float*)ptr;
		*fInVal = fSampleVal;
	}
	else // CTRL_RELATIVE
	{<commit_msg>issue #307 - started updating float controller to read from ILights<commit_after>#include "stdafx.h"
#include "Alembic.h"
#include "AlembicArchiveStorage.h"
#include "AlembicDefinitions.h"
#include "AlembicFloatController.h"
#include "Utility.h"
#include "AlembicNames.h"
#include "resource.h"
#include "AlembicMAXScript.h"
#include "AlembicCameraUtilities.h"

// This function returns a pointer to a class descriptor for our Utility
// This is the function that informs max that our plug-in exists and is 
// available to use
static AlembicFloatControllerClassDesc sAlembicFloatControllerClassDesc;
ClassDesc2* GetAlembicFloatControllerClassDesc()
{
	return &sAlembicFloatControllerClassDesc;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// Alembic_vis_Ctrl_Param_Blk
///////////////////////////////////////////////////////////////////////////////////////////////////

static ParamBlockDesc2 AlembicFloatControllerParams(
	0,
	_T(ALEMBIC_FLOAT_CONTROLLER_SCRIPTNAME),
	0,
	GetAlembicFloatControllerClassDesc(),
	P_AUTO_CONSTRUCT | P_AUTO_UI,
	0,

	// rollout description 
	IDD_ALEMBIC_FLOAT_CTRL_PARAMS, IDS_ALEMBIC, 0, 0, NULL,

    // params
	AlembicFloatController::ID_PATH, _T("path"), TYPE_FILENAME, P_RESET_DEFAULT, IDS_PATH,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_PATH_EDIT,
		p_assetTypeID,	AssetManagement::kExternalLink,
	 	p_end,
        
	AlembicFloatController::ID_IDENTIFIER, _T("identifier"), TYPE_STRING, P_RESET_DEFAULT, IDS_IDENTIFIER,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_IDENTIFIER_EDIT,
	 	p_end,

	AlembicFloatController::ID_PROPERTY, _T("property"), TYPE_STRING, P_RESET_DEFAULT, IDC_PROPERTY_EDIT,
	    p_default, "",
	    p_ui,        TYPE_EDITBOX,		IDC_PROPERTY_EDIT,
		p_end,

	AlembicFloatController::ID_TIME, _T("time"), TYPE_FLOAT, P_ANIMATABLE, IDS_TIME,
		p_default,       0.0f,
		p_range,         0.0f, 1000.0f,
		p_ui,            TYPE_SPINNER,       EDITTYPE_FLOAT, IDC_TIME_EDIT,    IDC_TIME_SPIN, 0.01f,
		p_end,

	AlembicFloatController::ID_MUTED, _T("muted"), TYPE_BOOL, P_ANIMATABLE, IDS_MUTED,
		p_default,       FALSE,
		p_ui,            TYPE_SINGLECHEKBOX,  IDC_MUTED_CHECKBOX,
		p_end,

	p_end
);

///////////////////////////////////////////////////////////////////////////////////////////////////
// AlembicFloatController Methods
///////////////////////////////////////////////////////////////////////////////////////////////////
IObjParam *AlembicFloatController::ip = NULL;
AlembicFloatController *AlembicFloatController::editMod = NULL;

void AlembicFloatController::GetValueLocalTime(TimeValue t, void *ptr, Interval &valid, GetSetMethod method)
{
 	ESS_CPP_EXCEPTION_REPORTING_START

	Interval interval = FOREVER;

   MCHAR const* strPath = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_PATH, t, strPath, interval);

	MCHAR const* strIdentifier = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_IDENTIFIER, t, strIdentifier, interval);
 
	MCHAR const* strProperty = NULL;
	this->pblock->GetValue( AlembicFloatController::ID_PROPERTY, t, strProperty, interval);

	float fTime;
	this->pblock->GetValue( AlembicFloatController::ID_TIME, t, fTime, interval);

	BOOL bMuted;
	this->pblock->GetValue( AlembicFloatController::ID_MUTED, t, bMuted, interval);

	extern bool g_bVerboseLogging;

	if(g_bVerboseLogging){
		ESS_LOG_INFO("Param block at tick "<<t<<"-----------------------");
		ESS_LOG_INFO("PATH: "<<strPath);
		ESS_LOG_INFO("IDENTIFIER: "<<strIdentifier);
		ESS_LOG_INFO("PROPERTY: "<<strProperty);
		ESS_LOG_INFO("TIME: "<<fTime);
		ESS_LOG_INFO("MUTED: "<<bMuted);
		ESS_LOG_INFO("Param block end -------------");
	}

   if (bMuted || !strProperty){
      return;
   }
	
	std::string szPath = EC_MCHAR_to_UTF8( strPath );
	std::string szIdentifier = EC_MCHAR_to_UTF8( strIdentifier );
	std::string szProperty = EC_MCHAR_to_UTF8( strProperty );	

	if( szProperty.size() == 0 ) {
	   ESS_LOG_ERROR( "No property specified." );
	   return;
	}


	AbcG::IObject iObj = getObjectFromArchive(szPath, szIdentifier);
    
	if(!iObj.valid() || !AbcG::ICamera::matches(iObj.getMetaData())) {
        return;
	}

	if(!iObj.valid() 
      || !Alembic::AbcGeom::ICamera::matches(iObj.getMetaData())
      || !Alembic::AbcGeom::ILight::matches(iObj.getMetaData())){
      return;
	}

   TimeValue dTicks = GetTimeValueFromSeconds( fTime );
   double sampleTime = GetSecondsFromTimeValue(dTicks);

   double sampleVal = 0.0;
   if(Alembic::AbcGeom::ICamera::matches(iObj.getMetaData())){

      Alembic::AbcGeom::ICamera objCamera = Alembic::AbcGeom::ICamera(iObj, Alembic::Abc::kWrapExisting);

	   SampleInfo sampleInfo = getSampleInfo(sampleTime,
                                             objCamera.getSchema().getTimeSampling(),
                                             objCamera.getSchema().getNumSamples());
      Alembic::AbcGeom::CameraSample sample;
      objCamera.getSchema().get(sample, sampleInfo.floorIndex);

	   if(!getCameraSampleVal(objCamera, sampleInfo, sample, strProperty, sampleVal)){
		   return;
	   }

      // Blend the camera values, if necessary
      if (sampleInfo.alpha != 0.0)
      {
         objCamera.getSchema().get(sample, sampleInfo.ceilIndex);
		   double sampleVal2 = 0.0;
		   if(getCameraSampleVal(objCamera, sampleInfo, sample, strProperty, sampleVal2)){
			   sampleVal = (1.0 - sampleInfo.alpha) * sampleVal + sampleInfo.alpha * sampleVal2;
		   }
      }
   }
   else if(Alembic::AbcGeom::ILight::matches(iObj.getMetaData())){

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

/*	   SampleInfo sampleInfo = getSampleInfo(sampleTime,
                                             objLight.getSchema().getTimeSampling(),
                                             objLight.getSchema().getNumSamples());
      Alembic::AbcGeo::LightSample sample;
      objLight.getSchema().get(sample, sampleInfo.floorIndex); */     



   }

	const float fSampleVal = (float)sampleVal;

	if(g_bVerboseLogging){
		ESS_LOG_INFO("Property "<<strProperty<<": "<<fSampleVal);
		
	}

	valid = interval;

	if (method == CTRL_ABSOLUTE)
	{
		float* fInVal = (float*)ptr;
		*fInVal = fSampleVal;
	}
	else // CTRL_RELATIVE
	{
{'fraction_non_alphanumeric': 0.18302076356329539, 'fraction_numerical': 0.0059444072337575355, 'mean_word_length': 3.0615436926215573, 'pattern_counts': {'":': 2, '<': 59, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5771256', 'n_tokens_mistral': 4179, 'n_tokens_neox': 3931, 'n_words': 692}