예제 #1
0
shared_ptr<SpriteSheet> SpriteSheet::create(const Any& a, Table<ModelID, shared_ptr<Model> >& modelTable) {
    a.verifyName("SpriteSheet");

    const shared_ptr<SpriteSheet>& s = shared_ptr<SpriteSheet>(new SpriteSheet());
    s->m_source = a.source();

    AnyTableReader r(a);

    // Read the textures
    Texture::Specification spec;
    if (r.getIfPresent("emissive", spec)) {
        spec.generateMipMaps = false;
        spec.encoding.format = ImageFormat::RGBA_DXT5();
        s->m_emissive = Texture::create(spec);
    } else {
        s->m_emissive = Texture::opaqueBlack();
    }

    if (r.getIfPresent("color", spec)) {
        spec.generateMipMaps = false;
        spec.encoding.format = ImageFormat::RGBA_DXT5();
        s->m_color = Texture::create(spec);
    } else {
        s->m_color = Texture::createColor(Color4unorm8(Color4::zero()));
    }

    String bumpFilename;
    spec = Texture::Specification("<white>");
    if (r.getFilenameIfPresent("bump", bumpFilename)) {
        spec.filename = bumpFilename;
    }
    spec.generateMipMaps = false;
    spec.preprocess = Texture::Preprocess::normalMap();
    spec.encoding.format = ImageFormat::RGBA8();
    spec.encoding.readMultiplyFirst = Color3(2.0f);
    spec.encoding.readAddSecond = Color3(-1.0f);
    s->m_normal = Texture::create(spec);

    // Read the animation table
    Table<String, Any> tbl;
    r.getIfPresent("modelTable", tbl);
    for (Table<String, Any>::Iterator it = tbl.begin(); it.hasMore(); ++it) {
        if (modelTable.containsKey(it.key())) {
            String msg = format("Two models with the same name, '%s': ", it.key().c_str());
            msg += format("the first %s:%d and ", modelTable[it.key()]->source().filename.c_str(), modelTable[it.key()]->source().line);
            msg += format("and the second from %s:%d.", it.value().source().filename.c_str(), it.value().source().line);
            report(msg, ReportLevel::ERROR);
        } else {
            modelTable.set(it.key(), Model::create(s, it.key(), it.value()));
        }
    }

    r.verifyDone();
    return s;
}
예제 #2
0
파일: App.cpp 프로젝트: A7med-Shoukry/g3d
void App::saveScene() {
    // Called when the "save" button is pressed
    if (m_scene.notNull()) {
        Any a = m_scene->toAny();
        const std::string& filename = a.source().filename;
        if (filename != "") {
            a.save(filename);
            debugPrintf("Saved %s\n", filename.c_str());
        } else {
            debugPrintf("Could not save: empty filename");
        }
    }
}