Blender  V2.93
abc_writer_points.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 Kévin Dietrich.
17  * All rights reserved.
18  */
19 
24 #include "abc_writer_points.h"
25 
26 #include "DNA_object_types.h"
27 #include "DNA_particle_types.h"
28 
29 #include "BKE_lattice.h"
30 #include "BKE_particle.h"
31 
32 #include "BLI_math.h"
33 
34 #include "DEG_depsgraph_query.h"
35 
36 #include "CLG_log.h"
37 static CLG_LogRef LOG = {"io.alembic"};
38 
39 namespace blender::io::alembic {
40 
41 using Alembic::AbcGeom::kVertexScope;
42 using Alembic::AbcGeom::OPoints;
43 using Alembic::AbcGeom::OPointsSchema;
44 
46 {
47 }
48 
50 {
51  CLOG_INFO(&LOG, 2, "exporting OPoints %s", args_.abc_path.c_str());
52  abc_points_ = OPoints(args_.abc_parent, args_.abc_name, timesample_index_);
53  abc_points_schema_ = abc_points_.getSchema();
54 }
55 
56 Alembic::Abc::OObject ABCPointsWriter::get_alembic_object() const
57 {
58  return abc_points_;
59 }
60 
61 Alembic::Abc::OCompoundProperty ABCPointsWriter::abc_prop_for_custom_props()
62 {
63  return abc_schema_prop_for_custom_props(abc_points_schema_);
64 }
65 
67 {
68  return ELEM(context->particle_system->part->type,
79 }
80 
82 {
83  /* We assume that particles are always animated. */
84  return true;
85 }
86 
88 {
89  BLI_assert(context.particle_system != nullptr);
90 
91  std::vector<Imath::V3f> points;
92  std::vector<Imath::V3f> velocities;
93  std::vector<float> widths;
94  std::vector<uint64_t> ids;
95 
96  ParticleSystem *psys = context.particle_system;
101  sim.ob = context.object;
102  sim.psys = psys;
103 
105 
106  uint64_t index = 0;
107  for (int p = 0; p < psys->totpart; p++) {
108  float pos[3], vel[3];
109 
110  if (psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) {
111  continue;
112  }
113 
115  if (psys_get_particle_state(&sim, p, &state, 0) == 0) {
116  continue;
117  }
118 
119  /* location */
120  mul_v3_m4v3(pos, context.object->imat, state.co);
121 
122  /* velocity */
123  sub_v3_v3v3(vel, state.co, psys->particles[p].prev_state.co);
124 
125  /* Convert Z-up to Y-up. */
126  points.emplace_back(pos[0], pos[2], -pos[1]);
127  velocities.emplace_back(vel[0], vel[2], -vel[1]);
128  widths.push_back(psys->particles[p].size);
129  ids.push_back(index++);
130  }
131 
132  if (psys->lattice_deform_data) {
134  psys->lattice_deform_data = nullptr;
135  }
136 
137  Alembic::Abc::P3fArraySample psample(points);
138  Alembic::Abc::UInt64ArraySample idsample(ids);
139  Alembic::Abc::V3fArraySample vsample(velocities);
140  Alembic::Abc::FloatArraySample wsample_array(widths);
141  Alembic::AbcGeom::OFloatGeomParam::Sample wsample(wsample_array, kVertexScope);
142 
143  OPointsSchema::Sample sample(psample, idsample, vsample, wsample);
145  sample.setSelfBounds(bounding_box_);
146  abc_points_schema_.set(sample);
147 }
148 
149 } // namespace blender::io::alembic
void BKE_lattice_deform_data_destroy(struct LatticeDeformData *lattice_deform_data)
struct LatticeDeformData * psys_create_lattice_deform_data(struct ParticleSimulationData *sim)
Definition: particle.c:696
int psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, int always)
Definition: particle.c:4854
#define BLI_assert(a)
Definition: BLI_assert.h:58
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
#define ELEM(...)
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:201
float DEG_get_ctime(const Depsgraph *graph)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
Object is a sort of wrapper for general info.
#define PARS_UNEXIST
#define PARS_NO_DISP
@ PART_FLUID_FLIP
@ PART_EMITTER
@ PART_FLUID_BUBBLE
@ PART_FLUID_SPRAYBUBBLE
@ PART_FLUID_TRACER
@ PART_FLUID_FOAM
@ PART_FLUID_SPRAYFOAMBUBBLE
@ PART_FLUID_SPRAYFOAM
@ PART_FLUID_SPRAY
@ PART_FLUID_FOAMBUBBLE
static CLG_LogRef LOG
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
const ABCWriterConstructorArgs args_
virtual void update_bounding_box(Object *object)
virtual void create_alembic_objects(const HierarchyContext *context) override
virtual bool is_supported(const HierarchyContext *context) const override
Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() override
virtual Alembic::Abc::OObject get_alembic_object() const override
virtual void do_write(HierarchyContext &context) override
ABCPointsWriter(const ABCWriterConstructorArgs &args)
virtual bool check_is_animated(const HierarchyContext &context) const override
uint pos
static ulong state[N]
static void sample(SocketReader *reader, int x, int y, float color[4])
struct SELECTID_Context context
Definition: select_engine.c:47
unsigned __int64 uint64_t
Definition: stdint.h:93
ParticleKey prev_state
struct Depsgraph * depsgraph
Definition: BKE_particle.h:87
struct Scene * scene
Definition: BKE_particle.h:88
struct ParticleSystem * psys
Definition: BKE_particle.h:90
struct Object * ob
Definition: BKE_particle.h:89
ParticleData * particles
struct LatticeDeformData * lattice_deform_data