Developer Documentation
SkeletalAnimationScripting.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 #include "SkeletalAnimationPlugin.hh"
44 
48 
49 void SkeletalAnimationPlugin::setDescriptions(){
50 
51  emit setSlotDescription("attachSkin(int,int)",tr("Attaches a mesh to a skeleton as skin. Each are identified by their objectIds"),
52  QString(tr("SkeletonObjectId,SkinObjectId")).split(","),
53  QString(tr("id of the skeleton object, id of the skin object")).split(","));
54 
55  emit setSlotDescription("detachSkin(int,int)",tr("Remove a specific skin from the skeleton"),
56  QString(tr("SkeletonObjectId,SkinObjectId")).split(","),
57  QString(tr("id of the skeleton object, id of the skin object")).split(","));
58 
59  emit setSlotDescription("clearSkins(int)",tr("Remove all skins from a skeleton"),
60  QStringList(tr("SkeletonObjectId")), QStringList(tr("ID of the skeleton object")));
61 }
62 
63 bool SkeletalAnimationPlugin::attachSkin(int skeletonId, int skinId) {
64  BaseObjectData* skeleton = NULL;
65  if (!PluginFunctions::getObject(skeletonId, skeleton)) {
66  emit log(LOGERR, "Could not retrieve skeleton");
67  return false;
68  }
69 
70  BaseObjectData* skin = NULL;
71  if (!PluginFunctions::getObject(skinId, skin)) {
72  emit log(LOGERR, "Could not retrieve skin");
73  return false;
74  }
75 
76  attachSkin(skin, skeleton);
77 
78  return true;
79 }
80 
81 bool SkeletalAnimationPlugin::detachSkin(int skeletonId, int skinId) {
82  BaseObjectData* skeleton = NULL;
83  if (!PluginFunctions::getObject(skeletonId, skeleton)) {
84  emit log(LOGERR, "Could not retrieve skeleton");
85  return false;
86  }
87 
88 
89  BaseObjectData* skin = NULL;
90  if (!PluginFunctions::getObject(skinId, skin)) {
91  emit log(LOGERR, "Could not retrieve skin");
92  return false;
93  }
94 
95  detachSkin(skin, skeleton);
96 
97  return true;
98 }
99 
101  BaseObjectData* skeleton = NULL;
102  if (!PluginFunctions::getObject(skeletonId, skeleton)) {
103  emit log(LOGERR, "Could not retrieve skeleton");
104  return false;
105  }
106 
107  clearSkins(skeleton);
108 
109  return true;
110 }
111 
113 
114  for (unsigned int i=0; i < activeSkeletons_.size(); i++){
115 
116  //get active skeleton
117  BaseObjectData* baseObject = 0;
118  PluginFunctions::getObject(activeSkeletons_[i], baseObject);
119 
120  if ( baseObject == 0 )
121  continue;
122 
123  SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(baseObject);
124 
125  AnimationHandle hAni = skeletonObject->skeletonNode()->activePose();
126  UpdateSkins(skeletonObject, hAni);
127  }
128 }
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
void UpdateSkins(BaseObjectData *_pSkeletonObject, AnimationHandle &_hAni)
Changes the mesh&#39;s pose to represent the frame given by the animation handle.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
A handle used to refer to an animation or to a specific frame in an animation.
void updateSkins()
Returns the number of frames in the currently active animation.
bool attachSkin(int skeletonId, int skinId)
Returns the number of frames in the currently active animation.
bool clearSkins(int skeletonId)
Returns the number of frames in the currently active animation.
bool detachSkin(int skeletonId, int skinId)
Returns the number of frames in the currently active animation.
virtual void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions)
Set a description for a public slot.