Пример #1
0
bool KRBundle::save(KRDataBlock &data) {
    if(m_pData->getSize() > KRENGINE_KRBUNDLE_HEADER_SIZE * 2) {
        // Only output krbundles that contain files
        data.append(*m_pData);
    }
    return true;
}
Пример #2
0
bool KRAnimation::save(KRDataBlock &data) {
    tinyxml2::XMLDocument doc;
    tinyxml2::XMLElement *animation_node =  doc.NewElement( "animation" );
    doc.InsertEndChild(animation_node);
    animation_node->SetAttribute("loop", m_loop ? "true" : "false");
    animation_node->SetAttribute("auto_play", m_auto_play ? "true" : "false");
    animation_node->SetAttribute("duration", m_duration);
    animation_node->SetAttribute("start_time", m_start_time);
    
    for(unordered_map<std::string, KRAnimationLayer *>::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){
        (*itr).second->saveXML(animation_node);
    }
    
    tinyxml2::XMLPrinter p;
    doc.Print(&p);
    data.append((void *)p.CStr(), strlen(p.CStr())+1);
    
    return true;
}
Пример #3
0
bool KRMaterial::save(KRDataBlock &data) {
    std::stringstream stream;
    stream.precision(std::numeric_limits<long double>::digits10);
    stream.setf(std::ios::fixed,std::ios::floatfield);
    
    stream << "newmtl " << m_name;
    stream << "\nka " << m_ambientColor.x << " " << m_ambientColor.y << " " << m_ambientColor.z;
    stream << "\nkd " << m_diffuseColor.x << " " << m_diffuseColor.y << " " << m_diffuseColor.z;
    stream << "\nks " << m_specularColor.x << " " << m_specularColor.y << " " << m_specularColor.z;
    stream << "\nkr " << m_reflectionColor.x << " " << m_reflectionColor.y << " " << m_reflectionColor.z;
    stream << "\nTr " << m_tr;
    stream << "\nNs " << m_ns;
    if(m_ambientMap.size()) {
        stream << "\nmap_Ka " << m_ambientMap << ".pvr -s " << m_ambientMapScale.x << " " << m_ambientMapScale.y << " -o " << m_ambientMapOffset.x << " " << m_ambientMapOffset.y;
    } else {
        stream << "\n# map_Ka filename.pvr -s 1.0 1.0 -o 0.0 0.0";
    }
    if(m_diffuseMap.size()) {
        stream << "\nmap_Kd " << m_diffuseMap << ".pvr -s " << m_diffuseMapScale.x << " " << m_diffuseMapScale.y << " -o " << m_diffuseMapOffset.x << " " << m_diffuseMapOffset.y;
    } else {
        stream << "\n# map_Kd filename.pvr -s 1.0 1.0 -o 0.0 0.0";
    }
    if(m_specularMap.size()) {
        stream << "\nmap_Ks " << m_specularMap << ".pvr -s " << m_specularMapScale.x << " " << m_specularMapScale.y << " -o " << m_specularMapOffset.x << " " << m_specularMapOffset.y << "\n";
    } else {
        stream << "\n# map_Ks filename.pvr -s 1.0 1.0 -o 0.0 0.0";
    }
    if(m_normalMap.size()) {
        stream << "\nmap_Normal " << m_normalMap << ".pvr -s " << m_normalMapScale.x << " " << m_normalMapScale.y << " -o " << m_normalMapOffset.x << " " << m_normalMapOffset.y;
    } else {
        stream << "\n# map_Normal filename.pvr -s 1.0 1.0 -o 0.0 0.0";
    }
    if(m_reflectionMap.size()) {
        stream << "\nmap_Reflection " << m_reflectionMap << ".pvr -s " << m_reflectionMapScale.x << " " << m_reflectionMapScale.y << " -o " << m_reflectionMapOffset.x << " " << m_reflectionMapOffset.y;
    } else {
        stream << "\n# map_Reflection filename.pvr -s 1.0 1.0 -o 0.0 0.0";
    }
    if(m_reflectionCube.size()) {
        stream << "\nmap_ReflectionCube " << m_reflectionCube << ".pvr";
    } else {
        stream << "\n# map_ReflectionCube cubemapname";
    }
    switch(m_alpha_mode) {
        case KRMATERIAL_ALPHA_MODE_OPAQUE:
            stream << "\nalpha_mode opaque";
            break;
        case KRMATERIAL_ALPHA_MODE_TEST:
            stream << "\nalpha_mode test";
            break;
        case KRMATERIAL_ALPHA_MODE_BLENDONESIDE:
            stream << "\nalpha_mode blendoneside";
            break;
        case KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE:
            stream << "\nalpha_mode blendtwoside";
            break;
    }
    stream << "\n# alpha_mode opaque, test, blendoneside, or blendtwoside";
    
    stream << "\n";
    data.append(stream.str());

    return true;
}