Blender  V3.3
BCSampleData.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
4 #include "BCSampleData.h"
5 #include "collada_utils.h"
6 
8 {
9  BCBoneMatrixMap::iterator it;
10  for (it = bonemats.begin(); it != bonemats.end(); ++it) {
11  delete it->second;
12  }
13 }
14 
15 void BCSample::add_bone_matrix(Bone *bone, Matrix &mat)
16 {
17  BCMatrix *matrix;
18  BCBoneMatrixMap::const_iterator it = bonemats.find(bone);
19  if (it != bonemats.end()) {
20  throw std::invalid_argument("bone " + std::string(bone->name) + " already defined before");
21  }
22  matrix = new BCMatrix(mat);
23  bonemats[bone] = matrix;
24 }
25 
26 bool BCSample::get_value(std::string channel_target, const int array_index, float *val) const
27 {
28  std::string bname = bc_string_before(channel_target, ".");
29  std::string channel_type = bc_string_after(channel_target, ".");
30 
31  const BCMatrix *matrix = &obmat;
32  if (bname != channel_target) {
33  bname = bname.substr(2);
34  bname = bc_string_before(bname, "\"");
35  BCBoneMatrixMap::const_iterator it;
36  for (it = bonemats.begin(); it != bonemats.end(); ++it) {
37  Bone *bone = it->first;
38  if (bname == bone->name) {
39  matrix = it->second;
40  break;
41  }
42  }
43  }
44  else {
45  matrix = &obmat;
46  }
47 
48  if (channel_type == "location") {
49  *val = matrix->location()[array_index];
50  }
51  else if (channel_type == "scale") {
52  *val = matrix->scale()[array_index];
53  }
54  else if (channel_type == "rotation" || channel_type == "rotation_euler") {
55  *val = matrix->rotation()[array_index];
56  }
57  else if (channel_type == "rotation_quaternion") {
58  *val = matrix->quat()[array_index];
59  }
60  else {
61  *val = 0;
62  return false;
63  }
64 
65  return true;
66 }
67 
68 const BCMatrix *BCSample::get_matrix(Bone *bone) const
69 {
70  BCBoneMatrixMap::const_iterator it = bonemats.find(bone);
71  if (it == bonemats.end()) {
72  return nullptr;
73  }
74  return it->second;
75 }
76 
78 {
79  return obmat;
80 }
float(& rotation() const)[3]
Definition: BCMath.cpp:216
float(& scale() const)[3]
Definition: BCMath.cpp:221
float(& location() const)[3]
Definition: BCMath.cpp:211
float(& quat() const)[4]
Definition: BCMath.cpp:226
bool get_value(std::string channel_target, int array_index, float *val) const
const BCMatrix & get_matrix() const
void add_bone_matrix(Bone *bone, Matrix &mat)
std::string bc_string_after(const std::string &s, const std::string probe)
std::string bc_string_before(const std::string &s, const std::string probe)
char name[64]