maya 粒子替代物体转为实体物体的方法 Mel脚本代码

2023-10-08 16:20

本文主要是介绍maya 粒子替代物体转为实体物体的方法 Mel脚本代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一个学生问如何把maya 粒子替代物体转为实体物体的方法脚本代码。我把以前用于一个广告项目的插件代码提取了一下。得到下面两个程序。可以实现以上功能。但需要注意的是,前提要提供粒子镁粒子物体的旋转和缩放属性名,以及粒子的种子物id属相名。此代码源于以前开发的 垃圾清道夫插件中的一个功能。也可以将物体转为粒子。便于加速动力学效果。
在这里插入图片描述

global proc string[] tjh_rubbish_dumper__select_seeds_from_particle(string $nParticle) 
{
string $all_tjh_tree_factory__objects[];
clear $all_tjh_tree_factory__objects;//$all_tjh_tree_factory__objects = `ls -dag  -type "particle" -type "nParticle" -sl`;if(size($nParticle)>0)
{
$all_tjh_tree_factory__objects = `ls  -dag -type "particle" -type "nParticle" $nParticle `;
}else{
$all_tjh_tree_factory__objects = `ls  -dag -type "particle" -type "nParticle" -sl`;
}string $particleShape = "";
string $seeds[];int $k = 0;
int $h = 0;
for($particleShape in $all_tjh_tree_factory__objects)
{
string $instancers[]=` listConnections -s 0 -d 1 ($particleShape ".instanceData")`;string $instancerObjs[]=` instancer -q -object $instancers[0]`;for($k=0;$k{$seeds[$h]=$instancerObjs[$k];$h ;}
};
//select -r $all_valid_tjh_objects;//particleShapes
select -r $seeds;//instancer seed objects
//select -add $instancerNodes;//instancer nodes
return $seeds;
}//粒子转换为实例物体 
global proc tjh_rubbish_dumper_replaceParticles_withObjects(string $nParticle, string $instancerPP,string $rotationPP,string $scalePP)
{
string $particleNode[];
//default define for none selected
if($instancerPP == "")  $instancerPP = "instancerPP";
if($rotationPP == "")  $rotationPP = "rotationPP";
if($scalePP == "")  $scalePP = "scalePP";if(size($nParticle)>0)
{
$particleNode = `ls  -dag -type "particle" -type "nParticle" $nParticle `;
}else{
$particleNode = `ls  -dag -type "particle" -type "nParticle" -sl`;
}if(size($particleNode) > 0)//判断选择物体有粒子物体
{
//得到种子物体
string $tjh_replaceWithInstancer_selectSeeds[];
$tjh_replaceWithInstancer_selectSeeds=`tjh_rubbish_dumper__select_seeds_from_particle("")`;//保存原有种子物的原始位置及缩放旋转值
float $old_posX[],$old_posY[],$old_posZ[];
//float $old_rotateX[],$old_rotateY[],$old_rotateZ[];
//float $old_scaleX[],$old_scaleY[],$old_scaleZ[];
for($i = 0; $i
{
$old_posX[$i] = ` getAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tx") `;
$old_posY[$i] = ` getAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "ty") `;
$old_posZ[$i] = ` getAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tz") `;}for($i = 0; $i
{
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tx") 0 ;
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "ty") 0 ;
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tz") 0 ;}int $seedsSize = size($tjh_replaceWithInstancer_selectSeeds) ;int $particlePointsSize = `getAttr ($particleNode[0] ".count")` ;//float $instancerPP[] =`getParticleAttr -at "instancerPP" -array true ($particleNode[0] ".pt[0:" ($seedsSize-1) "]")`;
//float $rotatePP[] =`getParticleAttr -at "rotationPP" -array true ($particleNode[0] ".pt[0:" ($seedsSize-1) "]")`;
//float $scalePP[] =`getParticleAttr -at "scalePP" -array true ($particleNode[0] ".pt[0:" ($seedsSize-1) "]")`;float $instancerPP_Array[];
float $rotatePP_Array[];
float $scalePP_Array[];if(` objExists  ($particleNode[0] "." $instancerPP)`)$instancerPP_Array =`getParticleAttr -at $instancerPP -array true $particleNode[0]`;
if(` objExists  ($particleNode[0] "." $rotationPP)`)$rotatePP_Array =`getParticleAttr -at $rotationPP -array true $particleNode[0]`;
if(` objExists  ($particleNode[0] "." $scalePP)`)$scalePP_Array =`getParticleAttr -at $scalePP -array true $particleNode[0]`;string $newObject_instancer[];
//replace process
for($i=0;$i<$particlePointsSize;$i )
{
//int $id = floor( rand($seedsSize) );
int $id =0;if(` objExists  ($particleNode[0] "." $instancerPP)`)$id= $instancerPP_Array[$i];string $newObject[]; 
//string $copyType =`radioCollection -q -select  tjh_replaceWithInstancer__radioCollection_copyType`;
//if($copyType == "tjh_replaceWithInstancer__radioButton_copyType_copy")
// $newObject= ` duplicate $tjh_replaceWithInstancer_selectSeeds[$id]`;
//if($copyType == "tjh_replaceWithInstancer__radioButton_copyType_instance")
$newObject= ` instance $tjh_replaceWithInstancer_selectSeeds[$id]`;
$newObject_instancer[$i] = $newObject[0];
float $positionPP_Array[] =`pointPosition -world ($particleNode[0] ".pt[" $i "]")`;string $cmd = "xform -r -t " ($positionPP_Array[0]) " " ($positionPP_Array[1]) " " ($positionPP_Array[2]) " ";
if(` objExists  ($particleNode[0] "." $rotationPP)`)  $cmd =" -ro " ($rotatePP_Array[$i*3]) " " ($rotatePP_Array[$i*3 1]) " " ($rotatePP_Array[$i*3 2]) " ";
if(` objExists  ($particleNode[0] "." $scalePP)`) $cmd =" -s " ($scalePP_Array[$i*3]) " " ($scalePP_Array[$i*3 1]) " " ($scalePP_Array[$i*3 2]) " ";$cmd =  $newObject[0];
eval_r($cmd);//xform -r -t ($positionPP[0]) ($positionPP[1]) ($positionPP[2]) -ro ($rotatePP[$i*3]) ($rotatePP[$i*3 1]) ($rotatePP[$i*3 2]) -s ($scalePP[$i*3]) ($scalePP[$i*3 1]) ($scalePP[$i*3 2]) $newObject[0];}//create new group for instancer-objs.
group -world -n ("tjh_rubbish_dumper_" $particleNode[0]) $newObject_instancer;
//delete $particle;//恢复原有位置
for($i = 0; $i
{
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tx") $old_posX[$i] ;
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "ty") $old_posY[$i] ;
setAttr  ($tjh_replaceWithInstancer_selectSeeds[$i] "." "tz") $old_posZ[$i] ;}}else{warning "no particle selected!";}
}

南无阿弥陀佛

这篇关于maya 粒子替代物体转为实体物体的方法 Mel脚本代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/166526

相关文章

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

判断PyTorch是GPU版还是CPU版的方法小结

《判断PyTorch是GPU版还是CPU版的方法小结》PyTorch作为当前最流行的深度学习框架之一,支持在CPU和GPU(NVIDIACUDA)上运行,所以对于深度学习开发者来说,正确识别PyTor... 目录前言为什么需要区分GPU和CPU版本?性能差异硬件要求如何检查PyTorch版本?方法1:使用命

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java中的工具类命名方法

《Java中的工具类命名方法》:本文主要介绍Java中的工具类究竟如何命名,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java中的工具类究竟如何命名?先来几个例子几种命名方式的比较到底如何命名 ?总结Java中的工具类究竟如何命名?先来几个例子JD

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊