const vector<Mesh*>& AnimationSequence::getFrame(size_t lowerFrame, size_t upperFrame, float bias) const { ASSERT(!keyFrames.empty(), "no keyframes in the animation sequence"); if(keyFrames.size()==1) return keyFrames[0].getMeshes(); ASSERT(lowerFrame < keyFrames.size(), "lower keyframe out of range:" + sizet_to_string(lowerFrame)); ASSERT(upperFrame < keyFrames.size(), "upper keyframe out of range: "+ sizet_to_string(upperFrame)); ASSERT(bias >= 0.0f && bias <= 1.0f, "bias is out of range: " + ftos(bias)); if(lowerFrame == upperFrame) return(keyFrames[lowerFrame].getMeshes()); const vector<Mesh*> &meshesA = keyFrames[lowerFrame].getMeshes(); const vector<Mesh*> &meshesB = keyFrames[upperFrame].getMeshes(); for(size_t i=0; i<meshes.size(); ++i) { Mesh*const mesh = meshes[i]; const Mesh*const a = meshesA[i]; const Mesh*const b = meshesB[i]; interpolate(bias, *mesh, *a, *b); } return meshes; }
color PropertyBag::getColor(const string &key, size_t instance) const { color x; VERIFY(get(key, x, instance), "Failed to get color from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
vec4 PropertyBag::getVec4(const string &key, size_t instance) const { vec4 x; VERIFY(get(key, x, instance), "Failed to get vec4 from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
PropertyBag PropertyBag::getBag(const string &key, size_t instance) const { PropertyBag x; VERIFY(get(key, x, instance), "Failed to get PropertyBag from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
bool PropertyBag::getBool(const string &key, size_t instance) const { bool x = false; VERIFY(get(key, x, instance), "Failed to get bool from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
float PropertyBag::getFloat(const string &key, size_t instance) const { float x = 0.0f; VERIFY(get(key, x, instance), "Failed to get float from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
double PropertyBag::getDouble(const string &key, size_t instance) const { double x = 0.0; VERIFY(get(key, x, instance), "Failed to get double from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
size_t PropertyBag::getSizeT(const string &key, size_t instance) const { size_t x = 0xdeadbeaf; VERIFY(get(key, x, instance), "Failed to get size_t from PropertyBag: " + key + " (instance #" + sizet_to_string(instance) + ")"); return x; }
bool PropertyBag::get(const string& key, PropertyBag &dest, size_t instance) const { if (data.find(key)==data.end()) return false; PropertyMap::const_iterator iter; // check that the desired instance exists ASSERT(instance<getNumInstances(key), "parameter \'instance\' is incorrect: " + sizet_to_string(instance)); // go to the desired instance iter = data.lower_bound(key); for (size_t q=0; q < instance; q++) iter++; ASSERT(dynamic_cast<PropertyBag*>(iter->second)!=0, "iter->second cannot be cast to a PropertyBag object: " \ "key = \"" + key + "\""); // I would rather have invalid behavior than a crash if (dynamic_cast<PropertyBag*>(iter->second)!=0) { dest = dynamic_cast<PropertyBag&>(*iter->second); return true; } else { return false; } }
string PropertyBag::getString(const string &key, size_t instance) const { ASSERT(getNumInstances(key) > 0, "Key \"" + key + "\" not found"); ASSERT(getNumInstances(key) > instance, "Not enough instances of key: " + key + " (wanted instance #" + sizet_to_string(instance) + " of only " + sizet_to_string(getNumInstances(key)) + ")"); string x = "nill"; VERIFY(get(key, x, instance), "Failed to get string from PropertyBag: " + key + " (wanted instance #" + sizet_to_string(instance) + " of " + sizet_to_string(getNumInstances(key)) + ")"); return x; }
void PropertyBag::add(const string& key, size_t data) { add(key, sizet_to_string(data)); }