本文整理汇总了C++中Any::load方法的典型用法代码示例。如果您正苦于以下问题:C++ Any::load方法的具体用法?C++ Any::load怎么用?C++ Any::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Any
的用法示例。
在下文中一共展示了Any::load方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filenameTable
/** Returns a table mapping scene names to filenames */
static Table<std::string, std::string>& filenameTable() {
static Table<std::string, std::string> filenameTable;
if (filenameTable.size() == 0) {
// Create a table mapping scene names to filenames
Array<std::string> filenameArray;
FileSystem::ListSettings settings;
settings.files = true;
settings.directories = false;
settings.includeParentPath = true;
settings.recursive = true;
FileSystem::list("*.scn.any", filenameArray, settings);
for (int i = 0; i < filenameArray.size(); ++i) {
Any a;
a.load(filenameArray[i]);
std::string name = a["name"].string();
alwaysAssertM(! filenameTable.containsKey(name),
"Duplicate scene names in " + filenameArray[i] + " and " +
filenameTable["name"]);
filenameTable.set(name, filenameArray[i]);
}
}
return filenameTable;
}
示例2: filenameTable
/** Returns a table mapping scene names to filenames */
static Table<std::string, std::string>& filenameTable() {
static Table<std::string, std::string> filenameTable;
if (filenameTable.size() == 0) {
if (searchPaths.size() == 0) {
setDefaultSearchPaths();
}
// Create a table mapping scene names to filenames
Array<std::string> filenameArray;
FileSystem::ListSettings settings;
settings.files = true;
settings.directories = false;
settings.includeParentPath = true;
settings.recursive = true;
for (int i = 0; i < searchPaths.size(); ++i) {
FileSystem::list(FilePath::concat(searchPaths[i], "*.scn.any"), filenameArray, settings);
FileSystem::list(FilePath::concat(searchPaths[i], "*.Scene.Any"), filenameArray, settings);
}
logLazyPrintf("Found scenes:\n");
for (int i = 0; i < filenameArray.size(); ++i) {
Any a;
std::string msg;
try {
a.load(filenameArray[i]);
const std::string& name = a["name"].string();
alwaysAssertM(! filenameTable.containsKey(name),
"Duplicate scene names in " + filenameArray[i] + " and " +
filenameTable[name]);
msg = format(" \"%s\" (%s)\n", name.c_str(), filenameArray[i].c_str());
filenameTable.set(name, filenameArray[i]);
} catch (const ParseError& e) {
msg = format(" <Parse error at %s:%d(%d): %s>\n", e.filename.c_str(), e.line, e.character, e.message.c_str());
} catch (...) {
msg = format(" <Error while loading %s>\n", filenameArray[i].c_str());
}
if (! msg.empty()) {
logLazyPrintf("%s", msg.c_str());
debugPrintf("%s", msg.c_str());
}
}
logPrintf("");
}
return filenameTable;
}
示例3: loadSoundscape
void App::loadSoundscape() {
Any a;
a.load(System::findDataFile(m_sonicSculptureFilename));
AnyTableReader r("SoundScape", a);
Array<Any> sonicSculptureArray;
r.getIfPresent("sonicSculptures", sonicSculptureArray);
r.verifyDone();
m_sonicSculpturePieces.fastClear();
for (int i = 0; i < sonicSculptureArray.size(); ++i) {
shared_ptr<UniversalMaterial> material = getSonicSculptureMaterial(m_sonicSculpturePieces.size());
m_sonicSculpturePieces.append(SonicSculpturePiece::create(material, sonicSculptureArray[i]));
}
}
示例4: filenameTable
/** Returns a table mapping scene names to filenames */
static Table<std::string, std::string>& filenameTable() {
static Table<std::string, std::string> filenameTable;
if (filenameTable.size() == 0) {
// Create a table mapping scene names to filenames
Array<std::string> filenameArray;
FileSystem::ListSettings settings;
settings.files = true;
settings.directories = false;
settings.includeParentPath = true;
settings.recursive = true;
FileSystem::list("*.scn.any", filenameArray, settings);
logLazyPrintf("Found scenes:\n");
for (int i = 0; i < filenameArray.size(); ++i) {
Any a;
try {
a.load(filenameArray[i]);
std::string name = a["name"].string();
alwaysAssertM(! filenameTable.containsKey(name),
"Duplicate scene names in " + filenameArray[i] + " and " +
filenameTable["name"]);
logLazyPrintf(" \"%s\" (%s)\n", name.c_str(), filenameArray[i].c_str());
filenameTable.set(name, filenameArray[i]);
} catch (const ParseError& e) {
logLazyPrintf(" <Parse error at %s:%d(%d): %s>\n", e.filename.c_str(), e.line, e.character, e.message.c_str());
} catch (...) {
logLazyPrintf(" <Error while loading %s>\n", filenameArray[i].c_str());
}
}
logPrintf("");
}
return filenameTable;
}
示例5: load
Any Scene::load(const std::string& scene) {
std::string filename;
clear();
m_modelTable.clear();
m_name = scene;
bool isFilename = endsWith(toLower(scene), ".scn.any") || endsWith(toLower(scene), ".Scene.Any");
if (isFilename) {
filename = scene;
} else {
const std::string* f = filenameTable().getPointer(scene);
if (f == NULL) {
throw "No scene with name '" + scene + "' found in (" +
stringJoin(filenameTable().getKeys(), ", ") + ")";
}
filename = *f;
}
Any any;
any.load(filename);
{
const std::string& n = any.get("name", filename);
// Ensure that this name appears in the filename table if it does not already,
// so that it can be loaded by name in the future.
if (! filenameTable().containsKey(n)) {
filenameTable().set(n, filename);
}
}
m_sourceAny = any;
// Load the lighting environment (do this before loading entities, since some of them may
// be lights that will enter this array)
bool hasEnvironmentMap = false;
if (any.containsKey("localLightingEnvironment")) {
m_localLightingEnvironment = any["localLightingEnvironment"];
hasEnvironmentMap = any["localLightingEnvironment"].containsKey("environmentMap");
}
// Load the models
if (any.containsKey("models")) {
Any models = any["models"];
if (models.size() > 0) {
for (Any::AnyTable::Iterator it = models.table().begin(); it.isValid(); ++it) {
const std::string name = it->key;
Any v = it->value;
createModel(v, name);
}
}
}
// Instance the models
if (any.containsKey("entities")) {
Any entities = any["entities"];
if (entities.size() > 0) {
for (Table<std::string, Any>::Iterator it = entities.table().begin(); it.isValid(); ++it) {
const std::string& name = it->key;
const std::string& entityType = it->value.name();
createEntity(entityType, name, it->value);
}
}
}
shared_ptr<Texture> skyboxTexture = Texture::whiteCube();
Any skyAny;
// Use the environment map as a skybox if there isn't one already, and vice versa
Array<shared_ptr<Skybox> > skyboxes;
getTypedEntityArray<Skybox>(skyboxes);
if ( skyboxes.size() == 0 ) {
if (any.containsKey("skybox")) {
createEntity("Skybox", "skybox", any["skybox"]);
m_skybox = typedEntity<Skybox>("skybox");
} else if (hasEnvironmentMap) {
m_skybox = Skybox::create("skybox", this, Array<ScaledTexture>(m_localLightingEnvironment.environmentMapArray[0]), Array<SimTime>(0.0), 0, SplineExtrapolationMode::CLAMP, false, false);
insert(m_skybox);
} else {
m_skybox = Skybox::create("skybox", this, Array<ScaledTexture>(ScaledTexture(Texture::whiteCube(), 1.0f)), Array<SimTime>(0.0), 0, SplineExtrapolationMode::CLAMP, false, false);
insert(m_skybox);
}
}
if (any.containsKey("environmentMap")) {
throw std::string("environmentMap field has been replaced with localLightingEnvironment");
}
// Default to using the skybox as an environment map if none is specified.
if (! hasEnvironmentMap) {
m_localLightingEnvironment.environmentMapArray.append(ScaledTexture(m_skybox->keyframeArray()[0].texture, m_skybox->keyframeArray()[0].constant));
}
//.........这里部分代码省略.........
示例6: loadGrid
void App::loadGrid() {
Any grid;
grid.load(System::findDataFile("grid.Grid.Any"));
m_automata.init(grid["width"], grid["height"], grid["startHeads"], 150, m_audioSettings.sampleRate);
m_gridColor = grid["color"];
}
示例7: onInit
void ArticulatedViewer::onInit(const String& filename) {
ArticulatedModel::clearCache();
Texture::clearCache();
m_filename = filename;
m_selectedPart = NULL;
m_selectedMesh = NULL;
m_selectedTriangleIndex = -1;
m_numFaces = 0;
m_numVertices = 0;
m_shadowMapDirty = true;
UniversalMaterial::clearCache();
const RealTime start = System::time();
if (toLower(FilePath::ext(filename)) == "any") {
if ((toLower(FilePath::ext(FilePath::base(filename))) == "material") ||
(toLower(FilePath::ext(FilePath::base(filename))) == "universalmaterial")) {
// Assume that this is an .UniversalMaterial.Any file. Load a square and apply the material
Any any(Any::TABLE, "ArticulatedModel::Specification");
any["filename"] = "model/crate/crate4xtex.obj";
any["stripMaterials"] = true;
any["preprocess"] = Any(Any::ARRAY);
Any arg(Any::ARRAY, "setMaterial");
arg.append(Any(Any::ARRAY, "all"));
arg.append(Any::fromFile(filename));
any["preprocess"].append(arg);
Any arg2(Any::ARRAY, "setTwoSided");
arg2.append(Any(Any::ARRAY, "all"));
arg2.append(true);
any["preprocess"].append(arg2);
m_model = ArticulatedModel::create(ArticulatedModel::Specification(any));
} else {
// Assume that this is an .ArticulatedModel.Any file
Any any;
any.load(filename);
m_model = ArticulatedModel::create(ArticulatedModel::Specification(any));
}
} else {
m_model = ArticulatedModel::fromFile(filename);
}
debugPrintf("%s loaded in %f seconds\n", filename.c_str(), System::time() - start);
Array<shared_ptr<Surface> > arrayModel;
if (m_model->usesSkeletalAnimation()) {
Array<G3D::String> animationNames;
m_model->getAnimationNames(animationNames);
// TODO: Add support for selecting animations.
m_model->getAnimation(animationNames[0], m_animation);
m_animation.getCurrentPose(0.0f, m_pose);
}
m_model->pose(arrayModel, CFrame(), m_pose);
m_model->countTrianglesAndVertices(m_numFaces, m_numVertices);
m_scale = 1;
m_offset = Vector3::zero();
bool overwrite = true;
// Find the size of the bounding box of the entire model
AABox bounds;
if (arrayModel.size() > 0) {
for (int x = 0; x < arrayModel.size(); ++x) {
//merges the bounding boxes of all the seperate parts into the bounding box of the entire object
AABox temp;
CFrame cframe;
arrayModel[x]->getCoordinateFrame(cframe);
arrayModel[x]->getObjectSpaceBoundingBox(temp);
Box partBounds = cframe.toWorldSpace(temp);
// Some models have screwed up bounding boxes
if (partBounds.extent().isFinite()) {
if (overwrite) {
partBounds.getBounds(bounds);
overwrite = false;
} else {
partBounds.getBounds(temp);
bounds.merge(temp);
}
}
}
if (overwrite) {
// We never found a part with a finite bounding box
bounds = AABox(Vector3::zero());
}
Vector3 extent = bounds.extent();
//.........这里部分代码省略.........
示例8: create
Scene::Ref Scene::create(const std::string& scene, GCamera& camera)
{
if (scene == "")
{
return NULL;
}
Scene::Ref s = new Scene();
const std::string* f = filenameTable().getPointer(scene);
if (f == NULL)
{
throw "No scene with name '" + scene + "' found in (" +
stringJoin(filenameTable().getKeys(), ", ") + ")";
}
const std::string& filename = *f;
Any any;
any.load(filename);
// Load the lighting
s->m_lighting = Lighting::create(any.get("lighting", Lighting::Specification()));
// Load the models
Any models = any["models"];
typedef ReferenceCountedPointer<ReferenceCountedObject> ModelRef;
Table< std::string, ModelRef > modelTable;
for (Any::AnyTable::Iterator it = models.table().begin(); it.hasMore(); ++it) {
ModelRef m;
Any v = it->value;
if (v.nameBeginsWith("ArticulatedModel")) {
m = ArticulatedModel::create(v);
} else if (v.nameBeginsWith("MD2Model")) {
m = MD2Model::create(v);
} else if (v.nameBeginsWith("MD3Model")) {
m = MD3Model::create(v);
} else {
debugAssertM(false, "Unrecognized model type: " + v.name());
}
modelTable.set(it->key, m);
}
// Instance the models
Any entities = any["entities"];
for (Table<std::string, Any>::Iterator it = entities.table().begin(); it.hasMore(); ++it) {
const std::string& name = it->key;
const Any& modelArgs = it->value;
modelArgs.verifyType(Any::ARRAY);
const ModelRef* model = modelTable.getPointer(modelArgs.name());
modelArgs.verify((model != NULL),
"Can't instantiate undefined model named " + modelArgs.name() + ".");
PhysicsFrameSpline frameSpline;
ArticulatedModel::PoseSpline poseSpline;
if (modelArgs.size() >= 1) {
frameSpline = modelArgs[0];
if (modelArgs.size() >= 2) {
// Poses
poseSpline = modelArgs[1];
}
}
ArticulatedModel::Ref artModel = model->downcast<ArticulatedModel>();
MD2Model::Ref md2Model = model->downcast<MD2Model>();
MD3Model::Ref md3Model = model->downcast<MD3Model>();
if (artModel.notNull()) {
s->m_entityArray.append(Entity::create(name, frameSpline, artModel, poseSpline));
} else if (md2Model.notNull()) {
s->m_entityArray.append(Entity::create(name, frameSpline, md2Model));
} else if (md3Model.notNull()) {
s->m_entityArray.append(Entity::create(name, frameSpline, md3Model));
}
}
// Load the camera
camera = any["camera"];
if (any.containsKey("skybox")) {
Any sky = any["skyBox"];
s->m_skyBoxConstant = sky.get("constant", 1.0f);
if (sky.containsKey("texture")) {
s->m_skyBoxTexture = Texture::create(sky["texture"]);
}
} else {
s->m_skyBoxTexture = s->m_lighting->environmentMapTexture;
s->m_skyBoxConstant = s->m_lighting->environmentMapConstant;
}
// Default to using the skybox as an environment map if none is specified.
if (s->m_skyBoxTexture.notNull() && s->m_lighting->environmentMapTexture.isNull()) {
s->m_lighting->environmentMapTexture = s->m_skyBoxTexture;
s->m_lighting->environmentMapConstant = s->m_skyBoxConstant;
}
return s;
}