-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluxsi_hair.cpp
222 lines (206 loc) · 8.1 KB
/
luxsi_hair.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
/*
This file is part of LuXSI;
LuXSI is a LuxRender Exporter for Autodesk(C) Softimage(C) ( ex-XSI )
http://www.luxrender.net
Copyright(C) 2007 - 2012 of all Authors:
Michael Gangolf, 'miga', mailto:miga@migaweb.de
Pedro Alcaide, 'povmaniaco', mailto:p.alcaide@hotmail.com
LuXSI is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
LuXSI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LuXSI. If not, see <http://www.gnu.org/licenses/>.
*/
/**/
#include "include\luxsi_main.h"
using namespace std;
using namespace XSI;
using namespace MATH;
/**/
extern Application app;
/**/
extern double ftime;
/**/
extern bool luxdebug;
/**/
extern Model root;
/**/
extern bool overrGeometry;
/**/
extern CString writeModel(X3DObject in_object);
/**/
extern CString writeLuxsiObj(X3DObject in_object);
/**/
CString luxNativeHair(X3DObject o, CFloatArray posVals)
{
Material m = o.GetMaterial();
CString hairData;
//- write object 'base'
hairData = L"\nObjectBegin \""+ o.GetName() + L"\"\n";
//-
hairData += L"NamedMaterial \""+ m.GetName() + L"\"\n";
hairData += L"Shape \"sphere\"\n";
hairData += L" \"float radius\" [ 0.2 ]\n";
hairData += L"\nObjectEnd \n";
//- instantiate object to each 'hair segment'
for(int j = 0; j < posVals.GetCount(); j +=3)
{
hairData += L"\nAttributeBegin \n";
hairData += L"Translate "
+ CString(posVals[j]) + L" "
+ CString(-posVals[j+2])+ L" "
+ CString(posVals[j+1]) + L"\n";
hairData += L"ObjectInstance \""+ o.GetName() + L"\"\n";
hairData += L"AttributeEnd #"+ o.GetName() + L"\n";
}
return hairData;
}
//-
CString instantiateHair(CFloatArray posVals, CString objName, long jump)
{
CString hairData;
//-
for(int j = 0; j < posVals.GetCount(); j += jump)
{
/* Use 'jump' for moved each object instanced to 'root' hair position
*/
hairData += L"\nAttributeBegin # "+ objName;
hairData += L"\nTransformBegin\n";
hairData += L"Translate "
+ CString(posVals[j]) + L" "
+ CString(-posVals[j+2]) + L" "
+ CString(posVals[j+1]) + L"\n";
//-
hairData += L"ObjectInstance \""+ objName + L"\"\n";
hairData += L"TransformEnd\n";
hairData += L"AttributeEnd\n";
}
return hairData;
}
//--
CString writeLuxsiHair(X3DObject o)
{
//--
CString hairData;
Material m = o.GetMaterial();
//-
HairPrimitive myHairPrim( o.GetActivePrimitive());
//-- add transform
KinematicState global_state = o.GetKinematics().GetGlobal();
CTransformation global_trans = global_state.GetTransform(ftime);
/**
* Use 'RenderPercentage' value for 'requesthaircount' ( is float, change to integer ?)\n
* Use 'TotalHairs' for 'chunksize.
*/
int percentaje = o.GetParameterValue(L"RenderPercentage");
int totalHairs = o.GetParameterValue(L"TotalHairs");
LONG request = (totalHairs /100) * percentaje;
/**
* Notes: XSI generate... \n
* 1 vector xyz por each 'hair root'. \n
* 1 vector xyz for each 'hair section'. \n
* 1 float for each radius of 'hair section'.
*/
int segment = o.GetParameterValue(L"Segments");
if (luxdebug) app.LogMessage(L"Segments: "+ CString(segment));
//
long jump = (segment + 1)*3;
if (luxdebug) app.LogMessage(L"Jump: "+ CString(jump));
//-
bool is_instanced = o.GetParameterValue(L"InstanceEnabled");
//-
CRenderHairAccessor rha;
rha = myHairPrim.GetRenderHairAccessor(request);
LONG nReqChunkSize = rha.GetRequestedChunkSize();
if (luxdebug) app.LogMessage( L"nReqChunkSize: " + CValue(nReqChunkSize).GetAsText() );
LONG nReqHairCount = rha.GetRequestedHairCount();
if (luxdebug) app.LogMessage( L"nReqHairCount: " + CValue(nReqHairCount).GetAsText() );
// get the values
while( rha.Next() )
{
// get the render hair positions
CFloatArray posVals;
rha.GetVertexPositions(posVals);
//-
if ( !is_instanced )
{
//- write object 'base'
hairData = L"\nObjectBegin \""+ o.GetName() + L"\"\n";
hairData += L"Shape \"sphere\"\n";
hairData += L" \"float radius\" [ 0.02 ]\n";
hairData += L"\nObjectEnd \n";
//- instantiate object to each 'hair segment'
for(int j = 0; j < posVals.GetCount(); j +=3)
{
hairData += L"\nAttributeBegin \n";
hairData += L"Translate "
+ CString(posVals[j]) + L" "
+ CString(-posVals[j+2])+ L" "
+ CString(posVals[j+1]) + L"\n";
//-
hairData += L"NamedMaterial \""+ m.GetName() + L"\"\n";
hairData += L"ObjectInstance \""+ o.GetName() + L"\"\n";
hairData += L"AttributeEnd #"+ o.GetName() + L"\n";
}
}
else //-- use instanced object
{
X3DObject objInstance;
//--
CRefArray grps = root.GetGroups();
//-
for (int i=0; i < grps.GetCount(); i++)
{
if (luxdebug) app.LogMessage(L"Group name: "+ Group(grps[i]).GetName());
CString gName = Group(grps[i]).GetName();
//
string::size_type gpname = string(CString(gName).GetAsciiString()).find( "HAIR", 0 );
//--
if ( gpname != string::npos )
{
CRefArray groupMembers = Group(grps[i]).GetMembers();
//-
for (int j = 0; j < groupMembers.GetCount(); j++)
{
objInstance = groupMembers[j];
CString oName = objInstance.GetName();
//-
if ( objInstance.GetType() == L"polymsh" )
{
overrGeometry = true;
//-
hairData += L"\nObjectBegin \""+ oName + L"\"\n";
hairData += writeLuxsiObj(objInstance);
hairData += L"\nObjectEnd # "+ oName + L"\n";
//-
overrGeometry = false;
//-
hairData += instantiateHair(posVals, oName, jump);
}
else if ( objInstance.GetType() == L"#model" )
{
hairData += writeModel(objInstance);
//-
hairData += instantiateHair(posVals, oName, jump);
}
else
{
app.LogMessage(L"Object type not valid for hair instances", siErrorMsg);
}
}
}
else
{
app.LogMessage(L"Not Group object with 'HAIR' string in your name", siErrorMsg);
}
}
}
}
//--
return hairData;
}