Код: Выделить всё
void readNodes(NodeData *node,char * buffer,unsigned int * fileindex) {
//some read before parsing transformation
glm::vec3 pos;
glm::quat rot;
glm::vec3 scale;
//I read data like this because i dont know glm order
memcpy(&pos.x, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&pos.y, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&pos.z, &buffer[*fileindex], 4);
*fileindex+=4;
//rotation
memcpy(&rot.z, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&rot.y, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&rot.x, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&rot.w, &buffer[*fileindex], 4);
*fileindex+=4;
//scale
memcpy(&scale.x, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&scale.y, &buffer[*fileindex], 4);
*fileindex+=4;
memcpy(&scale.z, &buffer[*fileindex], 4);
*fileindex+=4;
//calculate transformation
node->transformation=glm::mat4(1.0f);
node->transformation=glm::translate(node->transformation,pos);
node->transformation*=glm::toMat4(rot);
node->transformation=glm::scale(node->transformation,scale);
//read other data from node end and recursivle read other child nodes
}
< /code>
код для экспорта Bonedata: < /p>
def write_bone_node(self, file, bone):
"""Write one bone and all its children recursively."""
bone_id = self.armature_obj.data.bones.find(bone.name)
name_bytes = bone.name.encode('ascii', errors="ignore")[:255]
# Name length + name
file.write(struct.pack("B", len(name_bytes)))
file.write(name_bytes)
# Bone ID
file.write(struct.pack("B", bone_id))
# Inverse bind matrix (offset)
offset_matrix = (self.armature_obj.matrix_world @ bone.matrix_local).inverted()
loc, rot, scale = offset_matrix.decompose()
file.write(struct.pack("3f", *loc))
file.write(struct.pack("4f", *rot))
file.write(struct.pack("3f", *scale))
# Write children
children = bone.children
file.write(struct.pack("B", len(children)))
for child in children:
self.write_bone_node(file, child)
< /code>
боролся за несколько дней, изменяя порядок параметров и т. Д., Но не пытались использовать окончательное местоположение кости от Blender (кости. Управление данными экспортировано правильно, но это статическое место, если я не ошибаюсь), потому что я не знаю, как трансформированное проходное вращение кости с ним с ним. Должен ли я использовать окончательное положение кости из кости. Вместо этого от блендера расчет обратной матрицы и вращения вокруг этой точки?//Passing arm or root node with basic rotation or glm::mat(1.0f) to get reversed bind pose (i dont know how it should look)
void CalculateBasicBoneTransform(const NodeData* node, glm::mat4 parentTransform)
{
std::string nodeName = node->name;
std::coutchildren[i], globalTransformation);
}
Что я получаю, даже при изменении шагов расчета и заказов
Подробнее здесь: https://stackoverflow.com/questions/797 ... ta-for-cpp