/** \param any Must either Rect2D::xywh(#, #, #, #) or Rect2D::xyxy(#, #, #, #)*/ Rect2D::Rect2D(const Any& any) { any.verifyName("Rect2D"); any.verifyType(Any::ARRAY); any.verifySize(4); if (toUpper(any.name()) == "RECT2D::XYWH") { *this = Rect2D::xywh(any[0], any[1], any[2], any[3]); } else { any.verifyName("Rect2D::xyxy"); *this = Rect2D::xyxy(any[0], any[1], any[2], any[3]); } }
Matrix4::Matrix4(const Any& any) { any.verifyName("Matrix4"); any.verifyType(Any::ARRAY); const std::string& name = toLower(any.name()); if (name == "matrix4") { any.verifySize(16); for (int r = 0; r < 4; ++r) { for (int c = 0; c < 4; ++c) { elt[r][c] = any[r * 4 + c]; } } } else if (name == "matrix4::scale") { if (any.size() == 1) { *this = scale(any[0].number()); } else if (any.size() == 3) { *this = scale(any[0], any[1], any[2]); } else { any.verify(false, "Matrix4::scale() takes either 1 or 3 arguments"); } } else if (name == "matrix4::translation") { if (any.size() == 3) { *this = translation(any[0], any[1], any[2]); } else { any.verify(false, "Matrix4::translation() takes either 1 or 3 arguments"); } } else { any.verify(false, "Expected Matrix4 constructor"); } }
DeepGBufferRadiositySettings::DeepGBufferRadiositySettings(const Any& a) { *this = DeepGBufferRadiositySettings(); a.verifyName("DeepGBufferRadiositySettings"); AnyTableReader r(a); r.getIfPresent("enabled", enabled); r.getIfPresent("radius", radius); r.getIfPresent("bias", bias); r.getIfPresent("numSamples", numSamples); r.getIfPresent("edgeSharpness", edgeSharpness); r.getIfPresent("blurStepSize", blurStepSize); r.getIfPresent("blurRadius", blurRadius); r.getIfPresent("monotonicallyDecreasingBilateralWeights", monotonicallyDecreasingBilateralWeights); r.getIfPresent("useDepthPeelBuffer", useDepthPeelBuffer); r.getIfPresent("depthPeelSeparationHint", depthPeelSeparationHint); r.getIfPresent("temporalFilterSettings", temporalFilterSettings); r.getIfPresent("temporallyVarySamples", temporallyVarySamples); r.getIfPresent("computePeeledLayer", computePeeledLayer); r.getIfPresent("unsaturatedBoost", unsaturatedBoost); r.getIfPresent("saturatedBoost", saturatedBoost); r.getIfPresent("useMipMaps", useMipMaps); r.getIfPresent("numBounces", numBounces); r.getIfPresent("propagationDamping", propagationDamping); r.getIfPresent("useTapNormal", useTapNormal); r.getIfPresent("useOct16", useOct16); r.getIfPresent("minMipLevel", minMipLevel); r.getIfPresent("useHalfPrecisionColors", useHalfPrecisionColors); r.getIfPresent("computeGuardBandFraction", computeGuardBandFraction); r.verifyDone(); }
UprightFrame::UprightFrame(const Any& any) { any.verifyName("UprightFrame"); any.verifyType(Any::TABLE); translation = any["translation"]; pitch = any["pitch"]; yaw = any["yaw"]; }
ArticulatedModel::PoseSpline::PoseSpline(const Any& any) : castsShadows(true) { any.verifyName("ArticulatedModel::PoseSpline"); for (Any::AnyTable::Iterator it = any.table().begin(); it.isValid(); ++it) { if (it->key == "castsShadows") { castsShadows = it->value; } else { partSpline.getCreate(it->key) = it->value; } } }
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; }
TemporalFilter::Settings::Settings(const Any& a) { *this = Settings(); a.verifyName("TemporalFilter::Settings"); AnyTableReader r(a); r.getIfPresent("hysteresis", hysteresis); r.getIfPresent("falloffStartDistance", falloffStartDistance); r.getIfPresent("falloffEndDistance", falloffEndDistance); r.verifyDone(); }
Vector2int32::Vector2int32(const Any& any) { any.verifyName("Vector2int32", "Point2int32"); any.verifyType(Any::TABLE, Any::ARRAY); any.verifySize(2); if (any.type() == Any::ARRAY) { x = any[0]; y = any[1]; } else { // Table x = any["x"]; y = any["y"]; } }
Vector3::Vector3(const Any& any) { any.verifyName("Vector3"); any.verifyType(Any::TABLE, Any::ARRAY); any.verifySize(3); if (any.type() == Any::ARRAY) { x = any[0]; y = any[1]; z = any[2]; } else { // Table x = any["x"]; y = any["y"]; z = any["z"]; } }
BumpMap::Settings::Settings(const Any& any) { *this = Settings(); any.verifyName("BumpMap::Settings"); for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) { const std::string& key = toLower(it->key); if (key == "iterations") { iterations = iMax(0, iRound(it->value.number())); } else if (key == "scale") { scale = it->value; } else if (key == "bias") { bias = it->value; } else { any.verify(false, "Illegal key: " + it->key); } } }
Matrix2::Matrix2(const Any& any) { any.verifyName("Matrix2"); any.verifyType(Any::ARRAY); if (any.nameEquals("Matrix2::identity")) { *this = identity(); } else { any.verifySize(4); for (int r = 0; r < 3; ++r) { for (int c = 0; c < 3; ++c) { data[r][c] = any[r * 2 + c]; } } } }
ParseOBJ::Options::Options(const Any& a) { *this = Options(); a.verifyName("OBJOptions"); AnyTableReader r(a); String s; if (r.getIfPresent("texCoord1Mode", s)) { if (s == "NONE") { texCoord1Mode = NONE; } else if (s == "UNPACK_FROM_TEXCOORD0_Z") { texCoord1Mode = UNPACK_FROM_TEXCOORD0_Z; } else if (s == "TEXCOORD0_ZW") { texCoord1Mode = TEXCOORD0_ZW; } else { a.verify(false, "Unexpected value for texCoord3DMode"); } } r.getIfPresent("stripRefraction", stripRefraction); // r.getIfPresent("sampler", sampler); r.verifyDone(); }
Texture::Visualization::Visualization(const Any& a) { *this = Visualization(); if (a.type() == Any::ARRAY) { if (a.nameEquals("bumpInAlpha")) { *this = bumpInAlpha(); } else if (a.nameEquals("defaults")) { *this = defaults(); } else if (a.nameEquals("linearRGB")) { *this = linearRGB(); } else if (a.nameEquals("depthBuffer")) { *this = depthBuffer(); } else if (a.nameEquals("packedUnitVector")) { *this = packedUnitVector(); } else if (a.nameEquals("radiance")) { *this = radiance(); } else if (a.nameEquals("reflectivity")) { *this = reflectivity(); } else if (a.nameEquals("sRGB")) { *this = sRGB(); } else if (a.nameEquals("unitVector")) { *this = unitVector(); } else { a.verify(false, "Unrecognized Visualization factory method"); } } else { a.verifyName("Texture::Visualization", "Visualization"); AnyTableReader r(a); String c; if (r.getIfPresent("channels", c)) { channels = toChannels(c); } r.getIfPresent("documentGamma", documentGamma); r.getIfPresent("invertIntensity", invertIntensity); r.getIfPresent("max", max); r.getIfPresent("min", min); r.getIfPresent("layer", layer); r.getIfPresent("mipLevel", mipLevel); r.verifyDone(); } }
CoordinateFrame::CoordinateFrame(const Any& any) { *this = CFrame(); const std::string& n = toUpper(any.name()); if (beginsWith(n, "VECTOR3")) { translation = any; } else if (beginsWith(n, "MATRIX3")) { rotation = any; } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) { any.verifyType(Any::TABLE, Any::ARRAY); if (any.type() == Any::ARRAY) { any.verifySize(2); rotation = any[0]; translation = any[1]; } else { for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) { const std::string& n = toLower(it->key); if (n == "translation") { translation = Vector3(it->value); } else if (n == "rotation") { rotation = Matrix3(it->value); } else { any.verify(false, "Illegal table key: " + it->key); } } } } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) { *this = PhysicsFrame(any); } else { any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees"); any.verifyType(Any::ARRAY); any.verifySize(3, 6); int s = any.size(); *this = fromXYZYPRDegrees(any[0], any[1], any[2], (s > 3) ? any[3].number() : 0.0f, (s > 4) ? any[4].number() : 0.0f, (s > 5) ? any[5].number() : 0.0f); } }
CoordinateFrame::CoordinateFrame(const Any& any) { *this = CFrame(); const String& n = toUpper(any.name()); if (beginsWith(n, "VECTOR3") || beginsWith(n, "POINT3")) { translation = Point3(any); } else if (beginsWith(n, "MATRIX3")) { rotation = Matrix3(any); } else if (beginsWith(n, "MATRIX4")) { *this = Matrix4(any).approxCoordinateFrame(); } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) { any.verifyType(Any::TABLE, Any::ARRAY); if (any.type() == Any::ARRAY) { any.verifySize(2); rotation = any[0]; translation = any[1]; } else { AnyTableReader r(any); r.getIfPresent("translation", translation); r.getIfPresent("rotation", rotation); r.verifyDone(); } } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) { *this = PhysicsFrame(any); // } else if (beginsWith(n, "UPRIGHTFRAME") || beginsWith(n, "UFRAME")) { // *this = UprightFrame(any); } else { any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees"); any.verifyType(Any::ARRAY); any.verifySize(3, 6); int s = any.size(); *this = fromXYZYPRDegrees(any[0], any[1], any[2], (s > 3) ? (float)any[3].number() : 0.0f, (s > 4) ? (float)any[4].number() : 0.0f, (s > 5) ? (float)any[5].number() : 0.0f); } }
UprightSpline::UprightSpline(const Any& any) { any.verifyName("UprightSpline"); any.verifyType(Any::TABLE); cyclic = any["cyclic"]; const Any& controlsAny = any["control"]; controlsAny.verifyType(Any::ARRAY); control.resize(controlsAny.length()); for (int controlIndex = 0; controlIndex < control.length(); ++controlIndex) { control[controlIndex] = controlsAny[controlIndex]; } const Any& timesAny = any["time"]; timesAny.verifyType(Any::ARRAY); time.resize(timesAny.length()); for (int timeIndex = 0; timeIndex < time.length(); ++timeIndex) { time[timeIndex] = timesAny[timeIndex]; } }
CompassDelta::CompassDelta(const Any& a) { a.verifyType(Any::ARRAY); a.verifyName("CompassDelta", "CompassBearing", "degrees"); a.verifySize(1); m_angleDegrees = a[1]; }
CompassDirection::CompassDirection(const Any& a) { a.verifyType(Any::ARRAY); a.verifyName("CompassDirection", "degrees"); a.verifySize(1); m_angleDegrees = a[0]; }
GLight::GLight(const Any& any) { any.verifyName("GLight"); if (any.type() == Any::TABLE) { *this = GLight(); Vector3 spotTarget; bool hasSpotTarget = false; for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) { const std::string& key = toLower(it->key); if (key == "position") { position = it->value; } else if (key == "rightdirection") { rightDirection = it->value; } else if (key == "spotdirection") { spotDirection = Vector3(it->value).directionOrZero(); } else if (key == "spottarget") { spotTarget = it->value; hasSpotTarget = true; } else if (key == "spotcutoff") { spotCutoff = it->value.number(); } else if (key == "spotsquare") { spotSquare = it->value.boolean(); } else if (key == "attenuation") { attenuation[0] = it->value[0].number(); attenuation[1] = it->value[1].number(); attenuation[2] = it->value[2].number(); } else if (key == "color") { color = it->value; } else if (key == "enabled") { enabled = it->value.boolean(); } else if (key == "specular") { specular = it->value.boolean(); } else if (key == "diffuse") { diffuse = it->value.boolean(); } else { any.verify(false, "Illegal key: " + it->key); } } if (hasSpotTarget) { spotDirection = (spotTarget - position.xyz()).direction(); } } else if (toLower(any.name()) == "glight::directional") { *this = directional(any[0], any[1], (any.size() > 2) ? any[2] : Any(true), (any.size() > 3) ? any[3] : Any(true)); } else if (toLower(any.name()) == "glight::point") { *this = point(any[0], any[1], (any.size() > 2) ? any[2] : Any(1), (any.size() > 3) ? any[3] : Any(0), (any.size() > 4) ? any[4] : Any(0.5f), (any.size() > 5) ? any[5] : Any(true), (any.size() > 6) ? any[6] : Any(true)); } else if (toLower(any.name()) == "glight::spot") { *this = spot(any[0], any[1], any[2], any[3], (any.size() > 4) ? any[4] : Any(1), (any.size() > 5) ? any[5] : Any(0), (any.size() > 6) ? any[6] : Any(0), (any.size() > 7) ? any[7] : Any(true), (any.size() > 8) ? any[8] : Any(true)); } else { any.verify(false, "Unrecognized name"); } }