当前位置: 首页 > news >正文

maya打开bvh脚本

目录

maya打开脚本编辑器

运行打开bvh脚本

maya导出bvh脚本


maya打开脚本编辑器

打开Maya软件,点击右下角 “脚本编辑器”

运行打开bvh脚本

https://github.com/jhoolmans/mayaImporterBVH/blob/master/bvh_importer.py

import os
import re
from typing import Optionalimport maya.cmds as mcspace_re = re.compile(r"\s+")# This maps the BVH naming convention to Maya
translationDict = {"Xposition": "translateX","Yposition": "translateY","Zposition": "translateZ","Xrotation": "rotateX","Yrotation": "rotateY","Zrotation": "rotateZ"
}class TinyDAG(object):"""Tiny DAG class for storing the hierarchy of the BVH file."""def __init__(self, obj: str, parent: Optional["TinyDAG"] = None):"""Constructor"""self.obj = objself.__parent = parent@propertydef parent(self):"""Returns the parent of the object"""return self.__parentdef __str__(self) -> str:"""String representation of the object"""return str(self.obj)def full_path(self) -> str:"""Returns the full path of the object"""if self.parent is not None:return "%s|%s" % (self.parent.full_path(), str(self))return str(self.obj)class BVHImporterDialog(object):"""BVH Importer DialogThis class is the main dialog for the BVH importer."""def __init__(self, debug=False):self._name = "bvhImportDialog"self._title = "BVH Importer v2.0"if debug:print("Debug is deprecated.")# UI relatedself._textfield = ""self._scale_field = ""self._frame_field = ""self._rotation_order = ""self._reload = ""# Otherself._root_node = None  # Used for targeting# BVH specific stuffself._filename = ""self._channels = []self.setup_ui()def setup_ui(self):"""Builds the UI"""win = self._nameif mc.window(win, ex=True):mc.deleteUI(win)# Non sizeable dialogwin = mc.window(self._name, title=self._title, w=200, rtf=True,sizeable=False)mc.columnLayout(adj=1, rs=5)mc.separator()mc.text("Options")mc.separator()mc.rowColumnLayout(numberOfColumns=2,columnWidth=[(1, 80), (2, 150)],cal=[(1, "right"), (2, "center")],cs=[(1, 5), (2, 5)],rs=[(1, 5), (2, 5)])mc.text("Rig scale")self._scale_field = mc.floatField(minValue=0.01, maxValue=2, value=1)mc.text("Frame offset")self._frame_field = mc.intField(minValue=0)mc.text("Rotation Order")self._rotation_order = mc.optionMenu()mc.menuItem(label='XYZ')mc.menuItem(label='YZX')mc.menuItem(label='ZXY')mc.menuItem(label='XZY')mc.menuItem(label='YXZ')mc.menuItem(label='ZYX')mc.setParent("..")mc.separator()# Targeting UImc.text("Skeleton Targeting")mc.text("(Select the hips)")mc.separator()mc.rowColumnLayout(numberOfColumns=2,columnWidth=[(1, 150), (2, 80)],cs=[(1, 5), (2, 5)],rs=[(1, 5), (2, 5)])self._textfield = mc.textField(editable=False)mc.button("Select/Clear", c=self._on_select_root)mc.setParent("..")mc.separator()mc.button("Import..", c=self._on_select_file)self._reload = mc.button("Reload", enable=False, c=self._read_bvh)# Footermc.text("by Jeroen Hoolmans")mc.window(win, e=True, rtf=True, sizeable=False)mc.showWindow(win)def _on_select_file(self, e):"""Callback for the import button."""file_filter = "All Files (*.*);;Motion Capture (*.bvh)"result = mc.fileDialog2(fileFilter=file_filter, dialogStyle=1, fm=1)if result is None or not len(result):returnself._filename = result[0]mc.button(self._reload, e=True, enable=True)# Action!self._read_bvh()def load_bvh(self, filename):self._filename = filenameself._read_bvh()def _read_bvh(self, *_args):# Safe close is needed for End Site part to keep from setting new# parent.safe_close = False# Once motion is active, animate.motion = False# Clear channels before appendingself._channels = []# Scale the entire rig and animationrig_scale = mc.floatField(self._scale_field, q=True, value=True)frame = mc.intField(self._frame_field, q=True, value=True)rot_order = mc.optionMenu(self._rotation_order, q=True, select=True) - 1with open(self._filename) as f:# Check to see if the file is valid (sort of)if not f.readline().startswith("HIERARCHY"):mc.error("No valid .bvh file selected.")return Falseif self._root_node is None:# Create a group for the rig, easier to scale.# (Freeze transform when ungrouping please..)mocap_name = os.path.basename(self._filename)grp = mc.group(em=True, name="_mocap_%s_grp" % mocap_name)mc.setAttr("%s.scale" % grp, rig_scale, rig_scale, rig_scale)# The group is now the 'root'my_parent = TinyDAG(grp, None)else:my_parent = TinyDAG(self._root_node, None)self._clear_animation()for line in f:line = line.replace("	", " ")  # force spacesif not motion:# root jointif line.startswith("ROOT"):# Set the Hip joint as rootif self._root_node:my_parent = TinyDAG(str(self._root_node), None)else:my_parent = TinyDAG(line[5:].rstrip(), my_parent)# Update root node in case we want to reload.self._root_node = my_parentmc.textField(self._textfield,e=True,text=my_parent.full_path())if "JOINT" in line:jnt = space_re.split(line.strip())# Create the jointmy_parent = TinyDAG(jnt[1], my_parent)if "End Site" in line:# Finish up a hierarchy and ignore a closing bracketsafe_close = Trueif "}" in line:# Ignore when safeClose is onif safe_close:safe_close = Falsecontinue# Go up one levelif my_parent is not None:my_parent = my_parent.parentif my_parent is not None:mc.select(my_parent.full_path())if "CHANNELS" in line:chan = line.strip()chan = space_re.split(chan)# Append the channels that are animatedfor i in range(int(chan[1])):self._channels.append("%s.%s" % (my_parent.full_path(),translationDict[chan[2 + i]]))if "OFFSET" in line:offset = line.strip()offset = space_re.split(offset)jnt_name = str(my_parent)# When End Site is reached, name it "_tip"if safe_close:jnt_name += "_tip"# skip if existsif mc.objExists(my_parent.full_path()):jnt = my_parent.full_path()else:# Build a new jointjnt = mc.joint(name=jnt_name, p=(0, 0, 0))mc.setAttr(jnt + ".rotateOrder", rot_order)mc.setAttr(jnt + ".translate",float(offset[1]),float(offset[2]),float(offset[3]))if "MOTION" in line:# Animate!motion = Trueelse:# We don't really need to use Frame count and time# (since Python handles file reads nicely)if "Frame" not in line:data = space_re.split(line.strip())# Set the values to channelsfor index, value in enumerate(data):mc.setKeyframe(self._channels[index],time=frame,value=float(value))frame = frame + 1def _clear_animation(self):if self._root_node is None:mc.error("Could not find root node to clear animation.")return# Select hierarchymc.select(str(self._root_node), hi=True)nodes = mc.ls(sl=True)trans_attrs = ["translateX", "translateY", "translateZ"]rot_attrs = ["rotateX", "rotateY", "rotateZ"]for node in nodes:for attr in trans_attrs + rot_attrs:# Delete input connectionsconnections = mc.listConnections("%s.%s" % (node, attr),s=True,d=False)if connections is not None:mc.delete(connections)for attr in rot_attrs:# Reset rotationmc.setAttr("%s.%s" % (node, attr), 0)def _on_select_root(self, *_args):# When targeting, set the root joint (Hips)selection = mc.ls(sl=True, type="joint", l=True)if len(selection) == 0:self._root_node = Nonemc.textField(self._textfield, e=True, text="")else:self._root_node = selection[0]mc.textField(self._textfield, e=True, text=self._root_node)if __name__ == "__main__":dialog = BVHImporterDialog()

maya导出bvh脚本

https://github.com/zhaozigu/maya-export-bvh/blob/main/export_bvh.py

import os
import mathimport maya.cmds as cmds
import maya.api.OpenMaya as omdef get_bone_rotation(bone):cur_mat = om.MMatrix(cmds.xform(bone, q=True, ws=True, m=True))parent = cmds.listRelatives(bone, p=True)[0]parent_mat = om.MMatrix(cmds.xform(parent, q=True, ws=True, m=True))local_mat = cur_mat * parent_mat.inverse()cur_xfo_mat = om.MTransformationMatrix(local_mat)rotation = [math.degrees(x) for x in cur_xfo_mat.rotation().asVector()]return rotationdef export_motion(joints, start_frame, end_frame, rot_order: tuple):motion_str = ""root_joint = joints[0]for frame in range(start_frame, end_frame + 1):cmds.currentTime(frame)for joint in joints:joint_name = cmds.ls(joint, long=True)[0]rot = get_bone_rotation(joint_name)if joint == root_joint:loc = cmds.xform(joint_name, q=True, translation=True)motion_str += "%.6f %.6f %.6f " % (loc[0], loc[1], loc[2])motion_str += "%.6f %.6f %.6f " % (rot[rot_order[0]], rot[rot_order[1]], rot[rot_order[2]])motion_str += "\n"return motion_strdef export_hierarchy(joints, rot_order: str):hierarchy_str = "HIERARCHY\n"def _process_joint(joint, indent):nonlocal hierarchy_strjoint_name_raw = cmds.ls(joint, long=True)[0]joint_name = joint_name_raw.split("|")[-1].split(":")[-1]if indent == 0:hierarchy_str += "{}ROOT {}\n".format('\t' * indent, joint_name)else:hierarchy_str += "{}JOINT {}\n".format('\t' * indent, joint_name)loc = cmds.xform(joint_name_raw, q=True, translation=True)hierarchy_str += "{}{{\n".format('\t' * indent)hierarchy_str += "{}OFFSET {:.6f} {:.6f} {:.6f}\n".format('\t' * (indent + 1), loc[0], loc[1], loc[2])if indent == 0:hierarchy_str += "{}CHANNELS 6 Xposition Yposition Zposition {}rotation {}rotation {}rotation\n".format('\t' * (indent + 1), rot_order[0], rot_order[1], rot_order[2])else:hierarchy_str += "{}CHANNELS 3 {}rotation {}rotation {}rotation\n".format('\t' * (indent + 1), rot_order[0], rot_order[1], rot_order[2])children = cmds.listRelatives(joint, children=True, type="joint")if children:for child in children:_process_joint(child, indent + 1)else:hierarchy_str += "{}End Site\n".format('\t' * (indent + 1))hierarchy_str += "{}{{\n".format('\t' * (indent + 1))hierarchy_str += "{}OFFSET 0.0 0.0 0.0\n".format('\t' * (indent + 2))hierarchy_str += "{}}}\n".format('\t' * (indent + 1))hierarchy_str += "{}}}\n".format('\t' * indent)root_joint = joints[0]_process_joint(root_joint, 0)return hierarchy_strdef export_bvh(joints, output_file_path, start_frame, end_frame, rot_order="ZXY"):_order = {"XYZ": (0, 1, 2),"XZY": (0, 2, 1),"YXZ": (1, 0, 2),"YZX": (1, 2, 0),"ZXY": (2, 0, 1),"ZYX": (2, 1, 0),}assert rot_order in _order, "The parameters of the rotation order are incorrect"hierarchy = export_hierarchy(joints, rot_order)motion = export_motion(joints, start_frame, end_frame, _order[rot_order])num_frames = end_frame - start_frame + 1frame_rate = cmds.playbackOptions(query=True, framesPerSecond=True)if frame_rate == 0:frame_rate = 24.0frame_time = 1.0 / frame_ratewith open(output_file_path, "w") as output_file:output_file.write(hierarchy)output_file.write(f"MOTION\nFrames: {num_frames}\nFrame Time: {frame_time:.6f}\n")output_file.write(motion)def get_ordered_joints(joint):ordered_joints = [joint]children = cmds.listRelatives(joint, children=True, type="joint")if children:for child in children:ordered_joints.extend(get_ordered_joints(child))return ordered_jointsif __name__ == "__main__":root_joint_name = "root"root_joint = Nonechildren = cmds.listRelatives(root_joint_name, children=True, type="joint")if children:root_joint = children[0]else:raise ValueError(f"No joint found under {root_joint_name}")joints = get_ordered_joints(root_joint)print(joints)start_frame = int(cmds.playbackOptions(query=True, minTime=True))end_frame = int(cmds.playbackOptions(query=True, maxTime=True))# Set the output file pathoutput_file_path = os.path.join(os.path.expanduser("~"), "maya_body_test.bvh")export_bvh(joints, output_file_path, start_frame, end_frame, "ZYX")

相关文章:

maya打开bvh脚本

目录 maya打开脚本编辑器 运行打开bvh脚本 maya导出bvh脚本 maya打开脚本编辑器 打开Maya软件,点击右下角 “脚本编辑器” 运行打开bvh脚本 https://github.com/jhoolmans/mayaImporterBVH/blob/master/bvh_importer.py import os import re from typing impo…...

【JavaSE】数据类型和运算符

前言 从这一篇我们开始Java的学习~ 欢迎关注个人主页:逸狼 创造不易,可以点点赞吗~ 如有错误,欢迎指出~ 目录 前言 Java第一个程序 字面常量 字面常量的分类 结合代码理解 类型转换 类型提升 byte与byte的运算 正确写法 字符串类型St…...

Docker 哲学 - ip 的组成规则 与 网关介绍

在 IP 地址中,我们通常将 IP 地址分为两部分:网络部分和主机部分。网络部分用于标识网络,主机部分用于标识该网络中的特定主机。 IP 地址的每个部分(也被称为一个八位组或一个字节)可以是从0到255的任何值。 一个 IPv4…...

数学建模竞赛真的是模型解题一般,但是论文出彩而获奖的吗?

最近,数乐君发现有同学会有这样的问题:在数学建模国赛中,会因为参赛团队的模型解题一般,但论文写得非常精彩而获奖吗? 是的,确实会存在这样的情况。 我们都知道数学建模竞赛最终都是以提交成品论文的形式…...

深度学习常见的三种模型

深度学习模型实际上是一个包含多个隐藏层的神经网络,目前主要有卷积神经网络(CNN)、深度置信网络(DBN)、循环神经网络(RNN)。 1) 卷积神经网络 在机器学习领域,卷积神经网络属于前…...

接口自动化测试分层设计与实践总结

🍅 视频学习:文末有免费的配套视频可观看 🍅 关注公众号:互联网杂货铺,回复1 ,免费获取软件测试全套资料,资料在手,涨薪更快 接口测试三要素: 参数构造 发起请求&#x…...

集合(下)Map集合的使用

文章目录 前言一、Map接口二、Map接口的实现类 1.HashMap类2.TreeMap类总结 前言 Map集合没有继承Collection接口,不能像List集合和Set集合那样直接使用Collection接口的方法。Map集合其自身通过以key到value的映射关系实现的集合,也有相应的许多方法。类…...

AAPT: error: resource android:attr/dialogCornerRadius not found.

ERROR:D:\android.gradle\caches\transforms-3\b3b98118f65da38d0ad9da84cfc70a72\transformed\appcompat-1.0.0\res\values-v28\values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found. 请帮我看看这个错误是什么意思。我改如何做。 这个…...

数字功放VS模拟功放,选择适合你的音频解决方案

数字功放和模拟功放是音频系统中常用的两种功放技术,适用于不同的音频应用,都具有各自的优势和特点。本文将为您详细介绍数字功放和模拟功放的差异,并帮助您找到适合自己的音频解决方案。 1、数字功放是一种利用数字信号处理技术的功放。它将…...

5.88 BCC工具之tcpsynbl.py解读

一,工具简介 tcpsynbl工具以直方图的形式显示SYN到达时的TCP SYN积压大小。这可以让我们了解应用程序距离达到积压限制并丢弃SYN(导致SYN重传产生性能问题)还有多远。 TCP SYN 数据包则通常用于启动 TCP 三次握手过程的第一次握手。 二,代码示例 #!/usr/bin/env python…...

GVRP实现vlan的自动创建和注册

拓扑图 资源已上传 流程 第一、每台交换机的全局及端口下使能GVRP功能 第二、配置交换机的二层连通性,交换机某些端口配置Trunk端口,并允许相应的vlan通过 第三、在交换机4和5配置静态vlan100,然后查看1和3交换机是否有vlan100的定义&…...

Oracle VM VirtualBox修改磁盘大小

一、 修改虚拟机磁盘大小 先把虚拟机停掉。再增加磁盘大小。 路径中有空格的用""包起来。 D:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "D:\Program Files\VirtualBox VMs\mycentos\mycentos.vdi" --resize 30000 0%...10%...20%...3…...

【嵌入式硬件】步进电机

1.步进电机简介 1.1步进电机基本原理 步进电机的英文是stepping motor。step的中文意思是行走、迈步。所以仅从字面上我们就可以得知,步进电机就是一步一步移动的电动机。说的官方一点儿,步进电机是一种将电脉冲信号转换成相应角位移或者线位移的电动机(直线电机)。下图为…...

FlyControls 是 THREE.js 中用于实现飞行控制的类,它用于控制摄像机在三维空间中的飞行。

demo演示地址 FlyControls 是 THREE.js 中用于实现飞行控制的类,它用于控制摄像机在三维空间中的飞行。 入参: object:摄像机对象,即要控制的摄像机。domElement:用于接收用户输入事件的 HTML 元素,通常…...

【Java程序设计】【C00366】基于(JavaWeb)Springboot的纹理生产图片系统(有论文)

TOC 博主介绍:java高级开发,从事互联网行业六年,已经做了六年的毕业设计程序开发,开发过上千套毕业设计程序,博客中有上百套程序可供参考,欢迎共同交流学习。 项目简介 项目获取 🍅文末点击卡片…...

编译原理Lab. 1 初代编译器实验说明和要求

目录 Lab. 1 初代编译器实验说明和要求一、初代编译器功能描述二、初代编译器文法要求三、初代编译器测试样例四、初代编译器提交要求五、初代编译器实验测试框架说明 代码与思路 Lab. 1 初代编译器实验说明和要求 一、初代编译器功能描述 初代编译器将 C 语言顺序语句序列翻…...

python判断工作日,节假日

一、概述 需要判断一个日期是否为工作日,节假日。 找到一个现成的插件,蛮好用的。 插件介绍 https://pypi.org/project/chinesecalendar/ 判断某年某月某一天是不是工作日/节假日。 支持 2004年 至 2020年,包括 2020年 的春节延长。 兼容…...

练习4-权重衰减(李沐函数简要解析)

环境:练习1的环境 代码详解 0.导入库 import torch from torch import nn from d2l import torch as d2l1.初始化数据 这里初始化出train_iter test_iter 可以查一下之前的获取Fashion数据集后的数据格式与此对应 n_train, n_test, num_inputs, batch_size 20, 100, 200, …...

websocket 中 request-line 中的URI编码问题

首先,request-line组成如下: Request-Line Method SP Request-URI SP HTTP-Version CRLF 在 rfc6455 规范的 5.1.2 Request-URI 中,有这样的描述: The Request-URI is transmitted in the format specified in section 3.2.1. …...

为何ChatGPT日耗电超50万度?

看新闻说,ChatGPT每天的耗电量是50万度,国内每个家庭日均的耗电量不到10度,ChatGPT耗电相当于国内5万个家庭用量。 网上流传,英伟达创始人黄仁勋说:“AI的尽头是光伏和储能”,大佬的眼光就是毒辣&#xff…...

Cursor实现用excel数据填充word模版的方法

cursor主页:https://www.cursor.com/ 任务目标:把excel格式的数据里的单元格,按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例,…...

【Redis技术进阶之路】「原理分析系列开篇」分析客户端和服务端网络诵信交互实现(服务端执行命令请求的过程 - 初始化服务器)

服务端执行命令请求的过程 【专栏简介】【技术大纲】【专栏目标】【目标人群】1. Redis爱好者与社区成员2. 后端开发和系统架构师3. 计算机专业的本科生及研究生 初始化服务器1. 初始化服务器状态结构初始化RedisServer变量 2. 加载相关系统配置和用户配置参数定制化配置参数案…...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI

前一阵子在百度 AI 开发者大会上,看到基于小智 AI DIY 玩具的演示,感觉有点意思,想着自己也来试试。 如果只是想烧录现成的固件,乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外,还提供了基于网页版的 ESP LA…...

自然语言处理——Transformer

自然语言处理——Transformer 自注意力机制多头注意力机制Transformer 虽然循环神经网络可以对具有序列特性的数据非常有效,它能挖掘数据中的时序信息以及语义信息,但是它有一个很大的缺陷——很难并行化。 我们可以考虑用CNN来替代RNN,但是…...

Linux --进程控制

本文从以下五个方面来初步认识进程控制: 目录 进程创建 进程终止 进程等待 进程替换 模拟实现一个微型shell 进程创建 在Linux系统中我们可以在一个进程使用系统调用fork()来创建子进程,创建出来的进程就是子进程,原来的进程为父进程。…...

Springboot社区养老保险系统小程序

一、前言 随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,社区养老保险系统小程序被用户普遍使用,为方…...

【7色560页】职场可视化逻辑图高级数据分析PPT模版

7种色调职场工作汇报PPT,橙蓝、黑红、红蓝、蓝橙灰、浅蓝、浅绿、深蓝七种色调模版 【7色560页】职场可视化逻辑图高级数据分析PPT模版:职场可视化逻辑图分析PPT模版https://pan.quark.cn/s/78aeabbd92d1...

iOS性能调优实战:借助克魔(KeyMob)与常用工具深度洞察App瓶颈

在日常iOS开发过程中,性能问题往往是最令人头疼的一类Bug。尤其是在App上线前的压测阶段或是处理用户反馈的高发期,开发者往往需要面对卡顿、崩溃、能耗异常、日志混乱等一系列问题。这些问题表面上看似偶发,但背后往往隐藏着系统资源调度不当…...

【Linux】Linux 系统默认的目录及作用说明

博主介绍:✌全网粉丝23W,CSDN博客专家、Java领域优质创作者,掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域✌ 技术范围:SpringBoot、SpringCloud、Vue、SSM、HTML、Nodejs、Python、MySQL、PostgreSQL、大数据、物…...

根目录0xa0属性对应的Ntfs!_SCB中的FileObject是什么时候被建立的----NTFS源代码分析--重要

根目录0xa0属性对应的Ntfs!_SCB中的FileObject是什么时候被建立的 第一部分: 0: kd> g Breakpoint 9 hit Ntfs!ReadIndexBuffer: f7173886 55 push ebp 0: kd> kc # 00 Ntfs!ReadIndexBuffer 01 Ntfs!FindFirstIndexEntry 02 Ntfs!NtfsUpda…...