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