Assumption: My models contain only ComponentInstances.
My Approach:
- Get the models of each of the file, say m1,m2 (using
SUModelCreateFromFile
).
- Get entities of m1 and m2, say e1,e2 (using
SUModelGetEntities
).
- Get ComponentInstances from e2 (using
SUEntitiesGetInstances
).
- In a loop add each of the ComponentInstance of e2 into e1 (using
SUEntitiesAddInstance
).
- Write the model m1(with entities e1) to a new file.
//The new file contains the ComponentInstances of m1,m2.
Where I am stuck?
In the below code.
On a high level the below program does three things
- It gets the Model from file.
- From Model it gets Entities.
- From Entitites it gets ComponentInstances. Here it fails.
#include <slapi/slapi.h>
#include <slapi/geometry.h>
#include <slapi/initialize.h>
#include <slapi/model/model.h>
#include <slapi/model/entities.h>
#include <slapi/model/face.h>
#include <slapi/model/edge.h>
#include <slapi/model/vertex.h>
#include <vector>
#include <iostream>
#include <stdio.h>
int main() {
// Always initialize the API before using it
SUInitialize();
// Load the model from a file
SUModelRef model_to_write1 = SU_INVALID;
SUResult m1 = SUModelCreateFromFile(&model_to_write1, "model11.skp");
if(m1 == SU_ERROR_NONE)
std;;cout<<"SUModelCreateFromFile SUCCESS!!!!!";
else if(m1 == SU_ERROR_NULL_POINTER_INPUT)
std;;cout<<"Error_Entities -- Inside 1 file are";
else if(m1 == SU_ERROR_NULL_POINTER_OUTPUT)
std;;cout<<"NULLPOINTER_Entities -- Inside 1 file are";
else
printf("None of the above");
SUEntitiesRef entities1 = SU_INVALID;
size_t* size1 = NULL;
SUComponentInstanceRef comp1[10];
SUResult result = SUModelGetEntities(model_to_write1, &entities1);
if(result == SU_ERROR_NONE)
std;;cout<<"\n SUModelGetEntities SUCCESS !!!!!";
if(result == SU_ERROR_INVALID_INPUT)
std;;cout<<"Error_Entities Inside 1 file are";
if(result == SU_ERROR_NULL_POINTER_OUTPUT)
std;;cout<<"NULLPOINTER_Entities Inside 1 file are";
result = SUEntitiesGetInstances(entities1,2,comp1,size1);
if(result == SU_ERROR_NONE)
std;;cout<<"\n SUEntitiesGetInstances SUCCESS";
else if(result == SU_ERROR_INVALID_INPUT)
std;;cout<<"\n Error_Copy";
else if(result == SU_ERROR_NULL_POINTER_OUTPUT)
std;;cout<<"\n NULLPOINTER";
// Save the in-memory model to a file
SUModelSaveToFile(model_to_write1, "very_new_model.skp");
SUTerminate();
getchar();
return 0;
}
Output:
SUModelCreateFromFile SUCCESS!!!!!
SUModelGetEntities SUCCESS !!!!!
NULLPOINTER
Questions:
- In the above output I am getting NULLPOINTER(3rd line) which is the result of call
SUEntitiesGetInstances(entities1,2,comp1,size1)
in the above program. Why I am not able to get the ComponentInstances?
- Can you please review the approach which is mentioned at the beginning and let me know if is it right?
model11.skp