ArticulatedModel::Instruction::Identifier::Identifier(const Any& a) { switch (a.type()) { case Any::NUMBER: id = ID(iRound(a.number())); a.verify(id >= 0, "Illegal ID"); break; case Any::STRING: name = a.string(); break; case Any::ARRAY: a.verifySize(0); if (a.name() == "root") { *this = root(); } else if (a.name() == "all") { *this = all(); } else { a.verify(false, "Illegal function call: " + a.name()); } break; default: a.verify(false, "Expected a name, integer ID, root(), or all()"); } }
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"); } }
PhysicsFrame::PhysicsFrame(const Any& a) { const std::string& n = toLower(a.name()); *this = PhysicsFrame(); if (beginsWith(n, "vector3")) { *this = PhysicsFrame(Vector3(a)); } else if (beginsWith(n, "matrix3")) { *this = PhysicsFrame(Matrix3(a)); } else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) { *this = PhysicsFrame(CoordinateFrame(a)); } else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) { if (a.type() == Any::ARRAY) { a.verifySize(2); rotation = a[0]; translation = a[1]; } else { for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) { const std::string& n = toLower(it->key); if (n == "translation") { translation = it->value; } else if (n == "rotation") { rotation = it->value; } else { a.verify(false, "Illegal table key: " + it->key); } } } } }
Sampler::Sampler(const Any& any) { *this = Sampler::defaults(); any.verifyNameBeginsWith("Sampler"); if (any.type() == Any::TABLE) { AnyTableReader r(any); r.getIfPresent("maxAnisotropy", maxAnisotropy); r.getIfPresent("maxMipMap", maxMipMap); r.getIfPresent("minMipMap", minMipMap); r.getIfPresent("mipBias", mipBias); r.getIfPresent("xWrapMode", xWrapMode); if (! r.getIfPresent("yWrapMode", yWrapMode)) { yWrapMode = xWrapMode; } r.getIfPresent("depthReadMode", depthReadMode); r.getIfPresent("interpolateMode", interpolateMode); r.verifyDone(); } else { any.verifySize(0); const String& n = any.name(); if (n == "Sampler::defaults") { // Done! } else if (n == "Sampler::buffer") { *this = Sampler::buffer(); } else if (n == "Sampler::cubeMap") { *this = Sampler::cubeMap(); } else if (n == "Sampler::shadow") { *this = Sampler::shadow(); } else if (n == "Sampler::video") { *this = Sampler::video(); } else { any.verify(false, "Unrecognized name for Sampler constructor or factory method."); } } }
Matrix4::Matrix4(const Any& any) { any.verifyNameBeginsWith("Matrix4", "CFrame", "CoordinateFrame"); any.verifyType(Any::ARRAY); const std::string& name = 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].floatValue()); } 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::rollDegrees") { any.verifySize(1); *this = rollDegrees(any[0].floatValue()); } else if (name == "Matrix4::yawDegrees") { any.verifySize(1); *this = yawDegrees(any[0].floatValue()); } else if (name == "Matrix4::pitchDegrees") { any.verifySize(1); *this = pitchDegrees(any[0].floatValue()); } else if (name == "Matrix4::translation") { if (any.size() == 3) { *this = translation(any[0], any[1], any[2]); } else { any.verify(false, "Matrix4::translation() requires 3 arguments"); } } else if (name == "Matrix4::diagonal") { any.verifySize(4); *this = diagonal(any[0], any[1], any[2], any[3]); } else if (name == "Matrix4::identity") { *this = identity(); } else if (beginsWith(name, "CFrame") || beginsWith(name, "CoordinateFrame")) { *this = CFrame(any); } else { any.verify(false, "Expected Matrix4 constructor"); } }
Texture::Preprocess::Preprocess(const Any& any) { *this = Preprocess::defaults(); any.verifyNameBeginsWith("Texture::Preprocess"); if (any.type() == Any::TABLE) { for (Any::AnyTable::Iterator it = any.table().begin(); it.isValid(); ++it) { const String& key = it->key; if (key == "modulate") { modulate = Color4(it->value); } else if (key == "gammaAdjust") { gammaAdjust = it->value; } else if (key == "scaleFactor") { scaleFactor = it->value; } else if (key == "computeMinMaxMean") { computeMinMaxMean = it->value; } else if (key == "computeNormalMap") { computeNormalMap = it->value; } else if (key == "convertToPremultipliedAlpha") { convertToPremultipliedAlpha = it->value; } else if (key == "bumpMapPreprocess") { bumpMapPreprocess = it->value; } else { any.verify(false, "Illegal key: " + it->key); } } } else { const String& n = any.name(); if (n == "Texture::Preprocess::defaults") { any.verifySize(0); } else if (n == "Texture::Preprocess::gamma") { any.verifySize(1); *this = Texture::Preprocess::gamma(any[0]); } else if (n == "Texture::preprocess::none") { any.verifySize(0); *this = Texture::Preprocess::none(); } else if (n == "Texture::Preprocess::quake") { any.verifySize(0); *this = Texture::Preprocess::quake(); } else if (n == "Texture::Preprocess::normalMap") { any.verifySize(0); *this = Texture::Preprocess::normalMap(); } else { any.verify(false, "Unrecognized name for Texture::Preprocess constructor or factory method."); } } }
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); } }
/** \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]); } }
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); } }
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"]; } }
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]; } } } }
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]; }
ArticulatedModel::Instruction::Instruction(const Any& any) { any.verifyType(Any::ARRAY); source = any; part = Identifier(); mesh = Identifier(); arg = Any(); const std::string& instructionName = any.name(); if (instructionName == "scale") { type = SCALE; any.verifySize(1); arg = any[0]; } else if (instructionName == "moveCenterToOrigin") { type = MOVE_CENTER_TO_ORIGIN; any.verifySize(0); } else if (instructionName == "moveBaseToOrigin") { type = MOVE_BASE_TO_ORIGIN; any.verifySize(0); } else if (instructionName == "setCFrame") { type = SET_CFRAME; any.verifySize(2); part = any[0]; arg = any[1]; } else if (instructionName == "transformCFrame") { type = TRANSFORM_CFRAME; any.verifySize(2); part = any[0]; arg = any[1]; } else if (instructionName == "transformGeometry") { type = TRANSFORM_GEOMETRY; any.verifySize(2); part = any[0]; arg = any[1]; } else if (instructionName == "deleteMesh") { type = DELETE_MESH; any.verifySize(2); part = any[0]; mesh = any[1]; } else if (instructionName == "deletePart") { type = DELETE_PART; any.verifySize(1); part = any[0]; } else if (instructionName == "setMaterial") { type = SET_MATERIAL; any.verifySize(3); part = any[0]; mesh = any[1]; arg = any[2]; } else if (instructionName == "setTwoSided") { type = SET_TWO_SIDED; any.verifySize(3); part = any[0]; mesh = any[1]; arg = any[2]; } else if (instructionName == "mergeAll") { type = MERGE_ALL; any.verifySize(0); } else if (instructionName == "renamePart") { type = RENAME_PART; any.verifySize(2); part = any[0]; arg = any[1]; } else if (instructionName == "renameMesh") { type = RENAME_MESH; any.verifySize(3); part = any[0]; mesh = any[1]; arg = any[2]; } else if (instructionName == "add") { type = ADD; mesh = Identifier::none(); if (any.size() == 2) { any.verifySize(2); part = any[0]; arg = any[1]; } else { any.verifySize(1); part = Identifier::none(); arg = any[0]; } } else { any.verify(false, std::string("Unknown instruction: \"") + instructionName + "\""); } }