-
Notifications
You must be signed in to change notification settings - Fork 14
/
V2Renderer.cpp
275 lines (237 loc) · 8.08 KB
/
V2Renderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Sony Pictures Imageworks
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution. Neither the name of Sony Pictures Imageworks nor the
// names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
//
// V2Renderer.cpp
// spReticle.1.7
//
// Created by Henry Vera on 4/23/13.
//
//
#include <maya/MTypes.h>
#if (MAYA_API_VERSION >= 201400)
#include <stdio.h>
#include <maya/MGlobal.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MUintArray.h>
#include "V2Renderer.h"
V2Renderer::V2Renderer()
{
}
V2Renderer::~V2Renderer()
{
}
void V2Renderer::setDrawManager(MHWRender::MUIDrawManager* drawManager)
{
this->drawManager = drawManager;
}
void V2Renderer::prepareForDraw(float portWidth, float portHeight)
{
drawManager->beginDrawable();
}
void V2Renderer::postDraw()
{
drawManager->endDrawable();
}
// Given two Geom instances, this calculates the mask area between them.
//
void V2Renderer::drawMask( Geom g1, Geom g2, MColor color, bool sides, bool top=true )
{
//drawManager->beginDrawable();
drawManager->setColor(MColor(color.r, color.g, color.b, 1 - color.a));
MUintArray index;
index.append(0);
index.append(1);
index.append(3);
index.append(2);
if (top)
{
if ( (g2.y1 - g1.y1) > EPSILON )
{
// Bottom Mask
MPointArray bottomMask;
bottomMask.append(MPoint( g1.x1, g1.y1, 0.0));
bottomMask.append(MPoint( g1.x2, g1.y1, 0.0));
bottomMask.append(MPoint( g2.x2, g2.y1, 0.0));
bottomMask.append(MPoint( g2.x1, g2.y1, 0.0));
drawManager->mesh2d(MHWRender::MUIDrawManager::kTriStrip,bottomMask,NULL,&index);
}
if ( (g1.y2 - g2.y2) > EPSILON )
{
// Top Mask
MPointArray topMask;
topMask.append(MPoint( g2.x1, g2.y2, 0.0));
topMask.append(MPoint( g2.x2, g2.y2, 0.0));
topMask.append(MPoint( g1.x2, g1.y2, 0.0));
topMask.append(MPoint( g1.x1, g1.y2, 0.0));
drawManager->mesh2d(MHWRender::MUIDrawManager::kTriStrip,topMask,NULL,&index);
}
}
else
{
g1.y1 = g2.y1;
g1.y2 = g2.y2;
}
if (sides)
{
// Left side mask
if ((g2.x1 - g1.x1) > EPSILON)
{
MPointArray leftMask;
leftMask.append(MPoint( g1.x1, g1.y1, 0.0));
leftMask.append(MPoint( g2.x1, g2.y1, 0.0));
leftMask.append(MPoint( g2.x1, g2.y2, 0.0));
leftMask.append(MPoint( g1.x1, g1.y2, 0.0));
drawManager->mesh2d(MHWRender::MUIDrawManager::kTriStrip,leftMask,NULL,&index);
}
// right side mask
if ((g1.x2 - g2.x2) > EPSILON)
{
MPointArray rightMask;
rightMask.append(MPoint( g1.x2, g1.y1, 0.0));
rightMask.append(MPoint( g2.x2, g2.y1, 0.0));
rightMask.append(MPoint( g2.x2, g2.y2, 0.0));
rightMask.append(MPoint( g1.x2, g1.y2, 0.0));
drawManager->mesh2d(MHWRender::MUIDrawManager::kTriStrip,rightMask,NULL,&index);
}
}
//drawManager->endDrawable();
}
// This draws a single line between the specified points.
//
void V2Renderer::drawLine(double x1, double x2, double y1, double y2,
MColor color, bool stipple)
{
//drawManager->beginDrawable();
drawManager->setColor(color);
if(stipple)
{
drawManager->setLineStyle(2,0x0F0F);
//drawManager->setLineStyle(MHWRender::MUIDrawManager::LineStyle::kDashed);
}
else
{
drawManager->setLineStyle(MHWRender::MUIDrawManager::LineStyle::kSolid);
}
drawManager->line2d(MPoint(x1,y1),MPoint(x2,y2));
//drawManager->endDrawable();
}
// Given a Geom instance, this will draw a line connecting the points.
// The argument side determines whether the sides will be drawn (the top
// will always be drawn). The stipple argument specifies whether the line
// should be solid or dashed/stippled.
//
void V2Renderer::drawLines( Geom g, MColor color, bool sides, bool stipple)
{
//drawManager->beginDrawable();
drawManager->setColor(MColor(color.r,color.g,color.b,1-color.a));
if(stipple)
{
drawManager->setLineStyle(2,0x0F0F);
//drawManager->setLineStyle(MHWRender::MUIDrawManager::LineStyle::kDashed);
}
else
{
drawManager->setLineStyle(MHWRender::MUIDrawManager::LineStyle::kSolid);
}
if(sides)
{
drawManager->rect2d(MPoint ((g.x1 + g.x2)/2, (g.y1 + g.y2)/2),
MVector(0.0,1.0),
fabs(g.x1-g.x2)/2,fabs(g.y1-g.y2)/2);
}
else
{
drawManager->line2d(MPoint(g.x1,g.y1),MPoint(g.x2,g.y1));
drawManager->line2d(MPoint(g.x2,g.y2),MPoint(g.x1,g.y2));
}
//drawManager->endDrawable();
}
// This function uses MUIDrawManager to draw text.
//
void V2Renderer::drawText(TextData *td, double tx, double ty)
{
//drawManager->beginDrawable();
double screenScaleFactor = (td->textScale) ? filmback->filmbackGeom.x/1280.0f : 1.0f;
#if (MAYA_API_VERSION > 201500)
int fontSize = td->textSize * screenScaleFactor * 1.5;
drawManager->setFontSize(fontSize);
drawManager->setFontName("helvetica");
if (td->textBold)
{
drawManager->setFontWeight(MHWRender::MUIDrawManager::TextWeight::kWeightBold);
}
else
{
drawManager->setFontWeight(MHWRender::MUIDrawManager::TextWeight::kWeightLight);
}
#elif (MAYA_API_VERSION == 201500)
int fontSize = td->textSize * screenScaleFactor * 1.5;
drawManager->setFontSize(fontSize);
if (td->textBold)
{
drawManager->setFontName("Bitstream Vera Sans");
}
else
{
drawManager->setFontName("PT Sans");
}
#else
int fontSize = 14;
#endif
// Adjust ty for text alignment
switch (td->textVAlign) {
case 0:
ty -= (fontSize * 0.35f);
break;
case 1:
ty -= fontSize / 1.5f;
break;
case 2:
ty -= fontSize;
break;
}
// Adjust text position to account for screen scaling
tx += td->textPosX*screenScaleFactor;
ty += td->textPosY*screenScaleFactor;
// Note: the tz is slightly negative to make it draw above possible solid masks.
// If set to 0, text might disappear!!!
//
double tz = -0.0001;
drawManager->setColor(td->textColor);
drawManager->setColor(MColor(td->textColor.r,td->textColor.g,td->textColor.b,1-td->textColor.a));
drawManager->text2d(MPoint(tx,ty,tz),td->textStr,(MHWRender::MUIDrawManager::TextAlignment)td->textAlign);
//drawManager->endDrawable();
}
#endif