Texture::Encoding::Encoding(const Any& a) { *this = Encoding(); if (a.type() == Any::STRING) { format = ImageFormat::fromString(a); } else if (a.nameBeginsWith("Color4")) { readMultiplyFirst = a; } else if (anyNameIsColor3Variant(a)) { readMultiplyFirst = Color4(Color3(a), 1.0f); } else if (a.type() == Any::NUMBER) { readMultiplyFirst = Color4::one() * float(a.number()); } else { AnyTableReader r(a); r.getIfPresent("frame", frame); r.getIfPresent("readMultiplyFirst", readMultiplyFirst); r.getIfPresent("readAddSecond", readAddSecond); String fmt; if (r.getIfPresent("format", fmt)) { format = ImageFormat::fromString(fmt); } } }
ParticleSystemModel::Emitter::Specification::Specification(const Any& a) { a.verifyNameBeginsWith("ParticleSystemModel::Emitter"); *this = Specification(); AnyTableReader r(a); r.getIfPresent("location", location); r.getIfPresent("noisePower", noisePower); r.getIfPresent("initialDensity", initialDensity); r.getIfPresent("rateCurve", rateCurve); r.getIfPresent("coverageFadeInTime", coverageFadeInTime); r.getIfPresent("coverageFadeOutTime", coverageFadeOutTime); r.getIfPresent("particleLifetimeMean", particleLifetimeMean); r.getIfPresent("particleLifetimeVariance", particleLifetimeVariance); r.getIfPresent("angularVelocityMean", angularVelocityMean); r.getIfPresent("angularVelocityVariance", angularVelocityVariance); r.getIfPresent("material", material); r.getIfPresent("radiusMean", radiusMean); r.getIfPresent("radiusVariance", radiusVariance); r.getIfPresent("particleMassDensity", particleMassDensity); r.getIfPresent("dragCoefficient", dragCoefficient); shapeType = Shape::Type::NONE; Any shape; if (r.getIfPresent("shape", shape)) { if (shape.nameBeginsWith("ArticulatedModel") || (shape.type() == Any::STRING)) { shapeType = Shape::Type::MESH; } else { shapeType = Shape::Type(toUpper(shape.name())); } switch (shapeType) { case Shape::Type::BOX: box = Box(shape); break; case Shape::Type::CYLINDER: cylinder = Cylinder(shape); break; case Shape::Type::SPHERE: sphere = Sphere(shape); break; case Shape::Type::MESH: mesh = shape; break; default: shape.verify(false, "Shape must be a Box, Cylinder, Sphere, or ArticulatedModel specification"); } } r.getIfPresent("velocityDirectionMean", velocityDirectionMean); r.getIfPresent("velocityConeAngleDegrees", velocityConeAngleDegrees); r.getIfPresent("velocityMagnitudeMean", velocityMagnitudeMean); r.getIfPresent("velocityMagnitudeVariance", velocityMagnitudeVariance); r.verifyDone(); }
ParticleSystemModel::Specification::Specification(const Any& a) { *this = Specification(); if (a.nameBeginsWith("ParticleSystemModel::Emitter")) { emitterArray.append(a); } else { a.verifyNameBeginsWith("ParticleSystemModel::Specification"); Any array = a.get("emitterArray", Any(Any::ARRAY)); array.getArray(emitterArray); hasPhysics = a.get("hasPhysics", true); } }
Texture::Specification::Specification(const Any& any, bool assumesRGBForAuto, Dimension defaultDimension) { *this = Specification(); assumeSRGBSpaceForAuto = assumesRGBForAuto; dimension = defaultDimension; if (any.type() == Any::STRING) { filename = any.string(); if (filename == "<whiteCube>") { filename = "<white>"; dimension = Texture::DIM_CUBE_MAP; } if (! beginsWith(filename, "<")) { filename = any.resolveStringAsFilename(); if (FilePath::containsWildcards(filename)) { // Assume this is a cube map dimension = Texture::DIM_CUBE_MAP; } } } else if ((any.type() == Any::NUMBER) || any.nameBeginsWith("Color4") || anyNameIsColor3Variant(any)) { filename = "<white>"; encoding.readMultiplyFirst = Color4(any); } else { any.verifyNameBeginsWith("Texture::Specification"); AnyTableReader r(any); r.getFilenameIfPresent("filename", filename); r.getFilenameIfPresent("alphaFilename", alphaFilename); r.getIfPresent("encoding", encoding); r.getIfPresent("assumeSRGBSpaceForAuto", assumeSRGBSpaceForAuto); { Any a; if (r.getIfPresent("dimension", a)) { dimension = toDimension(a); } } r.getIfPresent("generateMipMaps", generateMipMaps); r.getIfPresent("preprocess", preprocess); r.getIfPresent("visualization", visualization); r.getIfPresent("cachable", cachable); r.verifyDone(); if (! any.containsKey("dimension") && FilePath::containsWildcards(filename)) { // Assume this is a cube map dimension = Texture::DIM_CUBE_MAP; } } }
shared_ptr<Model> Scene::createModel(const Any& v, const std::string& name) { shared_ptr<Model> m; v.verify(! m_modelTable.containsKey(name), "A model named '" + name + "' already exists in this scene."); if ((v.type() == Any::STRING) || v.nameBeginsWith("ArticulatedModel")) { m = ArticulatedModel::create(v, name); } else if (v.nameBeginsWith("MD2Model")) { m = MD2Model::create(v, name); } else if (v.nameBeginsWith("MD3Model")) { m = MD3Model::create(v, name); } else if (v.nameBeginsWith("HeightfieldModel")) { m = HeightfieldModel::create(v, name); } if (isNull(m)) { v.verify(false, "Unrecognized model type: " + v.name()); } m_modelTable.set(name, m); return m; }
static bool anyNameIsColor3Variant(const Any& a) { return a.nameBeginsWith("Color3") || a.nameBeginsWith("Power3") || a.nameBeginsWith("Radiance3") || a.nameBeginsWith("Biradiance3") || a.nameBeginsWith("Radiosity3"); }
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; }