Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #include "SkeletalAnimationPlugin.hh"
51
52 void SkeletalAnimationPlugin::setDescriptions(){
53
54 emit setSlotDescription("attachSkin(int,int)",tr("Attaches a mesh to a skeleton as skin. Each are identified by their objectIds"),
55 QString(tr("SkeletonObjectId,SkinObjectId")).split(","),
56 QString(tr("id of the skeleton object, id of the skin object")).split(","));
57
58 emit setSlotDescription("detachSkin(int,int)",tr("Remove a specific skin from the skeleton"),
59 QString(tr("SkeletonObjectId,SkinObjectId")).split(","),
60 QString(tr("id of the skeleton object, id of the skin object")).split(","));
61
62 emit setSlotDescription("clearSkins(int)",tr("Remove all skins from a skeleton"),
63 QStringList(tr("SkeletonObjectId")), QStringList(tr("ID of the skeleton object")));
64 }
65
66 bool SkeletalAnimationPlugin::attachSkin(int skeletonId, int skinId) {
67 BaseObjectData* skeleton = NULL;
68 if (!PluginFunctions::getObject(skeletonId, skeleton)) {
69 emit log(LOGERR, "Could not retrieve skeleton");
70 return false;
71 }
72
73 BaseObjectData* skin = NULL;
74 if (!PluginFunctions::getObject(skinId, skin)) {
75 emit log(LOGERR, "Could not retrieve skin");
76 return false;
77 }
78
79 attachSkin(skin, skeleton);
80
81 return true;
82 }
83
84 bool SkeletalAnimationPlugin::detachSkin(int skeletonId, int skinId) {
85 BaseObjectData* skeleton = NULL;
86 if (!PluginFunctions::getObject(skeletonId, skeleton)) {
87 emit log(LOGERR, "Could not retrieve skeleton");
88 return false;
89 }
90
91 BaseObjectData* skin = NULL;
92 if (!PluginFunctions::getObject(skinId, skin)) {
93 emit log(LOGERR, "Could not retrieve skin");
94 return false;
95 }
96
97 detachSkin(skin, skeleton);
98
99 return true;
100 }
101
102 bool SkeletalAnimationPlugin::clearSkins(int skeletonId) {
103 BaseObjectData* skeleton = NULL;
104 if (!PluginFunctions::getObject(skeletonId, skeleton)) {
105 emit log(LOGERR, "Could not retrieve skeleton");
106 return false;
107 }
108
109 clearSkins(skeleton);
110
111 return true;
112 }
113
114 void SkeletalAnimationPlugin::updateSkins(){
115
116 for (unsigned int i=0; i < activeSkeletons_.size(); i++){
117
118 //get active skeleton
119 BaseObjectData* baseObject = 0;
120 PluginFunctions::getObject(activeSkeletons_[i], baseObject);
121
122 if ( baseObject == 0 )
123 continue;
124
125 SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(baseObject);
126
127 AnimationHandle hAni = skeletonObject->skeletonNode()->activePose();
128 UpdateSkins(skeletonObject, hAni);
129 }
130 }
SkeletalAnimationPlugin::updateSkins
void updateSkins()
Returns the number of frames in the currently active animation.
Definition: SkeletalAnimationScripting.cc:114
LOGERR
Definition: LoggingInterface.hh:107
BaseObjectData
Definition: BaseObjectData.hh:105
SkeletalAnimationPlugin::attachSkin
bool attachSkin(int skeletonId, int skinId)
Returns the number of frames in the currently active animation.
Definition: SkeletalAnimationScripting.cc:66
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
SkeletalAnimationPlugin::UpdateSkins
void UpdateSkins(BaseObjectData *_pSkeletonObject, AnimationHandle &_hAni)
Changes the mesh's pose to represent the frame given by the animation handle.
Definition: SkeletalAnimationPlugin.cc:376
SkeletonObject
Definition: SkeletonObject.hh:82
BaseInterface::setSlotDescription
virtual void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions)
Set a description for a public slot.
Definition: BaseInterface.hh:306
SkeletalAnimationPlugin::detachSkin
bool detachSkin(int skeletonId, int skinId)
Returns the number of frames in the currently active animation.
Definition: SkeletalAnimationScripting.cc:84
AnimationHandle
A handle used to refer to an animation or to a specific frame in an animation.
Definition: AnimationHandle.hh:56
SkeletonObject::skeletonNode
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
Definition: SkeletonObject.cc:218
SkeletalAnimationPlugin::clearSkins
bool clearSkins(int skeletonId)
Returns the number of frames in the currently active animation.
Definition: SkeletalAnimationScripting.cc:102