Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deg_eval_runtime_backup_animation.cc « eval « intern « depsgraph « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29f70e8548e920e5253e54528eeddc4f9b75d3d5 (plain)
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
/*
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2019 Blender Foundation.
 * All rights reserved.
 */

/** \file
 * \ingroup depsgraph
 */

#include "intern/eval/deg_eval_runtime_backup_animation.h"

#include "DNA_anim_types.h"

#include "BKE_animsys.h"

#include "RNA_access.h"
#include "RNA_types.h"

#include "intern/depsgraph.h"

namespace DEG {

namespace {

struct AnimatedPropertyStoreCalbackData {
  AnimationBackup *backup;

  /* ID which needs to be stored.
   * Is used to check possibly nested IDs which f-curves are pointing to. */
  ID *id;

  PointerRNA id_pointer_rna;
};

void animated_property_store_cb(ID *id, FCurve *fcurve, void *data_v)
{
  AnimatedPropertyStoreCalbackData *data = reinterpret_cast<AnimatedPropertyStoreCalbackData *>(
      data_v);
  if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
    return;
  }
  if (id != data->id) {
    return;
  }

  /* Resolve path to the property. */
  PathResolvedRNA resolved_rna;
  if (!BKE_animsys_store_rna_setting(
          &data->id_pointer_rna, fcurve->rna_path, fcurve->array_index, &resolved_rna)) {
    return;
  }

  /* Read property value. */
  float value;
  if (!BKE_animsys_read_rna_setting(&resolved_rna, &value)) {
    return;
  }

  data->backup->values_backup.append({fcurve->rna_path, fcurve->array_index, value});
}

}  // namespace

AnimationValueBackup::AnimationValueBackup()
{
}

AnimationValueBackup::AnimationValueBackup(const string &rna_path, int array_index, float value)
    : rna_path(rna_path), array_index(array_index), value(value)
{
}

AnimationValueBackup::~AnimationValueBackup()
{
}

AnimationBackup::AnimationBackup(const Depsgraph *depsgraph)
{
  meed_value_backup = !depsgraph->is_active;
  reset();
}

void AnimationBackup::reset()
{
}

void AnimationBackup::init_from_id(ID *id)
{
  /* NOTE: This animation backup nicely preserves values which are animated and
   * are not touched by frame/depsgraph post_update handler.
   *
   * But it makes it impossible to have user edits to animated properties: for
   * example, translation of object with animated location will not work with
   * the current version of backup. */
  return;

  AnimatedPropertyStoreCalbackData data;
  data.backup = this;
  data.id = id;
  RNA_id_pointer_create(id, &data.id_pointer_rna);
  BKE_fcurves_id_cb(id, animated_property_store_cb, &data);
}

void AnimationBackup::restore_to_id(ID *id)
{
  return;

  PointerRNA id_pointer_rna;
  RNA_id_pointer_create(id, &id_pointer_rna);
  for (const AnimationValueBackup &value_backup : values_backup) {
    /* Resolve path to the property.
     *
     * NOTE: Do it again (after storing), since the sub-data pointers might be
     * changed after copy-on-write. */
    PathResolvedRNA resolved_rna;
    if (!BKE_animsys_store_rna_setting(&id_pointer_rna,
                                       value_backup.rna_path.c_str(),
                                       value_backup.array_index,
                                       &resolved_rna)) {
      return;
    }

    /* Write property value. */
    if (!BKE_animsys_write_rna_setting(&resolved_rna, value_backup.value)) {
      return;
    }
  }
}

}  // namespace DEG