# colorAtPoint for fluid emission rate

THREAD CLOSED
 Thread Tools Search this Thread Display Modes
 10 October 2013 #1 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 colorAtPoint for fluid emission rate Hello guys, i'm quite new to MEL, but i'm trying my best (not too much luck at the moment) to get the emission rate of my fluid be driven by an expression: I'm trying to emit a random value (fluidEmitter1.rate = rand(150,250) when the UV values on my surface are higher than 0, I can't really get how to calculate the UV values using the colorAtPoint, can someone help please? This is the idea i came up, obviously not working! if (float \$tempA[] = 'colorAtPoint -o RGB -u 0.0 -v 0.0 checker_1) fluidEmitter1.rate = rand(150,200); }else{ fluidEmitter1.rate = 0; { cheers! G share quote
 10 October 2013 #2 ogbonna Veteran portfolio Nathaniel Anozie Baltimore, USA   Join Date: Dec 2008 Posts: 70 You're on the right track! `colorAtPoint -o RGB -u 0.0 -v 0.0 checker_1` should give back 3 numbers the R, G, and B at U,V point (0,0). So maybe add some if's float \$R,\$G,\$B; \$R = \$tempA[0]; \$G = \$tempA[1]; \$B = \$tempA[2]; if (\$R > 0.0) && (\$G > 0.0) && (\$B > 0.0) { //do something } else{ //do something else } All this was for a single u,v point so maybe iterate over a whole bunch. Also it may be faster to use something like python with openMaya to speed some stuff up. Hope this is helpful. cheers, -Nate share quote
 10 October 2013 #3 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 Hello Nate, thanks for the tip! I kept on working and eventually came up with this in the last few days: int \$numUVs[] = `polyEvaluate -uv pSphere1`; float \$tempRGB[] = `colorAtPoint -o RGB -u 439 -v 439 noise2`; fluidEmitter2.fluidDensityEmission = \$tempRGB[1]*time; I now need to work more on the if statement (haven't applied it yet to my expression), also i need to calculate now the RGB for every point, would you have any idea how? and maybe carry on with my expression if (\$tempRGB > 0) && (\$tempRGB < 0.6) { //do something } else{ //do something else } would that work? I'll give it a go today anyways I'll keep on trying what you suggested as well as soon as i have time! Cheers! Gerry share quote
 10 October 2013 #4 ogbonna Veteran portfolio Nathaniel Anozie Baltimore, USA   Join Date: Dec 2008 Posts: 70 Hi, i think since this is an array \$tempRGB, would need to pick one of its 3 elements (the R,G,B) so maybe if wanted to check Red use \$tempRGB[0] to check blue \$tempRGB[1] ... for the "calculate now the RGB for every point" i think could loop over the vertices of the sphere and from that vertex get the uv from the texture using something like: polyListComponentConversion -fromVertex -tuv pShere1.vtx[1] which gives back something like pSphere1.map[2] which can be thrown into the colorAtPoint to get the RGB. (again using mel will probably be really slow doing this stuff, you may want to look into c++ and python using openmaya) here some mel stuff anyway: http://nathananozie.blogspot.com/20...polygon-uv.html (for the if statement check out the braces syntax i think would need a brace for the outside of them) cheers! -Nate share quote
 10 October 2013 #5 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 Thanks Nate! it is more or less working, your tip using polyListComponentConversion come very helpful! this is where I am at the moment, but what i dont get is why Maya comes back saying "// Error: line 4: Error while parsing arguments. // " this is the script: string \$vertex[] = `polyListComponentConversion -fv -tv pSphere1`; \$i = `polyListComponentConversion -fv -tuv \$vertex`; float \$coordUV[] = `polyEditUV -q -uValue -vValue \$i`; float \$tempRGB[] = `colorAtPoint -u("\$coordUV[0:878]") -v("\$coordUV[0:878]") noise2`; \$rgb = \$tempRGB[1]; Thanks Again Gerry share quote
 10 October 2013 #6 ogbonna Veteran portfolio Nathaniel Anozie Baltimore, USA   Join Date: Dec 2008 Posts: 70 Nice Work! I just made a couple of tweaks. I think the parse error had to do with Maya wanting a single item but getting multiple things ... Its helpful to write print lines to see whether have lots of things or one thing , or nothing ... Code: ``` select -r `polyListComponentConversion -tv pSphere1`; //new line string \$vertexAll[] = `filterExpand -ex true -sm 31`; //new line string \$vertex = \$vertexAll[0]; //new line … could use a variable for the 0 to loop over all verts .. for vertex in vertexAll string \$all_i[] = `polyListComponentConversion -fv -tuv \$vertex`; //Edited this line \$i = \$all_i[0]; //Edit line … because could get multiple uvs for a single vertex here its using just the first uv you may want to change this for i in all_i float \$coordUV[] = `polyEditUV -q -uValue -vValue \$i`; float \$tempRGB[] = `colorAtPoint -u \$coordUV[0] -v \$coordUV[1] -o "RGB" noise2`; //Edited this line \$r = \$tempRGB[0]; //Edited line \$g = \$tempRGB[1]; //Edited line \$b = \$tempRGB[2]; //Edited line \$rgb = {\$r,\$g,\$b}; //Edited this line ``` Hope this is helpful. Below is some rough python that might be helpful. There are probably much faster ways of doing this using python and open maya or using c++. Also i'm not sure how to efficiently loop over vertices with multiple .maps for the same vertex. Code: ``` #Python import maya.cmds as cmds cmds.select( cmds.polyListComponentConversion('pSphere1', tv = True) , replace = True) #new line vertexAll = cmds.filterExpand( ex = True, sm = 31) #new line vertex = vertexAll[0] #new line … could use a variable for the 0 to loop over all verts .. for vertex in vertexAll all_i = cmds.polyListComponentConversion( vertex, fv = True, tuv = True ) #Edited this line i = all_i[0] #new line … because could get multiple uvs for a single vertex here its using just the first uv you may want to change this for i in all_i coordUV = cmds.polyEditUV( i, q = True, uValue = True, vValue = True ) tempRGB = cmds.colorAtPoint( 'noise2', u = coordUV[0], v = coordUV[1], o = 'RGB' ) #Edited this line r = tempRGB[0] #Edited line g = tempRGB[1] #Edited line b = tempRGB[2] #Edited line rgb = [r,g,b] #Edited this line ``` Cheers! -Nate share quote
 10 October 2013 #7 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 Hey Nate! I gave a look at your script mixed with mine and works very well! but again it get stucked just on one vertex... I'll keep on trying and get back to you soon! Also when i declare a loop for the number of coords in the map it doesnt like it :( Cheers again for all the help! GerryG share quote
 10 October 2013 #8 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 The only way i could find was to insert the exact coords of a vertex for instance, like this one! string \$vertex[] = `polyListComponentConversion -fv -tv pSphere1`; string \$i[0] = `polyListComponentConversion -fv -tuv \$vertex`; float \$coordUV[] = `polyEditUV -q -uValue -vValue \$i`; float \$tempRGB[] = `colorAtPoint -o RGB -u 0 - v 0.666016 -u 1 -v 0.666016 noise1`; and yes it came back with the rub, now shall i just put in all the coords manually? is going to be long but i can do it :P also could you guess any way to link my rgbs with the right vertex? maybe i can use the polylistcomponentconversion you posted me in your blog (http://nathananozie.blogspot.co.uk/...polygon-uv.html)? Thanks! GerryG share quote
 10 October 2013 #9 ogbonna Veteran portfolio Nathaniel Anozie Baltimore, USA   Join Date: Dec 2008 Posts: 70 Hi, I don't think you want to enter the values in manually. Regarding how to associate rgb to vertex: I think the idea using the polyListComponentConversion is to change the vertex into uvs that vertex is linked to (it could be no uvs if vertex is not uv mapped, it could be more than one if the way the uv edges were sewn were not merged …). Then using polyEditUV and colorAtPoint the rgb's associated with one of the uvs linked to the vertex are figured out. I added a couple of comments to the code I posted earlier and at the bottom I put in some ideas for looping. Hope its helpful. Cheers, -Nate Code: ``` //This line is selecting all the vertices of a sphere select -r `polyListComponentConversion -tv pSphere1`; //new line //This line is making the list of vertices be in expanded form vertex1name, vertex2name … instead ofvertex1:vertexN … string \$vertexAll[] = `filterExpand -ex true -sm 31`; //new line ////////START //This line stores the first vertex as indicated by [0] to get second vertex use vertexAll[1] ... string \$vertex = \$vertexAll[0]; //This line is trying to get the uv map(s) linked to vertex, sometimes it could be 1 or 2 or 0 if no uv map or some other number. Depending on how uv edges were sewn… string \$all_i[] = `polyListComponentConversion -fv -tuv \$vertex`; //This line assumes we only care about the first uv(map)… it would bug out if there were no uv maps linked to the vertex so checking size(all_i) > 0 would be helpful \$i = \$all_i[0]; //Edit line … because could get multiple uvs for a single vertex here its using just the first uv you may want to change this for i in all_i //This line gets the U, V coordinates for a single UV(map) here were using the first uv linked to the first vertex of the sphere float \$coordUV[] = `polyEditUV -q -uValue -vValue \$i`; //This line gets the Red, Green and Blue channels for a single UV(map) associated with the texture noise2 float \$tempRGB[] = `colorAtPoint -u \$coordUV[0] -v \$coordUV[1] -o "RGB" noise2`; //These lines just store the R,G,B separately could use a vector to store it \$r = \$tempRGB[0]; //Edited line \$g = \$tempRGB[1]; //Edited line \$b = \$tempRGB[2]; //Edited line \$rgb = {\$r,\$g,\$b}; //Edited this line //////////END ``` Code: ``` ///////To loop over all vertices of sphere could do something like this with the code above select -r `polyListComponentConversion -tv pSphere1`; //new line string \$vertexAll[] = `filterExpand -ex true -sm 31`; //new line for(\$j = 0; \$j < size(\$vertexAll); \$j++ ){ //put in all the code between.. START .. and END changing the line string \$vertex = \$vertexAll[0]; into string \$vertex = \$vertexAll[\$j]; //also could save out all the r,g,b(s) for this single vertex so don't lose it. It might be a little tricky doing this in MEL because //each vertex may have different numbers of r,g,b(s) associated with it } ``` share quote
 10 October 2013 #10 GerryG New Member portfolio Gherardo Nitrici London,   Join Date: Jan 2013 Posts: 26 Hey Nate! Thanks as always! i'm quite happy! I got up to more or less where i wanted! i have an array that has inside all my RGBs (i'm using a greyscale so R=G=B)! I wanted to share it with you! string \$vtxs = `select -r pPlane1.vtx[0:224]` ; string \$allVerts[] = `ls -sl -fl`; string \$item; for (\$item in \$allVerts) { vector \$p = `pointPosition -w \$item`; float \$uv[2] = ` nearestPointOnMesh -ip (\$p.x) (\$p.y) (\$p.z) -q -u -v "pPlane1"`; float \$c[3] = `colorAtPoint -o RGB -u (\$uv[0]) -v (\$uv[1]) "checker1"`; setFluidAttr -at "density" (\$c[0]) fluidEmitter1; }; I now ned to fix the setFluidAttr as is not working.. i need to look a bit more inside you suggestions from last time! What do you think up to now? how does it look to you? Thanks again GerryG share quote
 10 October 2013 #11 ogbonna Veteran portfolio Nathaniel Anozie Baltimore, USA   Join Date: Dec 2008 Posts: 70 Looks Great, Nice Work! -Nate share quote
 10 October 2013 #12 CGTalk Moderation Expert   Join Date: Sep 2003 Posts: 1,066,478 Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. share quote
 Thread Closed share thread

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Gallery     Latest Entries     Featured Videos     Featured 3D     Featured 2D     CG Awards     Expose12 Call For Entries (closed) Main     News         Press Releases and Media     General Discussion         Legacy Threads     Off Topic     Recruitment     Education Software     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Autodesk Miscellaneous         Autodesk MotionBuilder         Autodesk Mudbox         Autodesk Softimage             XSI: Programming             ICE: Interactive Creative Environment     Autodesk 3ds max         3dsMax SDK and MaxScript         3dsMax Tutorials & Tips         3dsMax Resources         Plugins & Add-ons         Particle Flow     Maxon Cinema 4D         Cinema 4D Resources     The Foundry Modo         The Foundry Time Travel Challenge     Pixologic ZBrush     Photoshop / Painter     Side Effects Houdini     Blender     Lightwave 3D         LW Resources         LW Tutorials     Allegorithmic Substance         Substance Painter         Substance Designer     E-on Software Vue     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion Challenges     Modeling Challenge         Member Model Collection     Digital Matte Painting Challenge         DMP Mini Challenge Collection     Sketch Challenge         Member SKETCH Collection     FXWARS Challenge         Member FXGallery     Lighting Challenges WIP     Professional Feedback     WIP/Critique: 3D     WIP/Critique: 2D         Speedpaints & Sketchbooks     WIP/Critique: Animation     Collaborative Projects Techniques     Art Techniques and Theories     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Modeling     Texturing and Surfacing     Character Rigging     Animation     Lighting and Shaders     Compositing and Editing     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Technical     Virtual Reality     Game Engine     Graphics Programming     Technical and Hardware
Miscellaneous

All times are GMT. The time now is 03:12 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.