-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluxsi_camera.cpp
183 lines (170 loc) · 6.53 KB
/
luxsi_camera.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
/*
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_camera.h"
//--
CString luxsiCameraShaders(CRefArray camShaders)
{
CString dofData;
//-
for (int i=0; i < camShaders.GetCount(); i++)
{
//-
Shader cs(camShaders[i]);
CString vCSID((cs.GetProgID()).Split(L".")[1]);
if ( luxdebug ) app.LogMessage(L" Lens shader in use: "+ CString(vCSID));
//-
if ( vCSID == L"sib_dof")
{
int vdof_mode = cs.GetParameterValue(L"mode");
//--
if ( vdof_mode = 0 ) //- custom
{
/* custom_near_focus, custom_far_focus, custom_coc */
}
if ( vdof_mode = 1 ) //- auto
{
dofData += floatToString(cs, L"focaldistance", L"auto_focal_distance");
}
if ( vdof_mode = 2 ) //- lens
{
/* len_focal_distance, len_focal_lenght, len_fstop, len_coc */
dofData += floatToString(cs, L"focaldistance", L"len_focal_distance");
}
//-- commons
dofData += floatToString(cs, L"lensradius", L"strenght");
}
else if (vCSID == L"lux_camera_dof")
{
const char *distrib[] = {"uniform", "gaussian", "inverse gaussian", "exponential", "inverse exponential"};
int _dist = cs.GetParameterValue(L"distribution");
//object_dof /* TODO */
bool autofocus = cs.GetParameterValue(L"autofocus");
dofData += L" \"bool autofocus\" [\""+ CString(autofocus) + L"\"]\n";
//-
if (!autofocus) dofData += floatToString(cs, L"focaldistance", L"distance");
dofData += L" \"string distribution\" [\""+ CString(distrib[_dist]) + L"\"]\n";
dofData += integerToString(cs, L"power");
//-
dofData += floatToString(cs, L"lensradius");
dofData += integerToString(cs, L"blades");
//-
}
}
return dofData;
}
//--
CString writeLuxsiCam(X3DObject o)
{
/****************************
* Status: work in progress
****************************/
//- values
CString camShaderData, camData;
float vfov, aspect;
//-
X3DObject camInterest;
Camera cam;
cam = o.GetChildren()[0]; // camera
camInterest = o.GetChildren()[1]; // target
//camInterest = cam.GetInterest(); // other mode
/* Camera position */
KinematicState cam_global_state = cam.GetKinematics().GetGlobal();
CTransformation cam_global_transf = cam_global_state.GetTransform(ftime);
CVector3 camPos = cam_global_transf.GetTranslation();
/* Camera target position */
KinematicState target_global_state = camInterest.GetKinematics().GetGlobal();
CTransformation target_global_transf = target_global_state.GetTransform(ftime);
CVector3 targetPos = target_global_transf.GetTranslation();
//- shader nodes connect to camera
CRefArray cShaders = cam.GetShaders();
if ( cShaders.GetCount() > 0 )
{
//dofData = luxsiCameraShaders(cShaders);
camShaderData = luxsiCameraShaders(cShaders);
}
//--
if ((int)cam.GetParameterValue(L"fovtype")==1)
{
// calculate the proper FOV (horizontal -> vertical)
aspect = float(cam.GetParameterValue(L"aspect"));
float hfov = float(cam.GetParameterValue(L"fov"));
vfov = float( 2 * ( atan( (1/aspect) * tan(hfov / 2 * PI/180)) ) * (180/PI) );
}
else
{
// keep vertical FOV
vfov = float(cam.GetParameterValue(L"fov"));
}
//- test from liblux
//float frame = aspect;
float screen[4];
if (aspect > 1.f){
screen[0] = -aspect; screen[1] = aspect; screen[2] = -1.f; screen[3] = 1.f;
} else {
screen[0] = -1.f; screen[1] = 1.f; screen[2] = -1.f / aspect; screen[3] = 1.f / aspect;
}
//--
int camera_proj = cam.GetParameterValue(L"proj");
//--
camData = L"LookAt "
+ CString(camPos[0]) + L" "
+ CString(-camPos[2]) + L" "
+ CString(camPos[1]) + L"\n";
//-
camData += L" "
+ CString(targetPos[0]) + L" "
+ CString(-targetPos[2]) + L" "
+ CString(targetPos[1]) + L"\n";
//-
camData += L" 0 0 1 \n"; //TODO
//--
if ( camera_proj == 1 )
{
camData += L"Camera \"perspective\" \n";
camData += L" \"float fov\" ["+ CString( vfov ) + L"] \n";
camData += L" \"float screenwindow\" ["
+ CString(screen[0]) + L" "
+ CString(screen[1]) + L" "
+ CString(screen[2]) + L" "
+ CString(screen[3]) + L"]\n";
//camData += L"float shutteropen" [0.00]
//camData += L"float shutterclose" [0.04]
//- clipping ?
camData += L" \"float hither\" ["+ CString(cam.GetParameterValue(L"near"))+ L"]\n";
camData += L" \"float yon\" ["+ CString(cam.GetParameterValue(L"far"))+ L"]\n";
//-
if (!camShaderData.IsEmpty()) camData += camShaderData;
}
else //-- orthographic
{
camData += L"Camera \"orthographic\"\n";
/*
//- not dof / not clipping
"float screenwindow" [-3.65 3.65 -2.53 2.53]
"bool autofocus" ["false"]
"float shutteropen" [0.0]
"float shutterclose" [0.0416]
*/
}
/* panoramic = environment ?
Camera "environment"
*/
return camData;
}
//--