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

相关文章

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

Python实现Excel批量样式修改器(附完整代码)

《Python实现Excel批量样式修改器(附完整代码)》这篇文章主要为大家详细介绍了如何使用Python实现一个Excel批量样式修改器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一... 目录前言功能特性核心功能界面特性系统要求安装说明使用指南基本操作流程高级功能技术实现核心技术栈关键函

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

JavaScript中的高级调试方法全攻略指南

《JavaScript中的高级调试方法全攻略指南》什么是高级JavaScript调试技巧,它比console.log有何优势,如何使用断点调试定位问题,通过本文,我们将深入解答这些问题,带您从理论到实... 目录观点与案例结合观点1观点2观点3观点4观点5高级调试技巧详解实战案例断点调试:定位变量错误性能分

Python中 try / except / else / finally 异常处理方法详解

《Python中try/except/else/finally异常处理方法详解》:本文主要介绍Python中try/except/else/finally异常处理方法的相关资料,涵... 目录1. 基本结构2. 各部分的作用tryexceptelsefinally3. 执行流程总结4. 常见用法(1)多个e

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

504 Gateway Timeout网关超时的根源及完美解决方法

《504GatewayTimeout网关超时的根源及完美解决方法》在日常开发和运维过程中,504GatewayTimeout错误是常见的网络问题之一,尤其是在使用反向代理(如Nginx)或... 目录引言为什么会出现 504 错误?1. 探索 504 Gateway Timeout 错误的根源 1.1 后端

Redis实现高效内存管理的示例代码

《Redis实现高效内存管理的示例代码》Redis内存管理是其核心功能之一,为了高效地利用内存,Redis采用了多种技术和策略,如优化的数据结构、内存分配策略、内存回收、数据压缩等,下面就来详细的介绍... 目录1. 内存分配策略jemalloc 的使用2. 数据压缩和编码ziplist示例代码3. 优化的

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python