@@ -25,7 +25,7 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
25
25
Alembic::Abc::OArchive archive (Alembic::Abc::CreateArchiveWithInfo (Alembic::AbcCoreHDF5::WriteArchive (),
26
26
std::string (i_alembic_filename.c_str ()),
27
27
std::string (" Procedural Insight Pty. Ltd." ),
28
- std::string (" Multiple Samples Random points" ),
28
+ std::string (" nCache2Alembic points" ),
29
29
Alembic::Abc::ErrorHandler::kThrowPolicy ));
30
30
31
31
Alembic::AbcGeom::OObject iParent ( archive, Alembic::AbcGeom::kTop );
@@ -44,7 +44,7 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
44
44
std::cout << boost::format (" FPS (calculated) = %1%" ) % fps << std::endl;
45
45
std::cout << boost::format (" ncache_sampling_rate = %1%" ) % ncache_sampling_rate << std::endl;
46
46
47
- Alembic::Util::uint32_t num_time_samples = (i_ncache_loader. get_xml_reader (). get_time_range_end () - i_ncache_loader. get_xml_reader (). get_time_range_start ())/i_ncache_loader. get_xml_reader (). get_particle_count_sampling_rate ( ) + 1 ;
47
+ Alembic::Util::uint32_t num_time_samples = ((ncache_end - ncache_start)/ncache_sampling_rate ) + 1 ;
48
48
std::cout << boost::format (" num_time_samples = %1%" ) % num_time_samples << std::endl;
49
49
// Create the time sampling type.
50
50
Alembic::AbcCoreAbstract::TimeSampling ts (ncache_sampling_rate/6000.0 , ncache_start/(ncache_ticks_per_frame*fps));
@@ -83,7 +83,7 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
83
83
84
84
85
85
// Now process the individual *.mc/*.mcx files
86
- bool is_mcx = xml_reader.getCacheFormat ().compare (" mcx" ) == 0 ;
86
+ bool is_mcx = xml_reader.get_cache_format ().compare (" mcx" ) == 0 ;
87
87
std::string cache_extension (" mc" );
88
88
if (is_mcx)
89
89
cache_extension = " mcx" ;
@@ -92,7 +92,7 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
92
92
CacheReaderSharedPointerType cache_reader_ptr;
93
93
for (size_t frame_index = start_frame; frame_index <= end_frame; frame_index++)
94
94
{
95
- std::string per_initial_frame_full_path = (boost::format (" %1%/%2%Frame%3%.%4%" ) % xml_reader.get_cache_directory () % xml_reader.get_cache_name () % frame_index % cache_extension).str ();
95
+ std::string per_initial_frame_full_path = (boost::format (" %1%/%2%Frame%3%.%4%" ) % xml_reader.get_cache_directory () % xml_reader.get_base_cache_name () % frame_index % cache_extension).str ();
96
96
// std::cout << boost::format("per_initial_frame_full_path = '%1%'") % per_initial_frame_full_path << std::endl;
97
97
98
98
if (is_mcx)
@@ -113,7 +113,121 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
113
113
size_t accumulated_ticks = ncache_sampling_rate;
114
114
while ((accumulated_ticks < ncache_ticks_per_frame) && ((ncache_ticks_per_frame-accumulated_ticks)>=ncache_sampling_rate) )
115
115
{
116
- std::string per_sub_frame_full_path = (boost::format (" %1%/%2%Frame%3%Tick%4%.%5%" ) % xml_reader.get_cache_directory () % xml_reader.get_cache_name () % frame_index % accumulated_ticks % cache_extension).str ();
116
+ std::string per_sub_frame_full_path = (boost::format (" %1%/%2%Frame%3%Tick%4%.%5%" ) % xml_reader.get_cache_directory () % xml_reader.get_base_cache_name () % frame_index % accumulated_ticks % cache_extension).str ();
117
+ // std::cout << boost::format("\t""per_sub_frame_full_path '%1%'") % per_sub_frame_full_path << std::endl;
118
+
119
+ if (is_mcx)
120
+ cache_reader_ptr.reset (new MCXMemoryReader (per_sub_frame_full_path));
121
+ else
122
+ cache_reader_ptr.reset (new MCMemoryReader (per_sub_frame_full_path));
123
+
124
+ if (cache_reader_ptr)
125
+ {
126
+ process_single_sample (cache_reader_ptr,
127
+ position_channel_name,
128
+ id_channel_name,
129
+ pSchema);
130
+ }
131
+ accumulated_ticks += ncache_sampling_rate;
132
+ }
133
+ }
134
+ }
135
+ return true ;
136
+ }
137
+
138
+ bool nCacheAlembic::process_per_frame (const std::string& i_alembic_format_filename,
139
+ const nCacheLoader& i_ncache_loader)
140
+ {
141
+ const nCache::XMLReader& xml_reader = i_ncache_loader.get_xml_reader ();
142
+ size_t ncache_start = xml_reader.get_time_range_start ();
143
+ size_t ncache_end = xml_reader.get_time_range_end ();
144
+ size_t ncache_ticks_per_frame = xml_reader.get_cacheTimePerFrame_TimePerFrame ();
145
+
146
+ // Now process the individual *.mc/*.mcx files
147
+ bool is_mcx = xml_reader.get_cache_format ().compare (" mcx" ) == 0 ;
148
+ std::string cache_extension (" mc" );
149
+ if (is_mcx)
150
+ cache_extension = " mcx" ;
151
+ size_t start_frame = ncache_start / ncache_ticks_per_frame;
152
+ size_t end_frame = ncache_end / ncache_ticks_per_frame;
153
+ CacheReaderSharedPointerType cache_reader_ptr;
154
+ for (size_t frame_index = start_frame; frame_index <= end_frame; frame_index++)
155
+ {
156
+ std::string alembic_filename = (boost::format (i_alembic_format_filename) % frame_index).str ();
157
+
158
+ // Alembic file setup - START
159
+ Alembic::Abc::OArchive archive (Alembic::Abc::CreateArchiveWithInfo (Alembic::AbcCoreHDF5::WriteArchive (),
160
+ std::string (alembic_filename.c_str ()),
161
+ std::string (" Procedural Insight Pty. Ltd." ),
162
+ std::string (" nCache2Alembic points" ),
163
+ Alembic::Abc::ErrorHandler::kThrowPolicy ));
164
+
165
+ Alembic::AbcGeom::OObject iParent ( archive, Alembic::AbcGeom::kTop );
166
+ Alembic::AbcGeom::OXform xform = addXform (iParent," Xform" );
167
+
168
+ size_t ncache_sampling_rate = xml_reader.get_particle_count_sampling_rate ();
169
+ double fps = 6000.0 /ncache_ticks_per_frame;
170
+
171
+ std::cout << boost::format (" ncache_start = %1%" ) % ncache_start << std::endl;
172
+ std::cout << boost::format (" ncache_end = %1%" ) % ncache_end << std::endl;
173
+ std::cout << boost::format (" ncache_ticks_per_frame = %1%" ) % ncache_ticks_per_frame << std::endl;
174
+ std::cout << boost::format (" FPS (calculated) = %1%" ) % fps << std::endl;
175
+ std::cout << boost::format (" ncache_sampling_rate = %1%" ) % ncache_sampling_rate << std::endl;
176
+
177
+ Alembic::Util::uint32_t num_time_samples = (i_ncache_loader.get_xml_reader ().get_time_range_end () - i_ncache_loader.get_xml_reader ().get_time_range_start ())/i_ncache_loader.get_xml_reader ().get_particle_count_sampling_rate () + 1 ;
178
+ std::cout << boost::format (" num_time_samples = %1%" ) % num_time_samples << std::endl;
179
+ // Create the time sampling type.
180
+ Alembic::AbcCoreAbstract::TimeSampling ts (ncache_sampling_rate/6000.0 , ncache_start/(ncache_ticks_per_frame*fps));
181
+ std::cout << boost::format (" getNumStoredTimes = %1%" ) % ts.getNumStoredTimes () << std::endl;
182
+ Alembic::Util::uint32_t tsidx = iParent.getArchive ().addTimeSampling (ts);
183
+
184
+ // Find the required channels
185
+ std::string position_channel_name;
186
+ std::string id_channel_name;
187
+ if (!xml_reader.find_channel_ends_with (" _position" ,position_channel_name))
188
+ {
189
+ DLOG (INFO) << " BAD" << std::endl;
190
+ return false ;
191
+ }
192
+ if (!xml_reader.find_channel_ends_with (" _id" ,id_channel_name))
193
+ {
194
+ DLOG (INFO) << " BAD" << std::endl;
195
+ return false ;
196
+ }
197
+ std::cout << boost::format (" position_channel_name = '%1%'" ) % position_channel_name << std::endl;
198
+
199
+ // Create the Alembic OPoints schema
200
+ // Create our object.
201
+ Alembic::AbcGeom::OPoints partsOut ( xform, " nCacheParticles" , tsidx );
202
+
203
+ // Add attributes
204
+ Alembic::AbcGeom::OPointsSchema &pSchema = partsOut.getSchema ();
205
+
206
+ // Alembic file setup - END
207
+
208
+
209
+ std::string per_initial_frame_full_path = (boost::format (" %1%/%2%Frame%3%.%4%" ) % xml_reader.get_cache_directory () % xml_reader.get_base_cache_name () % frame_index % cache_extension).str ();
210
+ // std::cout << boost::format("per_initial_frame_full_path = '%1%'") % per_initial_frame_full_path << std::endl;
211
+
212
+ if (is_mcx)
213
+ cache_reader_ptr.reset (new MCXMemoryReader (per_initial_frame_full_path));
214
+ else
215
+ cache_reader_ptr.reset (new MCMemoryReader (per_initial_frame_full_path));
216
+
217
+ if (cache_reader_ptr)
218
+ {
219
+ process_single_sample (cache_reader_ptr,
220
+ position_channel_name,
221
+ id_channel_name,
222
+ pSchema);
223
+ }
224
+ // sub frame data
225
+ if ((ncache_sampling_rate < ncache_ticks_per_frame) && (frame_index!=end_frame))
226
+ {
227
+ size_t accumulated_ticks = ncache_sampling_rate;
228
+ while ((accumulated_ticks < ncache_ticks_per_frame) && ((ncache_ticks_per_frame-accumulated_ticks)>=ncache_sampling_rate) )
229
+ {
230
+ std::string per_sub_frame_full_path = (boost::format (" %1%/%2%Frame%3%Tick%4%.%5%" ) % xml_reader.get_cache_directory () % xml_reader.get_base_cache_name () % frame_index % accumulated_ticks % cache_extension).str ();
117
231
// std::cout << boost::format("\t""per_sub_frame_full_path '%1%'") % per_sub_frame_full_path << std::endl;
118
232
119
233
if (is_mcx)
@@ -136,9 +250,9 @@ bool nCacheAlembic::process(const std::string& i_alembic_filename,
136
250
}
137
251
138
252
void nCacheAlembic::process_single_sample (const CacheReaderSharedPointerType& i_cache_reader_ptr,
139
- const std::string& i_position_channel_name,
140
- const std::string& i_id_channel_name,
141
- Alembic::AbcGeom::OPointsSchema & o_pSchema)
253
+ const std::string& i_position_channel_name,
254
+ const std::string& i_id_channel_name,
255
+ Alembic::AbcGeom::OPointsSchema& o_pSchema)
142
256
{
143
257
const nCache::ChannelDataContainer& cdc = i_cache_reader_ptr->get_channels_data ();
144
258
@@ -182,3 +296,4 @@ void nCacheAlembic::process_single_sample(const CacheReaderSharedPointerType& i_
182
296
std::cout << boost::format (" position_data.size() = %1%, id_data.size() = %2%" ) % position_data.size () % id_data.size () << std::endl;
183
297
184
298
}
299
+
0 commit comments