1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/*
===========================================================================
Copyright (C) 2023 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// bonetable.cpp : Bone table
#include "q_shared.h"
#include "tiki.h"
void ChannelNameTable::CopyChannel(ChannelName_t *dest, const ChannelName_t *source)
{
memcpy(dest, source, sizeof(ChannelName_t));
}
void ChannelNameTable::SetChannelName(ChannelName_t *channel, const char *newName)
{
Q_strncpyz(channel->name, newName, sizeof(channel->name));
}
ChannelNameTable::ChannelNameTable()
{
memset(this, 0, sizeof(ChannelNameTable));
m_iNumChannels = 0;
}
void ChannelNameTable::PrintContents()
{
str channelList;
int i;
for (i = 0; i < m_iNumChannels; i++) {
if (!m_Channels[i].name[0]) {
continue;
}
channelList += str("c") + m_Channels[i].channelNum + ":" + str(m_Channels[i].name) + "\n";
}
SKEL_Message("ChannelNameTable contents:\n%s", channelList.c_str());
}
bool ChannelNameTable::FindIndexFromName(const char *name, int *indexPtr)
{
int sortValue;
int lowerBound;
int upperBound;
int index;
lowerBound = 0;
upperBound = m_iNumChannels - 1;
while (lowerBound <= upperBound) {
index = (lowerBound + upperBound) / 2;
sortValue = stricmp(name, m_Channels[index].name);
if (!sortValue) {
if (indexPtr) {
*indexPtr = index;
}
return true;
}
if (sortValue <= 0) {
upperBound = index - 1;
} else {
lowerBound = index + 1;
}
}
if (indexPtr) {
*indexPtr = lowerBound;
}
return false;
}
int ChannelNameTable::FindNameLookup(const char *name)
{
int index;
if (FindIndexFromName(name, &index)) {
return m_Channels[index].channelNum;
} else {
return -1;
}
}
const char *ChannelNameTable::FindName(int index)
{
return FindNameFromLookup(m_lookup[index]);
}
void ChannelNameTable::SortIntoTable(int index)
{
int i;
ChannelName_t tempName;
CopyChannel(&tempName, &m_Channels[m_iNumChannels]);
for (i = m_iNumChannels - 1; i >= index; i--) {
m_lookup[m_Channels[i].channelNum] = i + 1;
CopyChannel(&m_Channels[i + 1], &m_Channels[i]);
}
m_lookup[tempName.channelNum] = index;
CopyChannel(&m_Channels[index], &tempName);
}
static const char *bogusNameTable[] = {
"Bip01 Spine pos",
"Bip01 Spine1 pos",
"Bip01 Spine2 pos",
"Bip01 Neck pos",
"Bip01 Head pos",
"helmet bone pos",
"helmet bone rot",
"Bip01 R Clavicle pos",
"Bip01 R UpperArm pos",
"Bip01 R Forearm pos",
"Bip01 R Hand pos",
"Bip01 R Finger0 pos",
"Bip01 R Finger01 pos",
"Bip01 R Finger02 pos",
"Bip01 R Finger1 pos",
"Bip01 R Finger11 pos",
"Bip01 R Finger12 pos",
"Bip01 R Finger2 pos",
"Bip01 R Finger21 pos",
"Bip01 R Finger22 pos",
"Bip01 R Finger3 pos",
"Bip01 R Finger31 pos",
"Bip01 R Finger32 pos",
"Bip01 R Finger4 pos",
"Bip01 R Finger41 pos",
"Bip01 R Finger42 pos",
"Bip01 L Clavicle pos",
"Bip01 L UpperArm pos",
"Bip01 L Forearm pos",
"Bip01 L Hand pos",
"Bip01 L Finger0 pos",
"Bip01 L Finger01 pos",
"Bip01 L Finger02 pos",
"Bip01 L Finger1 pos",
"Bip01 L Finger11 pos",
"Bip01 L Finger12 pos",
"Bip01 L Finger2 pos",
"Bip01 L Finger21 pos",
"Bip01 L Finger22 pos",
"Bip01 L Finger3 pos",
"Bip01 L Finger31 pos",
"Bip01 L Finger32 pos",
"Bip01 L Finger4 pos",
"Bip01 L Finger41 pos",
"Bip01 L Finger42 pos",
"Bip01 L Toe0 pos",
"Bip01 R Toe0 pos",
"buckle bone pos",
"buckle bone rot",
"belt attachments bone pos",
"belt attachments bone rot",
"backpack bone pos",
"backpack bone rot",
"helper Lelbow pos",
"helper Lelbow rot",
"helper Lshoulder pos",
"helper Lshoulder rot",
"helper Lshoulder01 pos",
"helper Lshoulder01 rot",
"helper Rshoulder pos",
"helper Rshoulder rot",
"helper Lshoulder02 pos",
"helper Lshoulder02 rot",
"helper Relbow pos",
"helper Relbow rot",
"helper Lankle pos",
"helper Lankle rot",
"helper Lknee pos",
"helper Lknee rot",
"helper Rankle pos",
"helper Rankle rot",
"helper Rknee pos",
"helper Rknee rot",
"helper Lhip pos",
"helper Lhip rot",
"helper Lhip01 pos",
"helper Lhip01 rot",
"helper Rhip pos",
"helper Rhip rot",
"helper Rhip01 pos",
"helper Rhip01 rot",
"target_left_hand pos",
"target_left_hand rot",
"target_right_hand pos",
"target_right_hand rot",
"JAW open-closed pos",
"JAW open-closed rot",
"BROW_worry$",
"EYES_down$",
"EYES_Excited_$",
"EYES_L_squint$",
"EYES_left$",
"EYES_right$",
"EYES_smile$",
"EYES_up_$",
"JAW_open-open$",
"MOUTH_L_smile_open$",
"VISEME_Eat$",
"right foot placeholder pos"
"right foot placeholder rot"
"left foot placeholder pos"
"left foot placeholder rot"
};
bool IsBogusChannelName(const char *name)
{
int i;
for (i = 0; i < sizeof(bogusNameTable) / sizeof(bogusNameTable[0]); i++) {
if (!Q_stricmp(name, bogusNameTable[i])) {
return true;
}
}
if (strstr(name, "Bip0") && !strstr(name, "Bip01") && !strstr(name, "Footsteps")) {
return true;
}
return false;
}
channelType_t GetBoneChannelType(const char *name)
{
size_t len;
if (!name) {
return CHANNEL_NONE;
}
if (IsBogusChannelName(name)) {
return CHANNEL_NONE;
}
len = strlen(name);
if (len < 4) {
return CHANNEL_VALUE;
}
if (!strcmp(name + len - 4, " rot")) {
return CHANNEL_ROTATION;
}
if (!strcmp(name + len - 4, " pos")) {
return CHANNEL_POSITION;
}
if (len >= 6 && !strcmp(name + len - 6, " rotFK")) {
return CHANNEL_NONE;
}
return CHANNEL_VALUE;
}
int ChannelNameTable::RegisterChannel(const char *name)
{
int index;
if (IsBogusChannelName(name)) {
return -1;
}
if (FindIndexFromName(name, &index)) {
return m_Channels[index].channelNum;
}
if (m_iNumChannels >= MAX_SKELETOR_CHANNELS) {
Com_Printf("==========================================================================\n");
Com_Printf("Skeletor channel name table, contents (in order of addition):\n");
for (index = 0; index < MAX_SKELETOR_CHANNELS; index++) {
Com_Printf("%s\n", m_Channels[m_lookup[index]].name);
}
Com_Printf("==========================================================================\n");
SKEL_Error("Channel name table already has %i channels, can't add any more.", MAX_SKELETOR_CHANNELS);
return -1;
} else {
SetChannelName(&m_Channels[m_iNumChannels], name);
m_Channels[m_iNumChannels].channelNum = m_iNumChannels;
SortIntoTable(index);
return m_iNumChannels++;
}
}
const char *ChannelNameTable::FindNameFromLookup(int index)
{
if (index >= m_iNumChannels) {
return NULL;
}
return m_Channels[index].name;
}
|