Blender  V3.3
abc_writer_points.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Kévin Dietrich. All rights reserved. */
3 
8 #include "abc_writer_points.h"
9 
10 #include "DNA_object_types.h"
11 #include "DNA_particle_types.h"
12 
13 #include "BKE_lattice.h"
14 #include "BKE_particle.h"
15 
16 #include "BLI_math.h"
17 
18 #include "DEG_depsgraph_query.h"
19 
20 #include "CLG_log.h"
21 static CLG_LogRef LOG = {"io.alembic"};
22 
23 namespace blender::io::alembic {
24 
25 using Alembic::AbcGeom::kVertexScope;
26 using Alembic::AbcGeom::OPoints;
27 using Alembic::AbcGeom::OPointsSchema;
28 
30 {
31 }
32 
34 {
35  CLOG_INFO(&LOG, 2, "exporting OPoints %s", args_.abc_path.c_str());
36  abc_points_ = OPoints(args_.abc_parent, args_.abc_name, timesample_index_);
37  abc_points_schema_ = abc_points_.getSchema();
38 }
39 
40 Alembic::Abc::OObject ABCPointsWriter::get_alembic_object() const
41 {
42  return abc_points_;
43 }
44 
45 Alembic::Abc::OCompoundProperty ABCPointsWriter::abc_prop_for_custom_props()
46 {
47  return abc_schema_prop_for_custom_props(abc_points_schema_);
48 }
49 
51 {
52  return ELEM(context->particle_system->part->type,
63 }
64 
66 {
67  /* We assume that particles are always animated. */
68  return true;
69 }
70 
72 {
73  BLI_assert(context.particle_system != nullptr);
74 
75  std::vector<Imath::V3f> points;
76  std::vector<Imath::V3f> velocities;
77  std::vector<float> widths;
78  std::vector<uint64_t> ids;
79 
80  ParticleSystem *psys = context.particle_system;
85  sim.ob = context.object;
86  sim.psys = psys;
87 
88  psys_sim_data_init(&sim);
89 
90  uint64_t index = 0;
91  for (int p = 0; p < psys->totpart; p++) {
92  float pos[3], vel[3];
93 
94  if (psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) {
95  continue;
96  }
97 
99  if (psys_get_particle_state(&sim, p, &state, false) == 0) {
100  continue;
101  }
102 
103  /* location */
104  mul_v3_m4v3(pos, context.object->imat, state.co);
105 
106  /* velocity */
107  sub_v3_v3v3(vel, state.co, psys->particles[p].prev_state.co);
108 
109  /* Convert Z-up to Y-up. */
110  points.emplace_back(pos[0], pos[2], -pos[1]);
111  velocities.emplace_back(vel[0], vel[2], -vel[1]);
112  widths.push_back(psys->particles[p].size);
113  ids.push_back(index++);
114  }
115 
116  psys_sim_data_free(&sim);
117 
118  Alembic::Abc::P3fArraySample psample(points);
119  Alembic::Abc::UInt64ArraySample idsample(ids);
120  Alembic::Abc::V3fArraySample vsample(velocities);
121  Alembic::Abc::FloatArraySample wsample_array(widths);
122  Alembic::AbcGeom::OFloatGeomParam::Sample wsample(wsample_array, kVertexScope);
123 
124  OPointsSchema::Sample sample(psample, idsample, vsample, wsample);
126  sample.setSelfBounds(bounding_box_);
127  abc_points_schema_.set(sample);
128 }
129 
130 } // namespace blender::io::alembic
void psys_sim_data_free(struct ParticleSimulationData *sim)
Definition: particle.c:726
void psys_sim_data_init(struct ParticleSimulationData *sim)
Definition: particle.c:685
bool psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, bool always)
Definition: particle.c:4884
#define BLI_assert(a)
Definition: BLI_assert.h:46
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
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:187
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
const int state
unsigned __int64 uint64_t
Definition: stdint.h:90
ParticleKey prev_state
struct Depsgraph * depsgraph
Definition: BKE_particle.h:69
struct Scene * scene
Definition: BKE_particle.h:70
struct ParticleSystem * psys
Definition: BKE_particle.h:72
struct Object * ob
Definition: BKE_particle.h:71
ParticleData * particles