Keyframe times.
Keyframe values.
318 {
319 out_animation.name = in_animation.name;
320
321
322 std::vector<impeller::fb::ChannelT> translation_channels;
323 std::vector<impeller::fb::ChannelT> rotation_channels;
324 std::vector<impeller::fb::ChannelT> scale_channels;
325 for (auto& in_channel : in_animation.channels) {
326 auto out_channel = fb::ChannelT();
327
328 out_channel.node = in_channel.target_node;
329 auto& sampler = in_animation.samplers[in_channel.sampler];
330
331
332 auto& times_accessor = gltf.accessors[sampler.input];
333 if (times_accessor.count <= 0) {
334 continue;
335 }
336 {
337 auto& times_bufferview = gltf.bufferViews[times_accessor.bufferView];
338 auto& times_buffer = gltf.buffers[times_bufferview.buffer];
339 if (times_accessor.componentType != TINYGLTF_COMPONENT_TYPE_FLOAT) {
340 std::cerr << "Unexpected component type \""
341 << times_accessor.componentType
342 << "\" for animation channel times accessor. Skipping."
343 << std::endl;
344 continue;
345 }
346 if (times_accessor.type != TINYGLTF_TYPE_SCALAR) {
347 std::cerr << "Unexpected type \"" << times_accessor.type
348 << "\" for animation channel times accessor. Skipping."
349 << std::endl;
350 continue;
351 }
352 for (size_t time_i = 0; time_i < times_accessor.count; time_i++) {
353 const float* time_p = reinterpret_cast<const float*>(
354 times_buffer.data.data() + times_bufferview.byteOffset +
355 times_accessor.ByteStride(times_bufferview) * time_i);
356 out_channel.timeline.push_back(*time_p);
357 }
358 }
359
360
361 auto& values_accessor = gltf.accessors[sampler.output];
362 if (values_accessor.count != times_accessor.count) {
363 std::cerr << "Mismatch between time and value accessors for animation "
364 "channel. Skipping."
365 << std::endl;
366 continue;
367 }
368 {
369 auto& values_bufferview = gltf.bufferViews[values_accessor.bufferView];
370 auto& values_buffer = gltf.buffers[values_bufferview.buffer];
371 if (values_accessor.componentType != TINYGLTF_COMPONENT_TYPE_FLOAT) {
372 std::cerr << "Unexpected component type \""
373 << values_accessor.componentType
374 << "\" for animation channel values accessor. Skipping."
375 << std::endl;
376 continue;
377 }
378 if (in_channel.target_path == "translation") {
379 if (values_accessor.type != TINYGLTF_TYPE_VEC3) {
380 std::cerr << "Unexpected type \"" << values_accessor.type
381 << "\" for animation channel \"translation\" accessor. "
382 "Skipping."
383 << std::endl;
384 continue;
385 }
386 fb::TranslationKeyframesT keyframes;
387 for (size_t value_i = 0; value_i < values_accessor.count; value_i++) {
388 const float* value_p = reinterpret_cast<const float*>(
389 values_buffer.data.data() + values_bufferview.byteOffset +
390 values_accessor.ByteStride(values_bufferview) * value_i);
391 keyframes.values.push_back(
392 fb::Vec3(value_p[0], value_p[1], value_p[2]));
393 }
394 out_channel.keyframes.Set(std::move(keyframes));
395 translation_channels.push_back(std::move(out_channel));
396 } else if (in_channel.target_path == "rotation") {
397 if (values_accessor.type != TINYGLTF_TYPE_VEC4) {
398 std::cerr << "Unexpected type \"" << values_accessor.type
399 << "\" for animation channel \"rotation\" accessor. "
400 "Skipping."
401 << std::endl;
402 continue;
403 }
404 fb::RotationKeyframesT keyframes;
405 for (size_t value_i = 0; value_i < values_accessor.count; value_i++) {
406 const float* value_p = reinterpret_cast<const float*>(
407 values_buffer.data.data() + values_bufferview.byteOffset +
408 values_accessor.ByteStride(values_bufferview) * value_i);
409 keyframes.values.push_back(
410 fb::Vec4(value_p[0], value_p[1], value_p[2], value_p[3]));
411 }
412 out_channel.keyframes.Set(std::move(keyframes));
413 rotation_channels.push_back(std::move(out_channel));
414 } else if (in_channel.target_path == "scale") {
415 if (values_accessor.type != TINYGLTF_TYPE_VEC3) {
416 std::cerr << "Unexpected type \"" << values_accessor.type
417 << "\" for animation channel \"scale\" accessor. "
418 "Skipping."
419 << std::endl;
420 continue;
421 }
422 fb::ScaleKeyframesT keyframes;
423 for (size_t value_i = 0; value_i < values_accessor.count; value_i++) {
424 const float* value_p = reinterpret_cast<const float*>(
425 values_buffer.data.data() + values_bufferview.byteOffset +
426 values_accessor.ByteStride(values_bufferview) * value_i);
427 keyframes.values.push_back(
428 fb::Vec3(value_p[0], value_p[1], value_p[2]));
429 }
430 out_channel.keyframes.Set(std::move(keyframes));
431 scale_channels.push_back(std::move(out_channel));
432 } else {
433 std::cerr << "Unsupported animation channel target path \""
434 << in_channel.target_path << "\". Skipping." << std::endl;
435 continue;
436 }
437 }
438 }
439
440 std::vector<std::unique_ptr<impeller::fb::ChannelT>> channels;
441 for (const auto& channel_list :
442 {translation_channels, rotation_channels, scale_channels}) {
443 for (const auto& channel : channel_list) {
444 channels.push_back(std::make_unique<fb::ChannelT>(channel));
445 }
446 }
447 out_animation.channels = std::move(channels);
448}
skvx::Vec< 4, float > Vec4