Python API 2.0 Reference
python/api1/py1SolidMaterialInfo.py
1 #-
2 # ==========================================================================
3 # Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All
4 # rights reserved.
5 #
6 # The coded instructions, statements, computer programs, and/or related
7 # material (collectively the "Data") in these files contain unpublished
8 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
9 # licensors, which is protected by U.S. and Canadian federal copyright
10 # law and by international treaties.
11 #
12 # The Data is provided for use exclusively by You. You have the right
13 # to use, modify, and incorporate this Data into other products for
14 # purposes authorized by the Autodesk software license agreement,
15 # without fee.
16 #
17 # The copyright notices in the Software and this entire statement,
18 # including the above license grant, this restriction and the
19 # following disclaimer, must be included in all copies of the
20 # Software, in whole or in part, and all derivative works of
21 # the Software, unless such copies or derivative works are solely
22 # in the form of machine-executable object code generated by a
23 # source language processor.
24 #
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
26 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
27 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
28 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
29 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
30 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
31 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
32 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
33 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
34 # OR PROBABILITY OF SUCH DAMAGES.
35 #
36 # ==========================================================================
37 #+
38 
39 #
40 # Creation Date: 4 October 2006
41 #
42 # Example Plugin: materialInfoCmd.py
43 #
44 # Demonstrates use of the MPxMaterialInformation class
45 # assignViewportFactories -mf "solidMaterialInfo" -tf "solidTextureInfo" -nt "dgs_material"
46 #
47 
48 import math, sys
49 
50 import maya.OpenMaya as OpenMaya
51 import maya.OpenMayaMPx as OpenMayaMPx
52 
53 kMaterialName = "solidMaterialInfo"
54 kTextureName = "solidTextureInfo"
55 
56 class SolidMaterialInfo(OpenMayaMPx.MPxMaterialInformation):
57  def __init__(self, node):
58  OpenMayaMPx.MPxMaterialInformation.__init__(self, node)
59 
60 
61  def materialInfoIsDirty(self, plug):
62  return True
63 
64 
65  def connectAsTexture(self, plug):
66  return False
67 
68 
69  def textureDisconnected(self, plug):
70  return False
71 
72 
73  def computeMaterial(self, data):
74  data.diffuse = OpenMaya.MColor(1.0, 0.0, 0.0)
75  return True
76 
77 
78 class SolidTextureInfo(OpenMayaMPx.MPxBakeEngine):
79  def __init__(self):
80  print("text __init__")
81  OpenMayaMPx.MPxBakeEngine.__init__(self)
82 
83 
84  def bake(self, objectPath, cameraPath, samplePlug, bakeResult):
85  print("bake()")
86  pass
87 
88 ################################################################
89 
90 
91 def matCreator(node):
92  print("matCreator()\n")
93  return OpenMayaMPx.asMPxPtr(SolidMaterialInfo(node))
94 
95 
96 def textCreator():
97  print("textCreator()\n")
98  return OpenMayaMPx.asMPxPtr(SolidTextureInfo())
99 
100 
101 def initializePlugin(mobject):
102  print("initializePlugin()\n")
103  mplugin = OpenMayaMPx.MFnPlugin(mobject, "Autodesk", "1.0", "Any")
104  try:
105  mplugin.registerMaterialInfo(kMaterialName, matCreator)
106  except:
107  sys.stderr.write( "Failed to register material info: %s\n" % kMaterialName)
108  raise
109 
110  try:
111  mplugin.registerBakeEngine(kTextureName, textCreator)
112  except:
113  sys.stderr.write( "Failed to register material info: %s\n" % kTextureName)
114  raise
115 
116 
117 def uninitializePlugin(mobject):
118  print("uninitializePlugin()\n")
119  mplugin = OpenMayaMPx.MFnPlugin(mobject)
120  try:
121  mplugin.unregisterMaterialInfo(kMaterialName)
122  except:
123  sys.stderr.write("Failed to unregister material info: %s\n" % kMaterialName)
124  raise
125 
126  try:
127  mplugin.unregisterBakeEngine(kTextureName)
128  except:
129  sys.stderr.write("Failed to unregister material info: %s\n" % kTextureName)
130  raise