-
Notifications
You must be signed in to change notification settings - Fork 4
/
wsFunctions.cpp
145 lines (112 loc) · 4.26 KB
/
wsFunctions.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
#include "wsFunctions.h"
void DrawArrow(BaseDraw *bd, const Vector &pos, Float length, Bool extra)
{
// Good practice: Always check if required pointers are set, or if we need to draw anything at all
if (!bd || length == 0.0)
return;
// Precalculate some values we'll need a lot
const Float length025 = length * 0.25;
const Float length125 = length * 0.125;
const Vector tip = pos + Vector(0.0, 0.0, length);
bd->DrawLine(pos, tip, 0); // Main line
bd->DrawLine(tip, tip + Vector(length125, 0.0, -length025), 0); // Pointy line
bd->DrawLine(tip, tip + Vector(-length125, 0.0, -length025), 0); // Pointy line
// Draw even more pointy lines
if (extra)
{
bd->DrawLine(tip, tip + Vector(0.0, length125, -length025), 0);
bd->DrawLine(tip, tip + Vector(0.0, -length125, -length025), 0);
}
}
void DrawStar(BaseDraw *bd, const Vector &pos, Float size)
{
// Good practice: Always check if required pointers are set, or if we need to draw anything at all
if (!bd || size <= 0.0)
return;
// Precalculate this value, we'll need it a lot
const Float size2 = size * 0.7;
// Straight lines
bd->DrawLine(Vector(0.0, -size, 0.0), Vector(0.0, size, 0.0), 0);
bd->DrawLine(Vector(-size, 0.0, 0.0), Vector(size, 0.0, 0.0), 0);
bd->DrawLine(Vector(0.0, 0.0, -size), Vector(0.0, 0.0, size), 0);
// Diagonals
bd->DrawLine(Vector(-size2, -size2, -size2), Vector(size2, size2, size2), 0);
bd->DrawLine(Vector(-size2, size2, -size2), Vector(size2, -size2, size2), 0);
bd->DrawLine(Vector(-size2, -size2, size2), Vector(size2, size2, -size2), 0);
bd->DrawLine(Vector(size2, -size2, -size2), Vector(-size2, size2, size2), 0);
}
PolygonObject* GetRealGeometry(BaseObject* op)
{
// Create AliasTranslate
AutoAlloc<AliasTrans> aliasTrans;
if (!aliasTrans || !aliasTrans->Init(op->GetDocument()))
return nullptr;
// Create clone of op. We only need this for the modeling command.
BaseObject *tmpOp = static_cast<BaseObject*>(op->GetClone(COPYFLAGS::NONE, aliasTrans));
if (!tmpOp)
return nullptr;
// Translate BaseLinks, maybe the cloned object needs that
aliasTrans->Translate(true);
// Create temporary document
AutoAlloc<BaseDocument> tmpDoc;
if (!tmpDoc)
{
// Free tmpOp and return
BaseObject::Free(tmpOp);
return nullptr;
}
// Insert tmpOp into tmpDoc. From now on, tmpDoc has the ownership over tmpOp,
// so we don't need to free tmpOp manually anymore (because tmpDoc will auto-free itself at the end of the scope, as we used AutoAlloc to create it).
tmpDoc->InsertObject(tmpOp, nullptr, nullptr);
// Build modeling command data
ModelingCommandData mcd;
mcd.doc = tmpDoc;
mcd.op = tmpOp;
// Perform modeling command
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd))
return nullptr;
// Get result
PolygonObject *res = static_cast<PolygonObject*>(mcd.result->GetIndex(0));
// Set original matrix
if (res)
res->SetMg(op->GetMg());
// Return result
return res;
}
Bool GeneratesPolygons(BaseObject* op)
{
// Check for nullptr, otherwise the -GetInfo() call will crash
if (!op)
return false;
// Get node info
Int32 opInfo = op->GetInfo();
// Get some properties
Bool isGenerator = (opInfo&OBJECT_GENERATOR) == OBJECT_GENERATOR; // Is dropOp a generator object?
Bool isSpline = (opInfo&OBJECT_ISSPLINE) == OBJECT_ISSPLINE; // Is it a spline?
Bool isDeformer = (opInfo&OBJECT_MODIFIER) == OBJECT_MODIFIER; // Is it a deformer?
Bool isParticleModifier = (opInfo&OBJECT_PARTICLEMODIFIER) == OBJECT_PARTICLEMODIFIER;
Bool isPolygon = (opInfo&OBJECT_POLYGONOBJECT) == OBJECT_POLYGONOBJECT;
Bool isPolyInstance = op->IsInstanceOf(Opolygon); // Is it a polygon object instance?
// We want objects that are polygon object instances or generators that are neither splines nor deformers nor anything else we know we don't want.
// This part seems a bit messy, but there are so many possibilities that we should try and cover as many as we can.
return isPolyInstance || isPolygon || (isGenerator && !isSpline && !isDeformer && !isParticleModifier);
}
UInt32 AddDirtySums(BaseObject *op, Bool goDown, DIRTYFLAGS flags)
{
// Check for nullptr, for speed reasons
if (!op)
return 0;
UInt32 dirtyness = 0;
if (goDown)
{
}
else
{
while (op)
{
dirtyness += op->GetDirty(flags);
op = op->GetUp();
}
}
return dirtyness;
}