ruchit
Hi, this is first time i m going to try Maya Python API for creating custom 2D Swirl Texture like in 3ds max. Help me to define compute function in class of plugin.
 
GUID-F352BC73-8843-4FCE-9F2F-923D09D65826-low.png 

Math Link:
Shader Library Swirl Post Processing Filter In GLSL
Twist Effect In Webgl


Here is skeleton for texture plugin
Code:

#__________About________________
#maya software texture node
#Usage: createNode swirlTexture
#simple swirl generator
#_________Attributes________________
#Color1:-
#Color2:-
#centerX:-  The x coordinate of the center of the circular region.
#centerY:-  The y coordinate of the center of the circular region.
#radius:-  The radius of the circular region.
#angle:-  The angle in radians that the pixels in the center of the circular region will be rotated by.
# Import Module
import maya.OpenMaya as om
import maya.OpenMayaMPx as omMPx
kPluginNodeName = 'swirl'
kPluginNodeClassify = "texture/2d"
kPluginNodeId = OpenMaya.MTypeId(0x521E9)
class swirlTexture(omMPx.MPxNode):
  def __init__()
    omMPx.MPxNode.__init__(self)
    
  def compute()
def nodeInitializer():
  nAttr = OpenMaya.MFnNumericAttribute()
  
  #________________________________________
  #Input Attributes
  #________________________________________
  #Color1
  swirlTexture.acolor1 = nAttr.createColor('color1', 'c1')
  swirlTexture.addAttribute(swirlTexture.acolor1)
  #Color2
  swirlTexture.acolor2 = nAttr.createColor('color2', 'c2')
  swirlTexture.addAttribute(swirlTexture.acolor2)
  #CenterX
  swirlTexture.acenterX = nAttr.createColor('centerX', 'cenX', OpenMaya.MFnNumericData.kFloat, 0.5)
  swirlTexture.addAttribute(swirlTexture.acenterX)
  #CenterY
  swirlTexture.acenterY = nAttr.createColor('centerY', 'cenY', OpenMaya.MFnNumericData.kFloat, 0.5)
  swirlTexture.addAttribute(swirlTexture.acenterY)
  #Radius
  swirlTexture.aradius = nAttr.createColor('radius', 'r', OpenMaya.MFnNumericData.kFloat, 10)
  swirlTexture.addAttribute(swirlTexture.acolor2)
  #Angle
  swirlTexture.aangle = nAttr.createColor('angle', 'a', OpenMaya.MFnNumericData.kFloat, 10)
  swirlTexture.addAttribute(swirlTexture.angle)
  #________________________________________
  #OutPut Attributes
  #________________________________________
  
  #OutColor
  swirlTexture.aoutColor = nAttr.createColor("outColor", "oc")
  swirlTexture.addAttribute(swirlTexture.aOutColor)
  #swirlTex.attributeAffects(swirlTex.acolor1, swirlTex.aoutColor)

def nodeCreator():
  return omMPx.asMPxPtr( swirlTex() )
  
# initialize The Plug-in
def initializePlugin(mobject):
  mplugin = omMPx.MFnPlugin(mobject, 'Ruchit Bhatt', '1.0', 'Any')
  try:
    mplugin.registerNode( kPluginNodeName, kPluginNodeId, nodeCreator, nodeInitializer, omMPx.MPxNode.kDependNode, kPluginNodeClassify )
  except:
    sys.stderr.write( "Failed to register node: %s" % kPluginNodeName )
    raise
    
# Uninitialize The Plug-in
def uninitializePlugin(mobject):
  mplugin = omMPx.MFnPlugin(mobject)
  try:
    mplugin.deregisterNode( kPluginNodeId )
  except:
    sys.stderr.write( "Failed to deregister node: %s" % kPluginNodeName )
    raise

Quote 0 0
ruchit
Found circular swirl code on google & i modify it to make work in python.
Code:

import maya.cmds as mc
import maya.mel as mm
import math
pitch = 2.0
turns = 3.0
limit = pitch*turns
numturn = 100
step = 360/numturn

def linstep(val, origMin, origMax):
    return float(val - origMin) / float(origMax - origMin)
#variable2 = map(variable1, min1, max1, min2, max2);
def map(value, istart, istop, ostart, ostop):
    return (ostart + (ostop - ostart) * ((value - istart) / (istop - istart)))
  
deg = 0.0
while(deg<360*turns):
    r = pitch * linstep(deg,0,360)
    x = r * math.cos(math.radians(deg))
    y = r * math.sin(math.radians(deg))
  
    x_s = map(x,-limit,limit, 10, 190)
    y_s = map(y,-limit,limit, 10, 190)
    mc.polySphere(r=0.5, sx=8, sy=8, ax=(0,1,0), cuv=2,ch=1)
    mc.move(x_s,0,y_s)
    deg+=step

Quote 0 0
pshipkov
I will take a look at some point soon, but just wanted to clarify - you realize this will render only in Maya software.
Quote 0 0
ruchit
Quote:
but just wanted to clarify - you realize this will render only in Maya software.


Oh i see, but still want to complete this task to get learning experience.
Quote 0 0