int Skeleton::addBone(int i,Bone* parent) { // Check that this line in the file describes a joint. if (items[i]!="JOINT") DIE("Bad file format"); // Make a new bone Bone* newBone = new Bone(items[i+1].c_str(),numberOfBones); numberOfBones++; // Add it to its parent parent->addChild(newBone); // Skip three entries i+=3; if (items[i]!="OFFSET")DIE("Bad file format"); newBone->offset = glm::vec3(atof(items[i+1].c_str()),atof(items[i+3].c_str()),atof(items[i+2].c_str())); newBone->origTotOffset= parent->origTotOffset+ newBone->offset; newBone->origOffset = newBone->offset; i+=4; // Check that this specifies the channels and get the number of them if (items[i]!="CHANNELS") DIE("Bad file format"); int nc = atoi(items[i+1].c_str()); i+=2; // Now for each channel, check its type and put the relevant pointer in the correct place. for (int k = 0;k<nc;k++) { if (items[i+k]=="Xposition") placesForAnimation.push_back(&(newBone->offset.x)); else if (items[i+k]=="Yposition") placesForAnimation.push_back(&(newBone->offset.z)); else if (items[i+k]=="Zposition") placesForAnimation.push_back(&(newBone->offset.y)); else if (items[i+k]=="Zrotation") placesForAnimation.push_back(&(newBone->yRot)); else if (items[i+k]=="Yrotation") placesForAnimation.push_back(&(newBone->zRot)); else if (items[i+k]=="Xrotation") placesForAnimation.push_back(&(newBone->xRot)); else placesForAnimation.push_back(&dummy); } i+=nc; while (1) { if (items[i]=="End") { Bone* nnb = new Bone("end",numberOfBones);numberOfBones++; newBone->addChild(nnb); nnb->offset= glm::vec3(atof(items[i+4].c_str()),atof(items[i+6].c_str()),atof(items[i+5].c_str())); i+=8; } if (items[i]=="JOINT") i = addBone(i,newBone); else return i+1; } return i; }
void Mesh::loadSkeleton(std::string filename) { std::istream *file = getFile(filename, _lab); int numBones = readInt(*file); string boneName; string parentName; Bone *bone; Bone *parent; float angle = 0.0f; // Bones are listed in the same order as in the meshb. Vector3d *vec = 0; for(int i = 0;i < numBones; i++) { boneName = readCString(*file,32); parentName = readCString(*file,32); bone = _boneMap[boneName]; /* for (int j = 0; j < _numBones; j++) { if (_bones[j].getName() == boneName) { bone = _bones + j; break; } }*/ if (parentName != "no_parent") { /* for (int j = 0; j < _numBones; j++) { if (_bones[j].getName() == parentName) { parent = _bones + j; break; } }*/ parent = _boneMap[parentName]; assert(parent != 0); assert(bone != 0); if (!parent->hasChild(bone)) parent->addChild(bone); } bone->setPos(readVector3d(*file)); bone->setRot(readVector3d(*file)); bone->setAngle(readFloat(*file)); } }
//------------------------------------------------------------------- void XMLSkeletonSerializer::createHierarchy(Skeleton* skel, TiXmlElement* mHierNode) { LogManager::getSingleton().logMessage("XMLSkeletonSerializer: Reading Hierarchy data..."); Bone* bone; Bone* parent; String boneName; String parentName; for (TiXmlElement* hierElem = mHierNode->FirstChildElement(); hierElem != 0; hierElem = hierElem->NextSiblingElement()) { boneName = hierElem->Attribute("bone"); parentName = hierElem->Attribute("parent"); bone = skel->getBone(boneName); parent = skel->getBone(parentName); parent->addChild(bone); //LogManager::getSingleton().logMessage("XMLSkeletonSerialiser: lien: " + parent->getName() + "->" + bone->getName()); } }
void Armature::addChild(DBObject* object, std::string parentName){ if(!object) { return; } if(parentName != "") { Bone* boneParent = getBone(parentName); if (boneParent) { boneParent->addChild(object); } } else { if(object->parent) { object->parent->removeChild(object); } object->setArmature(this); } }
Person::Person() : Bone(getRoot()) { ColouredSurface* red = new ColouredSurface(1, 0, 0); ColouredSurface* green = new ColouredSurface(0, 1, 0); ColouredSurface* blue = new ColouredSurface(0, 0, 1); Shape* pelvis = new Cylinder(0.08, 0.15, Point(0.3, 0, 0)); pelvis->setSurface(blue); Bone* bPelvis = new Bone(pelvis); pelvis->setRotation(90, 0, 0); this->addChild("Pelvis", bPelvis); Shape* chest = new Cylinder(0.08, 0.1, Point(0, 0.125, 0)); chest->setSurface(green); Bone* bChest = new Bone(chest); chest->setRotation(90, 0, 0); Shape* head = new Sphere(0.08, Point(0, 0.13, 0)); TexturedSurface* headTex = new TexturedSurface("./face.jpg"); head->setTexture(headTex); Bone* bHead = new Bone(head); head->setRotation(90, 0, 0); Shape* upperLeftArm = new Cylinder(0.02, 0.08, Point(-0.1, 0, 0)); upperLeftArm->setSurface(red); upperLeftArm->setRotation(90, 0, 0); Bone* ula = new Bone(upperLeftArm); ula->setJointOffset(0, -0.04, 0); Shape* upperLeftArmJoint = new Sphere(0.04, Point(-0.1, 0, 0)); upperLeftArmJoint->setSurface(blue); upperLeftArmJoint->setRotation(90, 0, 0); Bone* ulaj = new Bone(upperLeftArmJoint); Shape* lowerLeftArm = new Cylinder(0.02, 0.08, Point(0, -0.08, 0)); lowerLeftArm->setSurface(green); lowerLeftArm->setRotation(90, 0, 0); Bone* lla = new Bone(lowerLeftArm); lla->setJointOffset(0, -0.04, 0); Shape* lowerLeftArmJoint = new Sphere(0.03, Point(0, -0.08, 0)); lowerLeftArmJoint->setSurface(blue); lowerLeftArmJoint->setRotation(90, 0, 0); Bone* llaj = new Bone(lowerLeftArmJoint); Shape* upperRightArm = new Cylinder(0.02, 0.08, Point(0.1, 0, 0)); upperRightArm->setSurface(red); upperRightArm->setRotation(90, 0, 0); Bone* ura = new Bone(upperRightArm); ura->setJointOffset(0, -0.04, 0); Shape* upperRightArmJoint = new Sphere(0.04, Point(0.1, 0, 0)); upperRightArmJoint->setSurface(blue); upperRightArmJoint->setRotation(90, 0, 0); Bone* uraj = new Bone(upperRightArmJoint); Shape* lowerRightArm = new Cylinder(0.02, 0.08, Point(0, -0.08, 0)); lowerRightArm->setSurface(green); lowerRightArm->setRotation(90, 0, 0); Bone* lra = new Bone(lowerRightArm); lra->setJointOffset(0, -0.04, 0); Shape* lowerRightArmJoint = new Sphere(0.03, Point(0, -0.08, 0)); lowerRightArmJoint->setSurface(blue); lowerRightArmJoint->setRotation(90, 0, 0); Bone* lraj = new Bone(lowerRightArmJoint); Shape* upperLeftLeg = new Cylinder(0.03, 0.09, Point(-0.04, -0.07, 0)); upperLeftLeg->setSurface(red); upperLeftLeg->setRotation(90, 0, 0); Bone* ull = new Bone(upperLeftLeg); ull->setJointOffset(0, -0.04, 0); Shape* lowerLeftLeg = new Cylinder(0.03, 0.09, Point(0, -0.1, 0)); lowerLeftLeg->setSurface(blue); lowerLeftLeg->setRotation(90, 0, 0); Bone* lll = new Bone(lowerLeftLeg); lll->setJointOffset(0, -0.02, 0); Shape* lowerLeftLegJoint = new Sphere(0.03, Point(0, -0.1, 0)); lowerLeftLegJoint->setSurface(green); Bone* lllj = new Bone(lowerLeftLegJoint); Shape* upperRightLeg = new Cylinder(0.03, 0.09, Point(0.04, -0.07, 0)); upperRightLeg->setSurface(red); upperRightLeg->setRotation(90, 0, 0); Bone* url = new Bone(upperRightLeg); url->setJointOffset(0, -0.04, 0); Shape* lowerRightLeg = new Cylinder(0.03, 0.09, Point(0, -0.1, 0)); lowerRightLeg->setSurface(blue); lowerRightLeg->setRotation(90, 0, 0); Bone* lrl = new Bone(lowerRightLeg); lrl->setJointOffset(0, -0.02, 0); Shape* lowerRightLegJoint = new Sphere(0.03, Point(0, -0.1, 0)); lowerRightLegJoint->setSurface(green); Bone* lrlj = new Bone(lowerRightLegJoint); bPelvis->addChild("Chest", bChest); bPelvis->addChild("LeftLeg", ull); bPelvis->addChild("RightLeg", url); bChest->addChild("Head", bHead); bChest->addChild("UpperRightArm", ura); bChest->addChild("UpperLeftArm", ula); bChest->addChild("LeftShoulder", ulaj); bChest->addChild("RightShoulder", uraj); ula->addChild("LowerArm", lla); ula->addChild("Elbow", llaj); ura->addChild("LowerArm", lra); ura->addChild("Elbow", lraj); ull->addChild("LowerLeg", lll); ull->addChild("Knee", lllj); url->addChild("LowerLeg", lrl); url->addChild("Knee", lrlj); ura->setAnimation(Point(10, 0, 0), Point(-90, 0, 0), 45, 0); lra->setRotation(-45, 0, 0); ula->setAnimation(Point(10, 0, 0), Point(-90, 0, 0), 45, 45); lla->setRotation(-45, 0, 0); ull->setAnimation(Point(10, 0, 0), Point(-90, 0, 0), 45, 0); lll->setRotation(45, 0, 0); url->setAnimation(Point(10, 0, 0), Point(-90, 0, 0), 45, 45); // lrl->setAnimation(Point(45, 0, 0), Point(-90, 0, 0), 90, 90); lrl->setRotation(45, 0, 0); bPelvis->setRotation(0, 180, 0); }
void Skeleton::loadSkeleton(const String& fileName) { OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb"); if(!inFile) { return; } bonesEntity = new Entity(); bonesEntity->visible = false; addChild(bonesEntity); unsigned int numBones; float t[3],rq[4],s[3]; OSBasics::read(&numBones, sizeof(unsigned int), 1, inFile); unsigned int namelen; char buffer[1024]; Matrix4 mat; unsigned int hasParent, boneID; for(int i=0; i < numBones; i++) { OSBasics::read(&namelen, sizeof(unsigned int), 1, inFile); memset(buffer, 0, 1024); OSBasics::read(buffer, 1, namelen, inFile); Bone *newBone = new Bone(String(buffer)); OSBasics::read(&hasParent, sizeof(unsigned int), 1, inFile); if(hasParent == 1) { OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile); newBone->parentBoneId = boneID; } else { newBone->parentBoneId = -1; } OSBasics::read(t, sizeof(float), 3, inFile); OSBasics::read(s, sizeof(float), 3, inFile); OSBasics::read(rq, sizeof(float), 4, inFile); bones.push_back(newBone); Quaternion bq; bq.set(rq[0], rq[1], rq[2], rq[3]); newBone->baseRotation = bq; newBone->baseScale = Vector3(s[0], s[1], s[2]); newBone->basePosition = Vector3(t[0], t[1], t[2]); newBone->setPosition(t[0], t[1], t[2]); newBone->setRotationQuat(rq[0], rq[1], rq[2], rq[3]); newBone->setScale(s[0], s[1], s[2]); newBone->rebuildTransformMatrix(); newBone->setBaseMatrix(newBone->getTransformMatrix()); newBone->setBoneMatrix(newBone->getTransformMatrix()); OSBasics::read(t, sizeof(float), 3, inFile); OSBasics::read(s, sizeof(float), 3, inFile); OSBasics::read(rq, sizeof(float), 4, inFile); Quaternion q; q.set(rq[0], rq[1], rq[2], rq[3]); Matrix4 m = q.createMatrix(); m.setPosition(t[0], t[1], t[2]); newBone->setRestMatrix(m); } Bone *parentBone; for(int i=0; i < bones.size(); i++) { if(bones[i]->parentBoneId != -1) { parentBone = bones[bones[i]->parentBoneId]; parentBone->addChildBone(bones[i]); bones[i]->setParentBone(parentBone); parentBone->addChild(bones[i]); } else { bonesEntity->addChild(bones[i]); } } OSBasics::close(inFile); }
void Skeleton::_mergeSkeletonAnimations(const Skeleton* src, const BoneHandleMap& boneHandleMap, const StringVector& animations) { ushort handle; ushort numSrcBones = src->getNumBones(); ushort numDstBones = this->getNumBones(); if (boneHandleMap.size() != numSrcBones) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Number of bones in the bone handle map must equal to " "number of bones in the source skeleton.", "Skeleton::_mergeSkeletonAnimations"); } bool existsMissingBone = false; // Check source skeleton structures compatible with ourself (that means // identically bones with identical handles, and with same hierarchy, but // not necessary to have same number of bones and bone names). for (handle = 0; handle < numSrcBones; ++handle) { const Bone* srcBone = src->getBone(handle); ushort dstHandle = boneHandleMap[handle]; // Does it exists in target skeleton? if (dstHandle < numDstBones) { Bone* destBone = this->getBone(dstHandle); // Check both bones have identical parent, or both are root bone. const Bone* srcParent = static_cast<Bone*>(srcBone->getParent()); Bone* destParent = static_cast<Bone*>(destBone->getParent()); if ((srcParent || destParent) && (!srcParent || !destParent || boneHandleMap[srcParent->getHandle()] != destParent->getHandle())) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Source skeleton incompatible with this skeleton: " "difference hierarchy between bone '" + srcBone->getName() + "' and '" + destBone->getName() + "'.", "Skeleton::_mergeSkeletonAnimations"); } } else { existsMissingBone = true; } } // Clone bones if need if (existsMissingBone) { // Create missing bones for (handle = 0; handle < numSrcBones; ++handle) { const Bone* srcBone = src->getBone(handle); ushort dstHandle = boneHandleMap[handle]; // The bone is missing in target skeleton? if (dstHandle >= numDstBones) { Bone* dstBone = this->createBone(srcBone->getName(), dstHandle); // Sets initial transform dstBone->setPosition(srcBone->getInitialPosition()); dstBone->setOrientation(srcBone->getInitialOrientation()); dstBone->setScale(srcBone->getInitialScale()); dstBone->setInitialState(); } } // Link new bones to parent for (handle = 0; handle < numSrcBones; ++handle) { const Bone* srcBone = src->getBone(handle); ushort dstHandle = boneHandleMap[handle]; // Is new bone? if (dstHandle >= numDstBones) { const Bone* srcParent = static_cast<Bone*>(srcBone->getParent()); if (srcParent) { Bone* destParent = this->getBone(boneHandleMap[srcParent->getHandle()]); Bone* dstBone = this->getBone(dstHandle); destParent->addChild(dstBone); } } } // Derive root bones in case it was changed this->deriveRootBone(); // Reset binding pose for new bones this->reset(true); this->setBindingPose(); } // // We need to adapt animations from source to target skeleton, but since source // and target skeleton bones bind transform might difference, so we need to alter // keyframes in source to suit to target skeleton. // // For any given animation time, formula: // // LocalTransform = BindTransform * KeyFrame; // DerivedTransform = ParentDerivedTransform * LocalTransform // // And all derived transforms should be keep identically after adapt to // target skeleton, Then: // // DestDerivedTransform == SrcDerivedTransform // DestParentDerivedTransform == SrcParentDerivedTransform // ==> // DestLocalTransform = SrcLocalTransform // ==> // DestBindTransform * DestKeyFrame = SrcBindTransform * SrcKeyFrame // ==> // DestKeyFrame = inverse(DestBindTransform) * SrcBindTransform * SrcKeyFrame // // We define (inverse(DestBindTransform) * SrcBindTransform) as 'delta-transform' here. // // Calculate delta-transforms for all source bones. vector<DeltaTransform>::type deltaTransforms(numSrcBones); for (handle = 0; handle < numSrcBones; ++handle) { const Bone* srcBone = src->getBone(handle); DeltaTransform& deltaTransform = deltaTransforms[handle]; ushort dstHandle = boneHandleMap[handle]; if (dstHandle < numDstBones) { // Common bone, calculate delta-transform Bone* dstBone = this->getBone(dstHandle); deltaTransform.translate = srcBone->getInitialPosition() - dstBone->getInitialPosition(); deltaTransform.rotate = dstBone->getInitialOrientation().Inverse() * srcBone->getInitialOrientation(); deltaTransform.scale = srcBone->getInitialScale() / dstBone->getInitialScale(); // Check whether or not delta-transform is identity const Real tolerance = 1e-3f; Vector3 axis; Radian angle; deltaTransform.rotate.ToAngleAxis(angle, axis); deltaTransform.isIdentity = deltaTransform.translate.positionEquals(Vector3::ZERO, tolerance) && deltaTransform.scale.positionEquals(Vector3::UNIT_SCALE, tolerance) && Math::RealEqual(angle.valueRadians(), 0.0f, tolerance); } else { // New bone, the delta-transform is identity deltaTransform.translate = Vector3::ZERO; deltaTransform.rotate = Quaternion::IDENTITY; deltaTransform.scale = Vector3::UNIT_SCALE; deltaTransform.isIdentity = true; } } // Now copy animations ushort numAnimations; if (animations.empty()) numAnimations = src->getNumAnimations(); else numAnimations = static_cast<ushort>(animations.size()); for (ushort i = 0; i < numAnimations; ++i) { const Animation* srcAnimation; if (animations.empty()) { // Get animation of source skeleton by the given index srcAnimation = src->getAnimation(i); } else { // Get animation of source skeleton by the given name const LinkedSkeletonAnimationSource* linker; srcAnimation = src->_getAnimationImpl(animations[i], &linker); if (!srcAnimation || linker) { OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "No animation entry found named " + animations[i], "Skeleton::_mergeSkeletonAnimations"); } } // Create target animation Animation* dstAnimation = this->createAnimation(srcAnimation->getName(), srcAnimation->getLength()); // Copy interpolation modes dstAnimation->setInterpolationMode(srcAnimation->getInterpolationMode()); dstAnimation->setRotationInterpolationMode(srcAnimation->getRotationInterpolationMode()); // Copy track for each bone for (handle = 0; handle < numSrcBones; ++handle) { const DeltaTransform& deltaTransform = deltaTransforms[handle]; ushort dstHandle = boneHandleMap[handle]; if (srcAnimation->hasNodeTrack(handle)) { // Clone track from source animation const NodeAnimationTrack* srcTrack = srcAnimation->getNodeTrack(handle); NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle)); dstTrack->setUseShortestRotationPath(srcTrack->getUseShortestRotationPath()); ushort numKeyFrames = srcTrack->getNumKeyFrames(); for (ushort k = 0; k < numKeyFrames; ++k) { const TransformKeyFrame* srcKeyFrame = srcTrack->getNodeKeyFrame(k); TransformKeyFrame* dstKeyFrame = dstTrack->createNodeKeyFrame(srcKeyFrame->getTime()); // Adjust keyframes to match target binding pose if (deltaTransform.isIdentity) { dstKeyFrame->setTranslate(srcKeyFrame->getTranslate()); dstKeyFrame->setRotation(srcKeyFrame->getRotation()); dstKeyFrame->setScale(srcKeyFrame->getScale()); } else { dstKeyFrame->setTranslate(deltaTransform.translate + srcKeyFrame->getTranslate()); dstKeyFrame->setRotation(deltaTransform.rotate * srcKeyFrame->getRotation()); dstKeyFrame->setScale(deltaTransform.scale * srcKeyFrame->getScale()); } } } else if (!deltaTransform.isIdentity) { // Create 'static' track for this bone NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle)); TransformKeyFrame* dstKeyFrame; dstKeyFrame = dstTrack->createNodeKeyFrame(0); dstKeyFrame->setTranslate(deltaTransform.translate); dstKeyFrame->setRotation(deltaTransform.rotate); dstKeyFrame->setScale(deltaTransform.scale); dstKeyFrame = dstTrack->createNodeKeyFrame(dstAnimation->getLength()); dstKeyFrame->setTranslate(deltaTransform.translate); dstKeyFrame->setRotation(deltaTransform.rotate); dstKeyFrame->setScale(deltaTransform.scale); } } } }
/** * Build and returns a new Armature instance. * @example * <listing> * var armature:Armature = factory.buildArmature('dragon'); * </listing> * @param armatureName The name of this Armature instance. * @param The name of this animation * @param The name of this SkeletonData. * @param The name of this textureAtlas. * @param The name of this skin. * @return A Armature instance. */ Armature* BaseFactory::buildArmature(const String &armatureName, const String &animationName, const String &skeletonName, const String &textureAtlasName, const String &skinName) { ArmatureData* armatureData = 0; SkeletonData *data = 0; if(!skeletonName.empty()) { std::map<String , SkeletonData*>::iterator iter = _dataDic.find(skeletonName); if(iter != _dataDic.end()) { data = iter->second; armatureData = data->getArmatureData(armatureName); } } //else //{ // for(skeletonName in _dataDic) // { // data = _dataDic[skeletonName]; // armatureData = data->getArmatureData(armatureName); // if(armatureData) // { // break; // } // } //} if(!armatureData) { return nullptr; } _currentDataName = skeletonName; _currentTextureAtlasName = textureAtlasName.empty() ? skeletonName : textureAtlasName; Armature* armature = generateArmature(); armature->name = armatureName; Bone* bone; for(size_t i = 0 ; i < armatureData->boneDataList.size() ; i ++) { BoneData* boneData = armatureData->boneDataList[i]; bone = new Bone(); bone->name = boneData->name; bone->fixedRotation = boneData->fixedRotation; bone->scaleMode = boneData->scaleMode; bone->origin = boneData->transform; if(armatureData->getBoneData(boneData->parent)) { armature->addBone(bone, boneData->parent); } else { armature->addBone(bone); } } ArmatureData* animationArmatureData = 0; SkinData *skinDataCopy = 0; if(!animationName.empty() && animationName != armatureName) { //ArmatureData* animationArmatureData = data->getArmatureData(animationName); // Get the default animation //if(!animationArmatureData) //{ // for (skeletonName in _dataDic) // { // data = _dataDic[skeletonName]; // animationArmatureData = data->getArmatureData(animationName); // if(animationArmatureData) // { // break; // } // } //} ArmatureData* armatureDataCopy = data->getArmatureData(animationName); if(armatureDataCopy) { skinDataCopy = armatureDataCopy->getSkinData(""); } } if(animationArmatureData) { armature->getAnimation()->setAnimationDataList(animationArmatureData->animationDataList); } else { armature->getAnimation()->setAnimationDataList(armatureData->animationDataList); } SkinData* skinData = armatureData->getSkinData(skinName); if(!skinData) { return nullptr; //throw new ArgumentError(); } Slot* slot; DisplayData* displayData; Armature* childArmature; size_t i; //var helpArray:Array = []; for(size_t j = 0 ; j < skinData->slotDataList.size() ; j ++) { SlotData* slotData = skinData->slotDataList[j]; bone = armature->getBone(slotData->parent); if(!bone) { continue; } slot = generateSlot(); slot->name = slotData->name; slot->setBlendMode(slotData->blendMode); slot->_originZOrder = slotData->zOrder; slot->_dislayDataList = slotData->displayDataList; std::vector<Object*> helpArray; i = slotData->displayDataList.size(); helpArray.resize(i); while(i --) { displayData = slotData->displayDataList[i]; if(displayData->type == DisplayData::ARMATURE) { DisplayData* displayDataCopy = 0; if(skinDataCopy) { SlotData* slotDataCopy = skinDataCopy->getSlotData(slotData->name); if(slotDataCopy) { displayDataCopy = slotDataCopy->displayDataList[i]; } } else { displayDataCopy = 0; } childArmature = buildArmature(displayData->name, displayDataCopy?displayDataCopy->name:"", _currentDataName, _currentTextureAtlasName); if(childArmature) { helpArray[i] = childArmature; } //fix by Wayne Dimart: // break; we don't use break here, or will crach the program due to incomplete helpArray. continue; } else { helpArray[i] = generateDisplay(getTextureAtlas(_currentTextureAtlasName), displayData->name, displayData->pivot.x, displayData->pivot.y); } } slot->setDisplayList(helpArray); slot->changeDisplay(0); bone->addChild(slot); } // i = armature->_boneList.size(); while(i --) { armature->_boneList[i]->update(); } i = armature->_slotList.size(); while(i --) { slot = armature->_slotList[i]; slot->update(); } armature->updateSlotsZOrder(); return armature; }
void BaseFactory::buildSlots(Armature *armature, const ArmatureData *armatureData, const SkinData *skinData, const SkinData *skinDataCopy) const { for (size_t i = 0, l = skinData->slotDataList.size(); i < l; ++i) { SlotData *slotData = skinData->slotDataList[i]; Bone *bone = armature->getBone(slotData->parent); if (!bone) { continue; } Slot *slot = generateSlot(slotData); slot->name = slotData->name; slot->_originZOrder = slotData->zOrder; slot->_slotData = slotData; std::vector<std::pair<void*, DisplayType>> displayList; void *frameDisplay = nullptr; for (size_t j = 0, l = slotData->displayDataList.size(); j < l; ++j) { const DisplayData *displayData = slotData->displayDataList[j]; switch (displayData->type) { case DisplayType::DT_ARMATURE: { DisplayData *displayDataCopy = nullptr; if (skinDataCopy) { const SlotData *slotDataCopy = skinDataCopy->getSlotData(slotData->name); if (slotDataCopy) { displayDataCopy = slotDataCopy->displayDataList[i]; } } std::string currentDragonBonesDataName = _currentDragonBonesDataName; std::string currentTextureAtlasName = _currentTextureAtlasName; Armature *childArmature = buildArmature(displayData->name, "", displayDataCopy ? displayDataCopy->name : "", currentDragonBonesDataName, currentTextureAtlasName); displayList.push_back(std::make_pair(childArmature, DisplayType::DT_ARMATURE)); _currentDragonBonesDataName = currentDragonBonesDataName; _currentTextureAtlasName = currentTextureAtlasName; break; } case DisplayType::DT_IMAGE: { void *display = getTextureDisplay(displayData->name, _currentTextureAtlasName, displayData); displayList.push_back(std::make_pair(display, DisplayType::DT_IMAGE)); break; } case DisplayType::DT_FRAME: { //j //frameDisplay = ; break; } default: break; } } bone->addChild(slot); if (!displayList.empty()) { slot->setDisplayList(displayList, false); } } }