Example #1
0
        // Main selection routine
        //
        public override bool select(MSelectInfo selectInfo,
                                    MSelectionList selectionList,
                                    MPointArray worldSpaceSelectPts)
        //
        // Description:
        //
        //     Main selection routine
        //
        // Arguments:
        //
        //     selectInfo           - the selection state information
        //     selectionList        - the list of selected items to add to
        //     worldSpaceSelectPts  -
        //
        {
            bool selected          = false;
            bool componentSelected = false;
            bool hilited           = false;

            hilited = (selectInfo.displayStatus == M3dView.DisplayStatus.kHilite);
            if (hilited)
            {
                componentSelected = selectVertices(selectInfo, selectionList,
                                                   worldSpaceSelectPts);
                selected = selected || componentSelected;
            }

            if (!selected)
            {
                apiMesh meshNode = (apiMesh)surfaceShape;

                // NOTE: If the geometry has an intersect routine it should
                // be called here with the selection ray to determine if the
                // the object was selected.

                selected = true;
                MSelectionMask priorityMask = new MSelectionMask(MSelectionMask.SelectionType.kSelectNurbsSurfaces);
                MSelectionList item         = new MSelectionList();
                item.add(selectInfo.selectPath);
                MPoint xformedPt = new MPoint();
                if (selectInfo.singleSelection)
                {
                    MPoint center = meshNode.boundingBox().center;
                    xformedPt = center;
                    xformedPt.multiplyEqual(selectInfo.selectPath.inclusiveMatrix);
                }

                selectInfo.addSelection(item, xformedPt, selectionList,
                                        worldSpaceSelectPts, priorityMask, false);
            }

            return(selected);
        }
Example #2
0
        // Main selection routine
        //
        public override bool select(MSelectInfo selectInfo,
                                    MSelectionList selectionList,
                                    MPointArray worldSpaceSelectPts)
        {
            bool           selected          = false;
            bool           componentSelected = false;
            bool           hilited           = false;
            apiSimpleShape shapeNode         = surfaceShape as apiSimpleShape;

            if (shapeNode == null)
            {
                return(false);
            }
            hilited = (selectInfo.displayStatus == M3dView.DisplayStatus.kHilite);
            if (hilited)
            {
                componentSelected = selectVertices(selectInfo, selectionList, worldSpaceSelectPts);
                selected          = selected || componentSelected;
            }

            if (!selected)
            {
                // NOTE: If the geometry has an intersect routine it should
                // be called here with the selection ray to determine if the
                // the object was selected.

                selected = true;
                MSelectionMask priorityMask = new MSelectionMask(MSelectionMask.SelectionType.kSelectNurbsSurfaces);
                MSelectionList item         = new MSelectionList();
                item.add(selectInfo.selectPath);
                MPoint xformedPt;
                if (selectInfo.singleSelection)
                {
                    MPoint center = shapeNode.boundingBox().center;
                    xformedPt = center.multiply(selectInfo.selectPath.inclusiveMatrix);
                }
                else
                {
                    xformedPt = new MPoint();
                }

                selectInfo.addSelection(item, xformedPt, selectionList,
                                        worldSpaceSelectPts, priorityMask, false);
            }

            return(selected);
        }
Example #3
0
        /* override */
        public override bool select(MSelectInfo selectInfo,
                                    MSelectionList selectionList,
                                    MPointArray worldSpaceSelectPts)
        //
        // Select function. Gets called when the bbox for the object is selected.
        // This function just selects the object without doing any intersection tests.
        //
        {
            MSelectionMask priorityMask = new MSelectionMask(MSelectionMask.SelectionType.kSelectObjectsMask);
            MSelectionList item         = new MSelectionList();

            item.add(selectInfo.selectPath);
            MPoint xformedPt = new MPoint();

            selectInfo.addSelection(item, xformedPt, selectionList,
                                    worldSpaceSelectPts, priorityMask, false);
            return(true);
        }
Example #4
0
        //
        // Description:
        //
        //        Check for matches between selection type / component list, and
        //        the type of this shape / or it's components
        //
        //      This is used by sets and deformers to make sure that the selected
        //      components fall into the "vertex only" category.
        //
        // Arguments
        //
        //        mask          - selection type mask
        //        componentList - possible component list
        //
        // Returns
        //        true if matched any
        //
        public override bool match(MSelectionMask mask, MObjectArray componentList)
        {
            bool result = false;

            if( componentList.length == 0 ) {
                result = mask.intersects( MSelectionMask.SelectionType.kSelectMeshes );
            }
            else {
                for ( int i=0; i<componentList.length; i++ ) {
                    if ( (componentList[i].apiType == MFn.Type.kMeshVertComponent) &&
                         (mask.intersects(MSelectionMask.SelectionType.kSelectMeshVerts))
                    ) {
                        result = true;
                        break;
                    }
                }
            }
            return result;
        }
Example #5
0
 //
 // Select function. Gets called when the bbox for the object is selected.
 // This function just selects the object without doing any intersection tests.
 //
 /* override */
 public override bool select(MSelectInfo selectInfo,
     MSelectionList selectionList,
     MPointArray worldSpaceSelectPts)
 {
     MSelectionMask priorityMask = new MSelectionMask(MSelectionMask.SelectionType.kSelectObjectsMask);
     MSelectionList item = new MSelectionList();
     item.add(selectInfo.selectPath);
     MPoint xformedPt = new MPoint();
     selectInfo.addSelection(item, xformedPt, selectionList,
                              worldSpaceSelectPts, priorityMask, false);
     return true;
 }
Example #6
0
		public override bool match(MSelectionMask mask, MObjectArray componentList)
		//
		// Description:
		//
		//		Check for matches between selection type / component list, and
		//		the type of this shape / or it's components
		//
		//      This is used by sets and deformers to make sure that the selected
		//      components fall into the "vertex only" category.
		//
		// Arguments
		//
		//		mask          - selection type mask
		//		componentList - possible component list
		//
		// Returns
		//		true if matched any
		//
		{
			bool result = false;

			if( componentList.length == 0 ) {
				result = mask.intersects( MSelectionMask.SelectionType.kSelectMeshes );
			}
			else {
				for ( int i=0; i<componentList.length; i++ ) {
					if ( (componentList[i].apiType == MFn.Type.kMeshVertComponent) &&
						 (mask.intersects(MSelectionMask.SelectionType.kSelectMeshVerts))
					) {
						result = true;
						break;
					}
				}
			}
			return result;
		}
Example #7
0
 /* override */
 public override bool select(MSelectInfo selectInfo,
                              MSelectionList selectionList,
                              MPointArray worldSpaceSelectPts)
 //
 // Select function. Gets called when the bbox for the object is selected.
 // This function just selects the object without doing any intersection tests.
 //
 {
     MSelectionMask priorityMask = new MSelectionMask(MSelectionMask.SelectionType.kSelectObjectsMask);
     MSelectionList item = new MSelectionList();
     item.add(selectInfo.selectPath);
     MPoint xformedPt = new MPoint();
     selectInfo.addSelection(item, xformedPt, selectionList,
                              worldSpaceSelectPts, priorityMask, false);
     return true;
 }
Example #8
0
        //
        // Description:
        //
        //     Vertex selection.
        //
        // Arguments:
        //
        //     selectInfo           - the selection state information
        //     selectionList        - the list of selected items to add to
        //     worldSpaceSelectPts  -
        //
        public bool selectVertices( MSelectInfo selectInfo,
            MSelectionList selectionList,
            MPointArray worldSpaceSelectPts)
        {
            bool selected = false;
            M3dView view = selectInfo.view;

            MPoint xformedPoint = new MPoint();
            MPoint selectionPoint = new MPoint();
            double z = 0.0;
            double previousZ = 0.0;
             			int closestPointVertexIndex = -1;

            MDagPath path = selectInfo.multiPath;

            // Create a component that will store the selected vertices
            //
            MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent();
            MObject surfaceComponent = fnComponent.create( MFn.Type.kMeshVertComponent );
            uint vertexIndex;

            // if the user did a single mouse click and we find > 1 selection
            // we will use the alignmentMatrix to find out which is the closest
            //
            MMatrix alignmentMatrix = new MMatrix();
            MPoint singlePoint = new MPoint();
            bool singleSelection = selectInfo.singleSelection;
            if( singleSelection ) {
                alignmentMatrix = selectInfo.alignmentMatrix;
            }

            // Get the geometry information
            //
            apiMesh meshNode = (apiMesh)surfaceShape;
            apiMeshGeom geom = meshNode.meshGeom();

            // Loop through all vertices of the mesh and
            // see if they lie withing the selection area
            //
            uint numVertices = geom.vertices.length;
            for ( vertexIndex=0; vertexIndex<numVertices; vertexIndex++ )
            {
                MPoint currentPoint = geom.vertices[ (int)vertexIndex ];

                // Sets OpenGL's render mode to select and stores
                // selected items in a pick buffer
                //
                view.beginSelect();

                OpenGL.glBegin(OpenGL.GL_POINTS);
                OpenGL.glVertex3f((float)currentPoint[0],
                            (float)currentPoint[1],
                            (float)currentPoint[2] );
                OpenGL.glEnd();

                if ( view.endSelect() > 0 )	// Hit count > 0
                {
                    selected = true;

                    if ( singleSelection ) {
                        xformedPoint = currentPoint;
                        xformedPoint.homogenize();
                        xformedPoint.multiplyEqual( alignmentMatrix );
                        z = xformedPoint.z;
                        if ( closestPointVertexIndex < 0 || z > previousZ ) {
                            closestPointVertexIndex = (int)vertexIndex;
                            singlePoint = currentPoint;
                            previousZ = z;
                        }
                    } else {
                        // multiple selection, store all elements
                        //
                        fnComponent.addElement( (int)vertexIndex );
                    }
                }
            }

            // If single selection, insert the closest point into the array
            //
            if ( selected && selectInfo.singleSelection ) {
                fnComponent.addElement(closestPointVertexIndex);

                // need to get world space position for this vertex
                //
                selectionPoint = singlePoint;
                selectionPoint.multiplyEqual( path.inclusiveMatrix );
            }

            // Add the selected component to the selection list
            //
            if ( selected ) {
                MSelectionList selectionItem = new MSelectionList();
                selectionItem.add( path, surfaceComponent );

                MSelectionMask mask = new MSelectionMask( MSelectionMask.SelectionType.kSelectComponentsMask );
                selectInfo.addSelection(
                    selectionItem, selectionPoint,
                    selectionList, worldSpaceSelectPts,
                    mask, true );
            }

            return selected;
        }
Example #9
0
        //
        // Description:
        //
        //     Main selection routine
        //
        // Arguments:
        //
        //     selectInfo           - the selection state information
        //     selectionList        - the list of selected items to add to
        //     worldSpaceSelectPts  -
        //
        // Main selection routine
        //
        public override bool select(MSelectInfo selectInfo,
            MSelectionList selectionList,
            MPointArray worldSpaceSelectPts)
        {
            bool selected = false;
            bool componentSelected = false;
            bool hilited = false;

            hilited = (selectInfo.displayStatus == M3dView.DisplayStatus.kHilite);
            if ( hilited ) {
                componentSelected = selectVertices( selectInfo, selectionList,
                                                    worldSpaceSelectPts );
                selected = selected || componentSelected;
            }

            if ( !selected ) {

                apiMesh meshNode = (apiMesh)surfaceShape;

                // NOTE: If the geometry has an intersect routine it should
                // be called here with the selection ray to determine if the
                // the object was selected.

                selected = true;
                MSelectionMask priorityMask = new MSelectionMask( MSelectionMask.SelectionType.kSelectNurbsSurfaces );
                MSelectionList item = new MSelectionList();
                item.add( selectInfo.selectPath );
                MPoint xformedPt = new MPoint();
                if ( selectInfo.singleSelection ) {
                    MPoint center = meshNode.boundingBox().center;
                    xformedPt = center;
                    xformedPt.multiplyEqual( selectInfo.selectPath.inclusiveMatrix );
                }

                selectInfo.addSelection( item, xformedPt, selectionList,
                                         worldSpaceSelectPts, priorityMask, false );
            }

            return selected;
        }
Example #10
0
        public bool selectVertices(MSelectInfo selectInfo,
                                   MSelectionList selectionList,
                                   MPointArray worldSpaceSelectPts)
        //
        // Description:
        //
        //     Vertex selection.
        //
        // Arguments:
        //
        //     selectInfo           - the selection state information
        //     selectionList        - the list of selected items to add to
        //     worldSpaceSelectPts  -
        //
        {
            bool    selected = false;
            M3dView view     = selectInfo.view;

            MPoint xformedPoint   = new MPoint();
            MPoint selectionPoint = new MPoint();
            double z         = 0.0;
            double previousZ = 0.0;
            int    closestPointVertexIndex = -1;

            MDagPath path = selectInfo.multiPath;

            // Create a component that will store the selected vertices
            //
            MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent();
            MObject surfaceComponent = fnComponent.create(MFn.Type.kMeshVertComponent);
            uint    vertexIndex;

            // if the user did a single mouse click and we find > 1 selection
            // we will use the alignmentMatrix to find out which is the closest
            //
            MMatrix alignmentMatrix = new MMatrix();
            MPoint  singlePoint     = new MPoint();
            bool    singleSelection = selectInfo.singleSelection;

            if (singleSelection)
            {
                alignmentMatrix = selectInfo.alignmentMatrix;
            }

            // Get the geometry information
            //
            apiMesh     meshNode = (apiMesh)surfaceShape;
            apiMeshGeom geom     = meshNode.meshGeom();

            // Loop through all vertices of the mesh and
            // see if they lie withing the selection area
            //
            uint numVertices = geom.vertices.length;

            for (vertexIndex = 0; vertexIndex < numVertices; vertexIndex++)
            {
                MPoint currentPoint = geom.vertices[(int)vertexIndex];

                // Sets OpenGL's render mode to select and stores
                // selected items in a pick buffer
                //
                view.beginSelect();

                OpenGL.glBegin(OpenGL.GL_POINTS);
                OpenGL.glVertex3f((float)currentPoint[0],
                                  (float)currentPoint[1],
                                  (float)currentPoint[2]);
                OpenGL.glEnd();

                if (view.endSelect() > 0)                       // Hit count > 0
                {
                    selected = true;

                    if (singleSelection)
                    {
                        xformedPoint = currentPoint;
                        xformedPoint.homogenize();
                        xformedPoint.multiplyEqual(alignmentMatrix);
                        z = xformedPoint.z;
                        if (closestPointVertexIndex < 0 || z > previousZ)
                        {
                            closestPointVertexIndex = (int)vertexIndex;
                            singlePoint             = currentPoint;
                            previousZ = z;
                        }
                    }
                    else
                    {
                        // multiple selection, store all elements
                        //
                        fnComponent.addElement((int)vertexIndex);
                    }
                }
            }

            // If single selection, insert the closest point into the array
            //
            if (selected && selectInfo.singleSelection)
            {
                fnComponent.addElement(closestPointVertexIndex);

                // need to get world space position for this vertex
                //
                selectionPoint = singlePoint;
                selectionPoint.multiplyEqual(path.inclusiveMatrix);
            }

            // Add the selected component to the selection list
            //
            if (selected)
            {
                MSelectionList selectionItem = new MSelectionList();
                selectionItem.add(path, surfaceComponent);

                MSelectionMask mask = new MSelectionMask(MSelectionMask.SelectionType.kSelectComponentsMask);
                selectInfo.addSelection(
                    selectionItem, selectionPoint,
                    selectionList, worldSpaceSelectPts,
                    mask, true);
            }

            return(selected);
        }