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

abc_writer_mball.cc « intern « alembic « io « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3593acf18b0375282a11ff09e5e75dd93c02a30f (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
/*
 * 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.
 */

/** \file
 * \ingroup balembic
 */

#include "abc_writer_mball.h"
#include "abc_writer_mesh.h"

#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_object_types.h"

#include "BKE_displist.h"
#include "BKE_lib_id.h"
#include "BKE_mball.h"
#include "BKE_mesh.h"
#include "BKE_object.h"

#include "BLI_utildefines.h"

AbcMBallWriter::AbcMBallWriter(Main *bmain,
                               Object *ob,
                               AbcTransformWriter *parent,
                               uint32_t time_sampling,
                               ExportSettings &settings)
    : AbcGenericMeshWriter(ob, parent, time_sampling, settings), m_bmain(bmain)
{
  m_is_animated = isAnimated();
}

AbcMBallWriter::~AbcMBallWriter()
{
}

bool AbcMBallWriter::isAnimated() const
{
  return true;
}

Mesh *AbcMBallWriter::getEvaluatedMesh(Scene * /*scene_eval*/, Object *ob_eval, bool &r_needsfree)
{
  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
  if (mesh_eval != NULL) {
    /* Mesh_eval only exists when generative modifiers are in use. */
    r_needsfree = false;
    return mesh_eval;
  }
  r_needsfree = true;

  /* The approach below is copied from BKE_mesh_new_from_object() */
  Mesh *tmpmesh = BKE_mesh_add(m_bmain, ((ID *)m_object->data)->name + 2);
  BLI_assert(tmpmesh != NULL);

  /* BKE_mesh_add gives us a user count we don't need */
  id_us_min(&tmpmesh->id);

  ListBase disp = {NULL, NULL};
  /* TODO(sergey): This is gonna to work for until Depsgraph
   *               only contains for_render flag. As soon as CoW is
   *               implemented, this is to be rethought.
   */
  BKE_displist_make_mball_forRender(m_settings.depsgraph, m_settings.scene, m_object, &disp);
  BKE_mesh_from_metaball(&disp, tmpmesh);
  BKE_displist_free(&disp);

  BKE_mesh_texspace_copy_from_object(tmpmesh, m_object);

  return tmpmesh;
}

void AbcMBallWriter::freeEvaluatedMesh(struct Mesh *mesh)
{
  BKE_id_free(m_bmain, mesh);
}

bool AbcMBallWriter::isBasisBall(Scene *scene, Object *ob)
{
  Object *basis_ob = BKE_mball_basis_find(scene, ob);
  return ob == basis_ob;
}