How to connect geometry data with object definitions/instances

Basically I have groups sharing the same vertex buffer and index buffer and some local transformations. All of the groups create a component definition.

Then separately I want to create instances of each object with some additional transformations. That would be the component instance.

How can I map all of this into actual code?

I’ve read about SUComponentDefinitionRef and SUComponentInstanceRef and SUGeometryInputRef and SUEntitiesRef and SUGroupRef - I just don’t know how to put them into actual code.

I’ve came a long way since and I’m currently creating an array of SUComponentInstanceRef using SUComponentDefinitionCreate. Then I’m obtaining the definition entities using SUComponentDefinitionGetEntities. After that I’m creating geometry and then SUEntitiesFill. Next I’m creating instances using SUComponentDefinitionCreateInstance of specific objects with transformation. Then I’m adding this to the entity from the component definition which the instance was created from. But it seems I’m doing something wrong since when I import the object in sketchup it says it is empty. Every method is being checked for SU_ERROR_NONE (with assert) so that is obviously not the problem. I feel like the problem is only the definitions get added and no actual geometry gets included.

What I feel like right now is that I need somehow to add multiple geometry inputs to the model entities since they are the only ones that get registered. I have no idea how to get SUComponentDefinitionGetEntities to work.

Hey! Do you solved a problem?
I want to create CopmponentDefinition, with some geometry, that I have created with SUFaceDef, but it definetly doesn’t work.
My variable “component” still empty.
variable “comp_len” = 0.

What am I doing wrong?

SUModelRef model = SU_INVALID;
SUResult res = SUModelCreate(&model);

SUEntitiesRef entities = SU_INVALID;
SUModelGetEntities(model, &entities);

SULoopInputRef outer_loop = SU_INVALID;
SULoopInputCreate(&outer_loop);

for (size_t i = 0; i < 4; ++i) {
	SULoopInputAddVertexIndex(outer_loop, i);
}

SUFaceRef face = SU_INVALID;
SUPoint3D vertices[4] = { { 0,   0,   0 },
					  { 100, 100, 0 },
					  { 100, 100, 100 },
					  { 0,   0,   100 }, };
SUFaceCreate(&face, vertices, &outer_loop);
	
SUComponentDefinitionRef component = SU_INVALID;
SUComponentDefinitionCreate(&component);
SUComponentDefinitionSetName(component, "name");
	
SUEntityRef MyEntity = SU_INVALID;
MyEntity = SUFaceToEntity(face);
component = SUComponentDefinitionFromEntity(MyEntity);

SUModelAddComponentDefinitions(model, componentNum, &component);
SUModelGetNumComponentDefinitions(model, &comp_len);

There is a solution

Just to clarify for other readers, you need to add the SUComponentDefinitionRef to the model before populating it with geometry.