Mel & Python Scripting 2

 

BACK

This is the second portion of my wire tool. This time round I will be trying to clean up my tool and make it more professional looking and usable. Previous problems are the particle Ids not being able to query and the wire tubes are randomly overlying each other and eating through each other as well. In this 5 weeks I will be hoping to create a neat and understandable GUI and also having the wires to behave and look more like realistic wires. My aim is realism and that has always been my goal in all projects.

More Reference Images

 

 

Solving the Particle ID Issue.

The Problem - when particle count is being set to any number, the integer generated by the loop in my script somehow does'nt get itself into the Id flag. Maya will just give me a message saying no particle id found, check query Id.

So I went in to create another loop which just creates numbers from 1 to a maxium number in a loop doing a plus one every round. Then using that variable and assigned it to the particle query command.

click here to see the portion of the script.

However, it still doesn't want to co-operate. So I went and look about in Maya help and found out about nParticles and I switch all the particles into nParticles hoping that it will be more stable. To my frustration its still the same stupid error. Well I am stuck here.

Having a meeting with Prof Ken Huff regarding this matter was really helpful. He pointed out to me when working with particles we can check the Ids in the particle Render Attributes, in Particle Render Type dropdown menu bar we can swtich it to Numeric which displays each particle's IDs. This was definitely my way to solving the Id problem.

Using This Method:

particleIdArray = mc.getAttr (particleShape.particleId)

With the Id information I will be able to loop through each Id and get its position.Therefore now I can limit my particle count which gives me the specific number of wires I want to generate.

The above image you are seeing curves generated from a source that emits a limited number of Particles.

Switching from particles to nParticles

Switching from particles to nParticles was an easy process of replacing all the words particle to nParticle in python. The process of creating nParticles were the same as creating particles.

Moreover, nParticles gave me alot more control over the particles. Self collision was also build into it which reduced part of my work load.

However, for nParticles to collide with an object. We have to use nCloth rigid object tab for collision. Select the objects and click the tab an easy step.

The above ambient Occlusion render shows that the tool is working out fine so far. When particles are running side by side they do collide with each other but if a particle runs infront another we will see that the generated wires will eat into each other. The process of figuring how to avoid each particle path is still in development.
Cleaning up the Script
This was the toughest portion at this stage because I have to read the script line for line again to see what is could be removed or optimized. There were some one line coding issues which took up hours of my time to solved some had to be recoded. However this process, made me understand the structure of maya python scripting. Most of the time was about understanding the line of code.

One Example :

This tool does alot of information listing and calling of information from an array or dictionary. At one point of time I was appending duplicated information into an array but kept failing. Below is the cause and solution.

Whatshappening is that inorder for the array to capture the result of the duplicate command. The command have to be executed first. Once executed there is something for the array to capture. The wrong method was executing 2 processes at a time which is capturing and duplicating which caused the script to give back an error.

This was a simple problem which took me some time to understand. It was really a waste of 4 hrs but at least I wont have to face this same problem again.

After Solving this I went in and remove most of the hardcoded names within the script. Everything is being recorded into an array and only information within the array is being used for further processing. This would lead me to create a tool where users dont have to worry about having errors if names of objects clashes.

The Cleaning up is still in Progress. To record curves generated are a little more tricky than the others as it is being used in different definations of procedures. So I have to make the information Global, which I am still not very familiar in python.

click to see Script Before Cleaning

click to see Script After Cleaning

Adding More Functions to Tool
To further upgrade the tool. I am adding in a button that assigns Goals to Particles giving a 3rd party control over the particles. However only one Goal can be activated a time, if not the particles will average out between the goals. Moreover goal weights tends to overpower particle fields influences. If I were to use it, I will have to set key frames to turn on the goals where and when I want it to be.

Above image shows that the particles are averaging out between the 2 goals. Its attracted to the center instead of the goals.

 

The other function is adding object shapes to the ends of each curve. Wires usually have a head and a tail and both ends usually have some sort of connecting object. (Power Plug, jack, etc..) I would like this tool to be able to get those objects and snap them the ends of each wire.

In order to line the objects up perpendicularly, I am either using tangent constraint or using the pointInfoNote which will give me the tangent value for calculating the angle.

pointOnCurve:

infoNode1 = mc.pointOnCurve(eachCurve, constructionHistory=True, parameter = -0.1)

attaches a node that shows the tangent, normal, position info.

angleBetween:

rotA = mc.angleBetween(euler=True, v1=(x,y,z), v2=(x,y,z))

returns the rotation B required to be perpendicular to A. Calculation between Position B and Tangent A.

However this does not give me the correct position and rotation.

Futher Tests.

 

Trying TangentConstraint:

mc.tangentConstraint( curveshape1, object1)

This seems simple and straight forward, however it only work at one end of the Curve .

Seems Fine NOW but when I try again.The starting point is tilted for some curious reasons.

However Time Is REALLY running OUT!!!!! Time to Move On!!!!

I did some additional Attributes to my GUI to make it easier for Users to set those Attributes.

These additional Attributes are the main attributes to run the simulation. Other attributes can be tweak to get other variations and interesting results too.

At this stage I am coming to think that there may be a better way to generate this wires other than particles, but its a good learning process.

StudioProject WIP. (Josh,Dorien,CheeLoong)

Above are two test that I rush out for submission. Compared to my 1st try on this tool which is in Mel and Python scripting 1, these ones seem to look more controlled.

Conclusion:

What have I done:

1. Solved my ID problem and now the tool is able to set a limited number of particles.

2. Took away a huge portion of hardcoded names in my script.

3. Added a Goal function but not fully fuctional yet.

4. Added a object to wire ends but not fully fuctional yet.

5. Changed my particles to nParticles which solved self collision issues. However, still need to figure a way to totally prevent particles to cross paths.

6. Added more functionalities to my GUI.

I have learned to be logical and neat in my creation process of a script. Moreover, through this quarter, neat and understandable scripting is also important as it really help me in future debugging or upgrades.

Lastest Version of the Script