<commit_before>#include "stdafx.h"
#include "Alembic.h"
#include "AlembicDefinitions.h"
#include "AlembicArchiveStorage.h"
#include "utility.h"
#include "AlembicXForm.h"
#include "AlembicVisibilityController.h"
#include "AlembicNames.h"
#include "AlembicMeshUtilities.h"
#include "AlembicMAXScript.h" 
#include "AlembicMetadataUtils.h"

#include "CommonProfiler.h"
#include "CommonMeshUtilities.h"

void AlembicImport_FillInPolyMesh_Internal(alembic_fillmesh_options &options);

void AlembicImport_FillInPolyMesh(alembic_fillmesh_options &options)
{ 
	ESS_STRUCTURED_EXCEPTION_REPORTING_START
		AlembicImport_FillInPolyMesh_Internal( options );
	ESS_STRUCTURED_EXCEPTION_REPORTING_END
}

void validateMeshes( alembic_fillmesh_options &options, char* szName ) {
	if (options.pMNMesh != NULL)
	{
		//ESS_LOG_WARNING( "options.pMNMesh->MNDebugPrint() ------------------------------------------------------------ section: " << szName );
		//options.pMNMesh->MNDebugPrint( FALSE );
		//if( ! options.pMNMesh->CheckAllData() ) {
		//	ESS_LOG_WARNING( "options.pMNMesh->CheckAllData() failed, section: " << szName );
		//	options.pMNMesh->MNDebugPrint();
		//}
	}
}

void AlembicImport_FillInPolyMesh_Internal(alembic_fillmesh_options &options)
{
   ESS_PROFILE_FUNC();
   AbcG::IPolyMesh objMesh;
   AbcG::ISubD objSubD;

   {

   ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - objMesh and objSubD");

   if(AbcG::IPolyMesh::matches((*options.pIObj).getMetaData()))
       objMesh = AbcG::IPolyMesh(*options.pIObj,Abc::kWrapExisting);
   else
       objSubD = AbcG::ISubD(*options.pIObj,Abc::kWrapExisting);

   }

   if(!objMesh.valid() && !objSubD.valid())
       return;


   int nTicks = options.dTicks;
   float fRoundedTimeAlpha = 0.0f;
   if(options.nDataFillFlags & ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES){
      RoundTicksToNearestFrame(nTicks, fRoundedTimeAlpha);
   }
   double sampleTime = GetSecondsFromTimeValue(nTicks);

   SampleInfo sampleInfo;
   if(objMesh.valid()) {
	  ESS_PROFILE_SCOPE("getSampleInfo");
      sampleInfo = getSampleInfo(
         sampleTime,
         objMesh.getSchema().getTimeSampling(),
         objMesh.getSchema().getNumSamples()
      );
   }
   else{
      sampleInfo = getSampleInfo(
         sampleTime,
         objSubD.getSchema().getTimeSampling(),
         objSubD.getSchema().getNumSamples()
      );
   }
   AbcG::IPolyMeshSchema::Sample polyMeshSample;
   AbcG::ISubDSchema::Sample subDSample;

   if(objMesh.valid()) objMesh.getSchema().get(polyMeshSample,sampleInfo.floorIndex);
   else objSubD.getSchema().get(subDSample,sampleInfo.floorIndex);

   int currentNumVerts = options.pMNMesh->numv;

   Abc::P3fArraySamplePtr meshPos;
   Abc::V3fArraySamplePtr meshVel;

   bool hasDynamicTopo = options.pObjectCache->isMeshTopoDynamic;//isAlembicMeshTopoDynamic( options.pIObj );
   if(objMesh.valid())
   {
   ESS_PROFILE_SCOPE("Mesh getPositions/getVelocities/faceCountProp");
     meshPos = polyMeshSample.getPositions();
     meshVel = polyMeshSample.getVelocities();
   }
   else
   {
   ESS_PROFILE_SCOPE("SubD getPositions/getVelocities/faceCountProp");
     meshPos = subDSample.getPositions();
     meshVel = subDSample.getVelocities();
   }

	//MH: What is this code for? //related to vertex blending
	//note that the fillInMesh call will crash if the points are not initilaized (tested max 2013)
   if(  ( options.nDataFillFlags & ALEMBIC_DATAFILL_FACELIST ) ||
	   ( options.nDataFillFlags & ALEMBIC_DATAFILL_VERTEX ) ) {
	   if (currentNumVerts != meshPos->size() && ! options.pMNMesh->GetFlag( MN_MESH_RATSNEST ) )
	   {
    		ESS_PROFILE_SCOPE("resize and clear vertices");
		   int numVerts = static_cast<int>(meshPos->size());
		   
		   options.pMNMesh->setNumVerts(numVerts);
		   MNVert* pMeshVerties = options.pMNMesh->V(0);
		   for(int i=0;i<numVerts;i++){
			   pMeshVerties[i].p = Point3(0,0,0);
		   }
	   }

		validateMeshes( options, "ALEMBIC_DATAFILL_FACELIST | ALEMBIC_DATAFILL_VERTEX" );
   }

   if ( options.nDataFillFlags & ALEMBIC_DATAFILL_VERTEX )
   {
       		ESS_PROFILE_SCOPE("ALEMBIC_DATAFILL_VERTEX");
	   Abc::V3f const* pPositionArray = ( meshPos.get() != NULL ) ? meshPos->get() : NULL;
	   Abc::V3f const* pVelocityArray = ( meshVel.get() != NULL ) ? meshVel->get() : NULL;

	   if( pPositionArray ){
	
		   std::vector<Abc::V3f> vArray;
		   vArray.reserve(meshPos->size());
		   //P3fArraySample* pPositionArray = meshPos->get();
		   for(size_t i=0;i<meshPos->size();i++) {
			  vArray.push_back(pPositionArray[i]);
		   }

           Abc::P3fArraySamplePtr meshPos2;

		   // blend - either between samples or using point velocities
		   if( ((options.nDataFillFlags & ~ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES) && sampleInfo.alpha != 0.0f ) || 
			   ((options.nDataFillFlags & ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES) && fRoundedTimeAlpha != 0.0f ) )
		   {
			   bool bSampleInterpolate = false;
			   bool bVelInterpolate = false;

			  if(objMesh.valid())
			  {
                 {
                     //ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - 2nd mesh sample read");
				     //AbcG::IPolyMeshSchema::Sample polyMeshSample2;
				     //objMesh.getSchema().get(polyMeshSample2,sampleInfo.ceilIndex);
				     //meshPos2 = polyMeshSample2.getPositions();

                     //ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - 2nd position sample read");

                     Abc::IP3fArrayProperty positionPropertyCeil = objMesh.getSchema().getPositionsProperty();
                     positionPropertyCeil.get(meshPos2, sampleInfo.floorIndex);

				     const int posSize = meshPos2 ? (const int)meshPos2->size() : 0;
				     const int velSize = meshVel ? (const int)meshVel->size() : 0;
   	             
				     if(meshPos2->size() == vArray.size() && !hasDynamicTopo)
					     bSampleInterpolate = true;
				     else if(meshVel && meshVel->size() == vArray.size())
					     bVelInterpolate = true;
                  }
			  }
			  else
			  {
				  AbcG::ISubDSchema::Sample subDSample2;
				  objSubD.getSchema().get(subDSample2,sampleInfo.ceilIndex);<commit_msg>issue #407 should have used ceil index<commit_after>#include "stdafx.h"
#include "Alembic.h"
#include "AlembicDefinitions.h"
#include "AlembicArchiveStorage.h"
#include "utility.h"
#include "AlembicXForm.h"
#include "AlembicVisibilityController.h"
#include "AlembicNames.h"
#include "AlembicMeshUtilities.h"
#include "AlembicMAXScript.h" 
#include "AlembicMetadataUtils.h"

#include "CommonProfiler.h"
#include "CommonMeshUtilities.h"

void AlembicImport_FillInPolyMesh_Internal(alembic_fillmesh_options &options);

void AlembicImport_FillInPolyMesh(alembic_fillmesh_options &options)
{ 
	ESS_STRUCTURED_EXCEPTION_REPORTING_START
		AlembicImport_FillInPolyMesh_Internal( options );
	ESS_STRUCTURED_EXCEPTION_REPORTING_END
}

void validateMeshes( alembic_fillmesh_options &options, char* szName ) {
	if (options.pMNMesh != NULL)
	{
		//ESS_LOG_WARNING( "options.pMNMesh->MNDebugPrint() ------------------------------------------------------------ section: " << szName );
		//options.pMNMesh->MNDebugPrint( FALSE );
		//if( ! options.pMNMesh->CheckAllData() ) {
		//	ESS_LOG_WARNING( "options.pMNMesh->CheckAllData() failed, section: " << szName );
		//	options.pMNMesh->MNDebugPrint();
		//}
	}
}

void AlembicImport_FillInPolyMesh_Internal(alembic_fillmesh_options &options)
{
   ESS_PROFILE_FUNC();
   AbcG::IPolyMesh objMesh;
   AbcG::ISubD objSubD;

   {

   ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - objMesh and objSubD");

   if(AbcG::IPolyMesh::matches((*options.pIObj).getMetaData()))
       objMesh = AbcG::IPolyMesh(*options.pIObj,Abc::kWrapExisting);
   else
       objSubD = AbcG::ISubD(*options.pIObj,Abc::kWrapExisting);

   }

   if(!objMesh.valid() && !objSubD.valid())
       return;


   int nTicks = options.dTicks;
   float fRoundedTimeAlpha = 0.0f;
   if(options.nDataFillFlags & ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES){
      RoundTicksToNearestFrame(nTicks, fRoundedTimeAlpha);
   }
   double sampleTime = GetSecondsFromTimeValue(nTicks);

   SampleInfo sampleInfo;
   if(objMesh.valid()) {
	  ESS_PROFILE_SCOPE("getSampleInfo");
      sampleInfo = getSampleInfo(
         sampleTime,
         objMesh.getSchema().getTimeSampling(),
         objMesh.getSchema().getNumSamples()
      );
   }
   else{
      sampleInfo = getSampleInfo(
         sampleTime,
         objSubD.getSchema().getTimeSampling(),
         objSubD.getSchema().getNumSamples()
      );
   }
   AbcG::IPolyMeshSchema::Sample polyMeshSample;
   AbcG::ISubDSchema::Sample subDSample;

   if(objMesh.valid()) objMesh.getSchema().get(polyMeshSample,sampleInfo.floorIndex);
   else objSubD.getSchema().get(subDSample,sampleInfo.floorIndex);

   int currentNumVerts = options.pMNMesh->numv;

   Abc::P3fArraySamplePtr meshPos;
   Abc::V3fArraySamplePtr meshVel;

   bool hasDynamicTopo = options.pObjectCache->isMeshTopoDynamic;//isAlembicMeshTopoDynamic( options.pIObj );
   if(objMesh.valid())
   {
   ESS_PROFILE_SCOPE("Mesh getPositions/getVelocities/faceCountProp");
     meshPos = polyMeshSample.getPositions();
     meshVel = polyMeshSample.getVelocities();
   }
   else
   {
   ESS_PROFILE_SCOPE("SubD getPositions/getVelocities/faceCountProp");
     meshPos = subDSample.getPositions();
     meshVel = subDSample.getVelocities();
   }

	//MH: What is this code for? //related to vertex blending
	//note that the fillInMesh call will crash if the points are not initilaized (tested max 2013)
   if(  ( options.nDataFillFlags & ALEMBIC_DATAFILL_FACELIST ) ||
	   ( options.nDataFillFlags & ALEMBIC_DATAFILL_VERTEX ) ) {
	   if (currentNumVerts != meshPos->size() && ! options.pMNMesh->GetFlag( MN_MESH_RATSNEST ) )
	   {
    		ESS_PROFILE_SCOPE("resize and clear vertices");
		   int numVerts = static_cast<int>(meshPos->size());
		   
		   options.pMNMesh->setNumVerts(numVerts);
		   MNVert* pMeshVerties = options.pMNMesh->V(0);
		   for(int i=0;i<numVerts;i++){
			   pMeshVerties[i].p = Point3(0,0,0);
		   }
	   }

		validateMeshes( options, "ALEMBIC_DATAFILL_FACELIST | ALEMBIC_DATAFILL_VERTEX" );
   }

   if ( options.nDataFillFlags & ALEMBIC_DATAFILL_VERTEX )
   {
       		ESS_PROFILE_SCOPE("ALEMBIC_DATAFILL_VERTEX");
	   Abc::V3f const* pPositionArray = ( meshPos.get() != NULL ) ? meshPos->get() : NULL;
	   Abc::V3f const* pVelocityArray = ( meshVel.get() != NULL ) ? meshVel->get() : NULL;

	   if( pPositionArray ){
	
		   std::vector<Abc::V3f> vArray;
		   vArray.reserve(meshPos->size());
		   //P3fArraySample* pPositionArray = meshPos->get();
		   for(size_t i=0;i<meshPos->size();i++) {
			  vArray.push_back(pPositionArray[i]);
		   }

           Abc::P3fArraySamplePtr meshPos2;

		   // blend - either between samples or using point velocities
		   if( ((options.nDataFillFlags & ~ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES) && sampleInfo.alpha != 0.0f ) || 
			   ((options.nDataFillFlags & ALEMBIC_DATAFILL_IGNORE_SUBFRAME_SAMPLES) && fRoundedTimeAlpha != 0.0f ) )
		   {
			   bool bSampleInterpolate = false;
			   bool bVelInterpolate = false;

			  if(objMesh.valid())
			  {
                 {
                     //ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - 2nd mesh sample read");
				     //AbcG::IPolyMeshSchema::Sample polyMeshSample2;
				     //objMesh.getSchema().get(polyMeshSample2,sampleInfo.ceilIndex);
				     //meshPos2 = polyMeshSample2.getPositions();

                     //ESS_PROFILE_SCOPE("AlembicImport_FillInPolyMesh_Internal - 2nd position sample read");

                     Abc::IP3fArrayProperty positionPropertyCeil = objMesh.getSchema().getPositionsProperty();
                     positionPropertyCeil.get(meshPos2, sampleInfo.ceilIndex);

				     const int posSize = meshPos2 ? (const int)meshPos2->size() : 0;
				     const int velSize = meshVel ? (const int)meshVel->size() : 0;
   	             
				     if(meshPos2->size() == vArray.size() && !hasDynamicTopo)
					     bSampleInterpolate = true;
				     else if(meshVel && meshVel->size() == vArray.size())
					     bVelInterpolate = true;
                  }
			  }
			  else
			  {
				  AbcG::ISubDSchema::Sample subDSample2;
				  objSubD.getSchema().get(subDSample2,sampleInfo.ceilIndex);
{'fraction_non_alphanumeric': 0.13099119660906422, 'fraction_numerical': 0.006765568959895663, 'mean_word_length': 3.5390307066222717, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480545', 'n_tokens_mistral': 4653, 'n_tokens_neox': 4245, 'n_words': 605}