简体   繁体   English

你能从 gltf 文件中得到一个明确的骨架吗?

[英]Can you get an explicit skeleton out of a gltf file?

For debugging purposes I want to render the skeleton of a skinned mesh.出于调试目的,我想渲染蒙皮网格的骨架。 However, in glTF they seem to be defined in a very abstract way.但是,在 glTF 中,它们似乎以非常抽象的方式定义。 That is to say, there is no "skeleton" as in, a set of vertices connected by lines.也就是说,没有“骨架”,如一组由线连接的顶点。 In other words this is not explicitly defined:换句话说,这没有明确定义: 在此处输入图片说明

Instead the "skeleton" is actually a collection of nodes that only specify matrices that convert the positions of the relevant vertices into the position of the joint.相反,“骨架”实际上是一组节点,这些节点仅指定将相关顶点的位置转换为关节位置的矩阵。

Is it nonetheless possible to extract where the joint is?尽管如此,是否有可能提取关节的位置? Maybe through inverting the inverseBindmatrix or something like that?也许通过反转 inverseBindmatrix 或类似的东西?

TL;DR I have a gltf model, I wanna render the skeleton of it like in blender. TL; DR 我有一个 gltf 模型,我想像在搅拌机中一样渲染它的骨架。

I'm sure you're not looking for a "mostly" or "kinda-sorta" answer here, but indeed there are some complicating factors.我敢肯定,您不是在这里寻找“主要”或“有点”的答案,但确实存在一些复杂的因素。

I'll start with the basic strategy: glTF is a last-mile format, a GPU-ready format designed to get data pumped into rendering APIs with minimal fuss.我将从基本策略开始:glTF 是一种最后一英里格式,一种 GPU 就绪格式,旨在以最少的麻烦将数据泵入渲染 API。 As such, glTF has no compassion for "artist asset interchange" type features that would be meaningless to an end-user client.因此,glTF 对“艺术家资产交换”类型的功能没有同情心,这些功能对最终用户客户来说毫无意义。 And in this case, we have a casualty of that philosophy: The bone's length.在这种情况下,我们有一个哲学的牺牲品:骨头的长度。

The bone's origin and orientation are well-known.骨骼的起源和方向是众所周知的。 They are (typically empty) nodes in the glTF scene hierarchy, and indeed we only know they count as "bones" when a skin comes along with a list of joints, that indicate which nodes are actually bones.它们是 glTF 场景层次结构中的(通常是空的)节点,实际上我们只知道当皮肤与关节列表一起出现时,它们才算作“骨骼”,这表明哪些节点实际上是骨骼。 Being a glTF node means that the bone has a known relationship to its parent, in the form of a transformation matrix, or more likely, in the form of translate, rotate, and scale parameters on the node.作为 glTF 节点意味着骨骼与其父节点具有已知关系,以变换矩阵的形式,或更可能以节点上的平移、旋转和缩放参数的形式。 This gives you the bone's origin and orientation.这为您提供了骨骼的原点和方向。 It can even be animated, just like any glTF node can have an animation applied (but only when using TRS, not with the matrix).它甚至可以设置动画,就像任何 glTF 节点都可以应用动画一样(但仅在使用 TRS 时,而不是使用矩阵时)。

But the length of the bone isn't needed in glTF.但是glTF不需要骨骼的长度。 Why not?为什么不? Because for the sake of getting the model rendered quickly, what's needed is the bone's influence over the surrounding vertices.因为为了快速渲染模型,需要的是骨骼对周围顶点的影响。 This is done with the JOINTS_0 and WEIGHTS_0 accessors (vertex attributes), so each vertex knows which bones can influence it, and by how much.这是通过JOINTS_0WEIGHTS_0访问器(顶点属性)完成的,因此每个顶点都知道哪些骨骼可以影响它,以及影响程度。 The "length" of the bone is a useful visualization parameter for artists, but is not needed in the vertex shader to calculate where the skin ended up.骨骼的“长度”对于艺术家来说是一个有用的可视化参数,但在顶点着色器中不需要计算皮肤的最终位置。 A given 3D app may use the bone length to help calculate or seed the vertex joint weights, but once those are calculated, they can be hand-tweaked and changed, and the original bone length is moot.给定的 3D 应用程序可能会使用骨骼长度来帮助计算或设定顶点关节权重,但是一旦计算出这些权重,就可以手动调整和更改它们,而原始骨骼长度则没有实际意义。

The inverseBindMatrix essentially holds the bind pose. inverseBindMatrix 本质上保持绑定姿势。 It is the inverse of the bone's original rest/bind position relative to the root (not parent).它是骨骼相对于根(不是父)的原始静止/绑定位置的倒数。 Take that arm bone for example, it has some non-zero +X position.以那个手臂骨骼为例,它有一些非零的 +X 位置。 But when it sits there in its own rest position, it should have essentially no effect on the skin, it shouldn't be pulling the skin further +X from where it originally was.但是当它以自己的静止位置坐在那里时,它应该对皮肤基本上没有影响,它不应该将皮肤从原来的位置拉得更远+X。 The fact that the arm bone is away from the model's origin makes it want to pull other vertices further away, and the inverseBindMatrix is there to un-do that effect.手臂骨骼远离模型原点的事实使其想要将其他顶点拉得更远,并且 inverseBindMatrix 可以取消这种效果。 So when the bone is at rest (in the bind pose), the bone and its inverseBindMatrix will cancel each other out perfectly.因此,当骨骼静止时(处于绑定姿势),骨骼及其 inverseBindMatrix 将完美地相互抵消。 As the bone starts to move away from that pose, it starts to exert influence.当骨骼开始远离那个姿势时,它开始施加影响。

For what it's worth, the Blender glTF importer has some fancy shenanigans to make a best-effort guess at the bone length when importing a glTF.就其价值而言,Blender glTF 导入器有一些花哨的诡计,可以在导入 glTF 时尽力猜测骨骼长度。 But it also imports the raw vertex weights, so, the bone length is merely for the artist's visual benefit, it has no effect on the skin.但它也导入了原始顶点权重,因此,骨骼长度只是为了美工的视觉利益,它对皮肤没有影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您可以使用带有指定初始值设定项的显式构造函数吗? - Can you use explicit constructors with designated initializers? gltf 没有在皮肤中指定骨架值是什么意思? - What does it mean when gltf does not specify a skeleton value in a skin? 如何将kinect骨架数据保存到文件中? - How can I save kinect skeleton data into a file? glTF文件中步幅的属性? - Properties of the stride in a glTF file? 您可以从C ++ Lib文件中获取信息,例如如何从Jar文件中获取信息吗? - Can you get information out of C++ Lib Files like How you can Get Info out of Jar files? 可以使用关键字explicit来防止方法参数的自动转换吗? - Can you use keyword explicit to prevent automatic conversion of method parameters? 您可以转发声明未声明模板类的显式特化吗? - Can you forward declare an explicit specialization of undeclared template class? C ++:可以优化未使用的lambda显式捕获吗? - C++: Can an unused lambda explicit capture be optimized out? 使用OpenCV获取图像的骨架 - Using OpenCV to get skeleton of an image 我可以在SWIG接口文件中结合显式声明和“真正懒惰”声明吗? - Can I combine explicit and “truly lazy” declarations in a SWIG interface file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM