void RecursiveProcessLodNode(Entity * curr, int32 lod, void * userData, void(*process)(Entity*, void*))
{
	LodComponent * lodComp = (LodComponent*)curr->GetComponent(Component::LOD_COMPONENT);
	if (lodComp)
	{
		Vector<LodComponent::LodData*> retLodLayers;
		lodComp->GetLodData(retLodLayers);
		for (Vector<LodComponent::LodData*>::iterator it = retLodLayers.begin(); it != retLodLayers.end(); ++it)
		{
			LodComponent::LodData * data = *it;
			if (data->layer == lod)
			{
				for (Vector<Entity*>::iterator i = data->nodes.begin(); i != data->nodes.end(); ++i)
				{
					process((*i), userData);
				}
				break;
			}
		}
	}
	else
	{
		for (int32 i = 0; i < curr->GetChildrenCount(); i++)
			RecursiveProcessLodNode(curr->GetChild(i), lod, userData, process);
	}
}
示例#2
0
void LodNodePropertyControl::ReadFrom(Entity * sceneNode)
{
	NodesPropertyControl::ReadFrom(sceneNode);

    LodComponent *lodComponent = GetLodComponent(sceneNode);
	DVASSERT(lodComponent);

    propertyList->AddSection("property.lodnode", GetHeaderState("property.lodnode", true));
    
    propertyList->AddBoolProperty("property.lodnode.forcedistance");
    propertyList->SetBoolPropertyValue("property.lodnode.forcedistance", false);
    propertyList->AddSliderProperty("property.lodnode.distanceslider", false);
    propertyList->SetSliderPropertyValue("property.lodnode.distanceslider", 0, LodComponent::MAX_LOD_DISTANCE, LodComponent::MIN_LOD_DISTANCE);

    int32 lodCount = lodComponent->GetLodLayersCount();
    if(1 < lodCount)
    {
        propertyList->AddDistanceProperty("property.lodnode.distances");
        float32 *distances = new float32[lodComponent->GetLodLayersCount()];
        int32 *triangles = new int32[lodComponent->GetLodLayersCount()];
        
        
        Vector<LodComponent::LodData*> lodLayers;
        lodComponent->GetLodData(lodLayers);
        
        Vector<LodComponent::LodData*>::const_iterator lodLayerIt = lodLayers.begin();
        for(int32 i = 0; i < lodComponent->GetLodLayersCount(); ++i)
        {
            distances[i] = lodComponent->GetLodLayerDistance(i);
            
            LodComponent::LodData *layer = *lodLayerIt;
            triangles[i] = GetTrianglesForLodLayer(layer);

            ++lodLayerIt;
        }
        
        propertyList->SetDistancePropertyValue("property.lodnode.distances", distances, triangles, lodComponent->GetLodLayersCount());
        
        
        SafeDeleteArray(distances);
        SafeDeleteArray(triangles);
    }
}
void SceneValidator::ValidateLodComponent(Entity *ownerNode, Set<String> &errorsLog)
{
    LodComponent *lodComponent = GetLodComponent(ownerNode);
    if(!lodComponent) return;

    int32 layersCount = lodComponent->GetLodLayersCount();
	if (GetEmitter(ownerNode))
		layersCount = LodComponent::MAX_LOD_LAYERS;
    
    if(layersCount == 0)
    {
        errorsLog.insert(Format("Node %s: Count of layers is 0", ownerNode->GetName().c_str()));
    }
    
    for(int32 layer = 0; layer < layersCount; ++layer)
    {
        float32 distance = lodComponent->GetLodLayerDistance(layer);
        if(LodComponent::INVALID_DISTANCE == distance)
        {
            //TODO: why this function isn't realized for lodcomponent?
            lodComponent->SetLodLayerDistance(layer, LodComponent::GetDefaultDistance(layer));
            errorsLog.insert(Format("Node %s: lod distances weren't correct. Re-save.", ownerNode->GetName().c_str()));
        }
    }
    
    Vector<LodComponent::LodData *>lodLayers;
    lodComponent->GetLodData(lodLayers);
    
    Vector<LodComponent::LodData *>::const_iterator endIt = lodLayers.end();
    int32 layer = 0;
    for(Vector<LodComponent::LodData *>::iterator it = lodLayers.begin(); it != endIt; ++it, ++layer)
    {
        LodComponent::LodData * ld = *it;
        
        if(ld->layer != layer)
        {
            ld->layer = layer;
            errorsLog.insert(Format("Node %s: lod layers weren't correct. Rename childs. Re-save.", ownerNode->GetName().c_str()));
        }
    }
}