Esempio n. 1
0
        //
        // Description
        //
        //    Returns offsets for the given components to be used my the
        //    move tool in normal/u/v mode.
        //
        // Arguments
        //
        //    component - components to calculate offsets for
        //    direction - array of offsets to be filled
        //    mode      - the type of offset to be calculated
        //    normalize - specifies whether the offsets should be normalized
        //
        // Returns
        //
        //    true if the offsets could be calculated, false otherwise
        //
        // Support the move tools normal/u/v mode (components)
        //
        public override bool vertexOffsetDirection( MObject component,
            MVectorArray direction,
            MVertexOffsetMode mode,
            bool normalize)
        {
            bool offsetOkay = false ;

            MFnSingleIndexedComponent fnComp = new MFnSingleIndexedComponent( component );
            if ( component.apiType != MFn.Type.kMeshVertComponent ) {
                return false;
            }

            offsetOkay = true ;

            apiMeshGeom geomPtr = meshGeom();
            if ( null == geomPtr ) {
                return false;
            }

            // For each vertex add the appropriate offset
            //
            int count = fnComp.elementCount;
            for ( int idx=0; idx<count; idx++ )
            {
                MVector normal = geomPtr.normals[ fnComp.element(idx) ];

                if( mode == MVertexOffsetMode.kNormal ) {
                    if( normalize ) normal.normalize() ;
                    direction.append( normal );
                }
                else {
                    // Construct an orthonormal basis from the normal
                    // uAxis, and vAxis are the new vectors.
                    //
                    MVector uAxis = new MVector();
                    MVector vAxis = new MVector();
                    uint i, j, k;
                    double a;
                    normal.normalize();

                    i = 0;
                    a = Math.Abs( normal[0] );
                    if ( a < Math.Abs(normal[1]) )
                    {
                        i = 1;
                        a = Math.Abs(normal[1]);
                    }

                    if ( a < Math.Abs(normal[2]) )
                    {
                        i = 2;
                    }

                    j = (i+1)%3;
                    k = (j+1)%3;

                    a = Math.Sqrt(normal[i]*normal[i] + normal[j]*normal[j]);
                    uAxis[i] = -normal[j]/a;
                    uAxis[j] = normal[i]/a;
                    uAxis[k] = 0.0;
                    vAxis = normal.crossProduct( uAxis );

                    if ( mode == MVertexOffsetMode.kUTangent ||
                         mode == MVertexOffsetMode.kUVNTriad )
                    {
                        if( normalize ) uAxis.normalize() ;
                        direction.append( uAxis );
                    }

                    if ( mode == MVertexOffsetMode.kVTangent ||
                         mode == MVertexOffsetMode.kUVNTriad )
                    {
                        if( normalize ) vAxis.normalize() ;
                        direction.append( vAxis );
                    }

                    if ( mode == MVertexOffsetMode.kUVNTriad ) {
                        if( normalize ) normal.normalize() ;
                        direction.append( normal );
                    }
                }
            }

            return offsetOkay;
        }
Esempio n. 2
0
		// Support the move tools normal/u/v mode (components)
		//
		public override bool vertexOffsetDirection( MObject component,
													MVectorArray direction,
													MVertexOffsetMode mode,
													bool normalize )
		//
		// Description
		//
		//    Returns offsets for the given components to be used my the
		//    move tool in normal/u/v mode.
		//
		// Arguments
		//
		//    component - components to calculate offsets for
		//    direction - array of offsets to be filled
		//    mode      - the type of offset to be calculated
		//    normalize - specifies whether the offsets should be normalized
		//
		// Returns
		//
		//    true if the offsets could be calculated, false otherwise
		//
		{
			bool offsetOkay = false ;

			MFnSingleIndexedComponent fnComp = new MFnSingleIndexedComponent( component );
			if ( component.apiType != MFn.Type.kMeshVertComponent ) {
				return false;
			}

			offsetOkay = true ;

			apiMeshGeom geomPtr = meshGeom();
			if ( null == geomPtr ) {
				return false;
			}

			// For each vertex add the appropriate offset
			//
			int count = fnComp.elementCount;
			for ( int idx=0; idx<count; idx++ )
			{
				MVector normal = geomPtr.normals[ fnComp.element(idx) ];

				if( mode == MVertexOffsetMode.kNormal ) {
					if( normalize ) normal.normalize() ;
					direction.append( normal );
				}
				else {
					// Construct an orthonormal basis from the normal
					// uAxis, and vAxis are the new vectors.
					//
					MVector uAxis = new MVector();
					MVector vAxis = new MVector();
					uint i, j, k;
					double a;
					normal.normalize();

					i = 0;
					a = Math.Abs( normal[0] );
					if ( a < Math.Abs(normal[1]) )
					{
						i = 1;
						a = Math.Abs(normal[1]);
					}

					if ( a < Math.Abs(normal[2]) )
					{
						i = 2;
					}

					j = (i+1)%3;
					k = (j+1)%3;

					a = Math.Sqrt(normal[i]*normal[i] + normal[j]*normal[j]);
					uAxis[i] = -normal[j]/a;
					uAxis[j] = normal[i]/a;
					uAxis[k] = 0.0;
					vAxis = normal.crossProduct( uAxis );

					if ( mode == MVertexOffsetMode.kUTangent ||
						 mode == MVertexOffsetMode.kUVNTriad )
					{
						if( normalize ) uAxis.normalize() ;
						direction.append( uAxis );
					}

					if ( mode == MVertexOffsetMode.kVTangent ||
						 mode == MVertexOffsetMode.kUVNTriad )
					{
						if( normalize ) vAxis.normalize() ;
						direction.append( vAxis );
					}

					if ( mode == MVertexOffsetMode.kUVNTriad ) {
						if( normalize ) normal.normalize() ;
						direction.append( normal );
					}
				}
			}

			return offsetOkay;
		}