void MipMapReplacer::EnumerateTexturesRecursive(Entity * entity, Set<Texture *> & textures)
{
    if(!entity)
        return;

    int32 childrenCount = entity->GetChildrenCount();
    for(int32 i = 0; i < childrenCount; i++)
        EnumerateTexturesRecursive(entity->GetChild(i), textures);

    RenderObject * ro = GetRenderObject(entity);
    if(ro)
    {
        int32 rbCount = ro->GetRenderBatchCount();
        for(int32 i = 0; i < rbCount; i++)
        {
            RenderBatch * rb = ro->GetRenderBatch(i);
            if(rb)
            {
                Material * material = rb->GetMaterial();
                if(material)
                {
                    Texture * texture = material->GetTexture(Material::TEXTURE_DIFFUSE);
                    if(texture)
                        textures.insert(texture);
                }
            }
        }
    }
}
int32 NodesPropertyControl::GetTrianglesForLodLayer(LodComponent::LodData *lodData)
{
    int32 trianglesCount = 0;
    for(int32 n = 0; n < (int32)lodData->nodes.size(); ++n)
    {
        Vector<Entity *> meshes;
        lodData->nodes[n]->GetChildNodes(meshes);
        
        meshes.push_back(lodData->nodes[n]);
        
        for(int32 m = 0; m < (int32)meshes.size(); ++m)
        {
            RenderObject *ro = GetRenerObject(meshes[m]);
            if(!ro || ro->GetType() != RenderObject::TYPE_MESH) continue;

            uint32 count = ro->GetRenderBatchCount();
            for(uint32 r = 0; r < count; ++r)
            {
                RenderBatch *batch = ro->GetRenderBatch(r);
                
                PolygonGroup *pg = batch->GetPolygonGroup();
                if(pg)
                {
                    trianglesCount += pg->GetIndexCount() / 3;
                }
            }
        }
    }
    return trianglesCount;
}
void MipMapReplacer::EnumerateTexturesRecursive(Entity * entity, Set<Texture *> & textures)
{
    if(!entity)
        return;

    int32 childrenCount = entity->GetChildrenCount();
    for(int32 i = 0; i < childrenCount; i++)
        EnumerateTexturesRecursive(entity->GetChild(i), textures);

    RenderObject * ro = GetRenderObject(entity);
    if(ro)
    {
        int32 rbCount = ro->GetRenderBatchCount();
        for(int32 i = 0; i < rbCount; i++)
        {
            RenderBatch * rb = ro->GetRenderBatch(i);
            if(rb)
            {
                DVASSERT(0 && "Vitaliy Borodovsky: Temporarly disabled. Need to rewrite for new materials");
                
                NMaterial * material = rb->GetMaterial();
                if(material)
                {
                    Texture * texture = material->GetTexture(NMaterial::TEXTURE_ALBEDO);
                    if(texture)
                        textures.insert(texture);
                }
            }
        }
    }
}
Beispiel #4
0
void SceneHelper::EnumerateMaterialInstances(DAVA::Entity *forNode, DAVA::Vector<DAVA::NMaterial *> &materials)
{
    uint32 childrenCount = forNode->GetChildrenCount();
    for(uint32 i = 0; i < childrenCount; ++i)
        EnumerateMaterialInstances(forNode->GetChild(i), materials);

    RenderObject * ro = GetRenderObject(forNode);
    if(!ro) return;
    
    uint32 batchCount = ro->GetRenderBatchCount();
    for(uint32 i = 0; i < batchCount; ++i)
        materials.push_back(ro->GetRenderBatch(i)->GetMaterial());

}
Beispiel #5
0
void BulletObject::CreateFromEntity()
{
	bool wasPolygonGroup = false;

	RenderObject * renderObject = ((RenderComponent*)entity->GetComponent(Component::RENDER_COMPONENT))->GetRenderObject();
	uint32 batchesCount = renderObject->GetRenderBatchCount();
	for(uint32 batchIndex = 0; batchIndex < batchesCount; ++batchIndex)
	{
		RenderBatch * batch = renderObject->GetRenderBatch(batchIndex);
		PolygonGroup * pg = batch->GetPolygonGroup();
		if(pg)
		{
			if(!wasPolygonGroup)
			{
				collisionObject = new btCollisionObject();
				trimesh = new btTriangleMesh();
				createdWith = entity->GetWorldTransform();
				wasPolygonGroup = true;
			}

			for(int32 i = 0; i < pg->indexCount / 3; i++)
			{
				uint16 index0 = pg->indexArray[i*3];
				uint16 index1 = pg->indexArray[i*3+1];
				uint16 index2 = pg->indexArray[i*3+2];
				Vector3 v;
				pg->GetCoord(index0, v);
				v = v * createdWith;
				btVector3 vertex0(v.x, v.y, v.z);
				pg->GetCoord(index1, v);
				v = v * createdWith;
				btVector3 vertex1(v.x, v.y, v.z);
				pg->GetCoord(index2, v);
				v = v * createdWith;
				btVector3 vertex2(v.x, v.y, v.z);

				trimesh->addTriangle(vertex0,vertex1,vertex2, false);
			}
		}
	}

	if(wasPolygonGroup)
	{
		shape = new btBvhTriangleMeshShape(trimesh, true, true);    
		collisionObject->setCollisionShape(shape);
		collWorld->addCollisionObject(collisionObject);
	}
}
Beispiel #6
0
void TextureHelper::EnumerateTextures(DAVA::Entity *forNode, Map<String, Texture *> &textures)
{
	if(!forNode)  return;

	Vector<Entity *> nodes;
	forNode->GetChildNodes(nodes);

	nodes.push_back(forNode);

	for(int32 n = 0; n < (int32)nodes.size(); ++n)
	{
		RenderComponent *rc = static_cast<RenderComponent *>(nodes[n]->GetComponent(Component::RENDER_COMPONENT));
		if(!rc) continue;

		RenderObject *ro = rc->GetRenderObject();
		if(!ro) continue;

		uint32 count = ro->GetRenderBatchCount();
		for(uint32 b = 0; b < count; ++b)
		{
			RenderBatch *renderBatch = ro->GetRenderBatch(b);

			NMaterial *material = renderBatch->GetMaterial();
			if(material)
			{
				for(int32 t = 0; t < material->GetTextureCount(); ++t)
				{
					Texture* tx = material->GetTexture(t);
					CollectTexture(textures, tx->GetPathname(), tx);
				}
			}

			/*InstanceMaterialState *instanceMaterial = renderBatch->GetMaterialInstance();
			if(instanceMaterial)
			{
				CollectTexture(textures, instanceMaterial->GetLightmapName(), instanceMaterial->GetLightmap());
			}*/
		}

		Landscape *land = dynamic_cast<Landscape *>(ro);
		if(land)
		{
			CollectLandscapeTextures(textures, land);
		}
	}
}
void SceneHelper::EnumerateDescriptors(DAVA::Entity *forNode, DAVA::Set<DAVA::FilePath> &descriptors)
{
	if(!forNode)  return;

	Vector<Entity *> nodes;
	forNode->GetChildNodes(nodes);

	nodes.push_back(forNode);

	for(int32 n = 0; n < (int32)nodes.size(); ++n)
	{
		RenderComponent *rc = static_cast<RenderComponent *>(nodes[n]->GetComponent(Component::RENDER_COMPONENT));
		if(!rc) continue;

		RenderObject *ro = rc->GetRenderObject();
		if(!ro) continue;

		uint32 count = ro->GetRenderBatchCount();
		for(uint32 b = 0; b < count; ++b)
		{
			RenderBatch *renderBatch = ro->GetRenderBatch(b);

			Material *material = renderBatch->GetMaterial();
			if(material)
			{
				for(int32 t = 0; t < Material::TEXTURE_COUNT; ++t)
				{
					CollectDescriptors(descriptors, material->GetTextureName((DAVA::Material::eTextureLevel)t));
				}
			}

			InstanceMaterialState *instanceMaterial = renderBatch->GetMaterialInstance();
			if(instanceMaterial)
			{
				CollectDescriptors(descriptors, instanceMaterial->GetLightmapName());
			}
		}

		Landscape *land = dynamic_cast<Landscape *>(ro);
		if(land)
		{
			CollectLandscapeDescriptors(descriptors, land);
		}
	}
}
void SceneHelper::EnumerateTextures(Entity *forNode, Map<String, Texture *> &textures)
{
	if(!forNode) return;

	Vector<Entity *> nodes;
	forNode->GetChildNodes(nodes);

	nodes.push_back(forNode);

	for(int32 n = 0; n < (int32)nodes.size(); ++n)
	{
		RenderObject *ro = GetRenderObject(nodes[n]);
		if(!ro) continue;

		uint32 count = ro->GetRenderBatchCount();
		for(uint32 b = 0; b < count; ++b)
		{
			RenderBatch *renderBatch = ro->GetRenderBatch(b);

			Material *material = renderBatch->GetMaterial();
			if(material)
			{
				for(int32 t = 0; t < Material::TEXTURE_COUNT; ++t)
				{
					CollectTexture(textures, material->GetTextureName((DAVA::Material::eTextureLevel)t).GetAbsolutePathname(), material->GetTexture((DAVA::Material::eTextureLevel)t));
				}
			}

			InstanceMaterialState *instanceMaterial = renderBatch->GetMaterialInstance();
			if(instanceMaterial)
			{
				CollectTexture(textures, instanceMaterial->GetLightmapName().GetAbsolutePathname(), instanceMaterial->GetLightmap());
			}
		}

		Landscape *land = dynamic_cast<Landscape *>(ro);
		if(land)
		{
			CollectLandscapeTextures(textures, land);
		}
	}
}
void SceneValidator::ValidateRenderComponent(Entity *ownerNode, Set<String> &errorsLog)
{
    RenderComponent *rc = static_cast<RenderComponent *>(ownerNode->GetComponent(Component::RENDER_COMPONENT));
    if(!rc) return;
    
    RenderObject *ro = rc->GetRenderObject();
    if(!ro) return;
    
    uint32 count = ro->GetRenderBatchCount();
    for(uint32 b = 0; b < count; ++b)
    {
        RenderBatch *renderBatch = ro->GetRenderBatch(b);
        ValidateRenderBatch(ownerNode, renderBatch, errorsLog);
    }
    
	if(ro->GetType() == RenderObject::TYPE_LANDSCAPE)
    {
		Landscape *landscape = static_cast<Landscape *>(ro);
        ValidateLandscape(landscape, errorsLog);

		ValidateCustomColorsTexture(ownerNode, errorsLog);
    }
}
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;
}