//- // ========================================================================== // 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. // ========================================================================== //+ /////////////////////////////////////////////////////////////////////////////// // // apiMeshCreator.cpp // //////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 #endif //////////////////////////////////////////////////////////////////////////////// // // Shape implementation // //////////////////////////////////////////////////////////////////////////////// MObject apiMeshCreator::size; MObject apiMeshCreator::shapeType; MObject apiMeshCreator::inputMesh; MObject apiMeshCreator::outputSurface; MTypeId apiMeshCreator::id( 0x80089 ); apiMeshCreator::apiMeshCreator() {} apiMeshCreator::~apiMeshCreator() {} /////////////////////////////////////////////////////////////////////////////// // // Overrides // /////////////////////////////////////////////////////////////////////////////// /* override */ MStatus apiMeshCreator::compute( const MPlug& plug, MDataBlock& datablock ) // // Description // // When input attributes are dirty this method will be called to // recompute the output attributes. // { MStatus stat; if ( plug == outputSurface ) { // Create some user defined geometry data and access the // geometry so we can set it // MFnPluginData fnDataCreator; MTypeId tmpid( apiMeshData::id ); MObject newDataObject = fnDataCreator.create( tmpid, &stat ); MCHECKERROR( stat, "compute : error creating apiMeshData") apiMeshData * newData = (apiMeshData*)fnDataCreator.data( &stat ); MCHECKERROR( stat, "compute : error gettin at proxy apiMeshData object") apiMeshGeom * geomPtr = newData->fGeometry; // If there is an input mesh then copy it's values // and construct some apiMeshGeom for it. // bool hasHistory = computeInputMesh( plug, datablock, geomPtr->vertices, geomPtr->face_counts, geomPtr->face_connects, geomPtr->normals ); // There is no input mesh so check the shapeType attribute // and create either a cube or a sphere. // if ( !hasHistory ) { MDataHandle sizeHandle = datablock.inputValue( size ); double shape_size = sizeHandle.asDouble(); MDataHandle typeHandle = datablock.inputValue( shapeType ); short shape_type = typeHandle.asShort(); switch( shape_type ) { case 0 : // build a cube buildCube( shape_size, geomPtr->vertices, geomPtr->face_counts, geomPtr->face_connects, geomPtr->normals ); break; case 1 : // buld a sphere buildSphere( shape_size, 32, geomPtr->vertices, geomPtr->face_counts, geomPtr->face_connects, geomPtr->normals ); break; } // end switch } geomPtr->faceCount = geomPtr->face_counts.length(); // Assign the new data to the outputSurface handle // MDataHandle outHandle = datablock.outputValue( outputSurface ); outHandle.set( newData ); datablock.setClean( plug ); return MS::kSuccess; } else { return MS::kUnknownParameter; } } /////////////////////////////////////////////////////////////////////////////// // // Helper routines // /////////////////////////////////////////////////////////////////////////////// void apiMeshCreator::buildCube( double cube_size, MPointArray& pa, MIntArray& faceCounts, MIntArray& faceConnects, MVectorArray& normals ) // // Description // // Constructs a cube // { const int num_faces = 6; const int num_face_connects = 24; const double normal_value = 0.5775; pa.clear(); faceCounts.clear(); faceConnects.clear(); pa.append( MPoint( -cube_size, -cube_size, -cube_size ) ); pa.append( MPoint( cube_size, -cube_size, -cube_size ) ); pa.append( MPoint( cube_size, -cube_size, cube_size ) ); pa.append( MPoint( -cube_size, -cube_size, cube_size ) ); pa.append( MPoint( -cube_size, cube_size, -cube_size ) ); pa.append( MPoint( -cube_size, cube_size, cube_size ) ); pa.append( MPoint( cube_size, cube_size, cube_size ) ); pa.append( MPoint( cube_size, cube_size, -cube_size ) ); normals.append( MVector( -normal_value, -normal_value, -normal_value ) ); normals.append( MVector( normal_value, -normal_value, -normal_value ) ); normals.append( MVector( normal_value, -normal_value, normal_value ) ); normals.append( MVector( -normal_value, -normal_value, normal_value ) ); normals.append( MVector( -normal_value, normal_value, -normal_value ) ); normals.append( MVector( -normal_value, normal_value, normal_value ) ); normals.append( MVector( normal_value, normal_value, normal_value ) ); normals.append( MVector( normal_value, normal_value, -normal_value ) ); // Set up an array containing the number of vertices // for each of the 6 cube faces (4 verticies per face) // int face_counts[num_faces] = { 4, 4, 4, 4, 4, 4 }; int i; for ( i=0; i