-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathviewSelect.cpp
More file actions
135 lines (114 loc) · 4.42 KB
/
viewSelect.cpp
File metadata and controls
135 lines (114 loc) · 4.42 KB
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
#include <maya/MIOStream.h>
#include <maya/M3dView.h>
#include <maya/MFnCamera.h>
#include <maya/MDrawTraversal.h>
#include <maya/MDagPath.h>
#include <maya/MSimple.h>
#include <maya/MGlobal.h>
#include <maya/MPlug.h>
#include <maya/MSelectionList.h>
#include <maya/MTime.h>
#include <maya/MAnimControl.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MStringArray.h>
// unused includes
//#include <maya/MPointArray.h>
//#include <maya/MMatrix.h>
//#include <maya/MFloatMatrix.h>
//#include <maya/MFnTransform.h>
DeclareSimpleCommand( viewSelector, "rbw", "8.5");
MStatus viewSelector::doIt( const MArgList& args )
{
MStatus stat = MS::kSuccess;
M3dView view;
MDagPath camera ;
MAnimControl mctrl;
//MSelectionList list;
MDagPath foundObj;
MTime cunit;
MStringArray selectionS;
// current viewport
M3dView activeView = view.active3dView();
// curren camera
activeView.getCamera(camera);
MFnCamera cameraFn(camera.node());
// get min/max frame range
MTime minT = mctrl.minTime();
MTime maxT = mctrl.maxTime();
// getCurrentFrame
MTime ctime = mctrl.currentTime();
// portH & portW
unsigned int portH = activeView.portHeight();
unsigned int portW = activeView.portWidth();
// for every frame
for(MTime u = minT.as(cunit.unit());u<=maxT.as(cunit.unit());u++){
// traverse scene from view
MDrawTraversal trav;
// set frustum for camera
trav.setFrustum(camera,portW,portH);
if (trav.frustumValid()){
// traverse scene from view
trav.traverse();
// get total number of selected items
unsigned int numObjs = trav.numberOfItems();
// for every object
for(unsigned int i=0;i<numObjs;i++){
// get item
trav.itemPath(i,foundObj);
MFnDependencyNode nodeFn(foundObj.node());
//cout << "nodeType:" << nodeFn.typeName() << "\n" << endl;
// select only meshes or..... to extend
if (nodeFn.typeName() == "mesh"){
// get transform over the shape
MObject tShape = foundObj.transform();
// add transform name to name list
MFnDependencyNode nodeTFn(tShape);
selectionS.append(nodeTFn.name());
}
//cout <<" found intem: "<<foundObj.partialPathName() <<" @time "<<u.as(cunit.unit()) <<"\n"<< endl;
}
}
// set current time to time u that is > mintime & <= maxtimme
mctrl.setCurrentTime(u);
}
// restore current frame
mctrl.setCurrentTime(ctime);
// set output
clearResult();
setResult(selectionS);
return stat;
}
/* appunti
// projection matrix
MFloatMatrix projMatrix = cameraFn.projectionMatrix();
// rendering frustum
double aspectRatio = cameraFn.aspectRatio();
double left, right,bottom,top;
cameraFn.getRenderingFrustum(aspectRatio,left,right,bottom,top);
cout<< " aspect ratio: " << aspectRatio << "\n" <<endl;
cout<< " rendering frustum left: " << left << " right: " << right << " top: " << top << " bottom: " << bottom << "\n" << endl;
// film frustum
double focalLength = cameraFn.focalLength();
MPointArray clipPlanes;
cameraFn.getFilmFrustum(focalLength,clipPlanes);
cout << " focal length : " << focalLength << "\n" << endl;
//cout << " portH: " << portH << " portW: " << portW<< "\n" << endl;
// Hfov Vfov
double hfov,vfov;
cameraFn.getPortFieldOfView(portH,portW,hfov,vfov);
cout << " hfov: " << hfov << " vfov: " << vfov<< "\n" << endl;
// clipping planes
double neardCp = cameraFn.nearClippingPlane();
double farCp = cameraFn.farClippingPlane();
cout << " neardCp: " << neardCp << " farCp: " << farCp<< "\n" << endl;
// camera dagMatrix
MObject camT = camera.transform();
MFnTransform cameraTr(camT);
MMatrix camWM = cameraTr.transformationMatrix();
//MMatrix camWM = cameraFn.transformationMatrix();
MMatrix viewM;
activeView.projectionMatrix(viewM);
//stat=trav.setPerspFrustum(hfov,aspectRatio,neardCp,farCp,camWM);
//stat=trav.setFrustum()
//cout <<" stat: " << stat << endl;
*/