Announcement

Collapse
No announcement yet.

Phoenix - script a cube kill in py

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Phoenix - script a cube kill in py

    I'm running this little script

    Code:
    import maya.cmds as cmds
    from phxfd import *
    
    def OnSimulationEnd(node, t, dt):
    	setsystem('core')
    
    	sx = cmds.getAttr(node + '.xSize')
    	sy = cmds.getAttr(node + '.ySize')
    	sz = cmds.getAttr(node + '.zSize')
    	cellSize = float(cmds.getAttr(node+'.cellSize'))
    	
    	nodeT = cmds.listRelatives(node, p=True)
    	nodeTranslate = cmds.xform(nodeT[0], query=True, ws=True, t= True)
    	#print nodeTranslate #Debug Purpose
    	
    	tx = nodeTranslate[0]
    	ty = nodeTranslate[1]
    	tz = nodeTranslate[2]
    	
    	cubeKill = cmds.xform("PhoenixCubeKill", query=True, ws=True, bb= True) ## xmin ymin zmin xmax ymax zmax.
    	print "PhoenixCubeKill in Action" # visual print check
    	for x in range(sx):
    		if ((x+tx)*cellSize)>=cubeKill[0] and ((x+tx)*cellSize)<=cubeKill[3]:
    			#print "found x"
    			#print str(x)+" - "+str((x+tx)*cellSize) + " major of " + str(cubeKill[0]) + " minor of " + str(cubeKill[3])
    			for y in range(sy):
    				if (((y+ty)*cellSize)+cellSize)>=cubeKill[1] and (((y+ty)*cellSize)+cellSize)<=cubeKill[4]:
    					#print "found y"
    					#print str(y)+" - "+str(((y+ty)*cellSize)+cellSize) + " major of " + str(cubeKill[1]) + " minor of " + str(cubeKill[4])
    					for z in range(sz):
    						if ((z+tz)*cellSize)>=cubeKill[3] and ((z+tz)*cellSize)<=cubeKill[5]:
    							#print "found z"
    							#print str(z)+" - "+str((z+tz)*cellSize) + " major of " + str(cubeKill[3]) + " minor of " + str(cubeKill[5])
    							setSm((x, y, z), 0)
    							setT((x, y, z), 0)
    							setFl((x, y, z), 0)
    							setV((x, y, z),[0,0,0])
    Now if you make a cube and called it "PhoenixCubeKill" and try to go and kill some data, that dosen't happen
    for sure I've to work more on it ad investigate better for what's going on, in the meantime, some one have an idea?
    From the documentation I don't get really weel how "set" call the value so that why I used all the set separately.

    thanks for your patience
    Simone.

  • #2
    Found the problem
    the way to get the matrix of position in the world is definitely wrong
    I will improve and fix in the spare time
    thanks

    Comment


    • #3
      close,
      sometimes work another is weired
      still i think some problem about the cube position

      Code:
      '''
      Simone Ciliani for Baseblack 2014
      PhoenixCubeKill v02 
      major fix done
      this is part of baseblackpieline plugin since v0.0.8
      to use it separate from BB pipeline plugin, just create cube called PhoenixKillValue
      '''
      import maya.cmds as cmds
      from phxfd import *
      
      ## This definition is only for debug purpose
      def OnSimulationBegin(node, t, dt):
      	cubeKill = cmds.xform("PhoenixCubeKill", query=True, ws=True, bb= True)
      	print "--------------------------------------------------\nCube Kill Tool in Action on this Simulation"
      	print "PhoenixCubeKill Trasformation matrix: "
      	print "xmin ymin zmin xmax ymax zmax " 
      	print ', '.join(map(str, cubeKill))  
      	
      	setsystem('core')
      	sx = cmds.getAttr(node + '.xSize')
      	sy = cmds.getAttr(node + '.ySize')
      	sz = cmds.getAttr(node + '.zSize')
      	cellSize = float(cmds.getAttr(node+'.cellSize'))
      	
      	## temp transformation
      	nodeT = cmds.listRelatives(node, p=True)
      	nodeTranslate = cmds.xform(nodeT[0], query=True, ws=True, t= True)
      	#print nodeTranslate #Debug Purpose
      	
      	tx = nodeTranslate[0]
      	ty = nodeTranslate[1]
      	tz = nodeTranslate[2]
      	print "phoenix transform node X: "+str(tx)+"  Y:  "+str(ty)+"  Z: "+str(tz)
      	
      	## Phoenix container in space calculation after transformation
      	pxmin = (((sx/2)-sx)*cellSize)+tx
      	pymin = ty
      	pzmin = (((sz/2)-sz)*cellSize)+tz
      	pxmax = ((sx/2)*cellSize)+tx
      	pymax = (sy*cellSize)+ty
      	pzmax = ((sz/2)*cellSize)+tz
      	
      	ptList = [pxmin,pymin,pzmin,pxmax,pymax,pzmax]
      	
      	print "PhoenixSim container in space matrix: "
      	print "xmin ymin zmin xmax ymax zmax " 
      	print ', '.join(map(str, ptList)) 
      	print"--------------------------------------------------\n"
      	
      	
      	
      def OnSimulationStep(node, t, dt):
      	setsystem('core')
      	sx = cmds.getAttr(node + '.xSize')
      	sy = cmds.getAttr(node + '.ySize')
      	sz = cmds.getAttr(node + '.zSize')
      	cellSize = float(cmds.getAttr(node+'.cellSize'))
      	
      	## temp transformation
      	nodeT = cmds.listRelatives(node, p=True)
      	nodeTranslate = cmds.xform(nodeT[0], query=True, ws=True, t= True)
      	#print nodeTranslate #Debug Purpose
      	
      	tx = nodeTranslate[0]
      	ty = nodeTranslate[1]
      	tz = nodeTranslate[2]
      	
      	#Phoenix world position in matrix world space
      	pxmin = (((sx/2)-sx)*cellSize)+tx
      	pymin = ty
      	pzmin = (((sz/2)-sz)*cellSize)+tz
      	pxmax = ((sx/2)*cellSize)+tx
      	pymax = (sy*cellSize)+ty
      	pzmax = ((sz/2)*cellSize)+tz
      	
      	ptList = [pxmin,pymin,pzmin,pxmax,pymax,pzmax]
      	
      	#cellSetTo = 0
      	cubeKill = cmds.xform("PhoenixCubeKill", query=True, ws=True, bb= True) ## xmin ymin zmin xmax ymax zmax.
      	print "PhoenixCubeKill in Action" # visual print check
      	
      	### Starting the performance
      	### check for x cells line
      	for x in range(sx):
      		#print "cell x:"+ str(x)+" - "+ str(cubeKill[0]) + " <= " + str(ptList[0]+((x-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[3]) #debug
      		if (ptList[0]+((x-1)*cellSize)) >= cubeKill[0] and (ptList[0]+(x*cellSize)) < cubeKill[3]:
      			#print "found intersection in x\n"
      			
      			### check for y cells line
      			for y in range(sy):
      				#print "cell y:"+ str(y)+" - "+ str(cubeKill[1]) + " <= " + str(ptList[1]+((y-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[4]) #debug
      				if (ptList[1]+((y-1)*cellSize)) >= cubeKill[1] and (ptList[1]+(y*cellSize)) < cubeKill[4]:
      					#print "found intersection in y\n"
      					
      					### check for Z cells line
      					for z in range(sz):
      						#print "cell z:"+ str(z)+" - "+ str(cubeKill[2]) + " <= " + str(ptList[2]+((z-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[5]) #debug
      						if (ptList[2]+((z-1)*cellSize)) >= cubeKill[2] and (ptList[2]+(z*cellSize)) < cubeKill[5]:
      							#print "found intersection in z\n"
      							
      							## Action to take
      							setSm((x, y, z), 1)
      							setT((x, y, z), 1000)
      							setFl((x, y, z), 0)
      							setV((x, y, z),[0,0,0])
      							#print " --- ALLELUJA --- " + str(x) +", "+ str(y) +", "+ str(z) # DEBUG
      							## cellSetTo # to find a way for purpose to print
      							## right now dosen't work the return becouse the loop is evaluating
      							#cellSetTo =+1
      						#return cellSetTo
      	#print "num of cell setted to 0 = " + str(cellSetTo)
      	
      	print "----------------------------- next step ------------------------\n" #debug
      ## ------------------------------------------------------------------------------ ##

      Anyone figure out better then me? thanks
      Simone

      Comment


      • #4
        OK I still developing that making a magic cube wich allow you to modified averything in and out in... I will post it soon
        But I've to say one thing ( i waste one hour to understand way)

        the documentation here is wrong:
        http://docs.chaosgroup.com/display/PFD2M/Scripting
        phoenix coordinate for Set is X, Z, Y instead what is wrote in the Documentation X Y Z

        Comment


        • #5
          what system are you using? if it is set to "core", really z and y are swapped, because the core was developed under 3dmax
          ______________________________________________
          VRScans developer

          Comment


          • #6
            Yes is with the core one!
            I realize infact was for that reason
            and if I not wrong you can't change that, set it will be always in core (correctly if I'm wrong)
            but there are no problem
            thanks again

            Comment


            • #7
              Hi Ivaylo
              So I Made it in the end,
              the code is still cheap and will slow down the performance but at list it works.
              So this one will be generate a cube which where inside you can modify all the value of the simulation (also you can animate the value).
              It could be in my opinion useful to cheat in some situation.
              As my wishlist it would be great have it "integrate" in proper solver instead to use as a callback.
              so if you want implement phoenix with something like that you can see/have an idea looking at this poor code here
              thanks for your interest and all the comment are welcome
              Simone

              Code:
              '''
              Simone Ciliani 2014
              Please contact me before use
              
              How to use:
              This is part of a major pipeline, to run it out that you have
              1) run the following commented line
              2) save this file in one of your location
              3) load that file under you PhoenixSimulator -> simulation -> scripting, and hit use script
              Run those commented follow line 
              ##START OUT
              to use it separate from BB pipeline plugin, just create cube called PhoenixKillValue (run the following comment to be faster)
              
              
              ## Read selection simulator node
              sel = cmds.ls( sl=True )
              
              ## Exit with a no sel#
              if len(sel)!=1:
              	cmds.warning("ERROR: you have must to select 1 at time PhoenixFDSimulator node")
              	sys.exit() 
              	
              ## Exit with a non appropriate phfd node selected##
              if cmds.objectType( cmds.listRelatives(sel[0]), isType='PhoenixFDSimulator' ) == False:
              	cmds.warning( "ERROR: you have must to select a proper PhoenixFDSimulator node") 
              	sys.exit()
              
              simNode = sel[0]
              
              ## the magic is here
              print "============================================================\nWe are now feeding your simulation node "+simNode+" with the tool plugin: Phoenix Cube Kill\n"
              print "HOW TO USE IT: It will be create a cube called \"PhoenixCubeKill\", use it to move and applicate the value where you want, \r in addition you can use some extra attribute parameter in the cube to make extension effects "
              cmds.setAttr (simNode+".useScript", 1)
              #cmds.setAttr (simNode+".scriptFile", "WRITE YOUR PATH/bbPhoenixCubeKill_v02.py", type="string") ## IF YOU WANT LOOK SMART USE THIS AFTER SEAVED THIS FILE
              ## Create the cube to use
              cmds.polyCube (name="PhoenixCubeKill", ch=False)
              
              cmds.addAttr( longName='PhoenixCubeKill_Parameter', numberOfChildren=10, attributeType='compound', k=True )
              cmds.addAttr ( ln="setSmA", nn="___Activate set Smoke___", dv=1, at="bool", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setSm", nn="Set Smoke Value",       at="double", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setTA", nn="___Activate set Temperature___", dv=0, at="bool", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setT",  nn="Set Temperature Value", at="double", dv=273, k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setFlA", nn="___Activate set Fuel___", dv=0, at="bool", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setFl", nn="Set Fuel Value",        at="double", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setVx", nn="Multiply Velocity X", dv=1, at="double", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setVy", nn="Multiply Velocity Y", dv=1, at="double", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="setVz", nn="Multiply Velocity Z", dv=1, at="double", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.addAttr ( ln="InverseSpace", nn="Inverse (_not_yet_implemented_)", dv=0, at="bool", k=True, parent="PhoenixCubeKill_Parameter")
              cmds.annotate( 'PhoenixCubeKill', tx='See the Extra attribute of the PhoenixCubeKill to access at more options', p=(0,0,0) )
              
              
              '''
              import maya.cmds as cmds
              import time
              import sys
              from phxfd import *
              
              ## This definition is only for debug purpose
              def OnSimulationBegin(node, t, dt):
              	cubeKill = cmds.xform("PhoenixCubeKill", query=True, ws=True, bb= True)
              	print "===================================================\nCube Kill Tool in Action on this Simulation"
              	print "PhoenixCubeKill Trasformation matrix: "
              	print "xmin ymin zmin xmax ymax zmax " 
              	print ', '.join(map(str, cubeKill))  
              	
              	## Query attribute of cube
              	cubeSetSm = cmds.getAttr('PhoenixCubeKill.setSm')
              	cubesetT  = cmds.getAttr('PhoenixCubeKill.setT')
              	cubeSetFl = cmds.getAttr('PhoenixCubeKill.setFl')
              	cubeSetVx = cmds.getAttr('PhoenixCubeKill.setVx')
              	cubeSetVy = cmds.getAttr('PhoenixCubeKill.setVy')
              	cubeSetVz = cmds.getAttr('PhoenixCubeKill.setVz')
              	## print the value to set
              	print "Smoke = "+str(cubeSetSm)+", Temperature = "+str(cubesetT)+", Fuel = "+str(cubeSetFl)+", Velocity multiply by = "+str(cubeSetVx)+", "+str(cubeSetVy)+", "+str(cubeSetVz)
              	
              	setsystem('core')
              	sx = cmds.getAttr(node + '.xSize')
              	sy = cmds.getAttr(node + '.ySize')
              	sz = cmds.getAttr(node + '.zSize')
              	cellSize = float(cmds.getAttr(node+'.cellSize'))
              	
              	## temp transformation
              	nodeT = cmds.listRelatives(node, p=True)
              	nodeTranslate = cmds.xform(nodeT[0], query=True, ws=True, t= True)
              	#print nodeTranslate #Debug Purpose
              	
              	tx = nodeTranslate[0]
              	ty = nodeTranslate[1]
              	tz = nodeTranslate[2]
              	print "phoenix transform node X: "+str(tx)+"  Y:  "+str(ty)+"  Z: "+str(tz)
              	
              	## Phoenix container in space calculation after transformation
              	pxmin = (((sx/2)-sx)*cellSize)+tx
              	pymin = ty
              	pzmin = (((sz/2)-sz)*cellSize)+tz
              	pxmax = ((sx/2)*cellSize)+tx
              	pymax = (sy*cellSize)+ty
              	pzmax = ((sz/2)*cellSize)+tz
              	
              	ptList = [pxmin,pymin,pzmin,pxmax,pymax,pzmax]
              	
              	print "PhoenixSim container in space matrix: "
              	print "xmin ymin zmin xmax ymax zmax " 
              	print ', '.join(map(str, ptList)) 
              	print"===================================================\n"
              	
              def OnSimulationStep(node, t, dt):
              	
              	start_time = time.time()
              	
              	setsystem('core')
              	sx = cmds.getAttr(node + '.xSize')
              	sy = cmds.getAttr(node + '.ySize')
              	sz = cmds.getAttr(node + '.zSize')
              	cellSize = float(cmds.getAttr(node+'.cellSize'))
              	
              	## temp transformation
              	nodeT = cmds.listRelatives(node, p=True)
              	nodeTranslate = cmds.xform(nodeT[0], query=True, ws=True, t= True)
              	#print nodeTranslate #Debug Purpose
              	tx = nodeTranslate[0]
              	ty = nodeTranslate[1]
              	tz = nodeTranslate[2]
              	#Phoenix world position in matrix world space
              	pxmin = (((sx/2)-sx)*cellSize)+tx
              	pymin = ty
              	pzmin = (((sz/2)-sz)*cellSize)+tz
              	pxmax = ((sx/2)*cellSize)+tx
              	pymax = (sy*cellSize)+ty
              	pzmax = ((sz/2)*cellSize)+tz
              	ptList = [pxmin,pymin,pzmin,pxmax,pymax,pzmax]
              	
              	
              	## Query attribute
              	cubeSetSm = cmds.getAttr('PhoenixCubeKill.setSm')
              	cubesetT  = cmds.getAttr('PhoenixCubeKill.setT')
              	cubeSetFl = cmds.getAttr('PhoenixCubeKill.setFl')
              	cubeSetVx = cmds.getAttr('PhoenixCubeKill.setVx')
              	cubeSetVy = cmds.getAttr('PhoenixCubeKill.setVy')
              	cubeSetVz = cmds.getAttr('PhoenixCubeKill.setVz')
              	cubeSetSmA = cmds.getAttr('PhoenixCubeKill.setSmA')
              	cubeSetTA = cmds.getAttr('PhoenixCubeKill.setTA')
              	cubeSetFlA = cmds.getAttr('PhoenixCubeKill.setFlA')
              
              		
              	#cellSetTo = 0
              	cubeKill = cmds.xform("PhoenixCubeKill", query=True, ws=True, bb= True) ## xmin ymin zmin xmax ymax zmax.
              	print "PhoenixCubeKill in Action" # visual print check
              	
              	### Starting the performance
              	### check for x cells line
              	for x in range(sx):
              		#print "cell x:"+ str(x)+" - "+ str(cubeKill[0]) + " <= " + str(ptList[0]+((x-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[3]) #debug
              		if (ptList[0]+((x-1)*cellSize)) >= cubeKill[0] and (ptList[0]+(x*cellSize)) <= cubeKill[3]:
              			#print "found intersection in x\n"
              			
              			### check for y cells line
              			for y in range(sy):
              				#print "cell y:"+ str(y)+" - "+ str(cubeKill[1]) + " <= " + str(ptList[1]+((y-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[4]) #debug
              				if (ptList[1]+((y-1)*cellSize)) >= cubeKill[1] and (ptList[1]+(y*cellSize)) <= cubeKill[4]:
              					#print "found intersection in y\n"
              					
              					### check for Z cells line
              					for z in range(sz):
              						#print "cell z:"+ str(z)+" - "+ str(cubeKill[2]) + " <= " + str(ptList[2]+((z-1)*cellSize))+" + "+ str(cellSize) + " < " + str(cubeKill[5]) #debug
              						if (ptList[2]+((z-1)*cellSize)) >= cubeKill[2] and (ptList[2]+(z*cellSize)) <= cubeKill[5]:
              							#print "found intersection in z\n"
              							
              							#Setting the magic
              							if (cubeSetSmA==1):
              								setSm((x, z, y), cubeSetSm)
              							if (cubeSetTA==1):
              								setT((x, z, y), cubesetT)
              							if (cubeSetFlA==1):
              								setFl((x, z, y), cubeSetFl)
              							setV((x, z, y),[cubeSetVx,cubeSetVz,cubeSetVy])
              							
              							#print " --- ALLELUJA --- " + str(x) +", "+ str(y) +", "+ str(z) # DEBUG
              							## cellSetTo # to find a way for purpose to print
              							## right now dosen't work the return becouse the loop is evaluating
              							#cellSetTo =+1
              						#return cellSetTo
              	#print "num of cell setted to 0 = " + str(cellSetTo)
              	end_time = time.time()
              	print("Elapsed time was %g seconds" % (end_time - start_time))
              	
              	print "=================================================== next step \n" #debug
              ## ------------------------------------------------------------------------------ ##

              Comment


              • #8
                Fast question about

                I'm trying this
                Code:
                ttt = (getSm(x, z, y))
                print ttt
                I tried in vary way but I receive this error here
                TypeError: function takes at most 2 arguments (3 given)

                Should the callback come with the Self?
                thanks
                S.

                Comment


                • #9
                  You must put x, y, z in a tuple, i.e. - getSm((x, z, y)). The second argument is the name of the simulator if you are not accessing it during the simulation (you ca use these function whenevery you want). You can check the syntax with help(phxfd)
                  Last edited by ivaylo.ivanov; 20-11-2014, 06:18 AM.
                  V-Ray/PhoenixFD for Maya developer

                  Comment


                  • #10
                    cool thanks
                    shame of me, I didn't check the help() but only the documentation
                    Thanks
                    S.

                    Comment


                    • #11
                      Querying the temperature inside the simulation I found value really low.. under the zero.
                      multiplying this value for 300 I finding the correct value that I suppose to find, is it correct? what is going on inside?
                      sorry for all the time I'm stealing from you, I just trying to take this like an excuse to skill up my python )))))))))))))))))))

                      thanks again
                      S.

                      Comment


                      • #12
                        Hm, it's possible, we must fix that. You are right about the internal multiplier - it's 300.
                        V-Ray/PhoenixFD for Maya developer

                        Comment

                        Working...
                        X