| 51 | Path::getExt(filename.toString()).empty() ? filename.toString() + ".model"s : filename.toString())) { } |
| 52 | |
| 53 | bool Model::init() { |
| 54 | if (!Playable::init()) return false; |
| 55 | if (!_modelDef) { |
| 56 | setAsManaged(); |
| 57 | return false; |
| 58 | } |
| 59 | _resetAnimation.end = std::make_pair(this, &Model::onResetAnimationEnd); |
| 60 | _root = Node::create(false); |
| 61 | const std::string& clipFile = _modelDef->getClipFile(); |
| 62 | if (!clipFile.empty()) { |
| 63 | ClipDef* clipDef = SharedClipCache.load(_modelDef->getClipFile()); |
| 64 | Model::visit(_modelDef->getRoot(), _root, clipDef); |
| 65 | Model::setupCallback(); |
| 66 | for (int i = 0; i < s_cast<int>(_animationGroups.size()); i++) { |
| 67 | const std::string& name = _modelDef->getAnimationNameByIndex(i); |
| 68 | _animationGroups[i]->animationEnd = [this, name](Model* model) { |
| 69 | emit("AnimationEnd"_slice, name, s_cast<Playable*>(model)); |
| 70 | _lastCompletedAnimationName = name; |
| 71 | }; |
| 72 | } |
| 73 | } |
| 74 | Size size = _modelDef->getSize(); |
| 75 | Model::setSize(size); |
| 76 | _root->setPosition(Vec2{size.width * 0.5f, size.height * 0.5f}); |
| 77 | addChild(_root); |
| 78 | handlers(this); |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | bool Model::hasAnimation(String name) const { |
| 83 | return _modelDef->getAnimationIndexByName(name) != Animation::None; |
nothing calls this directly
no test coverage detected