Dorian Fevrier's blog - Mot-clé - expression
Je m’appelle FEVRIER Dorian, je suis infographiste 3D passionné par mon métier, l’informatique en général, l’internet, la programmation et l’évolution de tout ce petit monde. Vous trouverez sur ce blog des tutoriaux, mes coups de cœurs, avis, etc.
2024-01-02T23:48:05+01:00
FEVRIER Dorian
urn:md5:695d9c73474c33ce3dab043823509c4b
Dotclear
Remplir un mesh de particules dans Maya: closestPointOnMesh again!
urn:md5:114949baea14101d160231df46e1ec62
2010-09-22T23:52:00+02:00
2013-07-26T18:13:13+02:00
Narann
Infographie 3D - Boulot
expression
fr
maya
mesh
particule
remplir
script
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule_tn.png" alt="remplir_mesh_particule_tn.png" style="float:left; margin: 0 1em 1em 0;" title="remplir_mesh_particule_tn.png, sept. 2010" height="150" width="150" />Boujour à tous! :dentcasse:</p>
<p>Dans Maya, il peut arriver que l'on veuille remplir un mesh de particules de manière complètement aléatoire. Il existe plusieurs méthodes pour ça.</p>
<p>On peut, par exemple, émettre des particules vers l'intérieur du mesh et les faire rebondir sur les parois. Mais cette méthode ne donne pas un résultat si aléatoire que ça. Et dans certains cas, cela se voit. :reflechi:</p>
<p>Si on a des pépettes, on peut aussi utiliser Houdini qui fait ça à merveille et récupérer les particules dans Maya.</p>
<p>Ce que je vous propose est une méthode un peu "clef en main". Vous sélectionnez votre mesh, appliquez le script, réglez deux trois trucs appuyez sur play pour lancer la génération et c'est bon!</p> <p>Si on a des pépettes, on peut aussi utiliser Houdini qui fait ça à merveille et récupérer les particules dans Maya.</p>
<p>Ce que je vous propose est une méthode un peu "clef en main". Vous sélectionnez votre mesh, appliquez le script, réglez deux trois trucs appuyez sur play pour lancer la génération et c'est bon!</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule001.png" alt="remplir_mesh_particule001.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule001.png, sept. 2010" height="397" width="470" /></p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule002.png" alt="remplir_mesh_particule002.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule002.png, sept. 2010" height="397" width="470" /></p>
<p>Mais avant ça, je vais vous expliquer un peu comment ça marche. :reflechi:</p>
<center>:longBar:</center>
<h5>Theorie</h5>
<p>:mayaProf:</p>
<p>Alors alors, comment ça se passe?</p>
<p>Pour faire simple, il faut lancer des particules dans un espace/volume, de manière aléatoire, puis déterminer si la particule créé est dans un mesh ou non...</p>
<p>Créer des particules de manière aléatoire dans un espace, ça on sait faire via un volume emitter</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule003.png" alt="remplir_mesh_particule003.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule003.png, sept. 2010" height="189" width="216" /></p>
<p>Avec cette méthode, chaque particule créé est placé quelque part dans le cube ou la sphere.</p>
<p>Bien, mais comment savoir si ses particules sont dans un mesh? Et bien on va se servir d'un node dont je vois ai déjà parlé (faire un lien): closestPointOnMesh.</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_13_oriente_particle_maya/oriente_particle_maya002.png" alt="oriente_particle_maya002.png" style="display:block; margin:0 auto;" title="oriente_particle_maya002.png, sept. 2010" height="424" width="556" /></p>
<p>Ce node permet de faire pas mal de choses. On lui donne en entrée un mesh ainsi qu'une position dans l'espace, et il nous donne, en sortie, d'autres informations.</p>
<p>Les informations qui nous intéressent sont:</p>
<ul>
<li>La position, sur le mesh, du point le plus proche du point donné en entré.</li>
<li>La normale de ce point.</li>
</ul>
<p>Et il n'en faut pas plus pour déterminer, avec ses informations, si le point est à l'intérieur ou à l'exterieur du mesh (si si je vous assure! :dentcasse: ).</p>
<p>Les plus perspicaces d'entre vous l'auront remarqué, votre mesh se doit d'être un minimum propre pour faire fonctionner correctement cette méthode.</p>
<p>En effet, si les normales du mesh sont "bizarre", il ne s'en sortira pas! :nannan:</p>
<p>Le principe est le suivant:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_001.png" alt="Schema_001.png" style="display:block; margin:0 auto;" title="Schema_001.png, sept. 2010" height="448" width="436" /></p>
<ul>
<li>Vous prenez un point, dans l'espace, notre particule.</li>
</ul>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_002.png" alt="Schema_002.png" style="display:block; margin:0 auto;" title="Schema_002.png, sept. 2010" height="448" width="436" /></p>
<ul>
<li>Vous cherchez le point le plus proche de votre particule sur le mesh à remplir.</li>
</ul>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_003.png" alt="Schema_003.png" style="display:block; margin:0 auto;" title="Schema_003.png, sept. 2010" height="448" width="436" /></p>
<ul>
<li>Vous récupérez la normale de ce point (sous forme de vecteur).</li>
</ul>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_004.png" alt="Schema_004.png" style="display:block; margin:0 auto;" title="Schema_004.png, sept. 2010" height="448" width="436" /></p>
<ul>
<li>Vous soustrayez la position du point sur le mesh à la position de la particule pour obtenir un vecteur du point du mesh vers votre particule.</li>
</ul>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_005.png" alt="Schema_005.png" style="display:block; margin:0 auto;" title="Schema_005.png, sept. 2010" height="448" width="436" /></p>
<center><i>V1-V2=V3 :sourit:</i></center>
<ul>
<li>Vous récupérez l'angle entre ses deux vecteurs (vecteurs normale et vecteurs "point du mesh vers particule").</li>
</ul>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/Schema_006.png" alt="Schema_006.png" style="display:block; margin:0 auto;" title="Schema_006.png, sept. 2010" height="448" width="436" /></p>
<ul>
<li>Si cet angle est supérieur à 90 degrée, le point est à l'intérieur du mesh!</li>
</ul>
<p>La magie des maths!</p>
<center>:longBar:</center>
<h5>Pratique :mechantCrash:</h5>
<p>Allez, on y va! Commencez par créer un emitter volumetric:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule004.png" alt="remplir_mesh_particule004.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule004.png, sept. 2010" height="109" width="213" /></p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule005.png" alt="remplir_mesh_particule005.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule005.png, sept. 2010" height="147" width="303" /></p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule006.png" alt="remplir_mesh_particule006.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule006.png, sept. 2010" height="68" width="323" /></p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule003.png" alt="remplir_mesh_particule003.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule003.png, sept. 2010" height="189" width="216" /></p>
<p>Créez un mesh:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule007.png" alt="remplir_mesh_particule007.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule007.png, sept. 2010" height="379" width="477" /></p>
<p>Créer un closestPointOnMesh:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule008.png" alt="remplir_mesh_particule008.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule008.png, sept. 2010" height="53" width="236" /></p>
<p>Connectez lui le mesh:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule009.png" alt="remplir_mesh_particule009.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule009.png, sept. 2010" height="111" width="606" /></p>
<center><i>worldMesh pour le mesh et worldMatrix pour savoir ou est placé le mesh dans l'espace. :hehe:</i></center>
<p>Maintenant on passe à la seconde partie de la création, la plus dur. :grenadelauncher:</p>
<p>Créez un expression de création de particule:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule010.png" alt="remplir_mesh_particule010.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule010.png, sept. 2010" height="52" width="140" /></p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule011.png" alt="remplir_mesh_particule011.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule011.png, sept. 2010" height="61" width="348" /></p>
<p>Et voici l'expression:</p>
<pre class="mel mel">vector $particlePos <span style="color: #339933;">=</span> myParticleSystem.<span style="color: #202020;">position</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionX</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">x</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionY</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">y</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionZ</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">z</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #993333;">float</span> $pointPos<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">position</span>`<span style="color: #339933;">;</span>
<span style="color: #993333;">float</span> $n<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">normal</span>`<span style="color: #339933;">;</span>
vector $difference <span style="color: #339933;">=</span> myParticleSystem.<span style="color: #202020;">position</span> <span style="color: #339933;">-</span> <span style="color: #339933;"><<</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span>
vector $normal <span style="color: #339933;">=</span> <span style="color: #339933;"><<</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span>
<span style="color: #993333;">float</span> $test <span style="color: #339933;">=</span> rad_to_deg<span style="color: #009900;">(</span>angle<span style="color: #009900;">(</span>$normal<span style="color: #339933;">,</span>unit<span style="color: #009900;">(</span>$difference<span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span>$test <span style="color: #339933;">></span> <span style="color: #0000dd;">90</span><span style="color: #009900;">)</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span></pre>
<p>(Ouïe que je suis méchant! :gne2: )</p>
<p>Voici les explications:</p>
<pre class="mel mel">vector $particlePos <span style="color: #339933;">=</span> myParticleSystem.<span style="color: #202020;">position</span><span style="color: #339933;">;</span></pre>
<p>Ici, on récupère la position de la particule courante, celle qu'on va créer.</p>
<pre class="mel mel">setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionX</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">x</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionY</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">y</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionZ</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">z</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>On entre les valeurs de position de la particule courante via "setAttr" (afin de s'assurer que le node est évalué).</p>
<pre class="mel mel"><span style="color: #993333;">float</span> $pointPos<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">position</span>`<span style="color: #339933;">;</span></pre>
<p>Dans le même esprit que précédemment, ici on récupère la position du point le plus proche de notre particule.</p>
<pre class="mel mel"><span style="color: #993333;">float</span> $n<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">normal</span>`<span style="color: #339933;">;</span></pre>
<p>On récupère, dans un array de float, les valeurs XYZ de la normal du point (sur le mesh) le plus proche de notre particule.</p>
<pre class="mel mel">vector $difference <span style="color: #339933;">=</span> myParticleSystem.<span style="color: #202020;">position</span> <span style="color: #339933;">-</span> <span style="color: #339933;"><<</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span></pre>
<p>On récupère le vecteur du "point sur la surface" vers la position de la particule (rappelez vous! Le coups de la soustraction des vecteurs. C'est ici! :hehe: ).</p>
<pre class="mel mel">vector $normal <span style="color: #339933;">=</span> <span style="color: #339933;"><<</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span></pre>
<p>On "convertie" nos valeurs de normal (qui étaient dans un array), en vecteur.</p>
<pre class="mel mel"><span style="color: #993333;">float</span> $test <span style="color: #339933;">=</span> rad_to_deg<span style="color: #009900;">(</span>angle<span style="color: #009900;">(</span>$normal<span style="color: #339933;">,</span> unit<span style="color: #009900;">(</span>$difference<span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>On récupère l'angle (en radian) entre les deux vecteurs ($normal et $difference) que l'on convertie en dégrée. (unit() sert à normaliser un vecteur, angle() sert a récupérer l'angle en radian entre deux vecteur et rad_to_deg() convertie un angle radian en dégrée).</p>
<pre class="mel mel"><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span>$test <span style="color: #339933;">></span> <span style="color: #0000dd;">90</span><span style="color: #009900;">)</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span></pre>
<p>Et pour finir, on test la valeur de l'angle. Si il est supérieur à 90°, on considère que la particule à une durée de vie infini (enfin très grande... :pasClasse: ).</p>
<p>Sinon, on la fait directement "mourrir" :gniarkgniark: .</p>
<center>:longBar:</center>
<h5>Le script MEL</h5>
<p>Ouf, bon, maintenant que vous avez tout bien compris (n'est ce pas? :seSentCon: ), je vous donne un script qui vous créé ce petit système tout seul!</p>
<p>La seul chose que vous ayez à faire, c'est sélectionner un mesh, appliquer le script et bien placer le cube emitter pour qu'il englobe intelligemment la géométrie. Lancer la dynamique (play) et c'est bon!</p>
<pre class="mel mel"><span style="color: #009900;">{</span>
string $mySelectedMeshArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `ls <span style="color: #339933;">-</span>sl`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on récupère la sélection</span>
string $mySelectedMesh <span style="color: #339933;">=</span> $mySelectedMeshArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on ne prend que le premier élément de la selection</span>
string $mySelectedMeshShapeArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `listRelatives <span style="color: #339933;">-</span>shapes $mySelectedMesh`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on récupère le node de mesh depuis le node de transforme</span>
string $mySelectedMeshShape <span style="color: #339933;">=</span> $mySelectedMeshShapeArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on ne prend que le premier élément de la liste renvoyé</span>
string $myClosestPointOnMeshNode <span style="color: #339933;">=</span> `createNode closestPointOnMesh`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on cree le node de closestPointOnMesh</span>
connectAttr <span style="color: #339933;">-</span>f <span style="color: #009900;">(</span>$mySelectedMeshShape<span style="color: #339933;">+</span><span style="color: #ff0000;">".worldMesh[0]"</span><span style="color: #009900;">)</span> <span style="color: #009900;">(</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inMesh"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on lui connecte le mesh</span>
connectAttr <span style="color: #339933;">-</span>f <span style="color: #009900;">(</span>$mySelectedMeshShape<span style="color: #339933;">+</span><span style="color: #ff0000;">".worldMatrix[0]"</span><span style="color: #009900;">)</span> <span style="color: #009900;">(</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inputMatrix"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// et la matrice de transformation</span>
<span style="color: #666666; font-style: italic;">//create Emitter Volume</span>
string $myEmitterArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `emitter <span style="color: #339933;">-</span>pos <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>type volume <span style="color: #339933;">-</span>r <span style="color: #0000dd;">100</span> <span style="color: #339933;">-</span>sro <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>nuv <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>cye none <span style="color: #339933;">-</span>cyi <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>spd <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>srn <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>nsp <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>tsp <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>mxd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>mnd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>dx <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>dy <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>dz <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>sp <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>vsh cube <span style="color: #339933;">-</span>vof <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>vsw <span style="color: #0000dd;">360</span> <span style="color: #339933;">-</span>tsr <span style="color:#800080;">0.5</span> <span style="color: #339933;">-</span>afc <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>afx <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>arx <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>alx <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>rnd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>drs <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>ssz <span style="color: #0000dd;">0</span>`<span style="color: #339933;">;</span>
string $myEmitter <span style="color: #339933;">=</span> $myEmitterArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
string $myParticleSystemArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `particle`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// créé un système de particule</span>
string $myParticleSystem <span style="color: #339933;">=</span> $myParticleSystemArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
connectDynamic <span style="color: #339933;">-</span>em $myEmitter $myParticleSystem<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// connecte l'emitter au système de particule</span>
setAttr <span style="color: #009900;">(</span>$myEmitter<span style="color: #339933;">+</span><span style="color: #ff0000;">".awayFromCenter"</span><span style="color: #009900;">)</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// désactive la vitesse des particules</span>
setAttr <span style="color: #009900;">(</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanMode"</span><span style="color: #009900;">)</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on va mettre le lifespan nous même</span>
<span style="color: #666666; font-style: italic;">// créé l'expression</span>
string $expression <span style="color: #339933;">=</span> <span style="color: #ff0000;">"vector $particlePos = "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".position;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionX ($particlePos.x);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionY ($particlePos.y);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionZ ($particlePos.z);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $n[] = `getAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".normal`;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $pointPos[] = `getAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".position`;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $difference = "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".position - <<$pointPos[0],$pointPos[1],$pointPos[2]>>;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $normal = <<$n[0],$n[1],$n[2]>>;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $test = rad_to_deg(angle($normal,unit($difference)));<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"if ($test > 90)<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"{<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanPP = 1000000;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"}<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"else<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"{<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanPP = 0;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"}<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
dynExpression <span style="color: #339933;">-</span>s $expression <span style="color: #339933;">-</span>c $myParticleSystem<span style="color: #339933;">;</span>
<span style="color: #009900;">}</span></pre>
<p>Et voila!</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule001.png" alt="remplir_mesh_particule001.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule001.png, sept. 2010" height="397" width="470" /></p>
<p>Et comme toujours: <a href="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule001.rar">->la scène Maya<</a> (bouton droit de souris, save as...).</p>
<center>:longBar:</center>
<h5>Conclusion</h5>
<p>Bien entendu, il reste un bon nombre de méthodes pour optimiser ce script (utiliser des produits scalaires plutôt que des angles, le lifespanPP = 1000000 est pas forcément des plus pratique, etc...).</p>
<p>Mais le principe est là! :)</p>
<p>N'hésitez pas à laisser un commentaire si vous voyez un moyen d'améliorer ce script. Je mettrai ce billet à jour.</p>
<center>:longBar:</center>
<h5>Le lien qui m'a beaucoup aidé</h5>
<p><a href="http://blog.maxtorag.sk/?p=39" hreflang="en">http://blog.maxtorag.sk/?p=39</a></p>
<p>Un grand merci à son auteur! :sourit:</p>
<p>A bientôt!</p>
<p>Dorian</p>
<center>:longBar:</center>
<h5>MAJ 8 Mars 2010 <a name="maj_8_mars_2010"></a></h5>
<p>On peut facilement faire évoluer cette expression. :reflechi:</p>
<p>L'exemple ci dessous vous permet de faire un dégradé du nombre de particules générées sur les bords du mesh.</p>
<pre class="mel mel"><span style="color: #993333;">float</span> $fallOffDist <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// la distance le long de laquelle la génération des particules est diminué.</span>
vector $particlePos <span style="color: #339933;">=</span> myParticleSystem.<span style="color: #202020;">position</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionX</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">x</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionY</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">y</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
setAttr myClosestPointOnMeshNode.<span style="color: #202020;">inPositionZ</span> <span style="color: #009900;">(</span>$particlePos.<span style="color: #202020;">z</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #993333;">float</span> $n<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">normal</span>`<span style="color: #339933;">;</span>
<span style="color: #993333;">float</span> $pointPos<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `getAttr myClosestPointOnMeshNode.<span style="color: #202020;">position</span>`<span style="color: #339933;">;</span>
vector $pointPosVec <span style="color: #339933;">=</span> <span style="color: #339933;"><<</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$pointPos<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span>
vector $difference <span style="color: #339933;">=</span> particleShape1.<span style="color: #202020;">position</span> <span style="color: #339933;">-</span> $pointPosVec<span style="color: #339933;">;</span>
vector $normal <span style="color: #339933;">=</span> <span style="color: #339933;"><<</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">1</span><span style="color: #009900;">]</span><span style="color: #339933;">,</span>$n<span style="color: #009900;">[</span><span style="color: #0000dd;">2</span><span style="color: #009900;">]</span><span style="color: #339933;">>>;</span>
<span style="color: #993333;">float</span> $test <span style="color: #339933;">=</span> rad_to_deg<span style="color: #009900;">(</span>angle<span style="color: #009900;">(</span>$normal<span style="color: #339933;">,</span>unit<span style="color: #009900;">(</span>$difference<span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span>$test <span style="color: #339933;">></span> <span style="color: #0000dd;">90</span><span style="color: #009900;">)</span>
<span style="color: #009900;">{</span>
<span style="color: #993333;">float</span> $dist <span style="color: #339933;">=</span> mag<span style="color: #009900;">(</span>$particlePos <span style="color: #339933;">-</span> $pointPosVec<span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on calcule la distance entre la particule et le point sur le mesh</span>
<span style="color: #993333;">float</span> $luck <span style="color: #339933;">=</span> $dist<span style="color: #339933;">/</span>$fallOffDist<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on fait un ratio.</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">(</span>$luck <span style="color: #339933;">></span> rand<span style="color: #009900;">(</span><span style="color: #0000dd;">1</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #666666; font-style: italic;">// si le ratio est plus grand qu'une valeur alléatoire entre 0 et 1, on genere la particule.</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">{</span>
myParticleSystem.<span style="color: #202020;">lifespanPP</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span></pre>
<p>Il suffit de faire varier la variable $fallOffDist pour agrandir ou diminuer la taille du dégradé.</p>
<p>Bien entendu, cette méthode est beaucoup plus longue que la précédente (qui n'était déjà pas un exemple en terme de rapidité. :seSentCon: ).</p>
<p>Exemple:</p>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule012.png" alt="remplir_mesh_particule012.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule012.png, mar. 2011" height="360" width="500" /></p>
<center><i>Avant. Les bords de la géométrie sont très facilement discernables.</i></center>
<p><img src="https://www.fevrierdorian.com/blog/public/billets/2010_09_22_remplir_mesh_particule/remplir_mesh_particule013.png" alt="remplir_mesh_particule013.png" style="display:block; margin:0 auto;" title="remplir_mesh_particule013.png, mar. 2011" height="360" width="500" /></p>
<center><i>Après. On voit bien que les bords ont moins de particules que l'intérieur.</i></center>
<p>Ducoup, le script MEL de génération de l'expression sur le mesh selectionné est le suivant:</p>
<pre class="mel mel"><span style="color: #009900;">{</span>
string $mySelectedMeshArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `ls <span style="color: #339933;">-</span>sl`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on récupère la sélection</span>
string $mySelectedMesh <span style="color: #339933;">=</span> $mySelectedMeshArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on ne prend que le premier élément de la selection</span>
string $mySelectedMeshShapeArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `listRelatives <span style="color: #339933;">-</span>shapes $mySelectedMesh`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on récupère le node de mesh depuis le node de transforme</span>
string $mySelectedMeshShape <span style="color: #339933;">=</span> $mySelectedMeshShapeArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on ne prend que le premier élément de la liste renvoyé</span>
string $myClosestPointOnMeshNode <span style="color: #339933;">=</span> `createNode closestPointOnMesh`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on cree le node de closestPointOnMesh</span>
connectAttr <span style="color: #339933;">-</span>f <span style="color: #009900;">(</span>$mySelectedMeshShape<span style="color: #339933;">+</span><span style="color: #ff0000;">".worldMesh[0]"</span><span style="color: #009900;">)</span> <span style="color: #009900;">(</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inMesh"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on lui connecte le mesh</span>
connectAttr <span style="color: #339933;">-</span>f <span style="color: #009900;">(</span>$mySelectedMeshShape<span style="color: #339933;">+</span><span style="color: #ff0000;">".worldMatrix[0]"</span><span style="color: #009900;">)</span> <span style="color: #009900;">(</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inputMatrix"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// et la matrice de transformation</span>
<span style="color: #666666; font-style: italic;">//create Emitter Volume</span>
string $myEmitterArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `emitter <span style="color: #339933;">-</span>pos <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>type volume <span style="color: #339933;">-</span>r <span style="color: #0000dd;">100</span> <span style="color: #339933;">-</span>sro <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>nuv <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>cye none <span style="color: #339933;">-</span>cyi <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>spd <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>srn <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>nsp <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>tsp <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>mxd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>mnd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>dx <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>dy <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>dz <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>sp <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>vsh cube <span style="color: #339933;">-</span>vof <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>vsw <span style="color: #0000dd;">360</span> <span style="color: #339933;">-</span>tsr <span style="color:#800080;">0.5</span> <span style="color: #339933;">-</span>afc <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>afx <span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span>arx <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>alx <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>rnd <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>drs <span style="color: #0000dd;">0</span> <span style="color: #339933;">-</span>ssz <span style="color: #0000dd;">0</span>`<span style="color: #339933;">;</span>
string $myEmitter <span style="color: #339933;">=</span> $myEmitterArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
string $myParticleSystemArray<span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #339933;">=</span> `particle`<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// créé un système de particule</span>
string $myParticleSystem <span style="color: #339933;">=</span> $myParticleSystemArray<span style="color: #009900;">[</span><span style="color: #0000dd;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">;</span>
connectDynamic <span style="color: #339933;">-</span>em $myEmitter $myParticleSystem<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// connecte l'emitter au système de particule</span>
setAttr <span style="color: #009900;">(</span>$myEmitter<span style="color: #339933;">+</span><span style="color: #ff0000;">".awayFromCenter"</span><span style="color: #009900;">)</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// désactive la vitesse des particules</span>
setAttr <span style="color: #009900;">(</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanMode"</span><span style="color: #009900;">)</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on va mettre le lifespan nous même</span>
<span style="color: #666666; font-style: italic;">// créé l'expression</span>
string $expression <span style="color: #339933;">=</span> <span style="color: #ff0000;">"float $fallOffDist = 2;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $particlePos = "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".position;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionX ($particlePos.x);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionY ($particlePos.y);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"setAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".inPositionZ ($particlePos.z);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $n[] = `getAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".normal`;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $pointPos[] = `getAttr "</span><span style="color: #339933;">+</span>$myClosestPointOnMeshNode<span style="color: #339933;">+</span><span style="color: #ff0000;">".position`;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $pointPosVec = <<$pointPos[0],$pointPos[1],$pointPos[2]>>;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $difference = "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".position - $pointPosVec;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"vector $normal = <<$n[0],$n[1],$n[2]>>;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"float $test = rad_to_deg(angle($normal,unit($difference)));<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"if ($test > 90)<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"{<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" float $dist = mag($particlePos - $pointPosVec);<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" float $luck = $dist/$fallOffDist;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" if($luck > rand(1))<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" {<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanPP = 1000000;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" }<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" else<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" {<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanPP = 0;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" }<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"}<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"else<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"{<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">" "</span><span style="color: #339933;">+</span>$myParticleSystem<span style="color: #339933;">+</span><span style="color: #ff0000;">".lifespanPP = 0;<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
$expression <span style="color: #339933;">+=</span> <span style="color: #ff0000;">"}<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: #339933;">;</span>
dynExpression <span style="color: #339933;">-</span>s $expression <span style="color: #339933;">-</span>c $myParticleSystem<span style="color: #339933;">;</span>
<span style="color: #009900;">}</span></pre>
<p>En espérant que ça vous aide! :sourit:</p>