//- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright // law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by the Autodesk software license agreement, // without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // ========================================================================== //+ // File Name: narrowPolyViewer.cpp // // Description: // A simple test of the MPx3dModelView code. // A view that allows multiple cameras to be added is made. // #include "narrowPolyViewer.h" #include #include #include #include #include #include #include #include #include #include #include #if defined(OSMac_MachO_) #include #else #include #endif #include narrowPolyViewer::narrowPolyViewer() : fDrawManips(true) , fLightTest(false) { setMultipleDrawEnable(true); tol = 10; } narrowPolyViewer::~narrowPolyViewer() { } MStatus narrowPolyViewer::setCameraList(const MDagPathArray &cameraList) // // Description: // Replace the contents of fCameraList with the passed list of cameras. // { setMultipleDrawEnable(true); fCameraList.clear(); unsigned ii = 0; unsigned nCameras = cameraList.length(); for (ii = 0; ii < nCameras; ++ii) { fCameraList.append(cameraList[ii]); } refresh(); return MS::kSuccess; } MStatus narrowPolyViewer::getCameraList(MDagPathArray &cameraList) const // // Description: // Fills the passed camera list with the current camera list used by // this view. The default camera is not added to the list. Also, the list // is cleared of any previous values. // { cameraList.clear(); unsigned ii = 0; unsigned nCameras = fCameraList.length(); for (ii = 0; ii < nCameras; ++ii) { cameraList.append(fCameraList[ii]); } return MS::kSuccess; } MStatus narrowPolyViewer::getCameraList(MStringArray &cameraList) const // // Description: // Fills the passed camera list with the current camera list used by // this view. The default camera is not added to the list. Also, the list // is cleared of any previous values. // { cameraList.clear(); unsigned ii = 0; unsigned nCameras = fCameraList.length(); for (ii = 0; ii < nCameras; ++ii) { cameraList.append(fCameraList[ii].partialPathName()); } return MS::kSuccess; } MStatus narrowPolyViewer::appendCamera(const MDagPath &camera) // // Description: // Append a camera to the list of cameras used by this view. // { MStatus ReturnStatus = fCameraList.append(camera); refresh(true); return ReturnStatus; } MStatus narrowPolyViewer::removeCamera(const MDagPath &camera) // // Description: // Removes the specified camera from the list of cameras. If the // camera is not on the list, it is still considered removed. // { // Loop backwards to avoid any array resize problems. // int ii = 0; bool cameraRemoved = false; int nCameras = (int)fCameraList.length(); for (ii = nCameras - 1; ii >= 0; ii--) { if (camera == fCameraList[ii]) { fCameraList.remove(ii); cameraRemoved = true; } } if (cameraRemoved) { refresh(); } return MS::kSuccess; } MStatus narrowPolyViewer::removeAllCameras() // // Description: // Remove all cameras from the list. // { MStatus ReturnStatus = fCameraList.clear(); refresh(); return ReturnStatus; } MString narrowPolyViewer::getCameraHUDName() { MString hudName("narrowPolyViewer: "); // Oops, well this method should be non-const, or there // should be a const version of get camera. For now, we will // live with a cast. // MDagPath cameraPath; getCamera(cameraPath); cameraPath.pop(); hudName += cameraPath.partialPathName(); return hudName; } MStatus narrowPolyViewer::setIsolateSelect(MSelectionList &list) { setViewSelected(true); return setObjectsToView(list); } MStatus narrowPolyViewer::setIsolateSelectOff() { return setViewSelected(false); } MStatus narrowPolyViewer::setLightTest(MSelectionList &list) { MStatus ReturnStatus = MS::kSuccess; MItSelectionList it(list, MFn::kLight, &ReturnStatus); if (MS::kSuccess != ReturnStatus) { return ReturnStatus; } for (; !it.isDone(); it.next()) { MDagPath lightPath; if (MS::kSuccess != it.getDagPath(lightPath)) { continue; } fLightList.append(lightPath); } if (fLightList.length() > 0) { fLightTest = true; } return ReturnStatus; } void narrowPolyViewer::preMultipleDraw() { fCurrentPass = 0; fDrawManips = false; MDagPath oldCamera; MStatus status = getCamera(oldCamera); if (MS::kSuccess != status) { status.perror("M3dView::getCamera"); } fOldCamera = oldCamera; // Check and see if this is in color index mode. // if (isColorIndexMode()) { setColorIndexMode(false); } displayHUD(false); // Clear the test camera list // fTestCameraList.clear(); ////////////////////////////////////////////////////////////////////////////////////////////////////// // get the first item in the selection list MStatus stat; MSelectionList sList; MGlobal::getActiveSelectionList(sList); MDagPath dagPath; stat = sList.getDagPath(0, dagPath); if (stat != MS::kSuccess) return; MItMeshPolygon itMeshPolygon(dagPath, MObject::kNullObj, &stat); if (stat != MS::kSuccess) return; beginGL(); // Iterate over all faces on the mesh for (; !itMeshPolygon.isDone(); itMeshPolygon.next()) { MPointArray points; itMeshPolygon.getPoints(points, MSpace::kWorld, &stat); int length = points.length(); // Only care about triangles if (length == 3) { // Iterate over all points on the triangle face and if the angle // between any 2 sides are less than the tolerance, then draw the // triangle white for (int i=0; i 0) { max--; } unsigned nLights = fLightList.length(); if (nLights < min) { setLightingMode(kLightDefault); } else { if (nLights < max) { max = nLights; } MSelectionList list; unsigned ii = 0; for (ii = min; ii < max; ii++) { list.add(fLightList[ii].node()); } MGlobal::setActiveSelectionList(list); setLightingMode(kLightSelected); } } else { setLightingMode(kLightDefault); } // Make every other pass alternate between shaded and wireframe. // if (fCurrentPass % 2 == 0) { setObjectDisplay(M3dView::kDisplayNurbsSurfaces, true); setObjectDisplay(M3dView::kDisplayNurbsCurves, true); } updateViewingParameters(); } void narrowPolyViewer::postMultipleDrawPass(unsigned index) { // Until better control over selection and picking is exposed, // turn on the display of everything after drawing. The selection // methods will not consider things that are not visible. // // If picking masks are to be used for the view, set them // here. // setObjectDisplay(M3dView::kDisplayEverything, true); } bool narrowPolyViewer::okForMultipleDraw(const MDagPath &dagPath) { // Don't draw manipulators unless the fDrawManips value is true. // if (!fDrawManips && dagPath.hasFn(MFn::kManipulator3D)) { return false; } return true; } unsigned narrowPolyViewer::multipleDrawPassCount() { // The camera list plus the main camera. // return fCameraList.length() + 1; } void narrowPolyViewer::removingCamera(MDagPath &cameraPath) // // Description: // A method that is called when the passed camera path is // being deleted. Be sure to reemove any call to this // camera. // { int ii = 0; int nCameras = (int)fCameraList.length(); for (ii = nCameras - 1; ii >= 0; ii--) { if (cameraPath == fCameraList[ii]) { fCameraList.remove(ii); } } } void * narrowPolyViewer::creator() { return new narrowPolyViewer(); } MStatus narrowPolyViewer::copy(MPx3dModelView &src) // // Description: // Copy the contents for the src and put them // into this. // { return MS::kSuccess; } MStatus narrowPolyViewer::swap(MPx3dModelView &src) // // Description: // Swap out the contents for the src and put them // into this. // { return MS::kSuccess; } MString narrowPolyViewer::viewType() const // // Description: // Returns a string with the type of the view. // { return MString("narrowPolyViewer"); }