Init
This commit is contained in:
113
06-DCC/Maya/Maya C++插件笔记.md
Normal file
113
06-DCC/Maya/Maya C++插件笔记.md
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: Maya插件笔记
|
||||
date: 2022-08-09 13:55:15
|
||||
tags: Maya
|
||||
rating: ⭐️⭐️
|
||||
---
|
||||
# Maya2022文档地址
|
||||
[Maya2022 C++ 文档](https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_cpp_ref_index_html)
|
||||
[Maya2022 Python1.0文档](https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_Maya_Python_API_Maya_Python_API_1_0_html)
|
||||
[Maya2022 Python2.0文档](https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_py_ref_index_html)
|
||||
|
||||
# 设置开发环境
|
||||
这里我比较推荐官方文档的设置方法:[Maya2022Devkit设置](https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_Setting_up_your_build_Windows_environment_64_bit_html)
|
||||
主要的步骤是将各个版本的Devkit放到User文件夹中,并且在各个版本的Maya中添加Maya.env文件以及3个路径信息:
|
||||
> `MAYA_PLUG_IN_PATH=C:\Users\<Username>\devkitBase\plug-ins\plug-ins`
|
||||
`MAYA_SCRIPT_PATH=C:\Users\<Username>\devkitBase\plug-ins\scripts`
|
||||
`XBMLANGPATH=C:\Users\<Username>\devkitBase\plug-ins\icons`
|
||||
之后设置CMake,将生成MLL与PDB放到`MAYA_PLUG_IN_PATH` 路径中即可。这样不会出现UAV导致的生成失败问题,以方便Maya插件的开发。
|
||||
|
||||
# 调试方法
|
||||
## 参考方法1
|
||||
1. 在Visual Studio中以debug模式生成目标mll
|
||||
2. 在Maya中加载此mll
|
||||
3. ctrl+alt+p打开附加到进程,然后附加到Maya进程中
|
||||
4. 建立断点(任何时候都可以)
|
||||
5. 执行mll中的命令或节点,当遇到断点时会自动停下切换到VS中
|
||||
|
||||
或者在你的项目上右键点击Properties,Configuration Properties->Debugging里设置(之后按F5即可):
|
||||
- Command为Maya路径,比如`D:\Program Files\Autodesk\Maya2022\bin\maya.exe`
|
||||
- Attach为true
|
||||
|
||||
## 测试方法2
|
||||
使用bat查看Log:
|
||||
```cd /d D:/Program Files/Autodesk/Maya2020/bin/
|
||||
mayabatch.exe -script D:/Work/MUTools/MUToolsUE/Plugins/MUTools/Mel/MayaDriverStartupScript.mel 127.0.0.1 8000
|
||||
|
||||
pause
|
||||
```
|
||||
|
||||
# Maya
|
||||
## MFnPlugin
|
||||
在MStatus initializePlugin(MObject obj)中使用**MFnPlugin**对象对命令与节点进行注册,initializePlugin()会在插件加载后立即调用;在MStatus uninitializePlugin ( MObject obj )进行卸载,插件卸载时会调用uninitializePlugin()。
|
||||
|
||||
所有插件都必须实现initializePlugin()与uninitializePlugin()。
|
||||
|
||||
## MPxCommand
|
||||
自定义的命令需继承自该类,并且实现:
|
||||
- void* creator()
|
||||
- virtual [MStatus](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_status.html) [doIt](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_px_command.html#ade7d0a873cbe811d6eab464e695390a9) (const [MArgList](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_arg_list.html) &args)
|
||||
|
||||
其他可选虚函数:
|
||||
- virtual [MStatus](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_status.html) [undoIt](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_px_command.html#a0789a8d51244cad0495abb2b811c39db) ()
|
||||
- virtual MStatus [redoIt](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_px_command.html#a3b583cbc082553f11853db459b2f7795) ()
|
||||
- virtual bool [isUndoable](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_px_command.html#a2f6c567cc02d575ab14006d9c5e37761) () const
|
||||
- virtual bool [hasSyntax](https://help.autodesk.com/cloudhelp/2015/ENU/Maya-SDK/cpp_ref/class_m_px_command.html#a8121b9d1e18f95acf1f634e29e3b3d54) () const
|
||||
|
||||
返回结果则需要使用appendToResult()与setResult();实现完Command之后就可以在MEL中调用命令了。
|
||||
|
||||
## DAG
|
||||
DAG名为有向非循环图(directed acyclic graph)。
|
||||
|
||||
- **DG** **node**
|
||||
- 基本上可以认为maya当中所有的node都是DG node,包括DAG node
|
||||
- **DAG** **node**
|
||||
- 只有两种DAG node,transform 和shape
|
||||
- shape永远是transform的child
|
||||
- 组transform+shape组成一组DAG 结构
|
||||
|
||||
在窗口->常规编辑器->Hypergraph:Connect中,选择选项->显示->形状节点就可以完整DAG。
|
||||
|
||||
**注意:一个DAG节点可以有多个DAG路径。** 因为DAG是图,而不是树,所以会出现一个子节点拥有一个父节点的情况。在Maya中就是实例化的情况(比如实例化复制某个模型),即多个transform节点将一个特定Node进行了多次形变。
|
||||
|
||||
以下代码将生成案例场景:
|
||||
```ptrhon
|
||||
import maya.cmds as cmds;
|
||||
sphere1 = cmds.polySphere(r=1);
|
||||
sphere2 = cmds.polySphere(r=0.5);
|
||||
cmds.xform(sphere2[0], t=[0,1,0]);
|
||||
cmds.parent(sphere2[0],sphere1[0])
|
||||
sphere3 = cmds.instance(sphere1[0]);
|
||||
cmds.xform(sphere3, t=[2,0,0], ro=[45,0,0]);
|
||||
cmds.xform(sphere2[0],t=[0,2,0]);
|
||||
```
|
||||
|
||||
显示sphere2的DAG路径:
|
||||
```python
|
||||
import maya.OpenMaya as om;
|
||||
sel = om.MSelectionList();
|
||||
sel.add(cmds.listRelatives(sphere2[0])[0]);
|
||||
shapeNode=om.MObject();
|
||||
sel.getDependNode(0,shapeNode);
|
||||
paths=om.MDagPathArray();
|
||||
om.MDagPath.getAllPathsTo(shapeNode,paths);
|
||||
for i in range(paths.length()):
|
||||
print(paths[i].fullPathName());
|
||||
```
|
||||
|
||||
- [MFnDagNode](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html)— 具有取得父节与父节点数量的方法。
|
||||
- [MObject](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_object.html) dagRoot([MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) * _ReturnStatus_ = `NULL`)
|
||||
- bool [hasParent](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#ae44174b85fc62850f863823a9f9f418f) (const [MObject](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_object.html) &node, [MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- bool [hasChild](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#a59dfb5113547bc4cb73fb1c030d3c6b9) (const [MObject](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_object.html) &node, [MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- bool [isChildOf](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#ab1ed8580ddc4046557612745812564a7) (const [MObject](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_object.html) &node, [MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- bool [isParentOf](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#afcdebae60da551fd16379fd296ffa1e3) (const [MObject](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_object.html) &node, [MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- unsigned int [childCount](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#a7c6cdc0f5380b205fcf6e524e307b47f) ([MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- bool [isInstanced](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html#a6a7ad65572dca3e5cbeab283ffc9c90b) (bool indirect=true, [MStatus](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_status.html) *ReturnStatus=NULL) const
|
||||
- [MFnTransform](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_transform.html)— 具有对节点进行形变操作的函数集(源自[MFnDagNode](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html)),并具有获取和设置变换的方法,例如旋转、平移或缩放。
|
||||
- [MFnNurbsSurface](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_nurbs_surface.html)— 具有操作多种类型形状节点的函数集(也派生自[MFnDagNode](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_dag_node.html),但不派生自[MFnTransform](https://help.autodesk.com/cloudhelp/2020/ENU/Maya-SDK-MERGED/cpp_ref/class_m_fn_transform.html)),并具有获取和设置曲面 CV 等的方法。
|
||||
- MItDag:为DAG迭代器,遍历方式有深度与广度。
|
||||
- MItDependencyGraph:为DG迭代器。从指定的根节点或插头开始对依赖图(DG)节点或插头进行迭代。
|
||||
- MItDependencyNodes:为依赖性节点迭代器。使用依赖性节点迭代器来遍历Maya的依赖性图中的所有节点。
|
||||
- MDagPath:Dag路径存储。
|
||||
- pop():取得上一层级路径。
|
||||
|
119
06-DCC/Maya/Maya CMake笔记.md
Normal file
119
06-DCC/Maya/Maya CMake笔记.md
Normal file
@@ -0,0 +1,119 @@
|
||||
---
|
||||
title: 编写CMake实现构建多版本工程
|
||||
date: 2022-08-09 13:55:15
|
||||
tags: Maya CMake
|
||||
rating: ⭐️⭐️
|
||||
---
|
||||
# 编写CMake实现构建多版本工程
|
||||
1. 点击Configure与Generate根据当前年份与起始年份生成对应的子项目CMakeList.txt。
|
||||
2. 填入所要生成版本的Devkit路径。
|
||||
3. 再次点击Configure与Generate,即可生成项目。
|
||||
|
||||
## 知识点
|
||||
### 变量共享
|
||||
在set中增加**CACHE**关键字就可以到主模块与子模块变量共享的目的。比如:
|
||||
> set("Maya${CURRENT_YEAR}_DEVKIT_LOCATION" "" CACHE PATH "")
|
||||
|
||||
### 子模块
|
||||
调用**add_subdirectory**添加含有CMakeList.txt的文件夹即可。
|
||||
|
||||
### CMake生成文件
|
||||
使用**file(GENERATE OUTPUT Path CONTENT Code)** 就可以生成文本文件了。这样就做到让CMake生成子CMakeList.txt的功能。代码如下(xxx为文本内容):
|
||||
```cmake
|
||||
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Maya${CURRENT_YEAR}/CMakeLists.txt" CONTENT XXXX)
|
||||
```
|
||||
|
||||
需要注意代码中的${},需要将他们拆开放置它转义。
|
||||
|
||||
### winsock库报错问题
|
||||
>在cmake里加上一行:**link_libraries(ws2_32)**
|
||||
|
||||
或者在VisualStudio的Linker->Input->AdditionalDependencies中添加 Ws2_32.lib即可。
|
||||
|
||||
## 具体代码
|
||||
具体代码如下:
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(DrivenByUE4)
|
||||
|
||||
# 取得现在是XX年,之后计算Maya最新版本
|
||||
string(TIMESTAMP COMPILE_TIME %Y)
|
||||
math(EXPR THIS_YEAR "${COMPILE_TIME} + 1")
|
||||
set(START_YEAR 2018)
|
||||
set(CURRENT_YEAR "${START_YEAR}")
|
||||
|
||||
# 生成设置变量
|
||||
while(CURRENT_YEAR LESS_EQUAL THIS_YEAR)
|
||||
set("Maya${CURRENT_YEAR}_DEVKIT_LOCATION" "" CACHE PATH "")
|
||||
set("Maya${CURRENT_YEAR}_LOCATION" "" CACHE PATH "")
|
||||
math(EXPR CURRENT_YEAR "${CURRENT_YEAR} + 1")
|
||||
# message(STATUS "result:${CURRENT_YEAR}")
|
||||
endwhile()
|
||||
|
||||
# 不存在子项目则生成
|
||||
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/Maya${CURRENT_YEAR}/CMakeLists.txt")
|
||||
set(CURRENT_YEAR "${START_YEAR}")
|
||||
while(CURRENT_YEAR LESS_EQUAL THIS_YEAR)
|
||||
# 防止生成文件把${}进行转义
|
||||
set(ENV_String "$")
|
||||
string(APPEND ENV_String "ENV{PATH}")
|
||||
string(APPEND ENV_String "\$ENV")
|
||||
string(APPEND ENV_String "{MAYA_LOCATION}/bin;")
|
||||
set(ENV_String2 "$")
|
||||
string(APPEND ENV_String2 "ENV{DEVKIT_LOCATION}")
|
||||
set(ENV_String3 "$")
|
||||
string(APPEND ENV_String3 "{PROJECT_NAME}")
|
||||
|
||||
# 因为生成文件会在Generate按钮按下后执行,所以需要执行2遍Configure与Generate
|
||||
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Maya${CURRENT_YEAR}/CMakeLists.txt" CONTENT
|
||||
"project(\"DrivenByUE4_Maya${CURRENT_YEAR}\")
|
||||
|
||||
set(ENV{DEVKIT_LOCATION} \"${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}\")
|
||||
set(ENV{MAYA_LOCATION} \"${Maya${CURRENT_YEAR}_LOCATION}\")
|
||||
set(ENV{PATH} \"${ENV_String}\")
|
||||
|
||||
include(${ENV_String2}/cmake/pluginEntry.cmake)
|
||||
set(SOURCE_FILES
|
||||
../DBU_AddMesh.cpp
|
||||
../DBU_AddMesh.h
|
||||
../DBU_ScenePrimitiveCollector.cpp
|
||||
../DBU_ScenePrimitiveCollector.h
|
||||
../DBU_ControlCmd.cpp
|
||||
../DBU_ControlCmd.h
|
||||
../DBU_TCPSocket.cpp
|
||||
../DBU_TCPSocket.h
|
||||
../PluginRegister.cpp)
|
||||
set(LIBRARIES OpenMaya Foundation)
|
||||
|
||||
set(PDB_OUTPUT_DIRECTORY ${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/plug-ins/plug-ins/DrivenByUE4.pdb)
|
||||
link_libraries(ws2_32)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/plug-ins/plug-ins)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/plug-ins/plug-ins)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/plug-ins/plug-ins)
|
||||
|
||||
set(VS_DEBUGGER_COMMAND ${Maya${CURRENT_YEAR}_LOCATION}/bin/mayabatch.exe)
|
||||
|
||||
set(INCLUDE_DIRS \"\")
|
||||
set(DEVKIT_BASE_DIR \"${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}\")
|
||||
set(LIBRARY_DIRS \"${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/lib\")
|
||||
set(Foundation_PATH \"${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/lib/Foundation.lib\")
|
||||
set(OpenMaya_PATH \"${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}/lib/OpenMaya.lib\")
|
||||
|
||||
build_plugin()
|
||||
set_target_properties(${ENV_String3} PROPERTIES OUTPUT_NAME \"DrivenByUE4\")")
|
||||
|
||||
math(EXPR CURRENT_YEAR "${CURRENT_YEAR} + 1")
|
||||
endwhile()
|
||||
endif()
|
||||
|
||||
set(CURRENT_YEAR "${START_YEAR}")
|
||||
|
||||
while(CURRENT_YEAR LESS_EQUAL THIS_YEAR)
|
||||
if(NOT "${Maya${CURRENT_YEAR}_DEVKIT_LOCATION}" STREQUAL "" AND EXISTS "${CMAKE_CURRENT_BINARY_DIR}/Maya${CURRENT_YEAR}/CMakeLists.txt")
|
||||
add_subdirectory("Maya${CURRENT_YEAR}" "Maya${CURRENT_YEAR}")
|
||||
endif()
|
||||
|
||||
math(EXPR CURRENT_YEAR "${CURRENT_YEAR} + 1")
|
||||
endwhile()
|
||||
```
|
312
06-DCC/Maya/Maya Python笔记.md
Normal file
312
06-DCC/Maya/Maya Python笔记.md
Normal file
@@ -0,0 +1,312 @@
|
||||
---
|
||||
title: Maya Python笔记
|
||||
date: 2022-08-09 13:55:15
|
||||
tags: Maya
|
||||
rating: ⭐️⭐️
|
||||
---
|
||||
# 前言
|
||||
# 前期准备
|
||||
开发环境搭建:https://www.jianshu.com/p/813b2cc71ca2
|
||||
|
||||
《Maya Python游戏与影视编程指南》这个书还是挺不错的。
|
||||
|
||||
# VSCode插件
|
||||
除了必须的Python(打开一个Py文件就会提示安装),我使用的是MayaPy与MayaCode。
|
||||
|
||||
# Maya开启端口
|
||||
在Maya中开启端口,这样就可以在VSCode中将代码直接发送到Maya中执行。
|
||||
## Mel
|
||||
commandPort -name "localhost:7001" -sourceType "mel" -echoOutput;
|
||||
|
||||
## Python
|
||||
```python
|
||||
import maya.cmds as cmds
|
||||
|
||||
cmds.commandPort(name=":7001", sourceType="mel",echoOutput=True)
|
||||
```
|
||||
|
||||
建议建一个脚本文件,这样就不用每次启动都手动开启端口了。以Python为例,把上面Python代码复制到新建的.py文件中,放到下面目录:
|
||||
```s
|
||||
Windows: <drive>:\Documents and Settings\<你的windows用户名>\My Documents\maya\<你maya的版本号>\scripts
|
||||
(其实就是我的文档下面maya文件夹)
|
||||
MacOSX: ~/Library/Preferences/Autodesk/maya/<你maya的版本号>/scripts.
|
||||
Linux: ~/maya/<你maya的版本号>/scripts.
|
||||
```
|
||||
|
||||
# Maya Python路径设置及代码自动补全
|
||||
VS Code中按Ctrl+Shift+P,输入Settings打开settings.json配置文件,在大括号里加入下面代码:
|
||||
```
|
||||
//python.pythonPath是指定Python命令路径,请根据你maya的安装路径来做修改
|
||||
"python.pythonPath": "C:/Program Files/Autodesk/Maya2019/bin/mayapy.exe",
|
||||
//python.autoComplete.extraPaths是代码自动补全路径,同样根据你自己的maya安装路径来写
|
||||
"python.autoComplete.extraPaths": "C:/Program Files/Autodesk/Maya2019/devkit/other/pymel/extras/completion/py"
|
||||
```
|
||||
|
||||
注意:settings.json文件中,每一项设置用","隔开,最后一项设置后面没有",",如果报错,检查一下是不是这里出现了问题。
|
||||
|
||||
# Flag参数
|
||||
```
|
||||
-e -edit
|
||||
-q -query
|
||||
-ax. -axis Length Length Length
|
||||
-cch -caching onloff
|
||||
-ch -constructionHistory onloff
|
||||
-cuv -createUVs Int
|
||||
-d -depth Length
|
||||
-h -height Length
|
||||
-n - name String
|
||||
- nds - nodeState Int
|
||||
-0 -object onlof f
|
||||
-sd -subdivisionsDepth Int
|
||||
-sh - subdivisionsHeight Int
|
||||
-sw -subdivis ionsWidth Int
|
||||
-SX -subdivisionsX Int
|
||||
-sy -subdivisionsY Int
|
||||
-sz - subdivisionsZ Int
|
||||
-tx -texture Int
|
||||
-W -width Length
|
||||
```
|
||||
## 查询参数
|
||||
使用以下命令可以查询具体函数的flag,例如polyCube:
|
||||
```
|
||||
print(cmds.help('polyCube'));
|
||||
```
|
||||
结果为:
|
||||
```
|
||||
Synopsis: polyCube [flags] [String...]
|
||||
Flags:
|
||||
-e -edit
|
||||
-q -query
|
||||
-ax -axis Length Length Length
|
||||
-cch -caching on|off
|
||||
-ch -constructionHistory on|off
|
||||
-cuv -createUVs Int
|
||||
-d -depth Length
|
||||
-fzn -frozen on|off
|
||||
-h -height Length
|
||||
-n -name String
|
||||
-nds -nodeState Int
|
||||
-o -object on|off
|
||||
-sd -subdivisionsDepth Int
|
||||
-sh -subdivisionsHeight Int
|
||||
-sw -subdivisionsWidth Int
|
||||
-sx -subdivisionsX Int
|
||||
-sy -subdivisionsY Int
|
||||
-sz -subdivisionsZ Int
|
||||
-tx -texture Int
|
||||
-w -width Length
|
||||
|
||||
```
|
||||
|
||||
|
||||
# 【10】Select Objects
|
||||
选择在Maya里要分为两部分作用,一个是从选择里获取,一个是把数据设置给当前选择的东西。
|
||||
要想从外界传数据进脚本,方法之一就是从maya的选择列表里拿物体数据
|
||||
```python
|
||||
import maya.cmds as cmd
|
||||
|
||||
selectObjectList = cmd.ls(orderedSelection = True)
|
||||
print selectObjectList
|
||||
```
|
||||
|
||||
把属性设置给选择的物体,这时我们需要手动调用select命令,因为有写操作是只能对选择物体生效的,所以在执行这些操作之前需要在代码里先选中这个物体。如果场景里面有个pSphere1物体
|
||||
```python
|
||||
import maya.cmds as cmd
|
||||
cmd.select('pSphere1')
|
||||
清除空选择列表:
|
||||
|
||||
import maya.cmds as cmd
|
||||
cmd.select(clear = True)
|
||||
加选
|
||||
|
||||
import maya.cmds as cmd
|
||||
cmd.select('pSphere1')
|
||||
cmd.select('pSphere2', add = True)
|
||||
```
|
||||
|
||||
从列表中获取所有节点
|
||||
```python
|
||||
nodes=cmds.ls();
|
||||
print(nodes)
|
||||
```
|
||||
|
||||
添加类型限制
|
||||
```python
|
||||
nodes=cmds.ls(type='transform');
|
||||
print(nodes)
|
||||
```
|
||||
|
||||
字符串配合通配符*
|
||||
```python
|
||||
nodes = cmds.ls('joint*');
|
||||
print(nodes);
|
||||
```
|
||||
|
||||
选中指定的物体
|
||||
```python
|
||||
cmds.select('side*','top*');
|
||||
```
|
||||
|
||||
select指令与ls指令可以结合使用,例如:
|
||||
```python
|
||||
cmds.ls(sl=True);
|
||||
cmds.select(cmds.ls('joint*'));
|
||||
```
|
||||
|
||||
# getAttr与setAttr
|
||||
通过字符串获取属性,不容易报错。
|
||||
```python
|
||||
loc=cmds.spaceLocator()[0]
|
||||
sx=cmds.getAttr(loc+'.scaleX')
|
||||
print(sx)
|
||||
```
|
||||
但注意,因为不确定类型,所以请注意数据格式
|
||||
|
||||
# 对应的容器
|
||||
有数组、map与set
|
||||
## 序列操作符
|
||||
```
|
||||
x in s 如在在序列中则返回true
|
||||
x not in s 如果不在序列中则返回true
|
||||
s+t 串联
|
||||
s[i] s序列中的第i项
|
||||
s[i:j] 取得指定范围的成员
|
||||
s[i:j:k] 取得指定范围的成员,k为步长
|
||||
len(s) 长度
|
||||
min(s) 最小项
|
||||
max(s) 最大项
|
||||
s.index(x) 第一次出现的index
|
||||
s.count(x) 出现次数
|
||||
```
|
||||
|
||||
# 可变参数的函数
|
||||
```python
|
||||
def function1(*args):
|
||||
print(args[0],args[1:]);
|
||||
```
|
||||
两个**则代表Map
|
||||
|
||||
# cmds.file
|
||||
可以用于保存、新建、打开新场景。
|
||||
|
||||
# 模块
|
||||
查看全局与本地队友对象:globals()与locals()
|
||||
|
||||
```
|
||||
__main__ #为当前MayaPython编辑器模块。
|
||||
__file__ #文件绝对路径
|
||||
__package__ #所在包名
|
||||
```
|
||||
|
||||
在一个文件夹中放入一个__init__.py与其他*.py文件,之后就可以
|
||||
```python
|
||||
import 文件夹名;
|
||||
文件夹名.py名.function()
|
||||
```
|
||||
调用函数
|
||||
# 路径
|
||||
```python
|
||||
import sys;
|
||||
for p in sys.path:
|
||||
print(p)
|
||||
```
|
||||
# 类
|
||||
```python
|
||||
class NewClass(object):
|
||||
pass;
|
||||
```
|
||||
实例化
|
||||
```python
|
||||
instance1=NewClass();
|
||||
instance2=NewClass();
|
||||
```
|
||||
构造函数
|
||||
```python
|
||||
class Human(object):
|
||||
def __init__(self):
|
||||
self.first_name='aaaa';
|
||||
self.last_name='bbbb';
|
||||
```
|
||||
# PyMel
|
||||
PyMel与maya.cmds不同在于,它返回的不是字符串,而是一个PyNode对象。它可以直接修改节点属性值,无需调用getAttr与setAttr。更加适合于习惯了OOP语言人士使用。同时PyMel可以简化GUI的构建。
|
||||
|
||||
# GUI
|
||||
开发包里有一些案例文件可以参考:
|
||||
- devkit\pythonScripts\widgetHierarchy.py
|
||||
|
||||
推荐使用Maya安装目录下的designer.exe
|
||||
|
||||
安装 PySide2:安装 python 后,在安装目录下有 /script 文件夹,里面有 pip.exe ,cmd执行:pip install PySide,pip install PySide2(注意: python2.x 对应 PySide,python3.x 对应PySide2)pyside-uic.exe 位于Python的安装目录下
|
||||
|
||||
## python HumanIK
|
||||
无效 https://forums.autodesk.com/t5/maya-programming/python-hik/td-p/4262564
|
||||
https://forums.autodesk.com/t5/maya-animation-and-rigging/pythonic-mel-way-to-retarget-hik/td-p/7609798
|
||||
|
||||
## 文档
|
||||
- http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-CEC1D76B-7568-4DCA-B80B-1DE49362492C&pl=CHS
|
||||
- http://help.autodesk.com/cloudhelp/2018/JPN/Maya-Tech-Docs/PyMel/generated/pymel.core.animation.html
|
||||
|
||||
## Pyside2文档
|
||||
百度的时候请搜索PyQt5
|
||||
https://doc.qt.io/qtforpython/modules.html
|
||||
|
||||
## 信号槽与解决生命周期问题
|
||||
其中SIGNAL需要先导入
|
||||
```python
|
||||
from PySide2.QtCore import SIGNAL, QObject
|
||||
|
||||
class MainWindow(QWidget, Ui_Form):
|
||||
def slotBtnClicked(self):
|
||||
msgBox = QMessageBox(self)
|
||||
msgBox.setText(u"The document has been modified.")
|
||||
msgBox.setInformativeText(u"Do you want to save your changes?")
|
||||
msgBox.setStandardButtons(QMessageBox.Save)
|
||||
msgBox.setDefaultButton(QMessageBox.Save)
|
||||
msgBox.show()
|
||||
def __init__(self, parent=None):
|
||||
self.pushButton_stop.clicked.connect(self.slotBtnClicked)
|
||||
QObject.connect(self.pushButton_targetSkin,SIGNAL('clicked()'), self.slotBtnClicked)
|
||||
```
|
||||
|
||||
# FBX Mel文档
|
||||
https://knowledge.autodesk.com/zh-hans/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2019/CHS/Maya-DataExchange/files/GUID-335F2172-DD4D-4D79-B969-55238C08F2EF-htm.html
|
||||
|
||||
# FBX导出
|
||||
```
|
||||
# FBX Exporter options. Set as required.
|
||||
# You can find a reference guide here: http://download.autodesk.com/us/fbx/20112/Maya/_index.html
|
||||
# Just add/change what you need.
|
||||
|
||||
# Geometry
|
||||
mm.eval("FBXExportSmoothingGroups -v true")
|
||||
mm.eval("FBXExportHardEdges -v false")
|
||||
mm.eval("FBXExportTangents -v false")
|
||||
mm.eval("FBXExportSmoothMesh -v true")
|
||||
mm.eval("FBXExportInstances -v false")
|
||||
mm.eval("FBXExportReferencedContainersContent -v false")
|
||||
# Animation
|
||||
mm.eval("FBXExportBakeComplexAnimation -v true")
|
||||
mm.eval("FBXExportBakeComplexStart -v "+str(exportStartFrame[x]))
|
||||
mm.eval("FBXExportBakeComplexEnd -v "+str(exportEndFrame[x]))
|
||||
mm.eval("FBXExportBakeComplexStep -v 1")
|
||||
# mm.eval("FBXExportBakeResampleAll -v true")
|
||||
mm.eval("FBXExportUseSceneName -v false")
|
||||
mm.eval("FBXExportQuaternion -v euler")
|
||||
mm.eval("FBXExportShapes -v true")
|
||||
mm.eval("FBXExportSkins -v true")
|
||||
# Constraints
|
||||
mm.eval("FBXExportConstraints -v false")
|
||||
# Cameras
|
||||
mm.eval("FBXExportCameras -v false")
|
||||
# Lights
|
||||
mm.eval("FBXExportLights -v false")
|
||||
# Embed Media
|
||||
mm.eval("FBXExportEmbeddedTextures -v false")
|
||||
# Connections
|
||||
mm.eval("FBXExportInputConnections -v false")
|
||||
# Axis Conversion
|
||||
mm.eval("FBXExportUpAxis y")
|
||||
|
||||
# Export!
|
||||
mm.eval("FBXExport -f "+exportNames[x]+".fbx -s")
|
||||
```
|
8
06-DCC/Maya/Maya Python调试方法.md
Normal file
8
06-DCC/Maya/Maya Python调试方法.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
title: Maya Python调试方法
|
||||
date: 2022-08-09 13:55:15
|
||||
tags: Maya
|
||||
rating: ⭐️⭐️
|
||||
---
|
||||
- PyCharm 调试MayaPython方法:https://www.youtube.com/watch?v=A_mjrCNtxlY
|
||||
- 国内大神开发的Maya Pyhton Debug插件:https://www.bilibili.com/read/cv16051640
|
Reference in New Issue
Block a user