-
Notifications
You must be signed in to change notification settings - Fork 0
/
ortoolview3d_tool.cxx
executable file
·320 lines (260 loc) · 9.39 KB
/
ortoolview3d_tool.cxx
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
/** \file ortoolview3d_tool.cxx
*/
//--- Class declaration
#include "ortoolview3d_tool.h"
#include <fbsdk/fbsystem.h>
//--- Registration defines
#define ORTOOLVIEW3D__CLASS ORTOOLVIEW3D__CLASSNAME
#define ORTOOLVIEW3D__LABEL "View3D"
#define ORTOOLVIEW3D__DESC "OR - 3D Viewer Tool"
//--- Implementation and registration
FBToolImplementation( ORTOOLVIEW3D__CLASS );
FBRegisterTool ( ORTOOLVIEW3D__CLASS,
ORTOOLVIEW3D__LABEL,
ORTOOLVIEW3D__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* Constructor.
************************************************/
bool ORToolView3D::FBCreate()
{
/* No effect
Border.Style = kFBNoBorder;
Border.Spacing = 0;
Border.Width = 0;
Border.Caption = "Blah 1";
Caption = "Blash";
*/
// Init oculus
mLensSeperation = 0.0635f;
mHScreenSize = 0.149759993f;
mInterpupillaryDistance = 0.064f;
mOffset = 0.f;
StartSize[0] = 1280;
StartSize[1] = 800;
#ifdef OCULUSSUPPORT
// Get oculus device info
OVR::System::Init(OVR::Log::ConfigureDefaultLog(OVR::LogMask_All));
OVR::Ptr<OVR::DeviceManager> pManager;
OVR::Ptr<OVR::HMDDevice> pHMD;
pManager = *OVR::DeviceManager::Create();
pHMD = *pManager->EnumerateDevices<OVR::HMDDevice>().CreateDevice();
OVR::HMDInfo hmd;
if (pHMD && pHMD->GetDeviceInfo(&hmd))
{
//std::string MonitorName(hmd.DisplayDeviceName);
/*float EyeDistance = hmd.InterpupillaryDistance;
float DistortionK[4];
DistortionK[0] = hmd.DistortionK[0];
DistortionK[1] = hmd.DistortionK[1];
DistortionK[2] = hmd.DistortionK[2];
DistortionK[3] = hmd.DistortionK[3];*/
StartSize[0] = hmd.HResolution;
StartSize[1] = hmd.VResolution;
StartPos[0] = hmd.DesktopX;
StartPos[1] = hmd.DesktopY;
mLensSeperation = hmd.LensSeparationDistance;
mHScreenSize = hmd.HScreenSize;
mInterpupillaryDistance = hmd.InterpupillaryDistance;
mOffset = (mHScreenSize * 0.25f - mLensSeperation * 0.5f) / mHScreenSize * hmd.HResolution;
}
#endif
// Manage UI
UICreate ();
UIConfigure ();
UIReset ();
// Add tool callbacks
OnShow.Add ( this, (FBCallback) &ORToolView3D::EventToolShow );
OnIdle.Add ( this, (FBCallback) &ORToolView3D::EventToolIdle );
OnResize.Add( this, (FBCallback) &ORToolView3D::EventToolResize );
OnPaint.Add ( this, (FBCallback) &ORToolView3D::EventToolPaint );
OnInput.Add ( this, (FBCallback) &ORToolView3D::EventToolInput );
return true;
}
void ORToolView3D::SetCamera()
{
FBSystem fb;
mCamera = NULL;
FBPropertyListCamera cams = fb.Scene->Cameras;
int ncams = cams.GetCount();
for (int i = 0; i < ncams; i++)
{
FBComponent *cam = cams.GetAt(i);
if (cam == NULL) continue;
if (cam->Name == "ORCamera")
{
if (cam->Is(FBCameraStereo::TypeInfo))
{
mCamera = dynamic_cast<FBCameraStereo*>(cam);
mViewL.SetCamera(mCamera->LeftCamera);
mViewR.SetCamera(mCamera->RightCamera);
mViewL.mOffset = mLensSeperation;
mViewR.mOffset = -mLensSeperation;
return;
}
}
}
mCamera = new FBCameraStereo("ORCamera");
mCamera->InteraxialSeparation = this->mInterpupillaryDistance * 100;
mCamera->InteractiveMode = true;
mCamera->Stereo = FBCameraStereoType::kFBCameraStereoParallel;
//mCamera->ViewShowName = false;
mCamera->ViewShowAxis = false;
mCamera->ViewShowGrid = true;
mCamera->ViewShowTimeCode = false;
mViewL.mOffset = mOffset;
mViewR.mOffset = -mOffset;
mViewL.SetCamera(mCamera->LeftCamera);
mViewR.SetCamera(mCamera->RightCamera);
}
/************************************************
* Create, configure & reset UI.
************************************************/
void ORToolView3D::UICreate()
{
SetCamera();
// Configure layout
AddRegion( "View3DL", "View3DL",
0, kFBAttachLeft, "", 1.0,
0, kFBAttachTop, "", 1.0,
0, kFBAttachWidth, "", 0.45,
0, kFBAttachBottom,"",1.0 );
AddRegion( "View3DR", "View3DR",
0, kFBAttachWidth, "", 0.5,
0, kFBAttachTop, "", 1.0,
0, kFBAttachWidth,"", 0.5,
0, kFBAttachBottom,"", 1.0 );
MoveRegion("View3DL", mOffset, 0);
MoveRegion("View3DR", -mOffset, 0);
// Assign regions
SetView( "View3DL", mViewL);
SetView( "View3DR", mViewR);
/* no effect
SetBorder("View3DL", FBBorderStyle::kFBNoBorder, false, false, 0, 0, 0, 0);
SetBorder("View3DR", FBBorderStyle::kFBNoBorder, false, false, 0, 0, 0, 0);
*/
}
void ORToolView3D::UIConfigure()
{
}
void ORToolView3D::UIReset()
{
}
/************************************************
* Destruction function.
************************************************/
void ORToolView3D::FBDestroy()
{
// Remove tool callbacks
OnShow.Remove ( this, (FBCallback) &ORToolView3D::EventToolShow );
OnIdle.Remove ( this, (FBCallback) &ORToolView3D::EventToolIdle );
OnPaint.Remove ( this, (FBCallback) &ORToolView3D::EventToolPaint );
OnInput.Remove ( this, (FBCallback) &ORToolView3D::EventToolInput );
OnResize.Remove ( this, (FBCallback) &ORToolView3D::EventToolResize );
#ifdef OCULUSSUPPORT
OVR::System::Destroy();
#endif
// Free user allocated memory
}
/************************************************
* UI Idle callback.
************************************************/
void ORToolView3D::EventToolIdle( HISender pSender, HKEvent pEvent )
{
RefreshView();
}
void ORToolView3D::RefreshView()
{
mViewL.Refresh(true);
mViewR.Refresh(true);
}
/************************************************
* Handle tool activation (selection/unselection).
************************************************/
void ORToolView3D::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
// Reset the UI here.
SetCamera();
}
else
{
mViewL.SetCamera(NULL);
mViewR.SetCamera(NULL);
mCamera = NULL;
}
}
/************************************************
* Paint callback for tool (on expose).
************************************************/
void ORToolView3D::EventToolPaint( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Tool resize callback.
************************************************/
void ORToolView3D::EventToolResize( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Handle input into the tool.
************************************************/
void ORToolView3D::EventToolInput( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* FBX Storage.
************************************************/
bool ORToolView3D::FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldWriteBegin( "ORToolView3DSection" );
{
}
pFbxObject->FieldWriteEnd();
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORToolView3D::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
pFbxObject->FieldReadBegin( "ORToolView3DSection" );
{
}
pFbxObject->FieldReadEnd();
return true;
}