예제 #1
0
/** Create a RIB representation of the given node in the DAG as a ribgen.
 */
liqRibObj::liqRibObj( const MDagPath &path, ObjectType objType )
:
  written( 0 ),
  instanceMatrices(),
  objectHandle( NULL ),
  referenceCount( 0 ),
  data()
{
  LIQDEBUGPRINTF( "-> creating dag node handle rep\n");

  MStatus status;
  MObject obj( path.node() );
  MObject skip;

  //lightSources = NULL;
  MFnDagNode nodeFn( obj );

  // Store the matrices for all instances of this node at this time
  // so that they can be used to determine if this node's transformation
  // is animated.  This information is used for doing motion blur.
  MDagPathArray instanceArray;
  nodeFn.getAllPaths( instanceArray );
  unsigned last( instanceArray.length() );
  instanceMatrices.resize( last );
  for ( unsigned i( 0 ); i < last; i++ ) instanceMatrices[ i ] = instanceArray[ i ].inclusiveMatrix();

  LIQDEBUGPRINTF( "-> checking handles display status\n");

  ignore = !areObjectAndParentsVisible( path );
  if ( !ignore ) ignore = !areObjectAndParentsTemplated( path );
  if ( !ignore ) ignore = !isObjectPrimaryVisible( path );

  // check that the shape's transform does not a have a liqIgnoreShapes attribute.
  ignoreShapes = false;
  MDagPath searchPath( path );
  while ( searchPath.apiType() != ( MFn::kTransform ) && searchPath.length() > 1 ) searchPath.pop();
  
  MFnDagNode transformDN( searchPath );
  status.clear();
  MPlug ignorePlug = transformDN.findPlug( "liqIgnoreShapes", &status );
  if ( status == MS::kSuccess ) ignorePlug.getValue( ignoreShapes );

  ignoreShadow = !isObjectCastsShadows( path );
  if ( !ignoreShadow ) ignoreShadow = !areObjectAndParentsVisible( path );
  if ( !ignoreShadow ) ignoreShadow = !areObjectAndParentsTemplated( path );
  
  receiveShadow = isObjectReceivesShadows( path );

  // don't bother storing it if it's not going to be visible!
  LIQDEBUGPRINTF( "-> about to create rep\n");

  if ( !ignore || !ignoreShadow ) 
  {
    if ( objType == MRT_RibGen ) 
    {
      type = MRT_RibGen;
      data = liqRibDataPtr( new liqRibGenData( obj, path ) );
    } 
    else 
    {
      // check to see if object's class is derived from liqCustomNode
      liqCustomNode *customNode( NULL );
      MFnDependencyNode mfnDepNode( obj, &status );
      if ( status ) 
      {
        MPxNode *mpxNode( mfnDepNode.userNode() );
        if ( mpxNode ) 
          customNode = dynamic_cast< liqCustomNode* >( mpxNode ); // will be NULL if cast is not invalid
      }
      // Store the geometry/light/shader data for this object in RIB format
      if ( customNode ) 
      {
        type = MRT_Custom;
        data = liqRibDataPtr( new liqRibCustomNode( (( !ignoreShapes )? obj : skip ), customNode ) );
      } 
      else if ( obj.hasFn(MFn::kNurbsSurface) ) 
      {
        type = MRT_Nurbs;
        data = liqRibDataPtr( new liqRibSurfaceData( ( !ignoreShapes )? obj : skip ) );
      } 
      else if ( obj.hasFn(MFn::kSubdiv) ) 
      {
        type = MRT_Subdivision;
        data = liqRibDataPtr( new liqRibMayaSubdivisionData( ( !ignoreShapes )? obj : skip ) );
      } 
      else if ( obj.hasFn(MFn::kNurbsCurve) ) 
      {
        type = MRT_NuCurve;
        data = liqRibDataPtr( new liqRibNuCurveData( ( !ignoreShapes )? obj : skip ) );
      } 
      else if ( obj.hasFn(MFn::kPfxGeometry) ) 
      {
	      type = objType;
        data = liqRibDataPtr( new liqRibPfxData( (( !ignoreShapes )? obj : skip), objType ) );
      } 
      else if ( obj.hasFn( MFn::kPfxToon ) ) 
      {
        type = MRT_PfxToon;
        data = liqRibDataPtr( new liqRibPfxToonData( ( !ignoreShapes )? obj : skip ) );
      } 
      else if ( obj.hasFn( MFn::kPfxHair ) ) 
      {
        type = MRT_PfxHair;
        //LIQDEBUGPRINTF( "--> new liqRibPfxHairData\n");
        data = liqRibDataPtr( new liqRibPfxHairData( ( !ignoreShapes )? obj : skip ) );
      } 
      else if ( obj.hasFn( MFn::kParticle ) || obj.hasFn( MFn::kNParticle ) ) 
      {
        type = MRT_Particles;
        data = liqRibDataPtr( new liqRibParticleData( ( !ignoreShapes )? obj : skip ) );
      } 
      // if you want to use plugin shapes as placeholders for example
			// i.e. you want to use shave & haircut and attach a custom shader to it
			else if ( obj.hasFn( MFn::kPluginShape ) )
			{
				type = MRT_Weirdo; // lets use this at least once :)
				data = liqRibDataPtr( new liqRibSurfaceData( skip ) ); // you could use any here
			}
      else if ( obj.hasFn( MFn::kMesh ) ) 
      {
        float   	areaIntensity;
        // may be explicit "areaLight" attribute would be better ...
        liquidGetPlugValue( nodeFn, "areaIntensity", areaIntensity, status );
        if ( status == MS::kSuccess )
        {
          // it should be AreaLight ( until better solution...)
          type = MRT_Light;
          data = liqRibDataPtr( new liqAreaLightData( ( !ignoreShapes )? obj : skip ) );
        }
        else
        { 
          // we know we are dealing with a mesh here, now we check to see if it
          // needs to be handled as a subdivision surface
          bool usingSubdiv ( false );
          liquidGetPlugValue( nodeFn, "liqSubdiv", usingSubdiv, status );

          bool usingSubdivOld ( false );
          liquidGetPlugValue( nodeFn, "subDMesh", usingSubdivOld, status );
 
          // make Liquid understand MTOR subdiv attribute
          bool usingSubdivMtor ( false );
          if ( liqglo_useMtorSubdiv ) 
            liquidGetPlugValue( nodeFn, "mtorSubdiv", usingSubdivMtor, status );

          usingSubdiv |= usingSubdivMtor | usingSubdivOld;
          if ( usingSubdiv ) 
          {
            // we've got a subdivision surface
            bool useHierarchicalSubdiv ( false );
            liquidGetPlugValue( nodeFn, "liqHierarchicalSubdiv", useHierarchicalSubdiv, status );
            
            type = MRT_Subdivision;
					  if ( useHierarchicalSubdiv )
						  data = liqRibDataPtr( new liqRibHierarchicalSubdivisionData( ( !ignoreShapes )? obj : skip ) );
					  else
						  data = liqRibDataPtr( new liqRibSubdivisionData( ( !ignoreShapes )? obj : skip ) );
          } 
          else 
          {
            // it's a regular mesh
            type = MRT_Mesh;
            data = liqRibDataPtr( new liqRibMeshData( ( !ignoreShapes )? obj : skip ) );
          }
        }
      } 
      else if ( obj.hasFn( MFn::kLight ) ) 
      {
        type = MRT_Light;
        data = liqRibDataPtr( new liqRibLightData( path ) );
      } 
      else if ( obj.hasFn( MFn::kLocator ) ) 
      {
        if ( mfnDepNode.typeName() == "liquidCoordSys" ) 
        {
          MStatus status;
          int coordSysType = 0;
          MPlug typePlug( mfnDepNode.findPlug( "type", &status ) );
          if ( MS::kSuccess == status ) typePlug.getValue( coordSysType );
          if ( coordSysType == 5 ) 
          {
            type = MRT_ClipPlane;
            data = liqRibDataPtr( new liqRibClipPlaneData( obj ) );
          } 
          else 
          {
            type = MRT_Coord;
            data = liqRibDataPtr( new liqRibCoordData( obj ) );
          }
        } 
        else
        {
          bool isCurveGroup( false );
				  if ( mfnDepNode.typeName() == "liqBoundingBoxLocator" )
				  {
            liquidGetPlugValue( mfnDepNode, "liquidCurveGroup", isCurveGroup, status );
					  if ( isCurveGroup )
					  {
						  type = MRT_Curves;
						  //if ( liqglo_renderAllCurves ) data = liqRibDataPtr( new liqRibCurvesData( obj ) );
						  //else                          data = liqRibDataPtr( new liqRibCurvesData( skip ) );
              data = liqRibDataPtr( new liqRibCurvesData( obj ) );
					  }
				  }
				  if ( !isCurveGroup )
				  {
					  type = MRT_Locator;
					  data = liqRibDataPtr( new liqRibLocatorData( obj ) );
				  }
        }
      } 
      else if ( obj.hasFn( MFn::kImplicitSphere ) ) 
      {
        type = MRT_ImplicitSphere;
        if ( !ignoreShapes ) data = liqRibDataPtr( new liqRibImplicitSphereData( obj ) );
        else                 data = liqRibDataPtr( new liqRibImplicitSphereData( skip ) );
      }
    }

    data->objDagPath = path;
  } 
  LIQDEBUGPRINTF( "==> done creating rep %s\n", path.fullPathName().asChar() );
}
예제 #2
0
void liqCoordSysNode::draw(  M3dView & view, const MDagPath & /*path*/,
                             M3dView::DisplayStyle displaystyle,
                             M3dView::DisplayStatus displaystatus )
{
  // Get the type
  //
  MObject thisNode = thisMObject();
  MPlug typePlug( thisNode, aCoordType );
  CHECK_MSTATUS(typePlug.getValue( m_coordType ));
  MPlug colorPlug( thisNode, aCoordColor );
  CHECK_MSTATUS(colorPlug.child(0).getValue( m_coordColor.r ));
  CHECK_MSTATUS(colorPlug.child(1).getValue( m_coordColor.g ));
  CHECK_MSTATUS(colorPlug.child(2).getValue( m_coordColor.b ));
  MPlug opacityPlug( thisNode, aCoordOpacity );
  CHECK_MSTATUS(opacityPlug.getValue( m_coordColor.a ));

  view.beginGL();

  // Draw the arrows
  //

  glPushAttrib( GL_ALL_ATTRIB_BITS );

  glBegin( GL_LINES );

    glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f );
    glVertex3f(  0.50f,  0.00f,  0.00f );
    glVertex3f(  0.50f,  0.00f,  0.00f );
    glVertex3f(  0.40f, -0.05f,  0.00f );
    glVertex3f(  0.40f, -0.05f,  0.00f );
    glVertex3f(  0.40f,  0.00f,  0.00f );

    glColor4f( 0.0f, 1.0f, 0.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f  );
    glVertex3f(  0.00f,  0.50f,  0.00f  );
    glVertex3f(  0.00f,  0.50f,  0.00f  );
    glVertex3f(  0.05f,  0.40f,  0.00f  );
    glVertex3f(  0.05f,  0.40f,  0.00f  );
    glVertex3f(  0.00f,  0.40f,  0.00f  );

    glColor4f( 0.0f, 0.0f, 1.0f, 1.0f );
    glVertex3f(  0.00f,  0.00f,  0.00f   );
    glVertex3f(  0.00f,  0.00f,  0.50f   );
    glVertex3f(  0.00f,  0.00f,  0.50f   );
    glVertex3f(  0.00f, -0.05f,  0.40f   );
    glVertex3f(  0.00f, -0.05f,  0.40f   );
    glVertex3f(  0.00f,  0.00f,  0.40f   );

  glEnd();

  glPopAttrib();


  // draw the warious primitives
  //

  switch( m_coordType ) 
  {
    case 0:
      // PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f,  0.50f,  0.00f );
      glEnd();
      glPopAttrib();
      break;

    case 1:
      // SPHERE
      {
        glPushAttrib( GL_ALL_ATTRIB_BITS );
        if ( displaystatus == M3dView::kDormant ) 
          glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        GLUquadricObj* pQuadric = gluNewQuadric();
        gluQuadricDrawStyle( pQuadric, GLU_LINE);
        gluSphere( pQuadric, 0.5f , 10, 6);
        gluDeleteQuadric(pQuadric);
        glPopAttrib();
      }
      break;

    case 2:
      // CYLINDER
      {
        glPushAttrib( GL_ALL_ATTRIB_BITS );
        if ( displaystatus == M3dView::kDormant ) 
          glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
        glTranslatef( 0.0f, -0.5f, 0.0f );
        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        GLUquadricObj* pQuadric = gluNewQuadric();
        gluQuadricDrawStyle( pQuadric, GLU_LINE);
        gluCylinder( pQuadric, 0.5f , 0.5f, 1.0f, 10, 2);
        gluDeleteQuadric(pQuadric);
        glPopAttrib();
      }
      break;

    case 3:
      // CUBE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );

        glVertex3f( -0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f, -0.50f );

        glVertex3f( -0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f, -0.50f );

        glVertex3f( -0.50f,  0.50f, -0.50f );
        glVertex3f( -0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f, -0.50f );
        glVertex3f(  0.50f, -0.50f, -0.50f );
        glVertex3f(  0.50f,  0.50f,  0.50f );
        glVertex3f(  0.50f, -0.50f,  0.50f );
        glVertex3f( -0.50f,  0.50f,  0.50f );
        glVertex3f( -0.50f, -0.50f,  0.50f );

      glEnd();
      glPopAttrib();
      break;

    case 4:
      // DEEP PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f,  0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f(  0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f, -0.50f,  0.00f );
        glVertex3f( -0.50f,  0.50f,  0.00f );
      glEnd();
      glEnable( GL_LINE_STIPPLE);
      glLineStipple(1,0xff);
      glBegin( GL_LINES );
        glVertex3f( -0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f,  0.50f,  1.00f );
        glVertex3f(  0.50f, -0.50f,  1.00f );
        glVertex3f(  0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f, -0.50f,  1.00f );
        glVertex3f( -0.50f,  0.50f,  1.00f );
      glEnd();
      glPopAttrib();
      break;

    case 5:
      // CLIPPING PLANE
      glPushAttrib( GL_ALL_ATTRIB_BITS );

      glEnable( GL_LINE_STIPPLE);
      glLineStipple(1,0xff);
      if ( displaystatus == M3dView::kDormant ) 
        glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, 1.0f );

      glBegin( GL_LINES );

        glVertex3f( -1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );
        glVertex3f( -1.0f,  1.0f,  0.0f );

        glVertex3f( -1.0f,  1.0f,  0.0f );
        glVertex3f(  1.0f, -1.0f,  0.0f );
        glVertex3f(  1.0f,  1.0f,  0.0f );
        glVertex3f( -1.0f, -1.0f,  0.0f );

      glEnd();

      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glEnable(GL_ALPHA_TEST);
      glAlphaFunc(GL_ALWAYS ,0.1);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
      glDepthMask( GL_FALSE );
      glColor4f( m_coordColor.r, m_coordColor.g, m_coordColor.b, m_coordColor.a );
      glBegin( GL_QUADS );
        glVertex3f( -1.0f , 1.0f, 0.0f );
        glVertex3f(  1.0f , 1.0f, 0.0f );
        glVertex3f(  1.0f ,-1.0f, 0.0f );
        glVertex3f( -1.0f ,-1.0f, 0.0f );
      glEnd();

      glPopAttrib();
      break;
  }
  view.endGL();
}