| Trees | Indices | Help |
|---|
|
|
1 #
2 # nodeFactory - a class used to register new maya nodes based on slum templates.
3 #
4 # Copyright (C) 2008 - Roberto Hradec
5 #
6 # ---------------------------------------------------------------------------
7 # This file is part of SLUM.
8 #
9 # SLUM is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # SLUM is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with SLUM. If not, see <http://www.gnu.org/licenses/>.
21 # ---------------------------------------------------------------------------
22
23 import copy
24 import maya.OpenMaya as OpenMaya
25 import maya.OpenMayaMPx as OpenMayaMPx
26 import maya.OpenMayaUI as OpenMayaUI
27 import maya.OpenMayaRender as OpenMayaRender
28 from shaderBase import *
29 from shaderSurface import *
30 from shaderLight import *
31 from glob import glob
32 import os,sys
33 import slum
34
35 userClassify = {
36 'surface' : 'shader/surface',
37 'displacement' : 'shader/displacement',
38 'float' : 'utility/general',
39 'color' : 'utility/color',
40 'light' : 'light',
41 }
42
45 OpenMayaRender.MSwatchRenderBase(self, mobj, mobjRender, res)
46 print mobj, mobjRender, res
47 pass
64
65
67 - def __init__(self, mplugin, pluginName, PluginNodeId, searchPath = ['SLUM_SEARCH_PATH', 'MAYA_SCRIPT_PATH', 'PYTHONPATH'] ):
68 # call generic slum code to find installed classes
69 self.classes = slum.collectSlumClasses( searchPath = searchPath ).allClasses
70 self.mplugin = mplugin
71 self.pluginName = pluginName
72 self.PluginNodeId = PluginNodeId
73 self.searchPath = searchPath
74 self.callbackIDs = []
75
77 '''
78 loop trough all gathered slum classes and register a new node type for each one
79 '''
80 xxx = OpenMayaUI.MHWShaderSwatchGenerator.initialize()
81 for classe in self.classes.keys():
82
83 nodeTypeName = 'slum_%s' % classe
84 #try:
85 # nodeType = OpenMayaMPx.MPxNode.kHardwareShader
86 #except:
87 # nodeType = OpenMayaMPx.MPxNode.kHwShaderNode
88 nodeType = OpenMayaMPx.MPxNode.kHwShaderNode
89
90 #nodeType = OpenMayaMPx.MPxNode.kHardwareShader
91 nodeCreator = shaderSurface.nodeCreator
92 nodeInitializer = shaderSurface.nodeInitializer
93 nodeInitializeCallback = shaderSurface.slumInitializer
94
95
96 # Don't initialize swatches in batch mode
97 if OpenMaya.MGlobal.mayaState() != OpenMaya.MGlobal.kBatch:
98 swatchName = "%sRenderSwatchGen" % nodeTypeName
99 #x = copy.deepcopy(OpenMayaUI.MHWShaderSwatchGenerator.createObj)
100 #OpenMayaRender.MSwatchRenderRegister.registerSwatchRender(swatchName, swatchRender.createObj )
101 swatchName = "/:swatch/%s" % swatchName
102 #print swatchName
103
104
105 #_0849aa18_p_MString ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__hex__', '__init__', '__int__', '__long__', '__new__', '__oct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'acquire', 'append', 'disown', 'next', 'own']
106 #<Swig Object of type 'MString *' at 0x18aa4908>
107
108 #swatchName = ''
109 #swatchName = "/:swatch/%s" % OpenMayaUI.MHWShaderSwatchGenerator.initialize()
110 #xxx = OpenMayaUI.MHWShaderSwatchGenerator.initialize()
111 #print xxx, dir(xxx)
112 #print xxx.__repr__()
113 #print xxx.__class__
114 #print xxx.next()
115 #swatchName = ":swatch/slumSwatch%s" % classe
116 #OpenMayaRender.MSwatchRenderRegister.registerSwatchRender(swatchName,
117 # OpenMayaUI.MHWShaderSwatchGenerator.createObj );
118
119 slumShader = slum.evalSlumClass(self.classes[classe]['code'], classe)
120
121 if slumShader.type() == 'light':
122 nodeTypeName = 'slumLight_%s' % classe
123 nodeType = OpenMayaMPx.MPxNode.kLocatorNode
124 nodeCreator = shaderLight.nodeCreator
125 nodeInitializer = shaderLight.nodeInitializer
126 nodeInitializeCallback = shaderLight.slumInitializer
127 swatchName = ''
128
129 #register a node for the current slum class
130
131 self.mplugin.registerNode(
132 nodeTypeName,
133 OpenMaya.MTypeId( self.PluginNodeId + slumShader.ID() ),
134 nodeCreator,
135 nodeInitializer,
136 nodeType,
137 '%s%s' % (userClassify[ slumShader.type() ], swatchName)
138 )
139 self.callbackIDs.append(
140 OpenMaya.MDGMessage.addNodeAddedCallback ( nodeInitializeCallback, nodeTypeName)
141 )
142 del slumShader
143
145 for classe in self.classes.keys():
146 slumShader = slum.evalSlumClass(self.classes[classe]['code'], classe)
147 self.mplugin.deregisterNode( OpenMaya.MTypeId( self.PluginNodeId + slumShader.ID() ) )
148
149 for each in self.callbackIDs:
150 removeCallback( each )
151
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Oct 28 16:21:55 2010 | http://epydoc.sourceforge.net |