Exemplo n.º 1
0
void RenderUpdateSystem::UpdateActiveIndexes(Entity *entity, RenderObject *object)
{
    Entity *parent;
    
    // search effective lod index
    parent = entity;
    while(NULL != parent)
    {
        LodComponent *lc = GetLodComponent(parent);
        if(NULL != lc)
        {
            object->SetLodIndex(lc->currentLod);
            break;
        }

        parent = parent->GetParent();
    }

    // search effective switch index
    parent = entity;
    while(NULL != parent)
    {
        SwitchComponent *sc = GetSwitchComponent(parent);
        if(NULL != sc)
        {
            object->SetSwitchIndex(sc->GetSwitchIndex());
            break;
        }

        parent = parent->GetParent();
    }
}
Exemplo n.º 2
0
QIcon SceneTreeItemEntity::ItemIcon() const
{
	static QIcon effectIcon(":/QtIcons/effect.png");
	static QIcon emitterIcon(":/QtIcons/emitter_particle.png");
	static QIcon renderobjIcon(":/QtIcons/render_object.png");
	static QIcon lodobjIcon(":/QtIcons/lod_object.png");
	static QIcon userobjIcon(":/QtIcons/user_object.png");
	static QIcon landscapeIcon(":/QtIcons/heightmapeditor.png");
	static QIcon cameraIcon(":/QtIcons/camera.png");
	static QIcon lightIcon(":/QtIcons/light.png");
	static QIcon shadowIcon(":/QtIcons/shadow.png");
	static QIcon switchIcon(":/QtIcons/switch.png");

	QIcon ret;

	if(NULL != entity)
	{
		if(NULL != DAVA::GetEmitter(entity))
		{
			ret = emitterIcon;
		}
		else if(NULL != DAVA::GetEffectComponent(entity))
		{
			ret = effectIcon;
		}
		else if(NULL != DAVA::GetLandscape(entity))
		{
			ret = landscapeIcon;
		}
		else if(NULL != GetLodComponent(entity))
		{
			ret = lodobjIcon;
		}
		else if(NULL != GetSwitchComponent(entity))
		{
			ret = switchIcon;
		}
		else if(NULL != DAVA::GetRenderObject(entity))
		{
			if(ConvertToShadowCommand::IsEntityWithShadowVolume(entity))
			{
				ret = shadowIcon;
			}
			else
			{
				ret = renderobjIcon;
			}
		}
		else if(NULL != entity->GetComponent(DAVA::Component::USER_COMPONENT))
		{
			ret = userobjIcon;
		}
		else if(NULL != DAVA::GetCamera(entity))
		{
			ret = cameraIcon;
		}
		else if(NULL != DAVA::GetLight(entity))
		{
			ret = lightIcon;
		}
	}

	if(ret.isNull())
	{
		ret = SceneTreeItem::ItemIcon();
	}

	return ret;
}
bool SwitchToRenerObjectConverter::MergeSwitch(Entity * entity)
{
    Vector<Entity*> entitiesToRemove;

    SwitchComponent * sw = GetSwitchComponent(entity);
    if(sw)
    {
        RenderComponent * rc = GetRenderComponent(entity);
        RenderObject * ro = 0;
        if(!rc)
        {
            ro = new Mesh();
            rc = new RenderComponent(ro);
            ro->Release();

            ro->SetAABBox(AABBox3(Vector3(0, 0, 0), Vector3(0, 0, 0)));
            entity->AddComponent(rc);
        }
        else
        {
            ro = rc->GetRenderObject();
        }

        DVASSERT(ro);

        int32 size = entity->GetChildrenCount();
        for(int32 i = 0; i < size; ++i)
        {
            Entity * sourceEntity = entity->GetChild(i);
            RenderObject * sourceRenderObject = GetRenderObject(sourceEntity);

            //workaround for custom properties for crashed model
            if(1 == i) // crash model
            {
                KeyedArchive *childProps = GetCustomPropertiesArchieve(sourceEntity);
                if(childProps && childProps->IsKeyExists("CollisionType"))
                {
                    KeyedArchive *entityProps = GetOrCreateCustomProperties(entity)->GetArchive();
                    entityProps->SetInt32("CollisionTypeCrashed", childProps->GetInt32("CollisionType", 0));
                }
            }
            //end of custom properties

            Vector<std::pair<Entity*, RenderObject*> > renderPairs;
            if(sourceRenderObject)
            {
                renderPairs.push_back(std::make_pair(sourceEntity, sourceRenderObject));
            }
            else
            {
                FindRenderObjectsRecursive(sourceEntity, renderPairs);
                DVASSERT(renderPairs.size() == 1);
                sourceRenderObject = renderPairs[0].second;
            }

            if(sourceRenderObject)
            {
                TransformComponent * sourceTransform = GetTransformComponent(sourceEntity);
                if (sourceTransform->GetLocalTransform() != Matrix4::IDENTITY)
                {
                    PolygonGroup * pg = sourceRenderObject->GetRenderBatchCount() > 0 ? sourceRenderObject->GetRenderBatch(0)->GetPolygonGroup() : 0;
                    if(pg && bakedPolygonGroups.end() == bakedPolygonGroups.find(pg))
                    {
                        sourceRenderObject->BakeGeometry(sourceTransform->GetLocalTransform());
                        bakedPolygonGroups.insert(pg);
                    }
                }

                uint32 sourceSize = sourceRenderObject->GetRenderBatchCount();
                while(sourceSize)
                {
                    int32 lodIndex, switchIndex;
                    RenderBatch * sourceRenderBatch = sourceRenderObject->GetRenderBatch(0, lodIndex, switchIndex);
                    sourceRenderBatch->Retain();
                    sourceRenderObject->RemoveRenderBatch(sourceRenderBatch);
                    ro->AddRenderBatch(sourceRenderBatch, lodIndex, i);
                    sourceRenderBatch->Release();
                    sourceSize--;
                }
            }

            renderPairs[0].first->RemoveComponent(Component::RENDER_COMPONENT);

            LodComponent * lc = GetLodComponent(sourceEntity);
            if((0 != lc) && (0 == GetLodComponent(entity)))
            {
                LodComponent * newLod = (LodComponent*)lc->Clone(entity);
                entity->AddComponent(newLod);
            }

            renderPairs[0].first->RemoveComponent(Component::LOD_COMPONENT);

            if(sourceEntity->GetChildrenCount() == 0)
            {
                entitiesToRemove.push_back(sourceEntity);
            }
        }
    }

    uint32 entitiesToRemoveCount = entitiesToRemove.size();
    for(uint32 i = 0; i < entitiesToRemoveCount; ++i)
    {
        entitiesToRemove[i]->GetParent()->RemoveNode(entitiesToRemove[i]);
    }

    return false;
}