Beispiel #1
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance Core::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
    {
        unsigned int childElementHash = hashString(childElement->Value());
        if (childElementHash == Material::m_hash)
        {
            const tinyxml2::XMLAttribute* nameAttribute = childElement->FindAttribute("name"); //This material needs a name to distinguish between normal and glowing versions of the material
            if (nameAttribute)
            {
                if (strICmp(nameAttribute->Value(), "CoreMaterialNormal"))
                {
                    m_forcefieldmatnormal.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString("cube_player_forcefield"), Material::TextureSlotMapping::Diffuse0));
                }
                else if( strICmp(nameAttribute->Value(), "CoreMaterialNormalGlow") )
                {
                    m_forcefieldmatglowing.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                }
            }
        }
        else if (childElementHash == hashString("Model"))
        {
            attribute = childElement->FindAttribute("file_name");
            if (attribute != nullptr)
            {
                //Heavily relies on the shader instance existing before we load the model, might be better to put the model construction in initialise instead
                m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, attribute->Value());
                m_drawableObject->setDirty();
            }
        }
    }

    //Get texture strings and load textures
    const SettingsManager& sm = getGameResource().getSettingsManager();
    TextureManager& tm = getWriteableGameResource().getTextureManager();
    const ISetting<std::string>* textureString = sm.getSetting<std::string>("Core");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }
    textureString = sm.getSetting<std::string>("ForceFieldCore");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }

    return shaderInstance;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
//! @brief   Deserialise a material from an xml node
//! @remark
//-----------------------------------------------------------------------------
void MaterialSetting::deserialise( const tinyxml2::XMLElement* element)
{
    DeserialisableSetting::deserialise(element);

    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement() )
    {
        if (strICmp(childElement->Value(), "Color") == 0)
        {
            Color color;
            for (const tinyxml2::XMLAttribute* attribute = childElement->FirstAttribute(); attribute; attribute = attribute->Next())
            {
                if ( strICmp(attribute->Name(), "r") == 0 )
                {
                    color.setRed((float)attribute->DoubleValue());
                }
                else if ( strICmp(attribute->Name(), "g") == 0 )
                {
                    color.setGreen((float)attribute->DoubleValue());
                }
                else if ( strICmp(attribute->Name(), "b") == 0 )
                {
                    color.setBlue((float)attribute->DoubleValue());
                }
                else if ( strICmp(attribute->Name(), "a") == 0 )
                {
                    color.setAlpha((float)attribute->DoubleValue());
                }
            }

            const char* materialPart = childElement->Attribute("material_part");
            if (strICmp(materialPart, "ambient"))
            {
                m_material.setAmbient(color);
            }
            else if (strICmp(materialPart, "diffuse"))
            {
                m_material.setDiffuse(color);
            }
            else if (strICmp(materialPart, "specular"))
            {
                m_material.setSpecular(color);
            }
            else if (strICmp(materialPart, "emissive"))
            {
                m_material.setEmissive(color);
            }
        }
        else if (strICmp(childElement->Value(), "Shininess") == 0)
        {
            //Deserialise the single float value of the material here
            m_material.setShininess(strTofloat(childElement->GetText()));
        }
    }
}
Beispiel #3
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance GunTurret::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    Matrix44 scaleTransform, translation, rotation;
    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
    {
        unsigned int childElementHash = hashString(childElement->Value());
        if (childElementHash == Vector3::m_hash)
        {
            const tinyxml2::XMLAttribute* nameAttribute = childElement->FindAttribute("name"); //This material needs a name to distinguish between normal and glowing versions of the material
            if (nameAttribute)
            {
                if (strICmp(nameAttribute->Value(), "position"))
                {
                    m_position.deserialise(childElement);
                    
                    scale(scaleTransform, 5.0f, 5.0f, 5.0f);
                    translate(translation, m_position);  
                }
                else if( strICmp(nameAttribute->Value(), "direction") )
                {
                    m_direction.deserialise(childElement);
                    m_direction.normalize();
                    rotation = rotationFromDirection(m_direction);
                }
            }
        }
        if (childElementHash == hashString("Model"))
        {
            attribute = childElement->FindAttribute("file");
            if (attribute != nullptr)
            {
                //Heavily relies on the shader instance existing before we load the model, might be better to put the model construction in initialise instead
                m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, attribute->Value());
                m_drawableObject->setDirty();
            }
        }
        if (childElementHash == Material::m_hash)
        {
            shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement );
        }
    }

    m_world = rotation * scaleTransform * translation;

    return shaderInstance;
}
Beispiel #4
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void RenderSetting::deserialise( const tinyxml2::XMLElement* element)
{
    DeserialisableSetting::deserialise(element);

    for (const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); attribute; attribute = attribute->Next())
    {
        if (strICmp(attribute->Name(), "use_cg") == 0)
        {
            m_useCG = attribute->BoolValue();
        }
        else if (strICmp(attribute->Name(), "renderer") == 0)
        {
            m_rendererType = (RendererType)attribute->IntValue();
        }
    }

    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement() )
    {
        if (strICmp(childElement->Value(), "WindowSettings") == 0)
        {
            for (const tinyxml2::XMLAttribute* attribute = childElement->FirstAttribute(); attribute; attribute = attribute->Next())
            {
                if (strICmp(attribute->Name(), "width") == 0)
                {
                    m_resolutionWidth = attribute->IntValue();
                }
                else if (strICmp(attribute->Name(), "height") == 0)
                {
                    m_resolutionHeight = (RendererType)attribute->IntValue();
                }
                else if (strICmp(attribute->Name(), "window_name") == 0)
                {
                    m_windowName = attribute->Value();
                }
            }
        }
    }
}