예제 #1
0
    //---------------------------------------------------------------------
    bool SubMesh::updateMaterialUsingTextureAliases(void)
    {
        bool newMaterialCreated = false;
        // if submesh has texture aliases
        // ask the material manager if the current summesh material exists
        if (hasTextureAliases() && MaterialManager::getSingleton().resourceExists(mMaterialName))
        {
            // get the current submesh material
            MaterialPtr material = MaterialManager::getSingleton().getByName( mMaterialName );
            // get test result for if change will occur when the texture aliases are applied
            if (material->applyTextureAliases(mTextureAliases, false))
            {
                Ogre::String newMaterialName;

                // If this material was already derived from another material
                // due to aliasing, let's strip off the aliasing suffix and
                // generate a new one using our current aliasing table.

                Ogre::String::size_type pos = mMaterialName.find("?TexAlias(", 0);
                if( pos != Ogre::String::npos )
                    newMaterialName = mMaterialName.substr(0, pos);
                else
                    newMaterialName = mMaterialName;

                newMaterialName += "?TexAlias(";
                // Iterate deterministically over the aliases (always in the same
                // order via std::map's sorted iteration nature).
                AliasTextureIterator aliasIter = getAliasTextureIterator();
                while( aliasIter.hasMoreElements() )
                {
                    newMaterialName += aliasIter.peekNextKey();
                    newMaterialName += "=";
                    newMaterialName += aliasIter.getNext();
                    newMaterialName += " ";
                }
                newMaterialName += ")";
                    
                // Reuse the material if it's already been created. This decreases batch
                // count and keeps material explosion under control.
                if(!MaterialManager::getSingleton().resourceExists(newMaterialName))
                {
                    Ogre::MaterialPtr newMaterial = Ogre::MaterialManager::getSingleton().create(
                        newMaterialName, material->getGroup());
                    // copy parent material details to new material
                    material->copyDetailsTo(newMaterial);
                    // apply texture aliases to new material
                    newMaterial->applyTextureAliases(mTextureAliases);
                }
                // place new material name in submesh
                setMaterialName(newMaterialName);
                newMaterialCreated = true;
            }
        }

        return newMaterialCreated;
    }
void PlaneNodeProcessor::createRenderToTextures(Ogre::Entity* entity, Plane* plane, MaterialPtr material, XERCES_CPP_NAMESPACE::DOMElement* rttElem)
{
    if(rttElem == NULL)
        return;

    Camera* cam = CoreSubsystem::getSingleton().getWorld()->getSceneManager()->createCamera("Cam" + entity->getName());
    cam->setNearClipDistance(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getNearClipDistance());
    cam->setFarClipDistance(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getFarClipDistance());
    //cam->setFarClipDistance(1000000);
    cam->setAspectRatio(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getAspectRatio());
    cam->setFOVy(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getFOVy());

    AliasTextureNamePairList aliases;

    if(getAttributeValueAsBool(rttElem, "reflection"))
    {
        TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "Reflection" + entity->getName(),
                             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
                             512, 512, 0, PF_R8G8B8, TU_RENDERTARGET );
        RenderTexture* rttTex = texture->getBuffer()->getRenderTarget();

        Viewport *v = rttTex->addViewport( cam );
        v->setOverlaysEnabled(false);
        rttTex->addListener(new PlaneReflectionTextureListener(entity, cam, plane));

        aliases["reflection"] = "Reflection" + entity->getName();

        cam->enableCustomNearClipPlane((MovablePlane*)plane);
    }
    if(getAttributeValueAsBool(rttElem, "refraction"))
    {
        TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "Refraction" + entity->getName(),
                             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
                             512, 512, 0, PF_R8G8B8, TU_RENDERTARGET );
        RenderTexture* rttTex = texture->getBuffer()->getRenderTarget();

        Viewport *v = rttTex->addViewport( cam);
        v->setOverlaysEnabled(false);
        rttTex->addListener(new PlaneRefractionTextureListener(entity, cam));

        aliases["refraction"] = "Refraction" + entity->getName();

        plane->normal = Vector3::NEGATIVE_UNIT_Y;
        cam->enableCustomNearClipPlane((MovablePlane*)plane);
    }
    if(!material->applyTextureAliases(aliases))
        LOG_ERROR("PLANE", "Texture Aliase konnten nicht angewandt werden");
}
예제 #3
0
    //---------------------------------------------------------------------
    bool SubMesh::updateMaterialUsingTextureAliases(void)
    {
        bool newMaterialCreated = false;
        // if submesh has texture aliases
        // ask the material manager if the current summesh material exists
        if (hasTextureAliases() && MaterialManager::getSingleton().resourceExists(mMaterialName))
        {
            // get the current submesh material
            MaterialPtr material = MaterialManager::getSingleton().getByName( mMaterialName );
            // get test result for if change will occur when the texture aliases are applied
            if (material->applyTextureAliases(mTextureAliases, false))
            {
                // material textures will be changed so copy material,
                // new material name is old material name + index
                // check with material manager and find a unique name
                size_t index = 0;
                String newMaterialName = mMaterialName + "_" + StringConverter::toString(index);
                while (MaterialManager::getSingleton().resourceExists(newMaterialName))
                {
                    // increment index for next name
                    newMaterialName = mMaterialName + "_" + StringConverter::toString(++index);
                }

                Ogre::MaterialPtr newMaterial = Ogre::MaterialManager::getSingleton().create(
                    newMaterialName, material->getGroup());
                // copy parent material details to new material
                material->copyDetailsTo(newMaterial);
                // apply texture aliases to new material
                newMaterial->applyTextureAliases(mTextureAliases);
                // place new material name in submesh
                setMaterialName(newMaterialName);
                newMaterialCreated = true;
            }
        }

        return newMaterialCreated;
    }