1 """Functions used by the ModelBuilder node"""
2
3 import nuke
4 import nukescripts
5
6
7
8
9
10
12 """Populate the bake menu on a ModelBuilder node."""
13 entries = [
14
15 ( 'Selected geometry', 'nukescripts.modelbuilder.bakeSceneSelection(nuke.thisNode())' ),
16 ( 'Projection', 'nukescripts.modelbuilder.bakeProjection(nuke.thisNode())' ),
17 ( 'Apply texture', 'nukescripts.modelbuilder.bakeApplyTexture(nuke.thisNode())' )
18
19 ]
20 k = mb['bakeMenu']
21 k.setValues([ "%s\t%s" % (script, label) for label, script in entries ])
22
23
24
25
26
27
51
52
54 """Create a projection setup for the current frame."""
55 if mb.Class() != "ModelBuilder":
56 return
57
58 clearNodeSelection()
59 srcCam = mb.input(1)
60 if not srcCam:
61 return
62 w = mb.screenWidth()
63 h = mb.screenHeight()
64 src = mb.input(0)
65 frame = nuke.frame()
66 if (mb['textureType'].getValue() > 0):
67 frame = mb['textureFrame'].getValue()
68 label = '(frame ' + str(frame) + ')'
69
70 srcdot = nuke.createNode('Dot','',False)
71 srcdot.setInput(0, src)
72 srchold = nuke.createNode('FrameHold','',False)
73 stamp = nuke.createNode('PostageStamp','',False)
74 project = nuke.createNode('Project3D','',False)
75 apply = nuke.createNode('ApplyMaterial','',False)
76
77 cam = copyCamera(srcCam)
78
79 camhold = nuke.clone(srchold,'',False)
80 camdot = nuke.createNode('Dot','',False)
81 project.setInput(1, camdot)
82
83 srcdot.setXYpos( int(mb.xpos() + w * 3.5), int(mb.ypos()) )
84 srchold.setXYpos( int(srchold.xpos()), int(srcdot.ypos() + w) )
85 stamp.setXYpos( int(stamp.xpos()), int(stamp.ypos() + srchold.screenHeight() + h * 2) )
86 cam.setXYpos( int(srchold.xpos() - w * 1.5), int(srchold.ypos() + srchold.screenHeight() / 2 - cam.screenHeight() / 2) )
87 camhold.setXYpos( int(cam.xpos() + cam.screenWidth() / 2 - srchold.screenWidth() / 2), int(stamp.ypos() + h) )
88 project.setXYpos( int(stamp.xpos()), int(stamp.ypos() + stamp.screenHeight() + h * 2) )
89 camdot.setXYpos( int(camdot.xpos()), int(project.ypos() + project.screenHeight() / 2 - camdot.screenHeight() / 2) )
90 apply.setXYpos( int(stamp.xpos()), int(apply.ypos() + w) )
91
92 srchold.knob('first_frame').setValue( frame )
93 srcdot.setSelected( True )
94 srchold.setSelected( True )
95 stamp.setSelected( True )
96 project.setSelected( True )
97 apply.setSelected( True )
98 cam.setSelected( True )
99 camhold.setSelected( True )
100 camdot.setSelected( True )
101 bd = nukescripts.autoBackdrop()
102 bd['label'].setValue('Frame %d' % frame)
103
104
106 if mb.Class() != "ModelBuilder":
107 return
108
109 texture = mb.input(3)
110 if not texture:
111 return
112
113 clearNodeSelection()
114 mb.setSelected(True)
115
116 amat = nuke.createNode('ApplyMaterial')
117 amat.setInput(1, texture)
118 amat['filter_type'].setValue('name')
119 amat['filter_name_match'].setValue('equals')
120 amat['filter_refresh'].execute()
121
122
123
124
125
126
130
131
143
144
145
146
147
148
151
152
153 assist = nuke.env['assist']
154 if not assist:
155 nuke.addOnCreate(modelbuilderCreateCallback, nodeClass='ModelBuilder')
156