Support matrices in gltf_accessor_iterator
This commit is contained in:
parent
6d13bfa407
commit
aa32b09fca
2 changed files with 38 additions and 3 deletions
|
|
@ -22,6 +22,9 @@ namespace psemek::gfx
|
|||
{
|
||||
return &value;
|
||||
}
|
||||
|
||||
static void finalize(T &)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -31,9 +34,7 @@ namespace psemek::gfx
|
|||
template <typename T>
|
||||
struct accessor_traits
|
||||
: accessor_traits_helper<T, std::is_arithmetic_v<T>>
|
||||
{
|
||||
|
||||
};
|
||||
{};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct accessor_traits<geom::vector<T, N>>
|
||||
|
|
@ -46,6 +47,9 @@ namespace psemek::gfx
|
|||
{
|
||||
return &value[0];
|
||||
}
|
||||
|
||||
static void finalize(geom::vector<T, N> &)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
|
|
@ -59,6 +63,9 @@ namespace psemek::gfx
|
|||
{
|
||||
return &value[0];
|
||||
}
|
||||
|
||||
static void finalize(geom::point<T, N> &)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -72,6 +79,29 @@ namespace psemek::gfx
|
|||
{
|
||||
return &value[0];
|
||||
}
|
||||
|
||||
static void finalize(geom::quaternion<T> &)
|
||||
{}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t R, std::size_t C>
|
||||
struct accessor_traits<geom::matrix<T, R, C>>
|
||||
{
|
||||
static constexpr bool is_floating_point = accessor_traits<T>::is_floating_point;
|
||||
static constexpr std::size_t components = R * C;
|
||||
using component_type = T;
|
||||
|
||||
static auto pointer(geom::matrix<T, R, C> & value)
|
||||
{
|
||||
return &value[0][0];
|
||||
}
|
||||
|
||||
static void finalize(geom::matrix<T, R, C> & value)
|
||||
{
|
||||
geom::matrix<T, C, R> temp;
|
||||
std::copy(value.coords, value.coords + R * C, temp.coords);
|
||||
value = geom::transpose(temp);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -189,6 +219,8 @@ namespace psemek::gfx
|
|||
ptr += component_size(accessor.component_type);
|
||||
}
|
||||
|
||||
traits::finalize(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -221,6 +221,9 @@ namespace psemek::gfx
|
|||
case type_t::vec2: return 2;
|
||||
case type_t::vec3: return 3;
|
||||
case type_t::vec4: return 4;
|
||||
case type_t::mat2: return 4;
|
||||
case type_t::mat3: return 9;
|
||||
case type_t::mat4: return 16;
|
||||
default: throw util::exception("Unsupported attribute type");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue