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
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
#include <iostream>
#include "shaveEngine.h"
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cerr << "Usage: " << argv[0] << " archiveFile [nodeName]" << endl;
return 1;
}
//
// Get the command line parameters.
//
char* archiveFile = argv[1];
char* nodeName = (argc > 2 ? argv[2] : NULL);
//
// Grab a Shave license.
//
if (!PRIMlogin())
{
cerr << "Could not get Shave license." << endl;
return 2;
}
//
// Load in the archive file.
//
int numVoxels = PRIMinit_hairstack(archiveFile);
cout << archiveFile << " contains " << numVoxels << " voxels." << endl;
//
// Display some information about the first 10 voxels (if there are
// that many).
//
int i;
int j;
int numVoxelsToShow = (numVoxels > 10 ? 10 : numVoxels);
for (i = 0; i < numVoxelsToShow; i++)
{
//
// Fetch the hairs in the voxel.
//
// If a node name was given on the command line, then only fetch
// hairs from that node.
//
HAIRTYPE hair;
UVSETS uvs;
if (nodeName)
{
PRIMfetch_voxel_by_name2(i, nodeName, &hair, &uvs, false);
cout << "Voxel " << i << " contains " << hair.totalfaces
<< " hairs with " << (int)uvs.totalUVSets
<< " uvs per hair, for node '" << nodeName << "'." << endl;
}
else
{
PRIMfetch_voxel(i, &hair, false);
cout << "Voxel " << i << " contains " << hair.totalfaces
<< " hairs." << endl;
}
//
// If there are some hairs in the voxel then dump out more
// information about the voxel.
//
if (hair.totalfaces > 0)
{
//
// Display the voxel's bounding box.
//
VERT minBound;
VERT maxBound;
PRIMfetch_bbox(i, &minBound, &maxBound);
cout << " bounding box is ("
<< minBound.x << ", " << minBound.y << ", " << minBound.z
<< ") to ( "
<< maxBound.x << ", " << maxBound.y << ", " << maxBound.z
<< ")" << endl;
//
// Display the vertices of the first hair in the voxel.
//
int startOfHairVertIndices = hair.face_start[0];
int endOfHairVertIndices = hair.face_end[0];
cout << " first hair has "
<< (endOfHairVertIndices - startOfHairVertIndices)
<< " vertices:" << endl;
for (j = startOfHairVertIndices; j < endOfHairVertIndices; j++)
{
int vertIndex = hair.facelist[j];
VERT& vert = hair.v[vertIndex];
cout << " (" << vert.x << ", " << vert.y << ", " << vert.z
<< ")" << endl;
}
//
// Display the uvs for the root of the first hair in the voxel.
//
if (nodeName && (uvs.totalUVSets > 0) && (uvs.totalRoots > 0))
{
cout << " first hair's uvs are:";
for (j = 0; j < (int)uvs.totalUVSets; j++)
{
cout << " (" << uvs.uvRoot[j].x << ", " << uvs.uvRoot[j].y
<< "," << uvs.uvRoot[j].z << ")" << endl;
}
}
else
cout << " (no UV info available)" << endl;
}
//
// We're done with 'hair' and 'uvs' so free up their memory.
//
PRIMfree_hairtype(&hair);
if (nodeName) PRIMfree_uvset(&uvs);
}
//
// Let Shave clean up its internals.
//
// We really don't need to do this in this case since we're about to
// exit, but it doesn't hurt.
//
PRIMclear_hairstack();
//
// Release the Shave license.
//
PRIMlogout();
return 0;
}
|