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