//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ //////////////////////////////////////////////////////////////////////// // // Translate selected objects // //////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class sampleCmd : public MPxCommand { MStatus printErr(); public: sampleCmd() {}; virtual ~sampleCmd(); MStatus doIt( const MArgList& args ); static void* creator(); }; sampleCmd::~sampleCmd() {} void* sampleCmd::creator() { return new sampleCmd(); } MStatus sampleCmd::printErr() { displayError( "Usage: sampleCmd [-shadow|-reuse] \n" " [-points p0.x p0.y p0.z p1.x p1.y p1.z ...]\n" " [-refPoints rp0.x rp0.y rp0.z rp1.x rp1.y rp1.z ...]\n" " [-uvs u0 v0 u1 v1 ...]\n" " [-normals n0.x n0.y n0.z n1.x n1.y n1.z ...]\n" " [-tangentUs tu0.x tu0.y tu0.z tu1.x tu1.y tu1.z ...]\n" " [-tangentVs tv0.x tv0.y tv0.z tv1.x tv1.y tv1.z ...]\n" " [-filterSizes f0 f1 ...]\n" "Result:\n" " clr0.r clr0.g clr0.b clr1.r clr1.g clr1.b ... transp0.r transp0.g transp0.b transp1.r transp1.g transp1.b ...\n" ); return MS::kFailure; } MStatus sampleCmd::doIt( const MArgList& args ) { MStatus stat; unsigned int i; bool shadow = 0; bool reuse = 0; for ( i = 0; i < args.length(); i++ ) { if ( args.asString(i) == MString("-shadow") || args.asString(i) == MString("-s") ) shadow = 1; else if ( args.asString(i) == MString("-reuse") || args.asString(i) == MString("-r") ) reuse = 1; else break; } // fprintf( stderr, "length: %d\n", args.length() - i ); if ( args.length() - i < 4 ) return printErr(); if ( reuse && !shadow ) // can only reuse if shadow is turned on reuse = 0; MString node = args.asString( i ); int numSamples = args.asInt( i+1 ); fprintf( stderr, "num samples: %d\n", numSamples ); MFloatArray uCoords, vCoords, filterSizes; MFloatPointArray points, refPoints; MFloatVectorArray normals, tanUs, tanVs; int j; MVector vector; MPoint point; i+=2; for ( ; i < args.length(); i++ ) { if ( args.asString( i ) == MString( "-points" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { if ( MS::kSuccess != args.get( i, point ) ) return printErr(); points.append( MFloatPoint((float)point.x, (float)point.y, (float)point.z) ); } } else if ( args.asString( i ) == MString( "-refPoints" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { if ( MS::kSuccess != args.get( i, point ) ) return printErr(); refPoints.append( MFloatPoint((float)point.x, (float)point.y, (float)point.z) ); } } else if ( args.asString( i ) == MString( "-normals" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { if ( MS::kSuccess != args.get( i, vector ) ) return printErr(); normals.append( MFloatVector((float)vector.x, (float)vector.y, (float)vector.z) ); } } else if ( args.asString( i ) == MString( "-tangentUs" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { if ( MS::kSuccess != args.get( i, vector ) ) return printErr(); tanUs.append( MFloatVector((float)vector.x, (float)vector.y, (float)vector.z) ); } } else if ( args.asString( i ) == MString( "-tangentVs" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { if ( MS::kSuccess != args.get( i, vector ) ) return printErr(); tanVs.append( MFloatVector((float)vector.x, (float)vector.y, (float)vector.z) ); } } else if ( args.asString( i ) == MString( "-uvs" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { double d = args.asDouble( i, &stat ); if ( stat != MS::kSuccess ) return printErr(); uCoords.append( (float)d ); i++; d = args.asDouble( i, &stat ); if ( stat != MS::kSuccess ) return printErr(); vCoords.append( (float)d ); i++; } } else if ( args.asString( i ) == MString( "-filterSizes" ) ) { i++; for ( j = 0; j < numSamples; j++ ) { double d = args.asDouble( i, &stat ); if ( stat != MS::kSuccess ) return printErr(); filterSizes.append( (float)d ); i++; } } else { fprintf( stderr, "*** ERROR: Bad args: %s\n", args.asString( i ).asChar() ); return printErr(); } } // for i < length() // get current camera MDagPath cameraPath; M3dView::active3dView().getCamera( cameraPath ); MMatrix mat = cameraPath.inclusiveMatrix(); MFloatMatrix cameraMat( mat.matrix ); MFloatVectorArray colors, transps; if ( MS::kSuccess == MRenderUtil::sampleShadingNetwork( node, numSamples, shadow, reuse, cameraMat, (points.length()>0) ? &points : NULL, (uCoords.length()>0) ? &uCoords : NULL, (vCoords.length()>0) ? &vCoords : NULL, (normals.length()>0) ? &normals : NULL, (refPoints.length()>0) ? &refPoints : NULL, (tanUs.length()>0) ? &tanUs : NULL, (tanVs.length()>0) ? &tanVs : NULL, (filterSizes.length()>0) ? &filterSizes : NULL, colors, transps ) ) { fprintf( stderr, "%d points sampled...\n", colors.length() ); for ( i = 0; i < colors.length(); i++ ) { appendToResult( (double) colors[i].x ); appendToResult( (double) colors[i].y ); appendToResult( (double) colors[i].z ); } for ( i = 0; i < transps.length(); i++ ) { appendToResult( (double) transps[i].x ); appendToResult( (double) transps[i].y ); appendToResult( (double) transps[i].z ); } } else { displayError( node + MString(" is not a shading engine! Specify node.attr or shading group node." ) ); } return MS::kSuccess; } // // The following routines are used to register/unregister // the command we are creating within Maya // MStatus initializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj, "Alias", "3.0", "Any"); status = plugin.registerCommand( "sampleCmd", sampleCmd::creator ); if (!status) { status.perror("registerCommand"); return status; } return status; } MStatus uninitializePlugin( MObject obj) { MStatus status; MFnPlugin plugin( obj ); status = plugin.deregisterCommand( "sampleCmd" ); if (!status) { status.perror("deregisterCommand"); return status; } return status; }