Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

SoftVolumeSphere.cpp

00001 
00013 #include "SoftVolumeSphere.h"
00014 #include <maya/MFnDagNode.h>
00015 #include <maya/MColor.h>
00016 
00018 const MTypeId SoftVolumeSphere::typeId( 0x70015 );
00019 
00021 const MString SoftVolumeSphere::typeName( "softVolumeSphere" );
00022 
00023 
00025 MObject SoftVolumeSphere::m_Radius;
00026 
00027 
00028 MObject SoftVolumeSphere::m_Weight;
00029 
00030 
00031 void SoftVolumeSphere:: OnDraw( M3dView::DisplayStyle style,
00032                                                         M3dView::DisplayStatus status)
00033 {
00034         float radius,inner;
00035 
00036         // we need to determine the size of the loocator node by reading back the
00037         // attributes contained on this node. To do this, we must attach a function
00038         // set to this node, and then read back the attributes.
00039         //
00040         MFnDagNode fn( thisMObject() );
00041 
00042         MPlug RadiusPlug = fn.findPlug( m_Radius );
00043         RadiusPlug.getValue( radius );
00044 
00045         // the MPxLocator::colorRGB() function returns the user specified colour for
00046         // a given selection state. For example, by default a selected item is green;
00047         // the user may however change this within the user preferences and say change
00048         // this to pink. In order for our node to maintain continuity with the rest
00049         // of the users settings, we should use this colour value somewhere obvious
00050         // on our nodes.
00051         MColor outlineCol = colorRGB(status);
00052 
00053         // if the object is the last selected, there seems to be no colour for this.
00054         // therefore i check to see if the locator is the last selected item and then
00055         // just use green. I might just be doing something stupid though ;)
00056         //
00057         if(status == M3dView::kLead )
00058                 glColor4f(0.0f,1.0f,0.0f,0.5f);
00059         else
00060                 // Otherwise i use a slightly varied intensity of the colour
00061                 glColor4f(outlineCol.r,outlineCol.g,outlineCol.b,0.5f);
00062 
00063         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00064         glEnable(GL_BLEND);
00065                 DrawCircleXY( radius, 32 );
00066                 DrawCircleXZ( radius, 32 );
00067                 DrawCircleYZ( radius, 32 );
00068                 DrawCrossXY( 2*radius, 2*radius );
00069                 DrawCrossXZ( 2*radius, 2*radius );
00070                 DrawCrossYZ( 2*radius, 2*radius );
00071         glDisable(GL_BLEND);
00072 
00073 
00074 }
00075 
00076 
00077 MBoundingBox SoftVolumeSphere::boundingBox() const
00078 {
00079         float radius,inner;
00080 
00081         // we need to determine the size of the loocator node by reading back the
00082         // attributes contained on this node. To do this, we must attach a function
00083         // set to this node, and then read back the attributes.
00084         //
00085         MFnDagNode fn( thisMObject() );
00086 
00087         MPlug RadiusPlug = fn.findPlug( m_Radius );
00088         RadiusPlug.getValue( radius );
00089 
00090         // expand the bounding box to fit all axes of the locator node
00091         MBoundingBox bbox;
00092 
00093         bbox.expand( MPoint( -radius, 0.0f, 0.0f ) );
00094         bbox.expand( MPoint(  radius, 0.0f, 0.0f ) );
00095 
00096         bbox.expand( MPoint(  0.0f,radius,  0.0f ) );
00097         bbox.expand( MPoint(  0.0f,-radius,  0.0f ) );
00098 
00099         bbox.expand( MPoint(  0.0f, 0.0f, -radius ) );
00100         bbox.expand( MPoint(  0.0f, 0.0f,  radius ) );
00101 
00102         return bbox;
00103 }
00104 
00105 void* SoftVolumeSphere::creator()
00106 {
00107         return new SoftVolumeSphere();
00108 }
00109 
00110 
00111 MStatus SoftVolumeSphere::initialize()
00112 {
00113         // in maya, all attributes are individual objects. The nodes within maya
00114         // maintain their own internal list of attribute objects. Thankfully
00115         // we don't have to manipulate this list of attributes ourselves. We simply
00116         // have to create all of the attributes and then add them to the node.
00117         //
00118         // A number of function sets allow you to create attributes of various
00119         // types, You may want attributes of various types, ie time, colour,
00120         // integer, float, string, bool, array etc, etc...
00121         //
00122         // The most common function set for creating an attribute is
00123         // MFnNumericAttribute since it handles floats, ints etc. In this case
00124         // however we want to add attributes that represents the nodes size.
00125         // This should be done using the MFnUnitAttribute function set. The
00126         // reason for this is that sizes may change since maya's units can
00127         // be changed to inches, meters, feet etc.
00128         //
00129         MFnUnitAttribute fn;
00130         MFnNumericAttribute nfn;
00131 
00132         MStatus stat;
00133 
00134         // create a size attribute. We specify the long and short name
00135         // for the attribute, as well as the data type.
00136         m_Radius = fn.create( "radius", "r", MFnUnitAttribute::kDistance );
00137 
00138         // set a default value of 1 for the size
00139         fn.setDefault( MDistance(5.0, MDistance::uiUnit()) );
00140 
00141         // An attribute will only appear in the channel box if it is keyable.
00142         // this means we usually make most attributes keyable, even if we
00143         // never want to animate them. (since the channel box is handy for
00144         // setting values).
00145         //
00146         // If we have an attribute that we want in the channel box, but we do
00147         // not want it to be keyed; we can overide the MPxNode::legalConnection()
00148         // function to say that anim curves should not be attached to the
00149         // non keyable attribute.
00150         //
00151         fn.setKeyable( true );
00152 
00153         // set a minim value for the attribute
00154         fn.setMin( 0.1f );
00155 
00156         // finally add the attribute to this node.
00157         stat = addAttribute( m_Radius );
00158 
00159         // check for error
00160         if( stat != MS::kSuccess ) {
00161                 stat.perror("Unable to attach radius attribute to the softVolumeSphere node");
00162                 return stat;
00163         }
00164         
00165         m_Weight = nfn.create("weight","w",MFnNumericData::kFloat);
00166         nfn.setDefault(1.0f);
00167         nfn.setKeyable(true);
00168         stat = addAttribute(m_Weight);
00169         
00170         // check for error
00171         if( stat != MS::kSuccess ) {
00172                 stat.perror("Unable to attach innerSize attribute to the softVolumeSphere node");
00173                 return stat;
00174         }
00175         
00176         return MS::kSuccess;
00177 }

Generated on Mon Jun 13 03:18:00 2005 for ImplicitFunctions by  doxygen 1.4.1