示例#1
0
void ModelWriter::visitFaces(SUEntitiesRef ents, VisitorFunc func, bool recursive, Transform transform)
{
	size_t count =0;
	SUEntitiesGetNumFaces(ents,&count);

	vector<SUFaceRef> faces(count);
	SUEntitiesGetFaces(ents,count,faces.data(),&count);

	for(int i=0; i < count; i++){
		(*this.*func)(faces[i], transform);
	}

	SUEntitiesGetNumGroups(ents,&count);
	vector<SUGroupRef> groups(count);
	SUEntitiesGetGroups(ents,count,groups.data(),&count);


	for(int i=0; i < count; i++){
		SUEntitiesRef ents2 = SU_INVALID;
		SUGroupGetEntities(groups[i],&ents2);

		Transform t;
		SUGroupGetTransform(groups[i], (SUTransformation*)&t);
		visitFaces(ents2,func,true, transform * t);
	}

	if(recursive) {
		
		SUEntitiesGetNumInstances(ents,&count);
		vector<SUComponentInstanceRef> instances(count);
		SUEntitiesGetInstances(ents,count,instances.data(),&count);
	
		for(int i=0; i < count; i++){
			
			Transform t;
			SUComponentDefinitionRef def = SU_INVALID;
			SUEntitiesRef ents2 = SU_INVALID;

			SUComponentInstanceGetTransform(instances[i],(SUTransformation*)&t);
			SUComponentInstanceGetDefinition(instances[i],&def);
			SUComponentDefinitionGetEntities(def,&ents2);

			visitFaces(ents2,func,true, transform * t);
		}
	}
}
示例#2
0
int SkpModel::LoadEntitiesRecursive(SUEntitiesRef entities){

	int out = 0;

	//Get Entities from Instances
	size_t instanceCount;
  SUResult res =  SUEntitiesGetNumInstances(entities, &instanceCount);
  if (res != SU_ERROR_NONE)
    return 1;

	if (instanceCount > 0) {
		std::vector<SUComponentInstanceRef> instances(instanceCount);
		std::vector<SUEntitiesRef> entities2(instanceCount);
		SUEntitiesGetInstances(entities, instanceCount,
													 &instances[0], &instanceCount);
		out += Instances2Entities(&instances, &entities2);

		for (size_t i = 0; i < instanceCount; i++) {
			entities_.push_back(entities2[i]);
			LoadEntitiesRecursive(entities2[i]);	
		}
	}

	//Get Entities from groups
	size_t groupCount = 0;
	res =  SUEntitiesGetNumGroups(entities, &groupCount);
  if (res != SU_ERROR_NONE)
    return 1;

	if (groupCount > 0){
		std::vector<SUGroupRef> groups(groupCount);
		std::vector<SUEntitiesRef> entities2(groupCount);
		SUEntitiesGetGroups(entities, groupCount, &groups[0], &groupCount);
		out += Groups2Entities(&groups, &entities2);
		for (size_t i=0; i < groupCount; i++){
			entities_.push_back(entities2[i]);
			LoadEntitiesRecursive(entities2[i]);	
		}
	}

	return out;
}
示例#3
0
int SkpModel::Entities2AllComponentCount(SUEntitiesRef entities){

	int out = 0;	
	if (SUIsInvalid(entities))
		return 1;
	
	size_t instanceCount = 0;
  SUResult res =  SUEntitiesGetNumInstances(entities, &instanceCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementInstances(instanceCount);

  /*	
	if (instanceCount > 0) {
		std::vector<SUComponentInstanceRef> instances(instanceCount);
		std::vector<SUEntitiesRef> entities2(instanceCount);
		SUEntitiesGetInstances(entities, instanceCount,
													 &instances[0], &instanceCount);
		out += Instances2Entities(&instances, &entities2);

		for (size_t i = 0; i < instanceCount; i++) {
			out += count_all_components_entities(entities2[i]);
		}
	}
	*/

	size_t groupCount = 0;
	res =  SUEntitiesGetNumGroups(entities, &groupCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementGroups(groupCount); 

	/*
	if (groupCount > 0){
		std::vector<SUGroupRef> groups(groupCount);
		std::vector<SUEntitiesRef> entities2(groupCount);
		SUEntitiesGetGroups(entities, groupCount, &groups[0], &groupCount);
		out += Groups2Entities(&groups, &entities2);
		for (size_t i=0; i < groupCount; i++){
			out += count_all_components_entities(entities2[i]);
		}
	}
	*/

	size_t edgeCount = 0;
	res = SUEntitiesGetNumEdges(entities, true,	&edgeCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementEdges(edgeCount);

	size_t guideCount = 0;
	res =  SUEntitiesGetNumGuidePoints(entities, &guideCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementGuides(guideCount);

	size_t curveCount = 0;
	res =  SUEntitiesGetNumCurves(entities, &curveCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementCurves(curveCount);

	size_t imCount = 0;
	res =  SUEntitiesGetNumImages(entities, &imCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementImages(imCount);

  size_t faceCount = 0;
  res = SUEntitiesGetNumFaces(entities, &faceCount);
  if (res != SU_ERROR_NONE)
    return 1;
	IncrementFaces(faceCount);

	return out;	
	
}