├── Volume-1 ├── Html │ ├── Contents.htm │ ├── DavidGouldStyles.css │ ├── Images │ │ └── Note.gif │ └── Main.htm ├── MEL Scripts │ ├── copySkeletonMotion.mel │ ├── listAll.mel │ ├── objToWorld.mel │ ├── outputJoints.mel │ ├── printAnim.mel │ ├── printTangentPositions.mel │ ├── scaleSkeleton.mel │ └── spaceToSpace.mel ├── Plugins │ ├── BasicLocator │ │ ├── BasicLocator.cpp │ │ ├── BasicLocator.dsp │ │ ├── BasicLocator.dsw │ │ ├── BasicLocator.h │ │ ├── Makefile │ │ └── PluginMain.cpp │ ├── BasicLocator2 │ │ ├── BasicLocator.cpp │ │ ├── BasicLocator.h │ │ ├── BasicLocator2.dsp │ │ ├── BasicLocator2.dsw │ │ ├── BasicLocatorManip.cpp │ │ ├── BasicLocatorManip.h │ │ ├── Makefile │ │ └── PluginMain.cpp │ ├── Clock │ │ ├── Clock.dsp │ │ ├── Clock.dsw │ │ ├── Makefile │ │ └── clockCmd.cpp │ ├── GoRolling │ │ ├── GoRolling.dsp │ │ ├── GoRolling.dsw │ │ ├── GoRollingCmd.cpp │ │ ├── GoRollingCmd.h │ │ ├── Makefile │ │ ├── RollingNode.cpp │ │ ├── RollingNode.h │ │ └── pluginMain.cpp │ ├── GroundShadow │ │ ├── GroundShadow.dsp │ │ ├── GroundShadow.dsw │ │ ├── GroundShadowCmd.cpp │ │ ├── GroundShadowCmd.h │ │ ├── GroundShadowNode.cpp │ │ ├── GroundShadowNode.h │ │ ├── Makefile │ │ └── PluginMain.cpp │ ├── HelloWorld │ │ ├── HelloWorld.dsp │ │ ├── HelloWorld.dsw │ │ ├── Makefile │ │ └── helloWorldCmd.cpp │ ├── HelloWorld2 │ │ ├── HelloWorld2.dsp │ │ ├── HelloWorld2.dsw │ │ ├── Makefile │ │ └── helloWorld2Cmd.cpp │ ├── Makefile │ ├── Melt │ │ ├── Makefile │ │ ├── Melt.dsp │ │ ├── Melt.dsw │ │ ├── MeltCmd.cpp │ │ ├── MeltCmd.h │ │ ├── MeltNode.cpp │ │ ├── MeltNode.h │ │ └── PluginMain.cpp │ ├── Posts1 │ │ ├── Makefile │ │ ├── Posts1.dsp │ │ ├── Posts1.dsw │ │ └── posts1Cmd.cpp │ ├── Posts2 │ │ ├── Makefile │ │ ├── Posts2.dsp │ │ ├── Posts2.dsw │ │ └── posts2Cmd.cpp │ ├── Posts3 │ │ ├── Makefile │ │ ├── Posts3.dsp │ │ ├── Posts3.dsw │ │ └── posts3Cmd.cpp │ ├── Posts4 │ │ ├── Makefile │ │ ├── Posts4.dsp │ │ ├── Posts4.dsw │ │ └── posts4Cmd.cpp │ ├── Posts5 │ │ ├── Makefile │ │ ├── Posts5.dsp │ │ ├── Posts5.dsw │ │ └── posts5Cmd.cpp │ ├── Squash │ │ ├── Makefile │ │ ├── Squash.dsp │ │ ├── Squash.dsw │ │ ├── SquashNode.cpp │ │ ├── SquashNode.h │ │ └── pluginMain.cpp │ ├── SwirlDeformer │ │ ├── Makefile │ │ ├── PluginMain.cpp │ │ ├── SwirlDeformer.cpp │ │ ├── SwirlDeformer.dsp │ │ ├── SwirlDeformer.dsw │ │ └── SwirlDeformer.h │ └── SwirlDeformer2 │ │ ├── Makefile │ │ ├── PluginMain.cpp │ │ ├── SwirlDeformer.cpp │ │ ├── SwirlDeformer.h │ │ ├── SwirlDeformer2.dsp │ │ └── SwirlDeformer2.dsw ├── ReadMe.htm ├── Scenes │ ├── Clock.ma │ ├── Flash.ma │ ├── GoRolling.ma │ ├── GroundShadow.ma │ ├── IKChain.ma │ ├── Magnet.ma │ ├── Melt.ma │ ├── MotionPathCone.ma │ ├── ParticleGrid.ma │ ├── Plane.ma │ ├── PostsCurve.ma │ ├── Primitives.ma │ ├── SimpleAnimatedSphere.ma │ ├── Skeleton.ma │ ├── SkeletonMotion.ma │ ├── Swirl.ma │ └── Wiggle.ma └── _notes │ └── dwSiteColumnsMe.xml └── Volume-2 ├── Html ├── DavidGouldStyles.css └── Images │ └── Note.gif ├── MEL Scripts ├── curveStar.mel ├── curveSwirl.mel ├── subdInfo1.mel └── tube.mel ├── Plugins ├── CurveInfo1 │ ├── CurveInfo1.ncb │ ├── CurveInfo1.vcproj │ ├── CurveInfo1Cmd.cpp │ └── Makefile ├── CurveInfo2 │ ├── CurveInfo2.vcproj │ ├── CurveInfo2Cmd.cpp │ └── Makefile ├── CurveStar │ ├── CurveStar.vcproj │ ├── CurveStarCmd.cpp │ └── Makefile ├── CurveSwirl │ ├── CurveSwirl.vcproj │ ├── CurveSwirlCmd.cpp │ └── Makefile ├── DisplaceMesh │ ├── CmpMeshModifierCmd.cpp │ ├── CmpMeshModifierCmd.h │ ├── CmpMeshModifierNode.cpp │ ├── CmpMeshModifierNode.h │ ├── DisplaceMesh.vcproj │ ├── DisplaceMeshCmd.cpp │ ├── DisplaceMeshCmd.h │ ├── DisplaceMeshNode.cpp │ ├── DisplaceMeshNode.h │ ├── Makefile │ ├── PluginMain.cpp │ └── smiley.jpg ├── Makefile ├── MeshBlindData │ ├── Makefile │ ├── MeshBlindData.vcproj │ └── MeshBlindDataCmd.cpp ├── MeshInfo1 │ ├── Makefile │ ├── MeshInfo1.vcproj │ └── MeshInfo1Cmd.cpp ├── MeshInfo2 │ ├── Makefile │ ├── MeshInfo2.vcproj │ └── MeshInfo2Cmd.cpp ├── MeshInfo3 │ ├── Makefile │ ├── MeshInfo3.vcproj │ └── MeshInfo3Cmd.cpp ├── MeshInfo4 │ ├── Makefile │ ├── MeshInfo4.vcproj │ └── MeshInfo4Cmd.cpp ├── MeshInfo5 │ ├── Makefile │ ├── MeshInfo5.vcproj │ └── MeshInfo5Cmd.cpp ├── MeshInfo6 │ ├── Makefile │ ├── MeshInfo6.vcproj │ └── MeshInfo6Cmd.cpp ├── Molecule1 │ ├── Makefile │ ├── Molecule1.vcproj │ ├── Molecule1Cmd.cpp │ ├── MoleculeUtils.cpp │ └── MoleculeUtils.h ├── Molecule2 │ ├── Makefile │ ├── Molecule2.vcproj │ ├── Molecule2Cmd.cpp │ ├── MoleculeUtils.cpp │ └── MoleculeUtils.h ├── Molecule3 │ ├── Makefile │ ├── Molecule3.vcproj │ ├── Molecule3Cmd.cpp │ ├── MoleculeUtils.cpp │ ├── MoleculeUtils.h │ ├── molecule3CreateUI.mel │ ├── molecule3DeleteUI.mel │ └── molecule3Window.mel ├── Molecule4 │ ├── Makefile │ ├── Molecule4.vcproj │ ├── Molecule4Cmd.cpp │ ├── Molecule4Cmd.h │ ├── Molecule4Node.cpp │ ├── Molecule4Node.h │ ├── MoleculeUtils.cpp │ ├── MoleculeUtils.h │ ├── PluginMain.cpp │ ├── molecule4CreateUI.mel │ ├── molecule4DeleteUI.mel │ └── molecule4Window.mel ├── SelectRingContext1 │ ├── Makefile │ ├── SelectRingContext1.cpp │ └── SelectRingContext1.vcproj ├── SelectRingContext2 │ ├── Makefile │ ├── SelectRingContext2.cpp │ ├── SelectRingContext2.vcproj │ ├── selectRingContext2.jpg │ ├── selectRingContext2.xpm │ ├── selectRingContext2Properties.mel │ └── selectRingContext2Values.mel ├── SelectVolumeContext1 │ ├── BasicLocator.cpp │ ├── Makefile │ ├── Plugin.cpp │ ├── SelectVolumeContext1.cpp │ ├── SelectVolumeContext1.h │ ├── SelectVolumeContext1.vcproj │ ├── SelectVolumeLocator1.cpp │ ├── SelectVolumeLocator1.h │ ├── selectVolumeContext1.xpm │ ├── selectVolumeContext1Icon.jpg │ ├── selectVolumeContext1Properties.mel │ └── selectVolumeContext1Values.mel ├── SubdCube │ ├── Makefile │ ├── SubdCube.vcproj │ └── SubdCubeCmd.cpp ├── SubdInfo1 │ ├── Makefile │ ├── SubdInfo1.vcproj │ └── SubdInfo1Cmd.cpp ├── SubdToMesh │ ├── Makefile │ ├── SubdToMesh.vcproj │ └── SubdToMeshCmd.cpp ├── SubdToNURBS │ ├── Makefile │ ├── SubdToNURBS.vcproj │ └── SubdToNURBSCmd.cpp ├── SurfaceInfo1 │ ├── Makefile │ ├── SurfaceInfo1.vcproj │ └── SurfaceInfo1Cmd.cpp ├── SurfaceInfo2 │ ├── Makefile │ ├── SurfaceInfo2.vcproj │ └── SurfaceInfo2Cmd.cpp └── Tube │ ├── Makefile │ ├── Tube.vcproj │ └── TubeCmd.cpp ├── Readme.htm ├── Scenes ├── BasicPolygon.ma ├── BoxMesh.ma ├── BoxMeshes.ma ├── ConeAndSphereMeshTextured.ma ├── CubeMesh.ma ├── CubeMeshDivided.ma ├── CubeSubd.ma ├── CubeSubdShaded.ma ├── PlaneMeshDetailed.ma ├── PlaneNurbs.ma ├── PlaneNurbsTrimmed.ma ├── SphereMesh.ma ├── SphereMeshTextured.ma ├── SphereNurbs.ma ├── TwoCurves.ma ├── TwoPlaneNurbs.ma └── TwoPolygonMesh.ma └── _notes └── dwSiteColumnsMe.xml /Volume-1/Html/Contents.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | Contents 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

Plugins
12 | Compiling
13 | Creating

14 |

Book
15 | Online

16 | 17 | 18 | -------------------------------------------------------------------------------- /Volume-1/Html/DavidGouldStyles.css: -------------------------------------------------------------------------------- 1 | p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 2 | body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 3 | h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14pt} 4 | .DGSymbol { font-family: Symbol; font-size: 12pt} 5 | h2 { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: bold} 6 | input { font-family: Arial, Helvetica, sans-serif; font-size: 9pt} 7 | li { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 8 | h3 { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold} 9 | .SourceCode { font-family: "Courier New", Courier, mono; font-size: 10pt} 10 | .NoteWell { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #3366FF} 11 | -------------------------------------------------------------------------------- /Volume-1/Html/Images/Note.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-1/Html/Images/Note.gif -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/copySkeletonMotion.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc copySkeletonMotion( string $srcRootNode, string $destRootNode ) 9 | { 10 | float $srcPos[] = `xform -query -worldSpace -translation $srcRootNode`; 11 | float $destPos[] = `xform -query -worldSpace -translation $destRootNode`; 12 | 13 | string $srcNodes[] = `listRelatives -fullPath 14 | -children -allDescendents $srcRootNode`; 15 | $srcNodes[ size($srcNodes) ] = $srcRootNode; 16 | 17 | string $destNodes[] = `listRelatives -fullPath 18 | -children -allDescendents $destRootNode`; 19 | $destNodes[ size($destNodes) ] = $destRootNode; 20 | 21 | if( size($srcNodes) != size($destNodes) ) 22 | { 23 | error "Source skeleton and destination skeleton are structurely different"; 24 | return; 25 | } 26 | 27 | string $attrs[] = { "translateX", "translateY", "translateZ", 28 | "scaleX", "scaleY", "scaleZ", 29 | "rotateX", "rotateY", "rotateZ" }; 30 | 31 | int $i; 32 | for( $i=0; $i < size($srcNodes); $i++ ) 33 | { 34 | for( $attr in $attrs ) 35 | { 36 | string $inPlugs[] = `listConnections -plugs yes 37 | -source yes -destination no 38 | ($srcNodes[$i] + "." + $attr)`; 39 | if( size($inPlugs) ) 40 | { 41 | string $tokens[]; 42 | tokenize $inPlugs[0] "." $tokens; 43 | string $inNode = $tokens[0]; 44 | string $inAttr = $tokens[1]; 45 | 46 | string $dupInNodes[] = `duplicate -upstreamNodes $inNode`; 47 | connectAttr -force 48 | ($dupInNodes[0] + "." + $inAttr) 49 | ($destNodes[$i] + "." + $attr); 50 | } 51 | else 52 | { 53 | $res = `getAttr ($srcNodes[$i] + "." + $attr)`; 54 | setAttr ($destNodes[$i] + "." + $attr) $res; 55 | } 56 | } 57 | } 58 | 59 | string $moveRoot; 60 | string $parentNodes[] = `listRelatives -parent $destRootNode`; 61 | string $found = `match "_moveSkeleton" $parentNodes[0]`; 62 | if( size($found) ) 63 | $moveRoot = $parentNodes[0]; 64 | else 65 | $moveRoot = `group -name "_moveSkeleton" -world $destRootNode`; 66 | 67 | move -worldSpace 68 | ($destPos[0] - $srcPos[0]) 69 | ($destPos[1] - $srcPos[1]) 70 | ($destPos[2] - $srcPos[0]) $moveRoot; 71 | } 72 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/listAll.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc listAll() 9 | { 10 | print( "\nNodes..." ); 11 | string $nodes[] = `ls`; 12 | for( $node in $nodes ) 13 | { 14 | string $nodeType = `objectType $node`; 15 | print ("\nNode: " + $node + " (" + $nodeType + ")"); 16 | } 17 | } 18 | 19 | listAll(); 20 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/objToWorld.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc float[] transformPoint( float $pt[], float $mtx[] ) 9 | { 10 | float $res[] = { 0.0, 0.0, 0.0 }; 11 | 12 | if( size($pt) != 3 && size($mtx) != 16 ) 13 | { 14 | warning "transformPoint proc: pt must have three elements and matrix must have 16 elements"; 15 | return $res; 16 | } 17 | 18 | $res[0] = $pt[0] * $mtx[0] + $pt[1] * $mtx[4] + 19 | $pt[2] * $mtx[8] + $mtx[12]; 20 | $res[1] = $pt[0] * $mtx[1] + $pt[1] * $mtx[5] + 21 | $pt[2] * $mtx[9] + $mtx[13]; 22 | $res[2] = $pt[0] * $mtx[2] + $pt[1] * $mtx[6] + 23 | $pt[2] * $mtx[10] + $mtx[14]; 24 | return $res; 25 | } 26 | 27 | proc float[] objToWorld( float $pt[], string $transformNode ) 28 | { 29 | float $mtx[16] = `xform -query -worldSpace -matrix $transformNode`; 30 | float $res[] = transformPoint( $pt, $mtx ); 31 | return $res; 32 | } 33 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/outputJoints.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc writeArray( int $fileHnd, float $array[] ) 9 | { 10 | float $v; 11 | for( $v in $array ) 12 | fwrite $fileHnd $v; 13 | } 14 | 15 | proc outputJoints( string $rootNode, string $filename, 16 | float $startFrame, float $endFrame, 17 | int $outputWS ) 18 | { 19 | int $fileHnd = `fopen $filename w`; 20 | if( $fileHnd == 0 ) 21 | { 22 | error ("Unable to open output file " + $filename + " for writing"); 23 | return; 24 | } 25 | 26 | string $childNodes[] = `listRelatives -fullPath 27 | -type joint -children -allDescendents $rootNode`; 28 | string $rn[] = { $rootNode }; 29 | string $nodes[] = stringArrayCatenate( $rn, $childNodes ); 30 | 31 | float $cTime = `currentTime -query`; 32 | 33 | string $spaceFlag = ($outputWS) ? "-worldSpace" : "-objectSpace"; 34 | 35 | print "\nOutputting joints..."; 36 | float $t; 37 | for( $t = $startFrame; $t <= $endFrame; $t++ ) 38 | { 39 | currentTime -update false $t; 40 | fwrite $fileHnd $t; 41 | print ("\nFrame: " + $t); 42 | 43 | for( $node in $nodes ) 44 | { 45 | fwrite $fileHnd $node; 46 | print ("\n Joint: " + $node ); 47 | 48 | float $pos[] = `xform $spaceFlag -query -translation $node`; 49 | float $rot[] = `xform $spaceFlag -query -rotation $node`; 50 | float $scl[] = `xform $spaceFlag -query -relative -scale $node`; 51 | 52 | writeArray( $fileHnd, $pos ); 53 | writeArray( $fileHnd, $rot ); 54 | writeArray( $fileHnd, $scl ); 55 | 56 | print ("\n pos=[ " + $pos[0] + " " 57 | + $pos[1] + " " + $pos[2] + " ]"); 58 | print ("\n rot=[ " + $rot[0] + " " 59 | + $rot[1] + " " + $rot[2] + " ]"); 60 | print ("\n scl=[ " + $scl[0] + " " 61 | + $scl[1] + " " + $scl[2] + " ]"); 62 | } 63 | } 64 | 65 | currentTime -update false $cTime; 66 | 67 | fclose $fileHnd; 68 | } 69 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/printAnim.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc printAnim( int $detailed ) 9 | { 10 | print "\nAnimation..."; 11 | string $animNodes[]; 12 | float $keytimes[]; 13 | string $sel[] = `ls -selection`; 14 | for( $node in $sel ) 15 | { 16 | print ("\nNode: " + $node); 17 | $animNodes = `keyframe -query -name $node`; 18 | for( $ac in $animNodes ) 19 | { 20 | print ("\nAnimCurve: " + $ac ); 21 | $keytimes = `keyframe -query -timeChange $ac`; 22 | print ("\n" + size($keytimes) + " keys: " ); 23 | for( $keyt in $keytimes ) 24 | { 25 | $keyv = `keyframe -time $keyt -query -valueChange $ac`; 26 | if( $detailed ) 27 | { 28 | float $isBd[] = `keyframe -time $keyt -query -breakdown $ac`; 29 | print ("\n" + ($isBd[0] ? "Breakdown" : "Normal") + " Key:" ); 30 | } 31 | 32 | print (" [" + $keyt + ", " + $keyv[0] + "]"); 33 | 34 | if( $detailed ) 35 | { 36 | print ("\nTangent: "); 37 | $keyinT = `keyTangent -time $keyt -query -inTangentType $ac`; 38 | $keyoutT = `keyTangent -time $keyt -query -outTangentType $ac`; 39 | $keyinA = `keyTangent -time $keyt -query -inAngle $ac`; 40 | $keyoutA = `keyTangent -time $keyt -query -outAngle $ac`; 41 | print ("("+ $keyinT[0] + " angle=" + $keyinA[0] + 42 | ", " + $keyoutT[0] + " angle=" + $keyoutA[0] + ")"); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/printTangentPositions.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc printTangentPostions( string $animCurve, int $absolute ) 9 | { 10 | print ("\nTangent Positions..."); 11 | 12 | float $ktimes[], $kvalues[]; 13 | if( $absolute ) 14 | { 15 | $ktimes = `keyframe -query -timeChange $animCurve`; 16 | $kvalues = `keyframe -query -valueChange $animCurve`; 17 | } 18 | 19 | float $xcomps[], $ycomps[], $weights[]; 20 | int $i, $j; 21 | for( $i=0; $i < 2; $i++ ) 22 | { 23 | string $xreq, $yreq, $wreq; 24 | if( $i == 0 ) 25 | { 26 | $xreq = "-ix"; 27 | $yreq = "-iy"; 28 | $wreq = "-inWeight"; 29 | } 30 | else 31 | { 32 | $xreq = "-ox"; 33 | $yreq = "-oy"; 34 | $wreq = "-outWeight"; 35 | } 36 | 37 | $xcomps = `keyTangent -query $xreq $animCurve`; 38 | $ycomps = `keyTangent -query $xreq $animCurve`; 39 | $weights = `keyTangent -query $wreq $animCurve`; 40 | 41 | print ("\n"); 42 | for( $j=0; $j < size($xcomps); $j = $j + 1 ) 43 | { 44 | $xcomps[$j] *= $weights[$j]; 45 | $ycomps[$j] *= $weights[$j]; 46 | if( $absolute ) 47 | { 48 | $xcomps[$j] += $ktimes[$j]; 49 | $ycomps[$j] += $kvalues[$j]; 50 | } 51 | 52 | print (" [" + $xcomps[$j] + ", " + $ycomps[$j] + "]"); 53 | } 54 | } 55 | } 56 | 57 | 58 | proc testProc() 59 | { 60 | string $animCurves[] = `keyframe -query -name ball.translateX`; 61 | printTangentPostions( $animCurves[0], true ); 62 | } 63 | 64 | testProc(); 65 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/scaleSkeleton.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc scaleSkeleton( string $rootNode, float $scale ) 9 | { 10 | string $childs[] = `listRelatives -fullPath -children 11 | -type joint -allDescendents $rootNode`; 12 | for( $child in $childs ) 13 | { 14 | float $pos[] = `joint -query -relative -position $child`; 15 | $pos[0] *= $scale; 16 | $pos[1] *= $scale; 17 | $pos[2] *= $scale; 18 | joint -edit -relative -position $pos[0] $pos[1] $pos[2] $child; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Volume-1/MEL Scripts/spaceToSpace.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 Morgan Kaufmann. All rights reserved. 3 | // 4 | // Companion file from "Complete Maya Programming" Book. 5 | // Please visit www.davidgould.com for further information. 6 | // 7 | 8 | proc float[] transformPoint( float $pt[], float $mtx[] ) 9 | { 10 | float $res[] = { 0.0, 0.0, 0.0 }; 11 | 12 | if( size($pt) != 3 && size($mtx) != 16 ) 13 | { 14 | warning "transformPoint proc: pt must have three elements and matrix must have 16 elements"; 15 | return $res; 16 | } 17 | 18 | $res[0] = $pt[0] * $mtx[0] + $pt[1] * $mtx[4] + 19 | $pt[2] * $mtx[8] + $mtx[12]; 20 | $res[1] = $pt[0] * $mtx[1] + $pt[1] * $mtx[5] + 21 | $pt[2] * $mtx[9] + $mtx[13]; 22 | $res[2] = $pt[0] * $mtx[2] + $pt[1] * $mtx[6] + 23 | $pt[2] * $mtx[10] + $mtx[14]; 24 | return $res; 25 | } 26 | 27 | proc int getInstanceIndex( string $nodePath ) 28 | { 29 | string $paths[] = `ls -allPaths $nodePath`; 30 | int $i; 31 | for( $i=0; $i < size($paths); $i++ ) 32 | { 33 | if( $paths[$i] == $nodePath ) 34 | return $i; 35 | } 36 | return -1; 37 | } 38 | 39 | proc float[] spaceToSpace( float $pt[], 40 | string $fromSpace, string $fromNode, 41 | string $toSpace, string $toNode ) 42 | { 43 | float $res[] = $pt; 44 | float $mtx[]; 45 | 46 | // Convert pt to world space 47 | if( $fromSpace == "local" ) 48 | { 49 | $mtx = `xform -query -worldSpace -matrix $fromNode`; 50 | $res = transformPoint( $res, $mtx ); 51 | } 52 | 53 | // Convert pt to destination space 54 | if( $toSpace == "local" ) 55 | { 56 | int $inst = getInstanceIndex( $toNode ); 57 | string $attr = $toNode + ".worldInverseMatrix[" + $inst + "]"; 58 | $mtx = `getAttr $attr`; 59 | print "\nInverse: "; 60 | print $mtx; 61 | $res = transformPoint( $res, $mtx ); 62 | } 63 | 64 | return $res; 65 | } 66 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator/BasicLocator.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "BasicLocator"=".\BasicLocator.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator/BasicLocator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef BASICLOCATOR_H 5 | #define BASICLOCATOR_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class BasicLocator : public MPxLocatorNode 24 | { 25 | public: 26 | virtual void draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ); 27 | 28 | virtual bool isBounded() const; 29 | virtual MBoundingBox boundingBox() const; 30 | 31 | static void *creator(); 32 | static MStatus initialize(); 33 | 34 | static const MTypeId typeId; 35 | static const MString typeName; 36 | 37 | // Attributes 38 | static MObject xWidth; 39 | static MObject zWidth; 40 | static MObject dispType; 41 | 42 | private: 43 | bool getCirclePoints( MPointArray &pts ) const; 44 | }; 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = BasicLocator.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | BasicLocator.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "BasicLocator.h" 5 | #include 6 | 7 | MStatus initializePlugin( MObject obj ) 8 | { 9 | MStatus stat; 10 | MString errStr; 11 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 12 | 13 | stat = plugin.registerNode( BasicLocator::typeName, 14 | BasicLocator::typeId, 15 | &BasicLocator::creator, &BasicLocator::initialize, 16 | MPxNode::kLocatorNode ); 17 | if ( !stat ) 18 | { 19 | errStr = "registerNode failed"; 20 | goto error; 21 | } 22 | 23 | return stat; 24 | 25 | error: 26 | 27 | stat.perror( errStr ); 28 | return stat; 29 | } 30 | 31 | MStatus uninitializePlugin( MObject obj) 32 | { 33 | MStatus stat; 34 | MString errStr; 35 | MFnPlugin plugin( obj ); 36 | 37 | stat = plugin.deregisterNode( BasicLocator::typeId ); 38 | if( !stat ) 39 | { 40 | errStr = "deregisterNode failed"; 41 | goto error; 42 | } 43 | 44 | return stat; 45 | 46 | error: 47 | 48 | stat.perror( errStr ); 49 | return stat; 50 | } 51 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator2/BasicLocator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef BASICLOCATOR_H 5 | #define BASICLOCATOR_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class BasicLocator : public MPxLocatorNode 24 | { 25 | public: 26 | BasicLocator(); 27 | virtual ~BasicLocator(); 28 | 29 | virtual MStatus compute( const MPlug& plug, MDataBlock& data ); 30 | virtual void draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ); 31 | 32 | virtual bool isBounded() const; 33 | virtual MBoundingBox boundingBox() const; 34 | 35 | static void *creator(); 36 | static MStatus initialize(); 37 | 38 | static const MTypeId typeId; 39 | static const MString typeName; 40 | 41 | // Attributes 42 | static MObject xWidth; 43 | static MObject zWidth; 44 | static MObject dispType; 45 | 46 | private: 47 | bool getCirclePoints( MPointArray &pts ) const; 48 | }; 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator2/BasicLocator2.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "BasicLocator2"=".\BasicLocator2.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator2/BasicLocatorManip.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2002 David Gould 3 | // 4 | #ifndef BASICLOCATORMANIP_H 5 | #define BASICLOCATORMANIP_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | class BasicLocatorManip : public MPxManipContainer 20 | { 21 | public: 22 | virtual MStatus createChildren(); 23 | virtual MStatus connectToDependNode(const MObject & node); 24 | virtual void draw(M3dView & view, const MDagPath & path, M3dView::DisplayStyle style,M3dView::DisplayStatus status); 25 | 26 | static void * creator(); 27 | 28 | MManipData startPointCallback(unsigned index) const; 29 | MManipData sideDirectionCallback(unsigned index) const; 30 | MManipData backDirectionCallback(unsigned index) const; 31 | 32 | MVector nodeTranslation() const; 33 | MVector worldOffset(MVector vect) const; 34 | 35 | static const MTypeId typeId; 36 | static const MString typeName; 37 | 38 | MManipData centerPointCallback(unsigned index) const; 39 | 40 | // Paths to child manipulators 41 | MDagPath xWidthDagPath; 42 | MDagPath zWidthDagPath; 43 | MDagPath typeDagPath; 44 | 45 | // Object that the manipulator will be operating on 46 | MObject targetObj; 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = BasicLocator.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | BasicLocator2.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/BasicLocator2/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "BasicLocator.h" 5 | #include "BasicLocatorManip.h" 6 | #include 7 | 8 | MStatus initializePlugin( MObject obj ) 9 | { 10 | MStatus stat; 11 | MString errStr; 12 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 13 | 14 | stat = plugin.registerNode( BasicLocator::typeName, 15 | BasicLocator::typeId, 16 | &BasicLocator::creator, &BasicLocator::initialize, 17 | MPxNode::kLocatorNode ); 18 | if ( !stat ) 19 | { 20 | errStr = "registerNode failed"; 21 | goto error; 22 | } 23 | 24 | stat = plugin.registerNode( BasicLocatorManip::typeName, 25 | BasicLocatorManip::typeId, 26 | &BasicLocatorManip::creator, 27 | &BasicLocatorManip::initialize, 28 | MPxNode::kManipContainer ); 29 | if ( !stat ) 30 | { 31 | errStr = "registerNode failed"; 32 | goto error; 33 | } 34 | 35 | return stat; 36 | 37 | error: 38 | 39 | stat.perror( errStr ); 40 | return stat; 41 | } 42 | 43 | MStatus uninitializePlugin( MObject obj) 44 | { 45 | MStatus stat; 46 | MString errStr; 47 | MFnPlugin plugin( obj ); 48 | 49 | stat = plugin.deregisterNode( BasicLocator::typeId ); 50 | if( !stat ) 51 | { 52 | errStr = "deregisterNode failed"; 53 | goto error; 54 | } 55 | 56 | stat = plugin.deregisterNode( BasicLocatorManip::typeId ); 57 | if( !stat ) 58 | { 59 | errStr = "deregisterNode failed"; 60 | goto error; 61 | } 62 | 63 | return stat; 64 | 65 | error: 66 | 67 | stat.perror( errStr ); 68 | return stat; 69 | } 70 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Clock/Clock.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="clock" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 6 | 7 | CFG=clock - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "clock.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "clock.mak" CFG="clock - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "clock - Win32 Release" (based on "Win32 (x86) Application") 21 | !MESSAGE "clock - Win32 Debug" (based on "Win32 (x86) Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | MTL=midl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "clock - Win32 Release" 33 | 34 | # PROP BASE Use_MFC 2 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release" 37 | # PROP BASE Intermediate_Dir "Release" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_MFC 2 40 | # PROP Use_Debug_Libraries 0 41 | # PROP Output_Dir "Release" 42 | # PROP Intermediate_Dir "Release" 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /YX /FD /c 45 | # ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "D:\AW\Maya4.0\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /D "NT_PLUGIN" /YX /FD /c 46 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 47 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 48 | # ADD BASE RSC /l 0xc09 /d "NDEBUG" /d "_AFXDLL" 49 | # ADD RSC /l 0xc09 /d "NDEBUG" /d "_AFXDLL" 50 | BSC32=bscmake.exe 51 | # ADD BASE BSC32 /nologo 52 | # ADD BSC32 /nologo 53 | LINK32=link.exe 54 | # ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 55 | # ADD LINK32 Foundation.lib OpenMaya.lib /nologo /subsystem:windows /dll /machine:I386 /out:"Release\myCmd.mll" /libpath:"D:\AW\Maya4.0\lib" /export:initializePlugin /export:uninitializePlugin 56 | 57 | !ELSEIF "$(CFG)" == "clock - Win32 Debug" 58 | 59 | # PROP BASE Use_MFC 2 60 | # PROP BASE Use_Debug_Libraries 1 61 | # PROP BASE Output_Dir "Debug" 62 | # PROP BASE Intermediate_Dir "Debug" 63 | # PROP BASE Target_Dir "" 64 | # PROP Use_MFC 2 65 | # PROP Use_Debug_Libraries 1 66 | # PROP Output_Dir "Debug" 67 | # PROP Intermediate_Dir "Debug" 68 | # PROP Ignore_Export_Lib 0 69 | # PROP Target_Dir "" 70 | # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /YX /FD /GZ /c 71 | # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "D:\AW\Maya4.0\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /D "NT_PLUGIN" /FR /YX /FD /GZ /c 72 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 73 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 74 | # ADD BASE RSC /l 0xc09 /d "_DEBUG" /d "_AFXDLL" 75 | # ADD RSC /l 0xc09 /d "_DEBUG" /d "_AFXDLL" 76 | BSC32=bscmake.exe 77 | # ADD BASE BSC32 /nologo 78 | # ADD BSC32 /nologo 79 | LINK32=link.exe 80 | # ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept 81 | # ADD LINK32 Foundation.lib OpenMaya.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug\clockCmd.mll" /pdbtype:sept /libpath:"D:\AW\Maya4.0\lib" /export:initializePlugin /export:uninitializePlugin 82 | 83 | !ENDIF 84 | 85 | # Begin Target 86 | 87 | # Name "clock - Win32 Release" 88 | # Name "clock - Win32 Debug" 89 | # Begin Group "Source Files" 90 | 91 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 92 | # Begin Source File 93 | 94 | SOURCE=.\clockCmd.cpp 95 | # End Source File 96 | # End Group 97 | # Begin Group "Header Files" 98 | 99 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 100 | # End Group 101 | # Begin Group "Resource Files" 102 | 103 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 104 | # End Group 105 | # End Target 106 | # End Project 107 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Clock/Clock.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "clock"=".\clock.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Clock/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = clockCmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | clockCmd.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/GoRolling.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "GoRolling"=".\GoRolling.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/GoRollingCmd.cpp: -------------------------------------------------------------------------------- 1 | #include "GoRollingCmd.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | MStatus GoRollingCmd::doIt ( const MArgList &args ) 10 | { 11 | MStatus stat; 12 | 13 | // Get a list of currently selected objects 14 | MSelectionList selection; 15 | MGlobal::getActiveSelectionList( selection ); 16 | 17 | MDagPath dagPath; 18 | MFnTransform transformFn; 19 | MString name; 20 | 21 | // Iterate over all the transforms 22 | MItSelectionList iter( selection, MFn::kTransform ); 23 | for ( ; !iter.isDone(); iter.next() ) 24 | { 25 | iter.getDagPath( dagPath ); 26 | transformFn.setObject( dagPath ); 27 | 28 | MObject rollNodeObj = dgMod.createNode( "RollingNode" ); 29 | MFnDependencyNode depNodeFn( rollNodeObj ); 30 | 31 | dgMod.connect( transformFn.findPlug( "translateX" ), depNodeFn.findPlug( "distance") ); 32 | dgMod.connect( transformFn.findPlug( "translateY" ), depNodeFn.findPlug( "radius" ) ); 33 | 34 | dgMod.connect( depNodeFn.findPlug( "rotation" ), transformFn.findPlug( "rotateZ" ) ); 35 | } 36 | 37 | return redoIt(); 38 | } 39 | 40 | MStatus GoRollingCmd::undoIt() 41 | { 42 | return dgMod.undoIt(); 43 | } 44 | 45 | MStatus GoRollingCmd::redoIt() 46 | { 47 | return dgMod.doIt(); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/GoRollingCmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef GOROLLINGCMD_H 5 | #define GOROLLINGCMD_H 6 | 7 | #include 8 | #include 9 | /* 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | */ 20 | 21 | class GoRollingCmd : public MPxCommand 22 | { 23 | public: 24 | virtual MStatus doIt ( const MArgList& ); 25 | virtual MStatus undoIt(); 26 | virtual MStatus redoIt(); 27 | virtual bool isUndoable() const { return true; } 28 | 29 | static void *creator() { return new GoRollingCmd; } 30 | static MSyntax newSyntax(); 31 | 32 | private: 33 | MDGModifier dgMod; 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = GoRollingCmd.o RollingNode.o pluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | GoRolling.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/RollingNode.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "RollingNode.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | MTypeId RollingNode::id( 0x00333 ); 13 | 14 | MObject RollingNode::distance; 15 | MObject RollingNode::radius; 16 | MObject RollingNode::rotation; 17 | 18 | const double PI = 3.1415926535; 19 | const double TWOPI = 2.0 * PI; 20 | 21 | MStatus RollingNode::compute( const MPlug& plug, MDataBlock& data ) 22 | { 23 | MStatus stat; 24 | 25 | if( plug == rotation ) 26 | { 27 | MDataHandle distData = data.inputValue( distance, &stat ); 28 | MDataHandle radData = data.inputValue( radius, &stat ); 29 | 30 | double dist = distData.asDouble(); 31 | double rad = radData.asDouble(); 32 | 33 | MDataHandle rotData = data.outputValue( rotation, &stat ); 34 | rotData.set( -dist / rad ); 35 | 36 | data.setClean( plug ); 37 | } 38 | else 39 | stat = MS::kUnknownParameter; 40 | 41 | return stat; 42 | } 43 | 44 | void *RollingNode::creator() 45 | { 46 | return new RollingNode(); 47 | } 48 | 49 | MStatus RollingNode::initialize() 50 | { 51 | MFnNumericAttribute nAttr; 52 | 53 | distance = nAttr.create( "distance", "dist", MFnNumericData::kDouble, 0.0 ); 54 | /* 55 | nAttr.setStorable(true); 56 | nAttr.setKeyable(true); 57 | */ 58 | 59 | radius = nAttr.create( "radius", "rad", MFnNumericData::kDouble, 0.0 ); 60 | /* 61 | nAttr.setStorable(true); 62 | nAttr.setKeyable(true); 63 | */ 64 | 65 | MFnUnitAttribute uAttr; 66 | rotation = uAttr.create( "rotation", "rot", MFnUnitAttribute::kAngle, 0.0 ); 67 | /* 68 | uAttr.setWritable(false); 69 | uAttr.setStorable(false); 70 | */ 71 | 72 | addAttribute( distance ); 73 | addAttribute( radius ); 74 | addAttribute( rotation ); 75 | 76 | attributeAffects( distance, rotation ); 77 | attributeAffects( radius, rotation ); 78 | 79 | return MS::kSuccess; 80 | } -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/RollingNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef ROLLINGNODE_H 5 | #define ROLLINGNODE_H 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class RollingNode : public MPxNode 12 | { 13 | public: 14 | virtual MStatus compute( const MPlug& plug, MDataBlock& data ); 15 | 16 | static void *creator(); 17 | static MStatus initialize(); 18 | 19 | public: 20 | static MObject distance; 21 | static MObject radius; 22 | static MObject rotation; 23 | 24 | static MTypeId id; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GoRolling/pluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "RollingNode.h" 5 | #include "GoRollingCmd.h" 6 | #include 7 | 8 | MStatus initializePlugin( MObject obj ) 9 | { 10 | MStatus stat; 11 | MString errStr; 12 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 13 | 14 | stat = plugin.registerCommand( "goRolling", GoRollingCmd::creator ); 15 | if ( !stat ) 16 | { 17 | errStr = "registerCommand failed"; 18 | goto error; 19 | } 20 | 21 | stat = plugin.registerNode( "RollingNode", RollingNode::id, 22 | RollingNode::creator, RollingNode::initialize ); 23 | if ( !stat ) 24 | { 25 | errStr = "registerNode failed"; 26 | goto error; 27 | } 28 | 29 | return stat; 30 | 31 | error: 32 | 33 | stat.perror( errStr ); 34 | return stat; 35 | } 36 | 37 | MStatus uninitializePlugin( MObject obj) 38 | { 39 | MStatus stat; 40 | MString errStr; 41 | MFnPlugin plugin( obj ); 42 | 43 | stat = plugin.deregisterCommand( "goRolling" ); 44 | if ( !stat ) 45 | { 46 | errStr = "deregisterCommand failed"; 47 | goto error; 48 | } 49 | 50 | stat = plugin.deregisterNode( RollingNode::id ); 51 | if( !stat ) 52 | { 53 | errStr = "deregisterNode failed"; 54 | goto error; 55 | } 56 | 57 | return stat; 58 | 59 | error: 60 | 61 | stat.perror( errStr ); 62 | return stat; 63 | } 64 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/GroundShadow.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "GroundShadow"=".\GroundShadow.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/GroundShadowCmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef GROUNDSHADOWCMD_H 5 | #define GROUNDSHADOWMD_H 6 | 7 | #include 8 | #include 9 | 10 | class GroundShadowCmd : public MPxCommand 11 | { 12 | public: 13 | virtual MStatus doIt ( const MArgList& ); 14 | virtual MStatus undoIt(); 15 | virtual MStatus redoIt(); 16 | virtual bool isUndoable() const { return true; } 17 | 18 | static void *creator() { return new GroundShadowCmd; } 19 | static MSyntax newSyntax(); 20 | 21 | private: 22 | MDagModifier dagMod; 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/GroundShadowNode.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "GroundShadowNode.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | const MTypeId GroundShadowNode::id( 0x00335 ); 21 | 22 | MObject GroundShadowNode::lightPosition; 23 | MObject GroundShadowNode::castingSurface; 24 | MObject GroundShadowNode::shadowSurface; 25 | MObject GroundShadowNode::groundHeight; 26 | 27 | MStatus GroundShadowNode::compute( const MPlug& plug, MDataBlock& data ) 28 | { 29 | MStatus stat; 30 | 31 | if( plug == shadowSurface ) 32 | { 33 | MDataHandle groundHeightHnd = data.inputValue( groundHeight ); 34 | MDataHandle lightPositionHnd = data.inputValue( lightPosition ); 35 | MDataHandle castingSurfaceHnd = data.inputValue( castingSurface ); 36 | MDataHandle shadowSurfaceHnd = data.outputValue( shadowSurface ); 37 | 38 | shadowSurfaceHnd.copy( castingSurfaceHnd ); 39 | 40 | double gHeight = groundHeightHnd.asDouble(); 41 | MVector lightPoint( lightPositionHnd.asDouble3() ); 42 | 43 | MVector planeNormal( 0.0, 1.0, 0.0 ); 44 | MVector planePoint( 0.0, gHeight, 0.0 ); 45 | double c = planeNormal * planePoint; 46 | 47 | MPoint surfPoint; 48 | double denom, t; 49 | MItGeometry iter( shadowSurfaceHnd, false ); 50 | for( ; !iter.isDone(); iter.next() ) 51 | { 52 | surfPoint = iter.position( MSpace::kWorld ); 53 | 54 | denom = planeNormal * (surfPoint - lightPoint); 55 | if( denom != 0.0 ) 56 | { 57 | t = (c - (planeNormal * lightPoint)) / denom; 58 | surfPoint = lightPoint + t * (surfPoint - lightPoint); 59 | } 60 | 61 | iter.setPosition( surfPoint, MSpace::kWorld ); 62 | } 63 | 64 | data.setClean( plug ); 65 | } 66 | else 67 | stat = MS::kUnknownParameter; 68 | 69 | return stat; 70 | } 71 | 72 | void *GroundShadowNode::creator() 73 | { 74 | return new GroundShadowNode(); 75 | } 76 | 77 | MStatus GroundShadowNode::initialize() 78 | { 79 | MFnNumericAttribute nAttr; 80 | lightPosition = nAttr.create( "lightPosition", "lpos", MFnNumericData::k3Double, 0.0 ); 81 | nAttr.setKeyable( true ); 82 | 83 | MFnUnitAttribute uAttr; 84 | groundHeight = uAttr.create( "groundHeight", "grnd", MFnUnitAttribute::kDistance, 0.0 ); 85 | uAttr.setKeyable( true ); 86 | 87 | MFnGenericAttribute gAttr; 88 | castingSurface = gAttr.create( "castingSurface", "csrf" ); 89 | gAttr.addAccept( MFnData::kMesh ); 90 | gAttr.addAccept( MFnData::kNurbsSurface ); 91 | gAttr.setHidden( true ); 92 | 93 | shadowSurface = gAttr.create( "shadowSurface", "ssrf" ); 94 | gAttr.addAccept( MFnData::kMesh ); 95 | gAttr.addAccept( MFnData::kNurbsSurface ); 96 | gAttr.setHidden( true ); 97 | gAttr.setStorable( false ); 98 | 99 | addAttribute( groundHeight ); 100 | addAttribute( lightPosition ); 101 | addAttribute( castingSurface ); 102 | addAttribute( shadowSurface ); 103 | 104 | attributeAffects( groundHeight, shadowSurface ); 105 | attributeAffects( lightPosition, shadowSurface ); 106 | attributeAffects( castingSurface, shadowSurface ); 107 | 108 | return MS::kSuccess; 109 | } -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/GroundShadowNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef GROUNDSHADOWNODE_H 5 | #define GROUNDSHADOWNODE_H 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class GroundShadowNode : public MPxNode 12 | { 13 | public: 14 | virtual MStatus compute( const MPlug& plug, MDataBlock& data ); 15 | 16 | static void *creator(); 17 | static MStatus initialize(); 18 | 19 | static const MTypeId id; 20 | 21 | public: 22 | static MObject lightPosition; 23 | static MObject castingSurface; 24 | static MObject shadowSurface; 25 | static MObject groundHeight; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = GroundShadowCmd.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | GroundShadow.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/GroundShadow/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "GroundShadowNode.h" 5 | #include "GroundShadowCmd.h" 6 | #include 7 | 8 | MStatus initializePlugin( MObject obj ) 9 | { 10 | MStatus stat; 11 | MString errStr; 12 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 13 | 14 | stat = plugin.registerCommand( "groundShadow", GroundShadowCmd::creator ); 15 | if ( !stat ) 16 | { 17 | errStr = "registerCommand failed"; 18 | goto error; 19 | } 20 | 21 | stat = plugin.registerNode( "groundShadow", GroundShadowNode::id, GroundShadowNode::creator, GroundShadowNode::initialize ); 22 | if ( !stat ) 23 | { 24 | errStr = "registerNode failed"; 25 | goto error; 26 | } 27 | 28 | return stat; 29 | 30 | error: 31 | 32 | stat.perror( errStr ); 33 | return stat; 34 | } 35 | 36 | MStatus uninitializePlugin( MObject obj) 37 | { 38 | MStatus stat; 39 | MString errStr; 40 | MFnPlugin plugin( obj ); 41 | 42 | stat = plugin.deregisterCommand( "groundShadow" ); 43 | if ( !stat ) 44 | { 45 | errStr = "deregisterCommand failed"; 46 | goto error; 47 | } 48 | 49 | stat = plugin.deregisterNode( GroundShadowNode::id ); 50 | if( !stat ) 51 | { 52 | errStr = "deregisterNode failed"; 53 | goto error; 54 | } 55 | 56 | return stat; 57 | 58 | error: 59 | 60 | stat.perror( errStr ); 61 | return stat; 62 | } 63 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld/HelloWorld.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "HelloWorld"=".\HelloWorld.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = helloWorldCmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | helloWorld.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld/helloWorldCmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | // File: helloWorldCmd.cpp 5 | // 6 | // MEL Command: helloWorld 7 | // 8 | // Author: Maya SDK Wizard 9 | // 10 | 11 | // Includes everything needed to register a simple MEL command with Maya. 12 | // 13 | #include 14 | #include 15 | 16 | // Use helper macro to register a command with Maya. It creates and 17 | // registers a command that does not support undo or redo. The 18 | // created class derives off of MPxCommand. 19 | // 20 | DeclareSimpleCommand( helloWorld, "David Gould", "4.0"); 21 | 22 | MStatus helloWorld::doIt( const MArgList& args ) 23 | // 24 | // Description: 25 | // implements the MEL helloWorld command. 26 | // 27 | // Arguments: 28 | // args - the argument list that was passes to the command from MEL 29 | // 30 | // Return Value: 31 | // MS::kSuccess - command succeeded 32 | // MS::kFailure - command failed (returning this value will cause the 33 | // MEL script that is being run to terminate unless the 34 | // error is caught using a "catch" statement. 35 | // 36 | { 37 | MStatus stat = MS::kSuccess; 38 | 39 | // Since this class is derived off of MPxCommand, you can use the 40 | // inherited methods to return values and set error messages 41 | // 42 | MGlobal::displayInfo( "Hello World\n" ); 43 | 44 | return stat; 45 | } 46 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld2/HelloWorld2.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "HelloWorld2"=".\HelloWorld2.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = helloWorld2Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | helloWorld2.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/HelloWorld2/helloWorld2Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include 5 | #include 6 | #include 7 | 8 | class HelloWorld2Cmd : public MPxCommand 9 | { 10 | public: 11 | virtual MStatus doIt ( const MArgList& ) { MGlobal::displayInfo( "Hello World\n" ); return MS::kSuccess; } 12 | static void *creator() { return new HelloWorld2Cmd; } 13 | }; 14 | 15 | MStatus initializePlugin( MObject obj ) 16 | { 17 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 18 | 19 | MStatus stat; 20 | stat = plugin.registerCommand( "helloWorld2", HelloWorld2Cmd::creator ); 21 | if ( !stat ) 22 | stat.perror( "registerCommand failed"); 23 | 24 | return stat; 25 | } 26 | 27 | MStatus uninitializePlugin( MObject obj ) 28 | { 29 | MFnPlugin plugin( obj ); 30 | 31 | MStatus stat; 32 | stat = plugin.deregisterCommand( "helloWorld2" ); 33 | if ( !stat ) 34 | stat.perror( "deregisterCommand failed" ); 35 | 36 | return stat; 37 | } 38 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | SUBDIRS = BasicLocator BasicLocator2 Clock GoRolling GroundShadow \ 7 | HelloWorld HelloWorld2 Melt Posts1 Posts2 Posts3 \ 8 | Posts4 Posts5 Squash SwirlDeformer SwirlDeformer2 9 | 10 | all: 11 | set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done 12 | 13 | clean: 14 | set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done 15 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = MeltCmd.o MeltNode.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | melt.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/Melt.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Melt"=".\Melt.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/MeltCmd.cpp: -------------------------------------------------------------------------------- 1 | #include "MeltCmd.h" 2 | #include "MeltNode.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | MStatus MeltCmd::doIt ( const MArgList &args ) 15 | { 16 | MStatus stat; 17 | 18 | // Get a list of currently selected objects 19 | MSelectionList selection; 20 | MGlobal::getActiveSelectionList( selection ); 21 | 22 | MTime startTime = MAnimControl::minTime(); 23 | MTime endTime = MAnimControl::maxTime(); 24 | 25 | // Iterate over all the nurbs surfaces nodes 26 | MItSelectionList iter( selection, MFn::kNurbsSurface ); 27 | for ( ; !iter.isDone(); iter.next() ) 28 | { 29 | // Get the shape node 30 | MObject shapeNode; 31 | iter.getDependNode( shapeNode ); 32 | MFnDependencyNode shapeFn( shapeNode ); 33 | 34 | MPlug createPlug = shapeFn.findPlug( "create" ); 35 | 36 | // Determine the input connections to the create plug 37 | MPlugArray srcPlugs; 38 | createPlug.connectedTo( srcPlugs, true, false ); 39 | assert( srcPlugs.length() == 1 ); 40 | MPlug srcPlug = srcPlugs[0]; 41 | 42 | // Create new Melt node 43 | MObject meltNode = dgMod.createNode( MeltNode::id ); 44 | assert( !meltNode.isNull() ); 45 | MFnDependencyNode meltFn( meltNode ); 46 | 47 | MPlug outputSurfacePlug = meltFn.findPlug( "outputSurface" ); 48 | MPlug inputSurfacePlug = meltFn.findPlug( "inputSurface" ); 49 | 50 | // Make the connections 51 | dgMod.disconnect( srcPlug, createPlug ); 52 | dgMod.connect( srcPlug, inputSurfacePlug ); 53 | dgMod.connect( outputSurfacePlug, createPlug ); 54 | 55 | static int i = 0; 56 | MString name = MString("melting") + i++; 57 | dgMod.renameNode( meltNode, name ); 58 | 59 | //MString n( meltFn.name() ); 60 | //MGlobal::displayInfo( "\nMelt node: " + name + " " + shapeFn.name() ); 61 | 62 | MString cmd; 63 | cmd = MString("setKeyframe -at amount -t ") + startTime.value() + " -v " + 0.0 + " " + name; 64 | dgMod.commandToExecute( cmd ); 65 | 66 | //MGlobal::displayInfo( cmd ); 67 | 68 | cmd = MString("setKeyframe -at amount -t ") + endTime.value() + " -v " + 1.0 + " " + name; 69 | dgMod.commandToExecute( cmd ); 70 | 71 | //MGlobal::displayInfo( cmd ); 72 | 73 | /* 74 | //MPlug interestPlug = meltFn.findPlug( "isHistoricallyInteresting 75 | // Setup animation 76 | MPlug amountPlug = meltFn.findPlug( "amount" ); 77 | 78 | MAnimControl::setCurrentTime( startTime ); 79 | amountPlug.setValue( double(0.0) ); 80 | MAnimControl::setCurrentTime( endTime ); 81 | amountPlug.setValue( double(1.0) ); 82 | */ 83 | } 84 | 85 | /* 86 | MAnimControl::setCurrentTime( curTime ); 87 | MAnimControl::setAutoKeyMode( autoKeyOn ); 88 | */ 89 | 90 | return redoIt(); 91 | } 92 | 93 | MStatus MeltCmd::undoIt() 94 | { 95 | return dgMod.undoIt(); 96 | } 97 | 98 | MStatus MeltCmd::redoIt() 99 | { 100 | return dgMod.doIt(); 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/MeltCmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef MELTCMD_H 5 | #define MELTCMD_H 6 | 7 | #include 8 | #include 9 | 10 | class MeltCmd : public MPxCommand 11 | { 12 | public: 13 | virtual MStatus doIt ( const MArgList& ); 14 | virtual MStatus undoIt(); 15 | virtual MStatus redoIt(); 16 | virtual bool isUndoable() const { return true; } 17 | 18 | static void *creator() { return new MeltCmd; } 19 | static MSyntax newSyntax(); 20 | 21 | private: 22 | MDGModifier dgMod; 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/MeltNode.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "MeltNode.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | const MTypeId MeltNode::id( 0x00334 ); 19 | 20 | MObject MeltNode::inputSurface; 21 | MObject MeltNode::outputSurface; 22 | MObject MeltNode::amount; 23 | 24 | MStatus MeltNode::compute( const MPlug& plug, MDataBlock& data ) 25 | { 26 | MStatus stat; 27 | 28 | if( plug == outputSurface ) 29 | { 30 | MDataHandle amountHnd = data.inputValue( amount ); 31 | MDataHandle inputSurfaceHnd = data.inputValue( inputSurface ); 32 | MDataHandle outputSurfaceHnd = data.outputValue( outputSurface ); 33 | 34 | double amt = amountHnd.asDouble(); 35 | MObject inputSurfaceObj = inputSurfaceHnd.asNurbsSurface(); 36 | 37 | MFnNurbsSurfaceData surfaceDataFn; 38 | MObject newSurfaceData = surfaceDataFn.create(); 39 | 40 | MFnNurbsSurface surfaceFn; 41 | surfaceFn.copy( inputSurfaceObj, newSurfaceData ); 42 | surfaceFn.setObject( newSurfaceData ); 43 | 44 | MPointArray pts; 45 | surfaceFn.getCVs( pts ); 46 | 47 | double minHeight = DBL_MAX, maxHeight = DBL_MIN, y; 48 | unsigned int i; 49 | for( i=0; i < pts.length(); i++ ) 50 | { 51 | y = pts[i].y; 52 | if( y < minHeight ) 53 | minHeight = y; 54 | if( y > maxHeight ) 55 | maxHeight = y; 56 | } 57 | 58 | double dist = amt * (maxHeight - minHeight); 59 | MVector vec; 60 | double d; 61 | for( i=0; i < pts.length(); i++ ) 62 | { 63 | MPoint &p = pts[i]; 64 | 65 | p.y -= dist; 66 | if( p.y < minHeight ) 67 | { 68 | d = minHeight - p.y; 69 | 70 | // Spread out by that distance 71 | vec = MVector( p.x, 0.0, p.z ); 72 | double len = vec.length(); 73 | if( len > 1.0e-3 ) 74 | { 75 | double newLen = len + d; 76 | vec *= newLen / len; 77 | p.x = vec.x; 78 | p.z = vec.z; 79 | } 80 | 81 | p.y = minHeight; 82 | } 83 | } 84 | 85 | surfaceFn.setCVs( pts ); 86 | 87 | // Be sure to call this since the surface has changed 88 | surfaceFn.updateSurface(); 89 | 90 | outputSurfaceHnd.set( newSurfaceData ); 91 | 92 | data.setClean( plug ); 93 | } 94 | else 95 | stat = MS::kUnknownParameter; 96 | 97 | return stat; 98 | } 99 | 100 | void *MeltNode::creator() 101 | { 102 | return new MeltNode(); 103 | } 104 | 105 | MStatus MeltNode::initialize() 106 | { 107 | MFnNumericAttribute nAttr; 108 | MFnTypedAttribute tAttr; 109 | 110 | amount = nAttr.create( "amount", "amt", MFnNumericData::kDouble, 0.0 ); 111 | nAttr.setKeyable( true ); 112 | 113 | inputSurface = tAttr.create( "inputSurface", "is", MFnNurbsSurfaceData::kNurbsSurface ); 114 | tAttr.setHidden( true ); 115 | 116 | outputSurface = tAttr.create( "outputSurface", "os", MFnNurbsSurfaceData::kNurbsSurface ); 117 | tAttr.setStorable( false ); 118 | tAttr.setHidden( true ); 119 | 120 | addAttribute( amount ); 121 | addAttribute( inputSurface ); 122 | addAttribute( outputSurface ); 123 | 124 | attributeAffects( amount, outputSurface ); 125 | attributeAffects( inputSurface, outputSurface ); 126 | 127 | return MS::kSuccess; 128 | } -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/MeltNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef MELTNODE_H 5 | #define MELTNODE_H 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class MeltNode : public MPxNode 12 | { 13 | public: 14 | virtual MStatus compute( const MPlug& plug, MDataBlock& data ); 15 | 16 | static void *creator(); 17 | static MStatus initialize(); 18 | 19 | static const MTypeId id; 20 | 21 | public: 22 | static MObject inputSurface; 23 | static MObject outputSurface; 24 | static MObject amount; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Melt/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "MeltNode.h" 5 | #include "MeltCmd.h" 6 | #include 7 | 8 | MStatus initializePlugin( MObject obj ) 9 | { 10 | MStatus stat; 11 | MString errStr; 12 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 13 | 14 | stat = plugin.registerCommand( "melt", MeltCmd::creator ); 15 | if ( !stat ) 16 | { 17 | errStr = "registerCommand failed"; 18 | goto error; 19 | } 20 | 21 | stat = plugin.registerNode( "melt", MeltNode::id, MeltNode::creator, MeltNode::initialize ); 22 | if ( !stat ) 23 | { 24 | errStr = "registerNode failed"; 25 | goto error; 26 | } 27 | 28 | return stat; 29 | 30 | error: 31 | 32 | stat.perror( errStr ); 33 | return stat; 34 | } 35 | 36 | MStatus uninitializePlugin( MObject obj) 37 | { 38 | MStatus stat; 39 | MString errStr; 40 | MFnPlugin plugin( obj ); 41 | 42 | stat = plugin.deregisterCommand( "melt" ); 43 | if ( !stat ) 44 | { 45 | errStr = "deregisterCommand failed"; 46 | goto error; 47 | } 48 | 49 | stat = plugin.deregisterNode( MeltNode::id ); 50 | if( !stat ) 51 | { 52 | errStr = "deregisterNode failed"; 53 | goto error; 54 | } 55 | 56 | return stat; 57 | 58 | error: 59 | 60 | stat.perror( errStr ); 61 | return stat; 62 | } 63 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = posts1Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | posts1.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts1/Posts1.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Posts1"=".\Posts1.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts1/posts1Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class Posts1Cmd : public MPxCommand 14 | { 15 | public: 16 | virtual MStatus doIt ( const MArgList& ); 17 | static void *creator() { return new Posts1Cmd; } 18 | }; 19 | 20 | MStatus Posts1Cmd::doIt ( const MArgList & ) 21 | { 22 | const int nPosts = 5; 23 | const double radius = 0.5; 24 | const double height = 5.0; 25 | 26 | // Get a list of currently selected objects 27 | MSelectionList selection; 28 | MGlobal::getActiveSelectionList( selection ); 29 | 30 | MDagPath dagPath; 31 | MFnNurbsCurve curveFn; 32 | double heightRatio = height / radius; 33 | 34 | // Iterate over the nurbs curves 35 | MItSelectionList iter( selection, MFn::kNurbsCurve ); 36 | for ( ; !iter.isDone(); iter.next() ) 37 | { 38 | // Get the curve and attach it to the function set 39 | iter.getDagPath( dagPath ); 40 | curveFn.setObject( dagPath ); 41 | 42 | // Get the domain of the curve, i.e. its start and end parametric values 43 | double tStart, tEnd; 44 | curveFn.getKnotDomain( tStart, tEnd ); 45 | 46 | MPoint pt; 47 | int i; 48 | double t; 49 | double tIncr = (tEnd - tStart) / (nPosts - 1); 50 | for( i=0, t=tStart; i < nPosts; i++, t += tIncr ) 51 | { 52 | // Get point along curve at parametric position t 53 | curveFn.getPointAtParam( t, pt, MSpace::kWorld ); 54 | pt.y += 0.5 * height; 55 | 56 | MGlobal::executeCommand( MString( "cylinder -pivot ") + pt.x + " " + pt.y + " " + pt.z 57 | + " -radius " + radius + " -axis 0 1 0 -heightRatio " + heightRatio ); 58 | } 59 | } 60 | 61 | return MS::kSuccess; 62 | } 63 | 64 | MStatus initializePlugin( MObject obj ) 65 | { 66 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 67 | 68 | MStatus stat; 69 | stat = plugin.registerCommand( "posts1", Posts1Cmd::creator ); 70 | if ( !stat ) 71 | stat.perror( "registerCommand failed"); 72 | 73 | return stat; 74 | } 75 | 76 | MStatus uninitializePlugin( MObject obj ) 77 | { 78 | MFnPlugin plugin( obj ); 79 | 80 | MStatus stat; 81 | stat = plugin.deregisterCommand( "posts1" ); 82 | if ( !stat ) 83 | stat.perror( "deregisterCommand failed" ); 84 | 85 | return stat; 86 | } 87 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = posts2Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | posts2.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts2/Posts2.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Posts1"=".\Posts2.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts2/posts2Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class Posts2Cmd : public MPxCommand 15 | { 16 | public: 17 | virtual MStatus doIt ( const MArgList& ); 18 | static void *creator() { return new Posts2Cmd; } 19 | }; 20 | 21 | MStatus Posts2Cmd::doIt ( const MArgList &args ) 22 | { 23 | int nPosts = 5; 24 | double radius = 0.5; 25 | double height = 5.0; 26 | 27 | unsigned index; 28 | index = args.flagIndex( "n", "number" ); 29 | if( MArgList::kInvalidArgIndex != index ) 30 | args.get( index+1, nPosts ); 31 | 32 | index = args.flagIndex( "r", "radius" ); 33 | if( MArgList::kInvalidArgIndex != index ) 34 | args.get( index+1, radius ); 35 | 36 | index = args.flagIndex( "h", "height" ); 37 | if( MArgList::kInvalidArgIndex != index ) 38 | args.get( index+1, height ); 39 | 40 | 41 | // Get a list of currently selected objects 42 | MSelectionList selection; 43 | MGlobal::getActiveSelectionList( selection ); 44 | 45 | MDagPath dagPath; 46 | MFnNurbsCurve curveFn; 47 | double heightRatio = height / radius; 48 | 49 | // Iterate over the nurbs curves 50 | MItSelectionList iter( selection, MFn::kNurbsCurve ); 51 | for ( ; !iter.isDone(); iter.next() ) 52 | { 53 | // Get the curve and attach it to the function set 54 | iter.getDagPath( dagPath ); 55 | curveFn.setObject( dagPath ); 56 | 57 | // Get the domain of the curve, i.e. its start and end parametric values 58 | double tStart, tEnd; 59 | curveFn.getKnotDomain( tStart, tEnd ); 60 | 61 | MPoint pt; 62 | int i; 63 | double t; 64 | double tIncr = (tEnd - tStart) / (nPosts - 1); 65 | for( i=0, t=tStart; i < nPosts; i++, t += tIncr ) 66 | { 67 | // Get point along curve at parametric position t 68 | curveFn.getPointAtParam( t, pt, MSpace::kWorld ); 69 | pt.y += 0.5 * height; 70 | 71 | MGlobal::executeCommand( MString( "cylinder -pivot ") + pt.x + " " + pt.y + " " + pt.z 72 | + " -radius " + radius + " -axis 0 1 0 -heightRatio " + heightRatio ); 73 | } 74 | } 75 | 76 | return MS::kSuccess; 77 | } 78 | 79 | MStatus initializePlugin( MObject obj ) 80 | { 81 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 82 | 83 | MStatus stat; 84 | stat = plugin.registerCommand( "posts2", Posts2Cmd::creator ); 85 | if ( !stat ) 86 | stat.perror( "registerCommand failed"); 87 | 88 | return stat; 89 | } 90 | 91 | MStatus uninitializePlugin( MObject obj ) 92 | { 93 | MFnPlugin plugin( obj ); 94 | 95 | MStatus stat; 96 | stat = plugin.deregisterCommand( "posts2" ); 97 | if ( !stat ) 98 | stat.perror( "deregisterCommand failed" ); 99 | 100 | return stat; 101 | } 102 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts3/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = posts3Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | posts3.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts3/Posts3.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Posts3"=".\Posts3.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts3/posts3Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class Posts3Cmd : public MPxCommand 17 | { 18 | public: 19 | virtual MStatus doIt ( const MArgList& ); 20 | static void *creator() { return new Posts3Cmd; } 21 | static MSyntax newSyntax(); 22 | }; 23 | 24 | const char *numberFlag = "-n", *numberLongFlag = "-number"; 25 | const char *radiusFlag = "-r", *radiusLongFlag = "-radius"; 26 | const char *heightFlag = "-h", *heightLongFlag = "-height"; 27 | 28 | MSyntax Posts3Cmd::newSyntax() 29 | { 30 | MSyntax syntax; 31 | 32 | syntax.addFlag( numberFlag, numberLongFlag, MSyntax::kLong ); 33 | syntax.addFlag( radiusFlag, radiusLongFlag, MSyntax::kDouble ); 34 | syntax.addFlag( heightFlag, heightLongFlag, MSyntax::kDouble ); 35 | 36 | return syntax; 37 | } 38 | 39 | MStatus Posts3Cmd::doIt ( const MArgList &args ) 40 | { 41 | int nPosts = 5; 42 | double radius = 0.5; 43 | double height = 5.0; 44 | 45 | MArgDatabase argData( syntax(), args ); 46 | 47 | if( argData.isFlagSet( numberFlag ) ) 48 | argData.getFlagArgument( numberFlag, 0, nPosts ); 49 | 50 | if( argData.isFlagSet( radiusFlag ) ) 51 | argData.getFlagArgument( radiusFlag, 0, radius ); 52 | 53 | if( argData.isFlagSet( heightFlag ) ) 54 | argData.getFlagArgument( heightFlag, 0, height ); 55 | 56 | // Get a list of currently selected objects 57 | MSelectionList selection; 58 | MGlobal::getActiveSelectionList( selection ); 59 | 60 | MDagPath dagPath; 61 | MFnNurbsCurve curveFn; 62 | double heightRatio = height / radius; 63 | 64 | // Iterate over the nurbs curves 65 | MItSelectionList iter( selection, MFn::kNurbsCurve ); 66 | for ( ; !iter.isDone(); iter.next() ) 67 | { 68 | // Get the curve and attach it to the function set 69 | iter.getDagPath( dagPath ); 70 | curveFn.setObject( dagPath ); 71 | 72 | // Get the domain of the curve, i.e. its start and end parametric values 73 | double tStart, tEnd; 74 | curveFn.getKnotDomain( tStart, tEnd ); 75 | 76 | MPoint pt; 77 | int i; 78 | double t; 79 | double tIncr = (tEnd - tStart) / (nPosts - 1); 80 | for( i=0, t=tStart; i < nPosts; i++, t += tIncr ) 81 | { 82 | // Get point along curve at parametric position t 83 | curveFn.getPointAtParam( t, pt, MSpace::kWorld ); 84 | pt.y += 0.5 * height; 85 | 86 | MGlobal::executeCommand( MString( "cylinder -pivot ") + pt.x + " " + pt.y + " " + pt.z 87 | + " -radius " + radius + " -axis 0 1 0 -heightRatio " + heightRatio ); 88 | } 89 | } 90 | 91 | return MS::kSuccess; 92 | } 93 | 94 | MStatus initializePlugin( MObject obj ) 95 | { 96 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 97 | 98 | MStatus stat; 99 | stat = plugin.registerCommand( "posts3", Posts3Cmd::creator, Posts3Cmd::newSyntax ); 100 | if ( !stat ) 101 | stat.perror( "registerCommand failed"); 102 | 103 | return stat; 104 | } 105 | 106 | MStatus uninitializePlugin( MObject obj ) 107 | { 108 | MFnPlugin plugin( obj ); 109 | 110 | MStatus stat; 111 | stat = plugin.deregisterCommand( "posts3" ); 112 | if ( !stat ) 113 | stat.perror( "deregisterCommand failed" ); 114 | 115 | return stat; 116 | } 117 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts4/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = posts4Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | posts4.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts4/Posts4.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Posts4"=".\Posts4.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts4/posts4Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class Posts4Cmd : public MPxCommand 17 | { 18 | public: 19 | virtual MStatus doIt ( const MArgList& ); 20 | static void *creator() { return new Posts4Cmd; } 21 | static MSyntax newSyntax(); 22 | }; 23 | 24 | const char *numberFlag = "-n", *numberLongFlag = "-number"; 25 | const char *radiusFlag = "-r", *radiusLongFlag = "-radius"; 26 | const char *heightFlag = "-he", *heightLongFlag = "-height"; 27 | const char *helpFlag = "-h", *helpLongFlag = "-help"; 28 | 29 | MSyntax Posts4Cmd::newSyntax() 30 | { 31 | MSyntax syntax; 32 | 33 | syntax.addFlag( numberFlag, numberLongFlag, MSyntax::kLong ); 34 | syntax.addFlag( radiusFlag, radiusLongFlag, MSyntax::kDouble ); 35 | syntax.addFlag( heightFlag, heightLongFlag, MSyntax::kDouble ); 36 | syntax.addFlag( helpFlag, helpLongFlag ); 37 | 38 | return syntax; 39 | } 40 | 41 | const char *helpText = 42 | "\nThe posts4 command is used to create a series of posts(cylinders) along all the selected curves." 43 | "\nIt is possible to set the number of posts, as well as their width and height." 44 | "\nFor further details consult the help documentation." 45 | "\nFor quick help use: help posts4"; 46 | 47 | MStatus Posts4Cmd::doIt ( const MArgList &args ) 48 | { 49 | int nPosts = 5; 50 | double radius = 0.5; 51 | double height = 5.0; 52 | 53 | MArgDatabase argData( syntax(), args ); 54 | 55 | if( argData.isFlagSet( numberFlag ) ) 56 | argData.getFlagArgument( numberFlag, 0, nPosts ); 57 | 58 | if( argData.isFlagSet( radiusFlag ) ) 59 | argData.getFlagArgument( radiusFlag, 0, radius ); 60 | 61 | if( argData.isFlagSet( heightFlag ) ) 62 | argData.getFlagArgument( heightFlag, 0, height ); 63 | 64 | if( argData.isFlagSet( helpFlag ) ) 65 | { 66 | setResult( helpText ); 67 | return MS::kSuccess; 68 | } 69 | 70 | // Get a list of currently selected objects 71 | MSelectionList selection; 72 | MGlobal::getActiveSelectionList( selection ); 73 | 74 | MDagPath dagPath; 75 | MFnNurbsCurve curveFn; 76 | double heightRatio = height / radius; 77 | 78 | // Iterate over the nurbs curves 79 | MItSelectionList iter( selection, MFn::kNurbsCurve ); 80 | for ( ; !iter.isDone(); iter.next() ) 81 | { 82 | // Get the curve and attach it to the function set 83 | iter.getDagPath( dagPath ); 84 | curveFn.setObject( dagPath ); 85 | 86 | // Get the domain of the curve, i.e. its start and end parametric values 87 | double tStart, tEnd; 88 | curveFn.getKnotDomain( tStart, tEnd ); 89 | 90 | MPoint pt; 91 | int i; 92 | double t; 93 | double tIncr = (tEnd - tStart) / (nPosts - 1); 94 | for( i=0, t=tStart; i < nPosts; i++, t += tIncr ) 95 | { 96 | // Get point along curve at parametric position t 97 | curveFn.getPointAtParam( t, pt, MSpace::kWorld ); 98 | pt.y += 0.5 * height; 99 | 100 | MGlobal::executeCommand( MString( "cylinder -pivot ") + pt.x + " " + pt.y + " " + pt.z 101 | + " -radius " + radius + " -axis 0 1 0 -heightRatio " + heightRatio ); 102 | } 103 | } 104 | 105 | return MS::kSuccess; 106 | } 107 | 108 | MStatus initializePlugin( MObject obj ) 109 | { 110 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 111 | 112 | MStatus stat; 113 | stat = plugin.registerCommand( "posts4", Posts4Cmd::creator, Posts4Cmd::newSyntax ); 114 | if ( !stat ) 115 | stat.perror( "registerCommand failed"); 116 | 117 | return stat; 118 | } 119 | 120 | MStatus uninitializePlugin( MObject obj ) 121 | { 122 | MFnPlugin plugin( obj ); 123 | 124 | MStatus stat; 125 | stat = plugin.deregisterCommand( "posts4" ); 126 | if ( !stat ) 127 | stat.perror( "deregisterCommand failed" ); 128 | 129 | return stat; 130 | } 131 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts5/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = posts5Cmd.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | posts5.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Posts5/Posts5.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "posts5"=".\posts5.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Squash/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = SquashNode.o pluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | SquashNode.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Squash/Squash.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Squash"=".\Squash.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Squash/SquashNode.h: -------------------------------------------------------------------------------- 1 | #ifndef _SquashNode 2 | #define _SquashNode 3 | // 4 | // Copyright (C) 2001 David Gould 5 | // 6 | // File: SquashNode.h 7 | // 8 | // Dependency Graph Node: Squash 9 | // 10 | // Author: Maya SDK Wizard 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | class Squash : public MPxNode 19 | { 20 | public: 21 | Squash(); 22 | virtual ~Squash(); 23 | 24 | virtual MStatus compute( const MPlug& plug, MDataBlock& data ); 25 | 26 | static void* creator(); 27 | static MStatus initialize(); 28 | 29 | public: 30 | 31 | // There needs to be a MObject handle declared for each attribute that 32 | // the node will have. These handles are needed for getting and setting 33 | // the values later. 34 | // 35 | static MObject input; // Example input attribute 36 | static MObject output; // Example output attribute 37 | 38 | 39 | // The typeid is a unique 32bit indentifier that describes this node. 40 | // It is used to save and retrieve nodes of this type from the binary 41 | // file format. If it is not unique, it will cause file IO problems. 42 | // 43 | static MTypeId id; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Volume-1/Plugins/Squash/pluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | // File: pluginMain.cpp 5 | // 6 | // Author: Maya SDK Wizard 7 | // 8 | 9 | #include "SquashNode.h" 10 | 11 | #include 12 | 13 | MStatus initializePlugin( MObject obj ) 14 | // 15 | // Description: 16 | // this method is called when the plug-in is loaded into Maya. It 17 | // registers all of the services that this plug-in provides with 18 | // Maya. 19 | // 20 | // Arguments: 21 | // obj - a handle to the plug-in object (use MFnPlugin to access it) 22 | // 23 | { 24 | MStatus status; 25 | MFnPlugin plugin( obj, "David Gould", "4.0", "Any"); 26 | 27 | status = plugin.registerNode( "Squash", Squash::id, Squash::creator, 28 | Squash::initialize ); 29 | if (!status) { 30 | status.perror("registerNode"); 31 | return status; 32 | } 33 | 34 | return status; 35 | } 36 | 37 | MStatus uninitializePlugin( MObject obj) 38 | // 39 | // Description: 40 | // this method is called when the plug-in is unloaded from Maya. It 41 | // deregisters all of the services that it was providing. 42 | // 43 | // Arguments: 44 | // obj - a handle to the plug-in object (use MFnPlugin to access it) 45 | // 46 | { 47 | MStatus status; 48 | MFnPlugin plugin( obj ); 49 | 50 | status = plugin.deregisterNode( Squash::id ); 51 | if (!status) { 52 | status.perror("deregisterNode"); 53 | return status; 54 | } 55 | 56 | return status; 57 | } 58 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = SwirlDeformer.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | swirlDeformer.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "SwirlDeformer.h" 5 | #include 6 | 7 | MStatus initializePlugin( MObject obj ) 8 | { 9 | MStatus stat; 10 | MString errStr; 11 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 12 | 13 | stat = plugin.registerNode( SwirlDeformer::typeName, 14 | SwirlDeformer::typeId, 15 | SwirlDeformer::creator, 16 | SwirlDeformer::initialize, 17 | MPxNode::kDeformerNode ); 18 | if ( !stat ) 19 | { 20 | errStr = "registerNode failed"; 21 | goto error; 22 | } 23 | 24 | return stat; 25 | 26 | error: 27 | 28 | stat.perror( errStr ); 29 | return stat; 30 | } 31 | 32 | MStatus uninitializePlugin( MObject obj) 33 | { 34 | MStatus stat; 35 | MString errStr; 36 | MFnPlugin plugin( obj ); 37 | 38 | stat = plugin.deregisterNode( SwirlDeformer::typeId ); 39 | if( !stat ) 40 | { 41 | errStr = "deregisterNode failed"; 42 | goto error; 43 | } 44 | 45 | return stat; 46 | 47 | error: 48 | 49 | stat.perror( errStr ); 50 | return stat; 51 | } 52 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer/SwirlDeformer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "SwirlDeformer.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | MTypeId SwirlDeformer::typeId( 0x0033A ); 11 | MString SwirlDeformer::typeName( "swirl" ); 12 | 13 | // Attributes 14 | MObject SwirlDeformer::startDist; 15 | MObject SwirlDeformer::endDist; 16 | 17 | void *SwirlDeformer::creator() 18 | { 19 | return new SwirlDeformer(); 20 | } 21 | 22 | MStatus SwirlDeformer::deform( MDataBlock& block, MItGeometry &iter, 23 | const MMatrix &localToWorld, unsigned int geomIndex ) 24 | { 25 | MStatus stat; 26 | 27 | MDataHandle envData = block.inputValue( envelope ); 28 | float env = envData.asFloat(); 29 | if( env == 0.0 ) // Deformer has no effect 30 | return MS::kSuccess; 31 | 32 | MDataHandle startDistHnd = block.inputValue( startDist ); 33 | double startDist = startDistHnd.asDouble(); 34 | 35 | MDataHandle endDistHnd = block.inputValue( endDist ); 36 | double endDist = endDistHnd.asDouble(); 37 | 38 | MPoint pt; 39 | float weight; 40 | double dist; 41 | double ang; 42 | double cosAng; 43 | double sinAng; 44 | double x; 45 | double distFactor; 46 | for( iter.reset(); !iter.isDone(); iter.next() ) 47 | { 48 | weight = weightValue( block, geomIndex, iter.index() ); 49 | if( weight == 0.0f ) 50 | continue; 51 | 52 | pt = iter.position(); 53 | 54 | dist = sqrt( pt.x * pt.x + pt.z * pt.z ); 55 | if( dist < startDist || dist > endDist ) 56 | continue; 57 | 58 | distFactor = 1 - ((dist - startDist) / (endDist - startDist)); 59 | 60 | ang = distFactor * M_PI * 2.0 * env * weight; 61 | if( ang == 0.0 ) 62 | continue; 63 | 64 | cosAng = cos( ang ); 65 | sinAng = sin( ang ); 66 | x = pt.x * cosAng - pt.z * sinAng; 67 | pt.z = pt.x * sinAng + pt.z * cosAng; 68 | pt.x = x; 69 | 70 | iter.setPosition( pt ); 71 | } 72 | 73 | return stat; 74 | } 75 | 76 | MStatus SwirlDeformer::initialize() 77 | { 78 | MFnUnitAttribute unitFn; 79 | startDist = unitFn.create( "startDist", "sd", MFnUnitAttribute::kDistance ); 80 | unitFn.setDefault( MDistance( 0.0, MDistance::uiUnit() ) ); 81 | unitFn.setMin( MDistance( 0.0, MDistance::uiUnit() ) ); 82 | unitFn.setKeyable( true ); 83 | 84 | endDist = unitFn.create( "endDist", "ed", MFnUnitAttribute::kDistance ); 85 | unitFn.setDefault( MDistance( 3.0, MDistance::uiUnit() ) ); 86 | unitFn.setMin( MDistance( 0.0, MDistance::uiUnit() ) ); 87 | unitFn.setKeyable( true ); 88 | 89 | addAttribute( startDist ); 90 | addAttribute( endDist ); 91 | 92 | attributeAffects( startDist, outputGeom ); 93 | attributeAffects( endDist, outputGeom ); 94 | 95 | return MS::kSuccess; 96 | } 97 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer/SwirlDeformer.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "SwirlDeformer"=".\SwirlDeformer.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer/SwirlDeformer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef SWIRLDEFORMER_H 5 | #define SWIRLDEFORMER_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class SwirlDeformer : public MPxDeformerNode 25 | { 26 | public: 27 | static void *creator(); 28 | static MStatus initialize(); 29 | 30 | virtual MStatus deform( MDataBlock &block, 31 | MItGeometry &iter, 32 | const MMatrix &mat, 33 | unsigned int multiIndex ); 34 | 35 | static MTypeId typeId; 36 | static MString typeName; 37 | 38 | private: 39 | // Attributes 40 | static MObject startDist; 41 | static MObject endDist; 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming" example plugins 3 | # Copyright (c) 2003 David Gould (www.davidgould.com) 4 | # 5 | 6 | C++ = c++ 7 | CFLAGS = -O3 -mpentiumpro -D_BOOL -DLINUX 8 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) 9 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 10 | LD = $(C++) -shared $(C++FLAGS) 11 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 12 | 13 | OBJECTS = SwirlDeformer.o PluginMain.o 14 | 15 | .SUFFIXES: .cpp .o .so 16 | 17 | .cpp.o: 18 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 19 | 20 | .o.so: 21 | $(LD) -o $@ $< $(LIBS) 22 | 23 | .cpp.so: 24 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 25 | 26 | swirlDeformer2.so: $(OBJECTS) 27 | $(LD) -o $@ $(OBJECTS) $(LIBS) 28 | 29 | clean: 30 | -rm -f *.o *.so 31 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer2/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "SwirlDeformer.h" 5 | #include 6 | 7 | MStatus initializePlugin( MObject obj ) 8 | { 9 | MStatus stat; 10 | MString errStr; 11 | MFnPlugin plugin( obj, "David Gould", "1.0", "Any"); 12 | 13 | stat = plugin.registerNode( SwirlDeformer::typeName, 14 | SwirlDeformer::typeId, 15 | SwirlDeformer::creator, 16 | SwirlDeformer::initialize, 17 | MPxNode::kDeformerNode ); 18 | if ( !stat ) 19 | { 20 | errStr = "registerNode failed"; 21 | goto error; 22 | } 23 | 24 | return stat; 25 | 26 | error: 27 | 28 | stat.perror( errStr ); 29 | return stat; 30 | } 31 | 32 | MStatus uninitializePlugin( MObject obj) 33 | { 34 | MStatus stat; 35 | MString errStr; 36 | MFnPlugin plugin( obj ); 37 | 38 | stat = plugin.deregisterNode( SwirlDeformer::typeId ); 39 | if( !stat ) 40 | { 41 | errStr = "deregisterNode failed"; 42 | goto error; 43 | } 44 | 45 | return stat; 46 | 47 | error: 48 | 49 | stat.perror( errStr ); 50 | return stat; 51 | } 52 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer2/SwirlDeformer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #include "SwirlDeformer.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | MTypeId SwirlDeformer::typeId( 0x00339 ); 11 | MString SwirlDeformer::typeName( "swirl" ); 12 | 13 | // Attributes 14 | MObject SwirlDeformer::deformSpace; 15 | MObject SwirlDeformer::startDist; 16 | MObject SwirlDeformer::endDist; 17 | 18 | void *SwirlDeformer::creator() 19 | { 20 | return new SwirlDeformer(); 21 | } 22 | 23 | MStatus SwirlDeformer::deform( MDataBlock& block, MItGeometry &iter, 24 | const MMatrix &localToWorld, unsigned int geomIndex ) 25 | { 26 | MStatus stat; 27 | 28 | MDataHandle envData = block.inputValue( envelope ); 29 | float env = envData.asFloat(); 30 | if( env == 0.0 ) // Deformer has no effect 31 | return MS::kSuccess; 32 | 33 | MDataHandle matData = block.inputValue( deformSpace ); 34 | MMatrix mat = matData.asMatrix(); 35 | MMatrix invMat = mat.inverse(); 36 | 37 | MDataHandle startDistHnd = block.inputValue( startDist ); 38 | double startDist = startDistHnd.asDouble(); 39 | 40 | MDataHandle endDistHnd = block.inputValue( endDist ); 41 | double endDist = endDistHnd.asDouble(); 42 | 43 | MPoint pt; 44 | float weight; 45 | double dist; 46 | double ang; 47 | double cosAng; 48 | double sinAng; 49 | double x; 50 | double distFactor; 51 | for( iter.reset(); !iter.isDone(); iter.next() ) 52 | { 53 | weight = weightValue( block, geomIndex, iter.index() ); 54 | if( weight == 0.0f ) 55 | continue; 56 | 57 | pt = iter.position(); 58 | pt *= invMat; 59 | 60 | dist = sqrt( pt.x * pt.x + pt.z * pt.z ); 61 | if( dist < startDist || dist > endDist ) 62 | continue; 63 | 64 | distFactor = 1 - ((dist - startDist) / (endDist - startDist)); 65 | 66 | ang = distFactor * M_PI * 2.0 * env * weight; 67 | if( ang == 0.0 ) 68 | continue; 69 | 70 | cosAng = cos( ang ); 71 | sinAng = sin( ang ); 72 | x = pt.x * cosAng - pt.z * sinAng; 73 | pt.z = pt.x * sinAng + pt.z * cosAng; 74 | pt.x = x; 75 | 76 | pt *= mat; 77 | 78 | iter.setPosition( pt ); 79 | } 80 | 81 | return stat; 82 | } 83 | 84 | MObject &SwirlDeformer::accessoryAttribute() const 85 | { 86 | return deformSpace; 87 | } 88 | 89 | MStatus SwirlDeformer::accessoryNodeSetup( MDagModifier &dagMod ) 90 | { 91 | MStatus stat; 92 | 93 | MObject locObj = dagMod.createNode( "locator", MObject::kNullObj, &stat ); 94 | if( !stat ) 95 | return stat; 96 | 97 | dagMod.renameNode( locObj, "swirlHandle" ); 98 | 99 | MFnDependencyNode locFn( locObj ); 100 | MObject attrMat = locFn.attribute( "matrix" ); 101 | stat = dagMod.connect( locObj, attrMat, thisMObject(), deformSpace ); 102 | 103 | return stat; 104 | } 105 | 106 | MStatus SwirlDeformer::initialize() 107 | { 108 | MFnMatrixAttribute mAttr; 109 | deformSpace = mAttr.create( "deformSpace", "dSp" ); 110 | mAttr.setStorable( false ); 111 | 112 | MFnUnitAttribute unitFn; 113 | startDist = unitFn.create( "startDist", "sd", MFnUnitAttribute::kDistance ); 114 | unitFn.setDefault( MDistance( 0.0, MDistance::uiUnit() ) ); 115 | unitFn.setMin( MDistance( 0.0, MDistance::uiUnit() ) ); 116 | unitFn.setKeyable( true ); 117 | 118 | endDist = unitFn.create( "endDist", "ed", MFnUnitAttribute::kDistance ); 119 | unitFn.setDefault( MDistance( 3.0, MDistance::uiUnit() ) ); 120 | unitFn.setMin( MDistance( 0.0, MDistance::uiUnit() ) ); 121 | unitFn.setKeyable( true ); 122 | 123 | addAttribute( deformSpace ); 124 | addAttribute( startDist ); 125 | addAttribute( endDist ); 126 | 127 | attributeAffects( deformSpace, outputGeom ); 128 | attributeAffects( startDist, outputGeom ); 129 | attributeAffects( endDist, outputGeom ); 130 | 131 | return MS::kSuccess; 132 | } 133 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer2/SwirlDeformer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2001 David Gould 3 | // 4 | #ifndef SWIRLDEFORMER_H 5 | #define SWIRLDEFORMER_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class SwirlDeformer : public MPxDeformerNode 25 | { 26 | public: 27 | static void *creator(); 28 | static MStatus initialize(); 29 | 30 | virtual MStatus deform( MDataBlock &block, 31 | MItGeometry &iter, 32 | const MMatrix &mat, 33 | unsigned int multiIndex ); 34 | 35 | virtual MObject &accessoryAttribute() const; 36 | virtual MStatus accessoryNodeSetup( MDagModifier &cmd ); 37 | 38 | static MTypeId typeId; 39 | static MString typeName; 40 | 41 | private: 42 | // Attributes 43 | static MObject deformSpace; 44 | static MObject startDist; 45 | static MObject endDist; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Volume-1/Plugins/SwirlDeformer2/SwirlDeformer2.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "SwirlDeformer2"=".\SwirlDeformer2.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /Volume-1/ReadMe.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | www.davidgould.com 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | <body bgcolor="#FFFFFF"> 14 | </body> 15 | 16 | 17 | -------------------------------------------------------------------------------- /Volume-1/_notes/dwSiteColumnsMe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Volume-2/Html/DavidGouldStyles.css: -------------------------------------------------------------------------------- 1 | p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 2 | body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 3 | h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14pt} 4 | .DGSymbol { font-family: Symbol; font-size: 12pt} 5 | h2 { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: bold} 6 | input { font-family: Arial, Helvetica, sans-serif; font-size: 9pt} 7 | li { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} 8 | h3 { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold} 9 | .SourceCode { font-family: "Courier New", Courier, mono; font-size: 10pt} 10 | .NoteWell { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #3366FF} 11 | -------------------------------------------------------------------------------- /Volume-2/Html/Images/Note.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-2/Html/Images/Note.gif -------------------------------------------------------------------------------- /Volume-2/MEL Scripts/curveStar.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc curveStar( 6 | float $innerRadius, 7 | float $outerRadius, 8 | int $spikes, 9 | int $degree, 10 | int $periodic 11 | ) 12 | { 13 | // Generate the control vertices 14 | vector $cvs[]; 15 | 16 | int $nSpikeCVs = 2 * $spikes; 17 | float $angleIncr = deg_to_rad(180) / $spikes; 18 | float $angle; 19 | float $x, $y, $z, $r; 20 | int $ci; 21 | for( $ci=0, $angle=0.0; $ci < $nSpikeCVs; $ci++, $angle+=$angleIncr ) 22 | { 23 | if( $ci % 2 ) // Odd 24 | $r = $outerRadius; 25 | else 26 | $r = $innerRadius; 27 | 28 | $x = $r * cos($angle); 29 | $y = 0.0; 30 | $z = $r * sin($angle); 31 | 32 | $cvs[$ci] = << $x, $y, $z >>; 33 | } 34 | 35 | // Duplicate the "degree" number of initial control vertices 36 | for( $ci=0; $ci < $degree; $ci++ ) 37 | $cvs[size($cvs)] = $cvs[$ci]; 38 | 39 | // Generate knots 40 | float $knots[]; 41 | 42 | int $nSpans = size($cvs) - $degree; 43 | int $nKnots = $nSpans + 2 * $degree - 1; 44 | int $ki; 45 | for( $i=-($degree-1), $ki=0; $ki < $nKnots; $i++, $ki++ ) 46 | $knots[$ki] = float($i); 47 | 48 | // Generate the curve command 49 | string $cmd = "curve -degree " + $degree + 50 | " -periodic " + $periodic; 51 | vector $p; 52 | for( $i=0; $i < size($cvs); $i++ ) 53 | { 54 | $p = $cvs[$i]; 55 | $cmd += " -p " + ($p.x) + " " + ($p.y) + " " + ($p.z); 56 | } 57 | for( $i=0; $i < size($knots); $i++ ) 58 | $cmd += " -k " + $knots[$i]; 59 | 60 | evalEcho( $cmd ); 61 | } -------------------------------------------------------------------------------- /Volume-2/MEL Scripts/curveSwirl.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc curveSwirl( 6 | float $radius, 7 | int $nSpans, 8 | int $nRevolutions, 9 | int $degree 10 | ) 11 | { 12 | int $nCVs = $degree + $nSpans; 13 | int $multiplicity = $degree; // Ensures that the curve begins and ends at first and last cvs 14 | 15 | // Generate the control vertices 16 | vector $cvs[]; 17 | float $azimIncr = deg_to_rad( $nRevolutions * float(360) / ($nCVs-1) ); 18 | float $zenIncr = deg_to_rad( float(180) / ($nCVs-1)); 19 | float $azimuth, $zenith, $sinZenith; 20 | float $x, $y, $z; 21 | int $cvi; 22 | for( $i=0, $cvi=0, $azimuth=0.0, $zenith=0.0; 23 | $cvi < $nCVs; 24 | $cvi++, $azimuth+=$azimIncr, $zenith+=$zenIncr ) 25 | { 26 | $sinZenith = sin( $zenith ); 27 | 28 | $x = $radius * $sinZenith * cos($azimuth); 29 | $y = $radius * cos($zenith); 30 | $z = $radius * $sinZenith * sin($azimuth); 31 | 32 | $cvs[$i++] = << $x, $y, $z >>; 33 | } 34 | 35 | // Generate the knot vector 36 | int $span, $m; 37 | float $knots[]; 38 | for( $i=0, $span=0, $i=0; $span <= $nSpans; $span++ ) 39 | { 40 | $knots[$i++] = float($span); 41 | 42 | // First or last knot 43 | if( $span == 0 || $span == $nSpans ) 44 | { 45 | // m is initialized to 1 since one knot has already been appended 46 | // above, that leaves multiplicity-1 knots to be appended 47 | for( $m=1; $m < $multiplicity; $m++ ) 48 | $knots[$i++] = float($span); 49 | } 50 | } 51 | 52 | string $cmd = "curve -degree " + $degree; 53 | vector $p; 54 | for( $i=0; $i < size($cvs); $i++ ) 55 | { 56 | $p = $cvs[$i]; 57 | $cmd += " -p " + ($p.x) + " " + ($p.y) + " " + ($p.z); 58 | } 59 | for( $i=0; $i < size($knots); $i++ ) 60 | $cmd += " -k " + $knots[$i]; 61 | 62 | evalEcho( $cmd ); 63 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveInfo1/CurveInfo1.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-2/Plugins/CurveInfo1/CurveInfo1.ncb -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveInfo1/CurveInfo1Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | DeclareSimpleCommand( curveInfo1, "David Gould", "1.0" ); 16 | 17 | MStatus curveInfo1::doIt( const MArgList& args ) 18 | { 19 | MStatus stat = MS::kSuccess; 20 | 21 | MSelectionList selection; 22 | MGlobal::getActiveSelectionList( selection ); 23 | 24 | MDagPath dagPath; 25 | MObject component; 26 | 27 | const char *formTxt[] = { "Invalid", "Open", "Closed", "Periodic", "Last" }; 28 | double start, end; 29 | int i, nCVs, nKnots; 30 | MPoint pt; 31 | double knot; 32 | 33 | MString txt; 34 | MItSelectionList iter( selection ); 35 | for ( ; !iter.isDone(); iter.next() ) 36 | { 37 | iter.getDagPath( dagPath, component ); 38 | 39 | MFnNurbsCurve curveFn( dagPath, &stat ); 40 | if( stat ) 41 | { 42 | txt += dagPath.fullPathName() + "\n"; 43 | 44 | txt += MString("Length: ") + curveFn.length() + "\n"; 45 | txt += MString("Degree: ") + curveFn.degree() + "\n"; 46 | txt += MString("Form: ") + formTxt[ curveFn.form() ] + "\n"; 47 | txt += MString("Spans: ") + curveFn.numSpans() + "\n"; 48 | 49 | curveFn.getKnotDomain( start, end ); 50 | txt += MString("MinValue: ") + start + " MaxValue: " + end + "\n"; 51 | 52 | nCVs = curveFn.numCVs(); 53 | txt += MString("CVs: ") + nCVs + "\n"; 54 | for( i=0; i < nCVs; i++ ) 55 | { 56 | curveFn.getCV( i, pt, MSpace::kWorld ); 57 | txt += MString(" (") + pt.x + ", " + pt.y + ", " + pt.z + ")"; 58 | } 59 | txt += "\n"; 60 | 61 | nKnots = curveFn.numKnots(); 62 | txt += MString("Knots: ") + nKnots + "\n"; 63 | for( i=0; i < nKnots; i++ ) 64 | { 65 | knot = curveFn.knot( i ); 66 | txt += MString(" ") + knot; 67 | } 68 | txt += "\n"; 69 | } 70 | } 71 | 72 | MGlobal::displayInfo( txt ); 73 | 74 | return MS::kSuccess; 75 | } 76 | -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveInfo1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = CurveInfo1Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | CurveInfo1Cmd.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveInfo2/CurveInfo2Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | DeclareSimpleCommand( curveInfo2, "David Gould", "1.0" ); 17 | 18 | MStatus curveInfo2::doIt( const MArgList& args ) 19 | { 20 | MStatus stat = MS::kSuccess; 21 | 22 | MSelectionList selection; 23 | MGlobal::getActiveSelectionList( selection ); 24 | 25 | MDagPath dagPath; 26 | MObject component; 27 | 28 | const int nSegs = 10; 29 | double start, end, t, tIncr; 30 | int seg; 31 | MPoint pt; 32 | MVector norm, tang; 33 | 34 | MString txt; 35 | MItSelectionList iter( selection ); 36 | for ( ; !iter.isDone(); iter.next() ) 37 | { 38 | iter.getDagPath( dagPath, component ); 39 | 40 | MFnNurbsCurve curveFn( dagPath, &stat ); 41 | if( stat ) 42 | { 43 | txt += dagPath.fullPathName() + "\n"; 44 | 45 | curveFn.getKnotDomain( start, end ); 46 | tIncr = (end - start) / nSegs; 47 | 48 | for( seg=0, t=start; seg < (nSegs+1); seg++, t+=tIncr ) 49 | { 50 | curveFn.getPointAtParam( t, pt, MSpace::kWorld ); 51 | norm = curveFn.normal( t, MSpace::kWorld ); 52 | tang = curveFn.tangent( t, MSpace::kWorld ); 53 | 54 | txt += MString("Segment: ") + seg + "\n"; 55 | txt += MString("Position: (") + pt.x + ", " + pt.y + ", " + pt.z + ")\n"; 56 | txt += MString("Normal: (") + norm.x + ", " + norm.y + ", " + norm.z + ")\n"; 57 | txt += MString("Tangent: (") + tang.x + ", " + tang.y + ", " + tang.z + ")\n"; 58 | } 59 | } 60 | } 61 | 62 | MGlobal::displayInfo( txt ); 63 | 64 | return MS::kSuccess; 65 | } 66 | -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveInfo2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = CurveInfo2Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | CurveInfo2Cmd.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveStar/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = CurveStarCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | CurveStarCmd.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/CurveSwirl/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = CurveSwirlCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | CurveSwirlCmd.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/CmpMeshModifierCmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef CMPMESHMODIFIERCMD_H 9 | #define CMPMESHMODIFIERCMD_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // N.B. This an abstract class since the doIt(MArgList &) function hasn't 29 | // been defined. Derived classes must define this function. 30 | // 31 | class CmpMeshModifierCmd : public MPxCommand 32 | { 33 | public: 34 | CmpMeshModifierCmd(); 35 | 36 | MStatus doIt( const MDagPath &dagPath, 37 | const MTypeId &meshModType ); 38 | virtual MStatus redoIt(); 39 | virtual MStatus undoIt(); 40 | virtual bool isUndoable() const { return true; } 41 | 42 | virtual MStatus initModifierNode( MObject &node, MDagModifier &dagMod ) = 0; 43 | 44 | private: 45 | MDagPath meshShapePath; 46 | MTypeId meshModifierNodeType; 47 | 48 | bool hasHistory; 49 | bool hasInternalTweaks; 50 | bool genHistory; 51 | 52 | enum { N_DAGMODIFIERS=3 }; 53 | MDagModifier dagMods[N_DAGMODIFIERS]; 54 | 55 | MStatus transferTweaks( const MDagPath &shapePath, 56 | MObject &tweakNode, 57 | MDagModifier &dagMod ); 58 | 59 | 60 | MObject copyTransform; // Parent transform of duplicated shape 61 | MObject origMeshData; // Copy of outMesh data when shape has no history, so that it can be undone 62 | }; 63 | 64 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/CmpMeshModifierNode.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include "CmpMeshModifierNode.h" 9 | #include 10 | 11 | MObject CmpMeshModifierNode::inMesh; 12 | MObject CmpMeshModifierNode::outMesh; 13 | 14 | MStatus CmpMeshModifierNode::initialize() 15 | { 16 | MFnTypedAttribute tAttr; 17 | inMesh = tAttr.create( "inMesh", "im", MFnData::kMesh ); 18 | 19 | outMesh = tAttr.create( "outMesh", "om", MFnData::kMesh ); 20 | tAttr.setStorable( false ); 21 | 22 | addAttribute( inMesh ); 23 | addAttribute( outMesh ); 24 | 25 | attributeAffects( inMesh, outMesh ); 26 | 27 | return MS::kSuccess; 28 | } 29 | -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/CmpMeshModifierNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef CMPMESHMODIFIERNODE_H 9 | #define CMPMESHMODIFIERNODE_H 10 | 11 | #include 12 | 13 | class CmpMeshModifierNode : public MPxNode 14 | { 15 | public: 16 | static MStatus initialize(); 17 | 18 | protected: 19 | static MObject inMesh; 20 | static MObject outMesh; 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/DisplaceMeshCmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include "DisplaceMeshCmd.h" 9 | #include "DisplaceMeshNode.h" 10 | #include 11 | 12 | const char *strengthFlag = "-s", *strengthLongFlag = "-strength"; 13 | const char *imageFilenameFlag = "-i", *imageFilenameLongFlag = "-image"; 14 | 15 | MSyntax DisplaceMeshCmd::newSyntax() 16 | { 17 | MSyntax syntax; 18 | 19 | syntax.addFlag( strengthFlag, strengthLongFlag, MSyntax::kDouble ); 20 | syntax.addFlag( imageFilenameFlag, imageFilenameLongFlag, MSyntax::kString ); 21 | 22 | syntax.enableQuery( false ); 23 | syntax.enableEdit( false ); 24 | 25 | return syntax; 26 | } 27 | 28 | MStatus DisplaceMeshCmd::doIt( const MArgList &args ) 29 | { 30 | // Initialize values to defaults 31 | strength = DisplaceMeshNode::strengthDefault(); 32 | imageFilename = DisplaceMeshNode::imageFilenameDefault(); 33 | 34 | // Get the options from the command line 35 | MStatus stat; 36 | MArgDatabase argData( syntax(), args, &stat ); 37 | if( !stat ) 38 | return stat; 39 | 40 | if( argData.isFlagSet( strengthFlag ) ) 41 | argData.getFlagArgument( strengthFlag, 0, strength ); 42 | 43 | if( argData.isFlagSet( imageFilenameFlag ) ) 44 | argData.getFlagArgument( imageFilenameFlag, 0, imageFilename ); 45 | 46 | // Iterate over the meshes 47 | // Get a list of currently selected objects 48 | MSelectionList selection; 49 | MGlobal::getActiveSelectionList( selection ); 50 | 51 | int nSelMeshes = 0; 52 | MDagPath dagPath; 53 | MItSelectionList iter( selection, MFn::kMesh ); 54 | for ( ; !iter.isDone(); iter.next() ) 55 | { 56 | nSelMeshes++; 57 | 58 | // Get DAG path to mesh shape node 59 | iter.getDagPath( dagPath ); 60 | dagPath.extendToShape(); 61 | 62 | break; 63 | } 64 | 65 | if( nSelMeshes == 0 ) 66 | { 67 | MGlobal::displayWarning( "Select one or more meshes" ); 68 | return MS::kFailure; 69 | } 70 | 71 | CmpMeshModifierCmd::doIt( dagPath, DisplaceMeshNode::id ); 72 | 73 | return MS::kSuccess; 74 | } 75 | 76 | void *DisplaceMeshCmd::creator() 77 | { 78 | return new DisplaceMeshCmd; 79 | } 80 | 81 | MStatus DisplaceMeshCmd::initModifierNode( MObject &node, MDagModifier &dagMod ) 82 | // 83 | // This function takes the newly created mesh modifier node and intializes it. 84 | // It should record all the changes it makes to the node in the supplied dagMod object. 85 | // This ensures that the changes can be undone. 86 | // 87 | { 88 | // @@@ to do, initialize the node 89 | //MGlobal::displayInfo( "displaceMesh1's initModifierNode is called" ); 90 | //MGlobal::displayInfo( MString( "s: " ) + strength + " name: " + imageFilename ); 91 | 92 | MFnDependencyNode depFn( node ); 93 | MString name = depFn.name(); 94 | 95 | 96 | dagMod.commandToExecute( MString( "setAttr " ) + name + ".strength " + strength ); 97 | dagMod.commandToExecute( MString( "setAttr -type \"string\"" ) + name + ".imageFilename \"" + imageFilename + "\"" ); 98 | 99 | return MS::kSuccess; 100 | } 101 | 102 | /* 103 | file -f -open -type "mayaAscii" "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/PlaneMeshDetailed.ma";addRecentFile("C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/PlaneMeshDetailed.ma", "mayaAscii"); 104 | displaceMesh -strength 0.1 -image "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition #1/Drafts/Plugins/DisplaceMesh/smiley.jpg"; 105 | */ 106 | -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/DisplaceMeshCmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef DISPLACEMESHCMD_H 9 | #define DISPLACEMESHCMD_H 10 | 11 | #include "CmpMeshModifierCmd.h" 12 | 13 | class DisplaceMeshCmd : public CmpMeshModifierCmd 14 | { 15 | public: 16 | virtual MStatus doIt( const MArgList &args ); 17 | 18 | virtual MStatus DisplaceMeshCmd::initModifierNode( MObject &node, MDagModifier &dagMod ); 19 | 20 | static void *creator(); 21 | static MSyntax newSyntax(); 22 | 23 | private: 24 | double strength; 25 | MString imageFilename; 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/DisplaceMeshNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef DISPLACEMESHNODE_H 9 | #define DISPLACEMESHNODE_H 10 | 11 | #include "CmpMeshModifierNode.h" 12 | 13 | class DisplaceMeshNode : public CmpMeshModifierNode 14 | { 15 | public: 16 | virtual MStatus compute( const MPlug &plug, MDataBlock &data ); 17 | static void *creator(); 18 | static MStatus initialize(); 19 | 20 | static MTypeId id; 21 | 22 | static MObject strength; 23 | static MObject imageFilename; 24 | 25 | static double strengthDefault(); 26 | static MString imageFilenameDefault(); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = CmpMeshModifierCmd.o CmpMeshModifierNode.o DisplaceMeshCmd.o \ 16 | DisplaceMeshNode.o PluginMain.o 17 | 18 | .SUFFIXES: .cpp .o .so 19 | 20 | .cpp.o: 21 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 22 | 23 | .o.so: 24 | $(LD) -o $@ $< $(LIBS) 25 | 26 | .cpp.so: 27 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 28 | 29 | displaceMesh.so: $(OBJECTS) 30 | $(LD) -o $@ $(OBJECTS) $(LIBS) 31 | 32 | clean: 33 | -rm -f *.o *.so 34 | -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include "DisplaceMeshCmd.h" 9 | #include "DisplaceMeshNode.h" 10 | #include 11 | 12 | MStatus initializePlugin( MObject obj ) 13 | { 14 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 15 | 16 | MStatus stat; 17 | stat = plugin.registerCommand( "displaceMesh", 18 | DisplaceMeshCmd::creator, 19 | DisplaceMeshCmd::newSyntax ); 20 | if( !stat ) 21 | { 22 | MGlobal::displayError( MString( "registerCommand failed: " ) + stat.errorString() ); 23 | return stat; 24 | } 25 | 26 | stat = plugin.registerNode( "displaceMesh", 27 | DisplaceMeshNode::id, 28 | DisplaceMeshNode::creator, 29 | DisplaceMeshNode::initialize ); 30 | if( !stat ) 31 | { 32 | MGlobal::displayError( MString( "registerNode failed: " ) + stat.errorString() ); 33 | return stat; 34 | } 35 | 36 | return stat; 37 | } 38 | 39 | MStatus uninitializePlugin( MObject obj ) 40 | { 41 | MFnPlugin plugin( obj ); 42 | 43 | MStatus stat; 44 | stat = plugin.deregisterCommand( "displaceMesh" ); 45 | if ( !stat ) 46 | { 47 | MGlobal::displayError( MString( "deregisterCommand failed: " ) + stat.errorString() ); 48 | return stat; 49 | } 50 | 51 | stat = plugin.deregisterNode( DisplaceMeshNode::id ); 52 | if ( !stat ) 53 | { 54 | MGlobal::displayError( MString( "deregisterNode failed: " ) + stat.errorString() ); 55 | return stat; 56 | } 57 | 58 | return stat; 59 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/DisplaceMesh/smiley.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-2/Plugins/DisplaceMesh/smiley.jpg -------------------------------------------------------------------------------- /Volume-2/Plugins/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | SUBDIRS = CurveInfo1 CurveInfo2 CurveStar \ 9 | CurveSwirl DisplaceMesh MeshBlindData \ 10 | MeshInfo1 MeshInfo2 MeshInfo3 \ 11 | MeshInfo4 MeshInfo5 MeshInfo6 \ 12 | Molecule1 Molecule2 Molecule3 \ 13 | Molecule4 \ 14 | SelectRingContext1 SelectRingContext2 \ 15 | SelectVolumeContext1 \ 16 | SubdCube SubdInfo1 SubdToMesh \ 17 | SubdToNURBS SurfaceInfo1 SurfaceInfo2 \ 18 | Tube 19 | 20 | all: 21 | set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done 22 | 23 | clean: 24 | set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done 25 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshBlindData/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshBlindDataCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshBlindData.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo1Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo1/MeshInfo1Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | DeclareSimpleCommand( meshInfo1, "David Gould", "1.0" ); 15 | 16 | MStatus meshInfo1::doIt( const MArgList& args ) 17 | { 18 | MStatus stat = MS::kSuccess; 19 | 20 | MSelectionList selection; 21 | MGlobal::getActiveSelectionList( selection ); 22 | 23 | MDagPath dagPath; 24 | MObject component; 25 | int vertCount, vertIndex; 26 | 27 | MString txt; 28 | MItSelectionList iter( selection ); 29 | for ( ; !iter.isDone(); iter.next() ) 30 | { 31 | iter.getDagPath( dagPath, component ); 32 | 33 | MItMeshVertex meshIter( dagPath, component, &stat ); 34 | if( stat == MS::kSuccess ) 35 | { 36 | txt += dagPath.fullPathName() + "\n"; 37 | 38 | vertCount = meshIter.count(); 39 | txt += MString("# Vertices: ") + vertCount + "\n"; 40 | 41 | for( ; !meshIter.isDone(); meshIter.next() ) 42 | { 43 | MPoint pt = meshIter.position( MSpace::kWorld ); 44 | 45 | vertIndex = meshIter.index(); 46 | 47 | txt += MString(" ") + vertIndex + ": " + pt.x + ", " + pt.y + ", " + pt.z + "\n"; 48 | } 49 | } 50 | } 51 | 52 | MGlobal::displayInfo( txt ); 53 | 54 | return MS::kSuccess; 55 | } 56 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo2Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo2.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo2/MeshInfo2Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | DeclareSimpleCommand( meshInfo2, "David Gould", "1.0" ); 15 | 16 | MStatus meshInfo2::doIt( const MArgList& args ) 17 | { 18 | MStatus stat = MS::kSuccess; 19 | 20 | MSelectionList selection; 21 | MGlobal::getActiveSelectionList( selection ); 22 | 23 | MDagPath dagPath; 24 | MObject component; 25 | 26 | int edgeCount, v0Index, v1Index, edgeIndex; 27 | MPoint v0, v1; 28 | 29 | MString txt; 30 | MItSelectionList iter( selection ); 31 | for ( ; !iter.isDone(); iter.next() ) 32 | { 33 | iter.getDagPath( dagPath, component ); 34 | 35 | MItMeshEdge edgeIter( dagPath, component, &stat ); 36 | if( stat == MS::kSuccess ) 37 | { 38 | txt += dagPath.fullPathName() + "\n"; 39 | 40 | edgeCount = edgeIter.count(); 41 | txt += MString("# Edges: ") + edgeCount + "\n"; 42 | 43 | for( ; !edgeIter.isDone(); edgeIter.next() ) 44 | { 45 | edgeIndex = edgeIter.index(); 46 | 47 | v0Index = edgeIter.index(0); 48 | v1Index = edgeIter.index(1); 49 | 50 | v0 = edgeIter.point( 0, MSpace::kWorld ); 51 | v1 = edgeIter.point( 1, MSpace::kWorld ); 52 | 53 | txt = txt + "Edge " + edgeIndex + ": " + 54 | v0Index + " (" + v0.x + ", " + v0.y + ", " + v0.z + ") " + 55 | v1Index + " (" + v1.x + ", " + v1.y + ", " + v1.z + ")\n"; 56 | } 57 | } 58 | } 59 | 60 | MGlobal::displayInfo( txt ); 61 | 62 | return MS::kSuccess; 63 | } 64 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo3/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo3Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo3.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo3/MeshInfo3Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | DeclareSimpleCommand( meshInfo3, "David Gould", "1.0" ); 15 | 16 | MStatus meshInfo3::doIt( const MArgList& args ) 17 | { 18 | MStatus stat = MS::kSuccess; 19 | 20 | MSelectionList selection; 21 | MGlobal::getActiveSelectionList( selection ); 22 | 23 | MDagPath dagPath; 24 | MObject component; 25 | 26 | int i, polyCount, polyIndex, vertCount; 27 | MPoint p; 28 | 29 | MString txt; 30 | MItSelectionList iter( selection ); 31 | for ( ; !iter.isDone(); iter.next() ) 32 | { 33 | iter.getDagPath( dagPath, component ); 34 | 35 | MItMeshPolygon polyIter( dagPath, component, &stat ); 36 | if( stat == MS::kSuccess ) 37 | { 38 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; 39 | 40 | polyCount = polyIter.count(); 41 | txt += MString("# Polygons: ") + polyCount + "\n"; 42 | 43 | for( ; !polyIter.isDone(); polyIter.next() ) 44 | { 45 | polyIndex = polyIter.index(); 46 | txt += MString("Poly ") + polyIndex + "\n"; 47 | 48 | vertCount = polyIter.polygonVertexCount(); 49 | txt += MString(" # Verts: ") + vertCount + "\n"; 50 | 51 | for( i=0; i < vertCount; i++ ) 52 | { 53 | p = polyIter.point( i, MSpace::kWorld ); 54 | txt += MString(" (") + p.x + ", " + p.y + ", " + p.z + ")"; 55 | } 56 | 57 | txt += "\n"; 58 | } 59 | } 60 | } 61 | 62 | MGlobal::displayInfo( txt ); 63 | 64 | return MS::kSuccess; 65 | } 66 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo4/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo4Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo4.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo4/MeshInfo4Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | DeclareSimpleCommand( meshInfo4, "David Gould", "1.0" ); 15 | 16 | MStatus meshInfo4::doIt( const MArgList& args ) 17 | { 18 | MStatus stat = MS::kSuccess; 19 | 20 | MSelectionList selection; 21 | MGlobal::getActiveSelectionList( selection ); 22 | 23 | MDagPath dagPath; 24 | MObject component; 25 | 26 | MColor c; 27 | 28 | MString txt; 29 | MItSelectionList iter( selection ); 30 | for ( ; !iter.isDone(); iter.next() ) 31 | { 32 | iter.getDagPath( dagPath, component ); 33 | 34 | MItMeshFaceVertex fvIter( dagPath, component, &stat ); 35 | if( stat == MS::kSuccess ) 36 | { 37 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; 38 | 39 | for( ; !fvIter.isDone(); fvIter.next() ) 40 | { 41 | int vertId = fvIter.vertId(); 42 | int faceId = fvIter.faceId(); 43 | int faceVertId = fvIter.faceVertId(); 44 | 45 | txt += MString(" Face ") + faceId + ": mesh-relative-vertexID (" + vertId + "), face-relative-vertexID (" + faceVertId + ")\n"; 46 | if( fvIter.hasColor() ) 47 | { 48 | fvIter.getColor( c ); 49 | txt += MString(" Color: ") + c.r + ", " + c.g + ", " + c.b + "\n"; 50 | } 51 | else 52 | txt += MString(" no color\n"); 53 | } 54 | } 55 | } 56 | 57 | MGlobal::displayInfo( txt ); 58 | 59 | return MS::kSuccess; 60 | } 61 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo5/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo5Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo5.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo5/MeshInfo5Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | void addData( MString &txt, 17 | const int fIndex, 18 | const int vIndex, 19 | const int fvIndex, 20 | const MVector &fNormal, 21 | const MVector &vNormal, 22 | const MVector &fvNormal 23 | ) 24 | { 25 | txt += MString(" Face: ") + fIndex + " Vertex: " + vIndex + " Face-Vertex: " + fvIndex + "\n"; 26 | txt += MString(" Face Normal: (") + fNormal.x + ", " + fNormal.y + ", " + fNormal.z + ")\n"; 27 | txt += MString(" Vertex Normal: (") + vNormal.x + ", " + vNormal.y + ", " + vNormal.z + ")\n"; 28 | txt += MString(" Face-Vertex Normal: (") + fvNormal.x + ", " + fvNormal.y + ", " + fvNormal.z + ")\n"; 29 | } 30 | 31 | DeclareSimpleCommand( meshInfo5, "David Gould", "1.0" ); 32 | 33 | MStatus meshInfo5::doIt( const MArgList& args ) 34 | { 35 | MStatus stat = MS::kSuccess; 36 | 37 | MSelectionList selection; 38 | MGlobal::getActiveSelectionList( selection ); 39 | 40 | MDagPath dagPath; 41 | MObject component; 42 | 43 | unsigned int i, nVerts; 44 | int fIndex, vIndex, fvIndex; 45 | MVector fNormal, vNormal, fvNormal; 46 | 47 | MString txt; 48 | MItSelectionList iter( selection ); 49 | for ( ; !iter.isDone(); iter.next() ) 50 | { 51 | iter.getDagPath( dagPath, component ); 52 | 53 | MFnMesh meshFn( dagPath ); 54 | 55 | // This handles whole mesh selections and mesh-face component selections 56 | MItMeshPolygon faceIter( dagPath, component, &stat ); 57 | if( stat == MS::kSuccess ) 58 | { 59 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; 60 | 61 | for( ; !faceIter.isDone(); faceIter.next() ) 62 | { 63 | nVerts = faceIter.polygonVertexCount(); 64 | 65 | for( i=0; i < nVerts; i++ ) 66 | { 67 | fvIndex = i; 68 | fIndex = faceIter.index(); 69 | vIndex = faceIter.vertexIndex( i ); 70 | 71 | faceIter.getNormal( fNormal ); 72 | meshFn.getVertexNormal( vIndex, vNormal ); 73 | faceIter.getNormal( fvIndex, fvNormal ); 74 | 75 | addData( txt, fIndex, vIndex, fvIndex, fNormal, vNormal, fvNormal ); 76 | } 77 | } 78 | } 79 | else 80 | { 81 | // This handles mesh-vertex component selections 82 | MItMeshVertex vertIter( dagPath, component, &stat ); 83 | if( stat == MS::kSuccess ) 84 | { 85 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; 86 | 87 | MIntArray faceIds; 88 | MIntArray vertIds; 89 | 90 | for( ; !vertIter.isDone(); vertIter.next() ) 91 | { 92 | vIndex = vertIter.index(); 93 | 94 | vertIter.getNormal( vNormal ); 95 | vertIter.getConnectedFaces( faceIds ); 96 | 97 | for( i=0; i < faceIds.length(); i++ ) 98 | { 99 | fIndex = faceIds[i]; 100 | 101 | meshFn.getPolygonNormal( fIndex, fNormal ); 102 | meshFn.getFaceVertexNormal( fIndex, vIndex, fvNormal ); 103 | meshFn.getPolygonVertices( fIndex, vertIds ); 104 | 105 | for( fvIndex=0; fvIndex < int(vertIds.length()); fvIndex++ ) 106 | { 107 | if( vertIds[fvIndex] == vIndex ) 108 | break; 109 | } 110 | 111 | addData( txt, fIndex, vIndex, fvIndex, fNormal, vNormal, fvNormal ); 112 | } 113 | } 114 | } 115 | } 116 | } 117 | 118 | MGlobal::displayInfo( txt ); 119 | 120 | return MS::kSuccess; 121 | } 122 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo6/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = MeshInfo6Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | meshInfo6.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/MeshInfo6/MeshInfo6Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | DeclareSimpleCommand( meshInfo6, "David Gould", "1.0" ); 16 | 17 | MStatus meshInfo6::doIt( const MArgList& args ) 18 | { 19 | MStatus stat = MS::kSuccess; 20 | 21 | MSelectionList selection; 22 | MGlobal::getActiveSelectionList( selection ); 23 | 24 | MDagPath dagPath; 25 | MObject component; 26 | 27 | unsigned int i; 28 | int fIndex, vIndex; 29 | 30 | MString txt; 31 | MItSelectionList iter( selection ); 32 | for ( ; !iter.isDone(); iter.next() ) 33 | { 34 | iter.getDagPath( dagPath, component ); 35 | 36 | MFnMesh meshFn( dagPath, &stat ); 37 | if( !stat ) 38 | continue; 39 | 40 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; 41 | 42 | MStringArray uvSetNames; 43 | meshFn.getUVSetNames( uvSetNames ); 44 | 45 | for( i=0; i < uvSetNames.length(); i++ ) 46 | { 47 | txt += MString(" UV Set: " ) + uvSetNames[i]; 48 | txt += MString(" # UVs: " ) + meshFn.numUVs(uvSetNames[i]) + "\n"; 49 | } 50 | 51 | MString cUVSetName; 52 | meshFn.getCurrentUVSetName( cUVSetName ); 53 | 54 | txt += MString(" Current UV Set: ") + cUVSetName + "\n"; 55 | 56 | // This handles mesh and mesh-vertex component selections 57 | MItMeshVertex vertIter( dagPath, component, &stat ); 58 | if( !stat ) 59 | continue; 60 | 61 | float2 vUV; 62 | MFloatArray fvUs; 63 | MFloatArray fvVs; 64 | MIntArray faceIds; 65 | MIntArray vertIds; 66 | unsigned int fvIndex; 67 | 68 | for( ; !vertIter.isDone(); vertIter.next() ) 69 | { 70 | vIndex = vertIter.index(); 71 | txt += MString(" Vertex: ") + vIndex + "\n"; 72 | 73 | bool hasUV = false; 74 | 75 | stat = vertIter.getUV( vUV, &cUVSetName ); 76 | if( stat ) 77 | { 78 | txt += MString(" Vertex UV: (") + vUV[0] + ", " + vUV[1] + ")\n"; 79 | hasUV = true; 80 | } 81 | 82 | stat = vertIter.getUVs( fvUs, fvVs, faceIds, &cUVSetName ); 83 | if( stat ) 84 | { 85 | for( i=0; i < faceIds.length(); i++ ) 86 | { 87 | fIndex = faceIds[i]; 88 | 89 | meshFn.getPolygonVertices( fIndex, vertIds ); 90 | 91 | for( fvIndex=0; fvIndex < vertIds.length(); fvIndex++ ) 92 | { 93 | if( vertIds[fvIndex] == vIndex ) 94 | break; 95 | } 96 | 97 | txt += MString(" Face-vertex UV: face,vertex: (") + fIndex + ", " + fvIndex + ") uv: (" + fvUs[i] + ", " + fvVs[i] + ")\n"; 98 | } 99 | hasUV = true; 100 | } 101 | 102 | if( !hasUV ) 103 | txt += " No assigned uv\n"; 104 | } 105 | } 106 | 107 | MGlobal::displayInfo( txt ); 108 | 109 | return MS::kSuccess; 110 | } 111 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = Molecule1Cmd.o MoleculeUtils.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | molecule1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule1/MoleculeUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | 12 | MStatus genBall( 13 | const MPoint ¢re, 14 | const double radius, 15 | const unsigned nSegs, 16 | 17 | int &nPolys, 18 | MPointArray &verts, 19 | MIntArray &polyCounts, 20 | MIntArray &polyConnects 21 | ); 22 | 23 | MStatus genRod( 24 | const MPoint &p0, 25 | const MPoint &p1, 26 | const double radius, 27 | const unsigned nSegs, 28 | 29 | int &nPolys, 30 | MPointArray &verts, 31 | MIntArray &polyCounts, 32 | MIntArray &polyConnects 33 | ); 34 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = Molecule2Cmd.o MoleculeUtils.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | molecule2.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule2/MoleculeUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | MStatus genBall( 14 | const MPoint ¢re, 15 | const double radius, 16 | const unsigned nSegs, 17 | 18 | int &nPolys, 19 | MPointArray &verts, 20 | MIntArray &polyCounts, 21 | MIntArray &polyConnects, 22 | 23 | const bool genUVs, 24 | MFloatArray &uCoords, 25 | MFloatArray &vCoords, 26 | MIntArray &fvUVIDs 27 | ); 28 | 29 | MStatus genRod( 30 | const MPoint &p0, 31 | const MPoint &p1, 32 | const double radius, 33 | const unsigned nSegs, 34 | 35 | int &nPolys, 36 | MPointArray &verts, 37 | MIntArray &polyCounts, 38 | MIntArray &polyConnects, 39 | 40 | const bool genUVs, 41 | MFloatArray &uCoords, 42 | MFloatArray &vCoords, 43 | MIntArray &fvUVIDs 44 | ); 45 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule3/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = Molecule3Cmd.o MoleculeUtils.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | molecule3.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule3/MoleculeUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | MStatus genBall( 14 | const MPoint ¢re, 15 | const double radius, 16 | const unsigned nSegs, 17 | 18 | int &nPolys, 19 | MPointArray &verts, 20 | MIntArray &polyCounts, 21 | MIntArray &polyConnects, 22 | 23 | const bool genUVs, 24 | MFloatArray &uCoords, 25 | MFloatArray &vCoords, 26 | MIntArray &fvUVIDs 27 | ); 28 | 29 | MStatus genRod( 30 | const MPoint &p0, 31 | const MPoint &p1, 32 | const double radius, 33 | const unsigned nSegs, 34 | 35 | int &nPolys, 36 | MPointArray &verts, 37 | MIntArray &polyCounts, 38 | MIntArray &polyConnects, 39 | 40 | const bool genUVs, 41 | MFloatArray &uCoords, 42 | MFloatArray &vCoords, 43 | MIntArray &fvUVIDs 44 | ); 45 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule3/molecule3CreateUI.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule3CreateUI() 6 | { 7 | global string $gMainPolygonsMenu; 8 | 9 | if (`menu -exists $gMainPolygonsMenu`) 10 | { 11 | setParent -menu $gMainPolygonsMenu; 12 | menuItem -divider true molecule3DividerItem; 13 | menuItem -label "Molecule3" 14 | -command "molecule3MenuItemCallback 0" 15 | -annotation "Molecule: Create ball-rod model" 16 | molecule3Item; 17 | menuItem -optionBox true 18 | -command "molecule3MenuItemCallback 1"; 19 | } 20 | else 21 | error "molecule3: Unable to get the \"Polygons\" menu"; 22 | } 23 | 24 | global proc molecule3SetupOptions( int $reset ) 25 | { 26 | if( $reset || !`optionVar -exists "molecule3Radius"` ) 27 | optionVar -floatValue "molecule3Radius" 0.1; 28 | if( $reset || !`optionVar -exists "molecule3Segments"` ) 29 | optionVar -intValue "molecule3Segments" 6; 30 | if( $reset || !`optionVar -exists "molecule3BallRatio"` ) 31 | optionVar -floatValue "molecule3BallRatio" 2.0; 32 | } 33 | 34 | global proc molecule3MenuItemCallback( int $showOptions ) 35 | { 36 | molecule3SetupOptions(0); 37 | if( $showOptions ) 38 | molecule3Window(); 39 | else 40 | molecule3Execute(); 41 | } 42 | 43 | global proc molecule3Execute() 44 | { 45 | // Retrieve the option variables 46 | float $rad = `optionVar -q "molecule3Radius"`; 47 | int $segs = `optionVar -q "molecule3Segments"`; 48 | float $br = `optionVar -q "molecule3BallRatio"`; 49 | 50 | evalEcho( "molecule3 -radius " + $rad + " -segments " + $segs + " -ballRatio " + $br ); 51 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule3/molecule3DeleteUI.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule3DeleteUI() 6 | { 7 | global string $gMainPolygonsMenu; 8 | 9 | if (`menu -exists $gMainPolygonsMenu`) 10 | { 11 | deleteUI -menuItem molecule3DividerItem; 12 | deleteUI -menuItem molecule3Item; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule3/molecule3Window.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule3Window() 6 | { 7 | string $layout = getOptionBox(); 8 | setParent $layout; 9 | setUITemplate -pushTemplate DefaultTemplate; 10 | waitCursor -state 1; 11 | 12 | // Retrieve the option variables 13 | float $rad = `optionVar -q "molecule3Radius"`; 14 | int $segs = `optionVar -q "molecule3Segments"`; 15 | float $br = `optionVar -q "molecule3BallRatio"`; 16 | 17 | // Create the controls for the options 18 | string $parent = `columnLayout -adjustableColumn 1`; 19 | floatSliderGrp -label "Radius" -value $rad -min 0.00001 -max 100 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule3Radius; 20 | intSliderGrp -label "Segments" -value $segs -min 1 -max 60 -fieldMinValue 1 -fieldMaxValue 10000 molecule3Segments; 21 | floatSliderGrp -label "Ball-Rod Ratio" -value $br -min 0.00001 -max 10 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule3BallRatio; 22 | 23 | waitCursor -state 0; 24 | setUITemplate -popTemplate; 25 | 26 | string $applyBtn = getOptionBoxApplyBtn(); 27 | button -edit -label "Create" 28 | -command ("molecule3SaveOptions( \"" + $parent + "\" ); molecule3Execute();") 29 | $applyBtn; 30 | string $saveBtn = getOptionBoxSaveBtn(); 31 | button -edit 32 | -command ("molecule3SaveOptions( \"" + $parent + "\");") 33 | $saveBtn; 34 | string $resetBtn = getOptionBoxResetBtn(); 35 | button -edit 36 | -command "molecule3SetupOptions(1); molecule3UpdateWindow();" 37 | $resetBtn; 38 | 39 | setOptionBoxTitle( "Molecule3 Options" ); 40 | 41 | showOptionBox(); 42 | } 43 | 44 | global proc molecule3SaveOptions( string $parent ) 45 | { 46 | // Get values of controls 47 | setParent $parent; 48 | float $rad = `floatSliderGrp -query -value molecule3Radius`; 49 | int $segs = `intSliderGrp -query -value molecule3Segments`; 50 | float $br = `floatSliderGrp -query -value molecule3BallRatio`; 51 | 52 | // Update option variables 53 | optionVar -floatValue molecule3Radius $rad; 54 | optionVar -intValue molecule3Segments $segs; 55 | optionVar -floatValue molecule3BallRatio $br; 56 | } 57 | 58 | global proc molecule3UpdateWindow() 59 | { 60 | // Retrieve the option variables 61 | float $rad = `optionVar -q "molecule3Radius"`; 62 | int $segs = `optionVar -q "molecule3Segments"`; 63 | float $br = `optionVar -q "molecule3BallRatio"`; 64 | 65 | floatSliderGrp -edit -value $rad "molecule3Radius"; 66 | intSliderGrp -edit -value $segs "molecule3Segments"; 67 | floatSliderGrp -edit -value $br "molecule3BallRatio"; 68 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = Molecule4Cmd.o Molecule4Node.o MoleculeUtils.o PluginMain.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | molecule4.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/Molecule4Cmd.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef MOLECULE4CMD_H 9 | #define MOLECULE4CMD_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class Molecule4Cmd : public MPxCommand 29 | { 30 | public: 31 | virtual MStatus doIt( const MArgList& ); 32 | virtual MStatus redoIt(); 33 | virtual MStatus undoIt(); 34 | virtual bool isUndoable() const { return true; } 35 | 36 | static void *creator() { return new Molecule4Cmd; } 37 | static MSyntax newSyntax(); 38 | 39 | private: 40 | // Command options 41 | MDistance radius; 42 | int segs; 43 | double ballRodRatio; 44 | 45 | // Utility members 46 | MDagModifier dagMods[2]; 47 | MObjectArray moleculeNodes; 48 | MObjectArray meshShapeNodes; 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/Molecule4Node.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef MOLECULE4NODE_H 9 | #define MOLECULE4NODE_H 10 | 11 | #include 12 | #include 13 | 14 | class Molecule4Node : public MPxNode 15 | { 16 | public: 17 | virtual MStatus compute( const MPlug &plug, MDataBlock &data ); 18 | static void *creator(); 19 | static MStatus initialize(); 20 | 21 | static MObject radius; 22 | static MObject segments; 23 | static MObject ballRatio; 24 | static MObject inMesh; 25 | static MObject outMesh; 26 | 27 | static MTypeId id; 28 | 29 | static MDistance radiusDefault(); 30 | static int segmentsDefault(); 31 | static double ballRatioDefault(); 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/MoleculeUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | MStatus genBall( 14 | const MPoint ¢re, 15 | const double radius, 16 | const unsigned nSegs, 17 | 18 | int &nPolys, 19 | MPointArray &verts, 20 | MIntArray &polyCounts, 21 | MIntArray &polyConnects, 22 | 23 | const bool genUVs, 24 | MFloatArray &uCoords, 25 | MFloatArray &vCoords, 26 | MIntArray &fvUVIDs 27 | ); 28 | 29 | MStatus genRod( 30 | const MPoint &p0, 31 | const MPoint &p1, 32 | const double radius, 33 | const unsigned nSegs, 34 | 35 | int &nPolys, 36 | MPointArray &verts, 37 | MIntArray &polyCounts, 38 | MIntArray &polyConnects, 39 | 40 | const bool genUVs, 41 | MFloatArray &uCoords, 42 | MFloatArray &vCoords, 43 | MIntArray &fvUVIDs 44 | ); 45 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/PluginMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include "Molecule4Cmd.h" 9 | #include "Molecule4Node.h" 10 | #include 11 | 12 | MStatus initializePlugin( MObject obj ) 13 | { 14 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 15 | 16 | MStatus stat; 17 | stat = plugin.registerCommand( "molecule4", 18 | Molecule4Cmd::creator, 19 | Molecule4Cmd::newSyntax ); 20 | if( !stat ) 21 | { 22 | MGlobal::displayError( MString( "registerCommand failed: " ) + stat.errorString() ); 23 | return stat; 24 | } 25 | 26 | stat = plugin.registerNode( "molecule4", 27 | Molecule4Node::id, 28 | Molecule4Node::creator, 29 | Molecule4Node::initialize ); 30 | if( !stat ) 31 | { 32 | MGlobal::displayError( MString( "registerNode failed: " ) + stat.errorString() ); 33 | return stat; 34 | } 35 | 36 | stat = plugin.registerUI( "molecule4CreateUI", "molecule4DeleteUI"); 37 | if( !stat ) 38 | { 39 | MGlobal::displayError( MString( "registerUI failed: " ) + stat.errorString() ); 40 | return stat; 41 | } 42 | 43 | return stat; 44 | } 45 | 46 | MStatus uninitializePlugin( MObject obj ) 47 | { 48 | MFnPlugin plugin( obj ); 49 | 50 | MStatus stat; 51 | stat = plugin.deregisterCommand( "molecule4" ); 52 | if ( !stat ) 53 | { 54 | MGlobal::displayError( MString( "deregisterCommand failed: " ) + stat.errorString() ); 55 | return stat; 56 | } 57 | 58 | stat = plugin.deregisterNode( Molecule4Node::id ); 59 | if ( !stat ) 60 | { 61 | MGlobal::displayError( MString( "deregisterNode failed: " ) + stat.errorString() ); 62 | return stat; 63 | } 64 | 65 | return stat; 66 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/molecule4CreateUI.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule4CreateUI() 6 | { 7 | global string $gMainPolygonsMenu; 8 | 9 | if (`menu -exists $gMainPolygonsMenu`) 10 | { 11 | // Force creation of Polygons menu 12 | string $postMenuCmd = `menu -query -postMenuCommand $gMainPolygonsMenu`; 13 | catch( eval( $postMenuCmd ) ); 14 | 15 | setParent -menu $gMainPolygonsMenu; 16 | menuItem -divider true molecule4DividerItem; 17 | menuItem -label "Molecule4" 18 | -command "molecule4MenuItemCallback 0" 19 | -annotation "Molecule: Create ball-rod model" 20 | molecule4Item; 21 | menuItem -optionBox true 22 | -command "molecule4MenuItemCallback 1"; 23 | } 24 | else 25 | error "molecule4: Unable to get the \"Polygons\" menu"; 26 | } 27 | 28 | global proc molecule4SetupOptions( int $reset ) 29 | { 30 | if( $reset || !`optionVar -exists "molecule4Radius"` ) 31 | optionVar -floatValue "molecule4Radius" 0.1; 32 | if( $reset || !`optionVar -exists "molecule4Segments"` ) 33 | optionVar -intValue "molecule4Segments" 6; 34 | if( $reset || !`optionVar -exists "molecule4BallRatio"` ) 35 | optionVar -floatValue "molecule4BallRatio" 2.0; 36 | } 37 | 38 | global proc molecule4MenuItemCallback( int $showOptions ) 39 | { 40 | molecule4SetupOptions(0); 41 | if( $showOptions ) 42 | molecule4Window(); 43 | else 44 | molecule4Execute(); 45 | } 46 | 47 | global proc molecule4Execute() 48 | { 49 | // Retrieve the option variables 50 | float $rad = `optionVar -q "molecule4Radius"`; 51 | int $segs = `optionVar -q "molecule4Segments"`; 52 | float $br = `optionVar -q "molecule4BallRatio"`; 53 | 54 | evalEcho( "molecule4 -radius " + $rad + " -segments " + $segs + " -ballRatio " + $br ); 55 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/molecule4DeleteUI.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule4DeleteUI() 6 | { 7 | global string $gMainPolygonsMenu; 8 | 9 | if (`menu -exists $gMainPolygonsMenu`) 10 | { 11 | deleteUI -menuItem molecule4DividerItem; 12 | deleteUI -menuItem molecule4Item; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Volume-2/Plugins/Molecule4/molecule4Window.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // 4 | 5 | global proc molecule4Window() 6 | { 7 | string $layout = getOptionBox(); 8 | setParent $layout; 9 | setUITemplate -pushTemplate DefaultTemplate; 10 | waitCursor -state 1; 11 | 12 | // Retrieve the option variables 13 | float $rad = `optionVar -q "molecule4Radius"`; 14 | int $segs = `optionVar -q "molecule4Segments"`; 15 | float $br = `optionVar -q "molecule4BallRatio"`; 16 | 17 | // Create the controls for the options 18 | string $parent = `columnLayout -adjustableColumn 1`; 19 | floatSliderGrp -label "Radius" -value $rad -min 0.00001 -max 100 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule4Radius; 20 | intSliderGrp -label "Segments" -value $segs -min 1 -max 60 -fieldMinValue 1 -fieldMaxValue 10000 molecule4Segments; 21 | floatSliderGrp -label "Ball-Rod Ratio" -value $br -min 0.00001 -max 10 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule4BallRatio; 22 | 23 | waitCursor -state 0; 24 | setUITemplate -popTemplate; 25 | 26 | string $applyBtn = getOptionBoxApplyBtn(); 27 | button -edit -label "Create" 28 | -command ("molecule4SaveOptions( \"" + $parent + "\" ); molecule4Execute();") 29 | $applyBtn; 30 | string $saveBtn = getOptionBoxSaveBtn(); 31 | button -edit 32 | -command ("molecule4SaveOptions( \"" + $parent + "\");") 33 | $saveBtn; 34 | string $resetBtn = getOptionBoxResetBtn(); 35 | button -edit 36 | -command "molecule4SetupOptions(1); molecule4UpdateWindow();" 37 | $resetBtn; 38 | 39 | setOptionBoxTitle( "Molecule3 Options" ); 40 | 41 | showOptionBox(); 42 | } 43 | 44 | global proc molecule4SaveOptions( string $parent ) 45 | { 46 | // Get values of controls 47 | setParent $parent; 48 | float $rad = `floatSliderGrp -query -value molecule4Radius`; 49 | int $segs = `intSliderGrp -query -value molecule4Segments`; 50 | float $br = `floatSliderGrp -query -value molecule4BallRatio`; 51 | 52 | // Update option variables 53 | optionVar -floatValue molecule4Radius $rad; 54 | optionVar -intValue molecule4Segments $segs; 55 | optionVar -floatValue molecule4BallRatio $br; 56 | } 57 | 58 | global proc molecule4UpdateWindow() 59 | { 60 | // Retrieve the option variables 61 | float $rad = `optionVar -q "molecule4Radius"`; 62 | int $segs = `optionVar -q "molecule4Segments"`; 63 | float $br = `optionVar -q "molecule4BallRatio"`; 64 | 65 | floatSliderGrp -edit -value $rad "molecule4Radius"; 66 | intSliderGrp -edit -value $segs "molecule4Segments"; 67 | floatSliderGrp -edit -value $br "molecule4BallRatio"; 68 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectRingContext1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SelectRingContext1.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | selectRingContext1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectRingContext2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SelectRingContext2.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | selectRingContext2.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectRingContext2/selectRingContext2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-2/Plugins/SelectRingContext2/selectRingContext2.jpg -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectRingContext2/selectRingContext2Properties.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // www.davidgould.com 4 | // 5 | 6 | global proc selectRingContext2Properties() 7 | { 8 | if( !`control -exists selectRing2` ) 9 | { 10 | setUITemplate -pushTemplate OptionsTemplate; 11 | 12 | string $parent = `toolPropertyWindow -query -location`; 13 | setParent $parent; 14 | 15 | columnLayout selectRing2; 16 | frameLayout -collapsable true -collapse false 17 | -l "Select Ring Settings" selectRing2Frame; 18 | columnLayout selectRing2Options; 19 | $parent = `setParent -query`; 20 | 21 | separator -style "none"; 22 | 23 | checkBoxGrp -ncb 3 24 | -l "Components:" 25 | -l1 "Vertices" 26 | -l2 "Edges" 27 | -l3 "Faces" 28 | selectRing2Components; 29 | 30 | radioButtonGrp -nrb 2 31 | -l "Type:" 32 | -l1 "Ring" 33 | -l2 "Loop" 34 | selectRing2Type; 35 | 36 | setParent ..; 37 | setParent ..; 38 | setParent ..; 39 | 40 | setUITemplate -popTemplate; 41 | } 42 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectRingContext2/selectRingContext2Values.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // www.davidgould.com 4 | // 5 | 6 | global proc selectRingContext2Values( string $ctxName ) 7 | { 8 | string $icon = "selectRingContext2.xpm"; 9 | string $helpTag = "Select Ring"; 10 | toolPropertySetCommon $ctxName $icon $helpTag; 11 | 12 | string $parent = (`toolPropertyWindow -q -location` + "|selectRing2"); 13 | setParent $parent; 14 | 15 | int $selVerts = `selectRingContext2 -q -selectVertices $ctxName`; 16 | int $selEdges = `selectRingContext2 -q -selectEdges $ctxName`; 17 | int $selFaces = `selectRingContext2 -q -selectFaces $ctxName`; 18 | 19 | checkBoxGrp -e 20 | -v1 $selVerts 21 | -cc1 ("selectRingContext2 -e -selectVertices #1 " + $ctxName) 22 | -v2 $selEdges 23 | -cc2 ("selectRingContext2 -e -selectEdges #1 " + $ctxName) 24 | -v3 $selFaces 25 | -cc3 ("selectRingContext2 -e -selectFaces #1 " + $ctxName) 26 | selectRing2Components; 27 | 28 | int $selType = `selectRingContext2 -q -selectType $ctxName`; 29 | 30 | radioButtonGrp -e 31 | -on1 ("selectRingContext2 -e -selectType 0 " + $ctxName) 32 | -on2 ("selectRingContext2 -e -selectType 1 " + $ctxName) 33 | -select (!$selType ? 1 : 2) 34 | selectRing2Type; 35 | 36 | toolPropertySelect selectRing2; 37 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = Plugin.o SelectVolumeContext1.o SelectVolumeLocator1.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | selectVolumeContext1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/Plugin.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include "SelectVolumeContext1.h" 10 | #include "SelectVolumeLocator1.h" 11 | 12 | MStatus initializePlugin( MObject obj ) 13 | { 14 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 15 | 16 | MStatus stat; 17 | 18 | stat = plugin.registerNode( SelectVolumeLocator1::typeName, 19 | SelectVolumeLocator1::typeId, 20 | &SelectVolumeLocator1::creator, &SelectVolumeLocator1::initialize, 21 | MPxNode::kLocatorNode ); 22 | if ( !stat ) 23 | { 24 | stat.perror( "registerNode failed"); 25 | return stat; 26 | } 27 | 28 | stat = plugin.registerContextCommand( SelectVolumeContextCmd1::commandName, 29 | SelectVolumeContextCmd1::creator, 30 | SelectVolumeToolCmd1::commandName, 31 | SelectVolumeToolCmd1::creator, 32 | SelectVolumeToolCmd1::newSyntax ); 33 | if ( !stat ) 34 | stat.perror( "registerContextCommand failed"); 35 | 36 | return stat; 37 | } 38 | 39 | MStatus uninitializePlugin( MObject obj ) 40 | { 41 | MFnPlugin plugin( obj ); 42 | 43 | MStatus stat; 44 | 45 | stat = plugin.deregisterNode( SelectVolumeLocator1::typeId ); 46 | if( !stat ) 47 | { 48 | stat.perror( "deregisterNode failed" ); 49 | return stat; 50 | } 51 | 52 | stat = plugin.deregisterContextCommand( SelectVolumeContextCmd1::commandName, 53 | SelectVolumeToolCmd1::commandName ); 54 | if ( !stat ) 55 | stat.perror( "deregisterContextCommand failed" ); 56 | 57 | return stat; 58 | } 59 | 60 | /* 61 | loadPlugin "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition #1/Drafts/Plugins/SelectVolumeContext1/Debug/selectVolumeContext1.mll"; 62 | 63 | file -f -open -type "mayaBinary" "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/tmp9.mb";addRecentFile("C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/tmp9.mb", "mayaBinary"); 64 | setToolTo `selectVolumeContext1`; 65 | 66 | 67 | selectVolumeToolCmd1 -sphere 0.5 0 0.5 0.35 -sphere 0 0 0 0.25; 68 | 69 | selectVolumeToolCmd1 -sphere 0.35 0 0.35 0.1 -sphere 0 0 0 0.25; 70 | selectVolumeToolCmd1 -listAdjust 3 -sphere 0.35 0 0.35 0.1; 71 | 72 | file -f -new;loadPlugin "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition #1/Drafts/Plugins/SelectVolumeContext1/Debug/selectVolumeContext1.mll"; 73 | 74 | file -f -open -type "mayaBinary" "C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/tmp9.mb";addRecentFile("C:/DavidGould.com/Writing/Morgan Kaufmann/Complete Maya Programming II/Edition 0/Drafts/Projects/MayaProgramming/scenes/tmp9.mb", "mayaBinary"); 75 | setToolTo `selectVolumeContext1`; 76 | 77 | unloadPlugin selectVolumeContext1; 78 | 79 | 80 | 81 | createNode selectVolumeLocator1; 82 | 83 | 84 | */ -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/SelectVolumeContext1.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef SELECTVOLUMECONTEXT1_H 9 | #define SELECTVOLUMECONTEXT1_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // 29 | // ToolCommand 30 | // 31 | class SelectVolumeToolCmd1 : public MPxToolCommand 32 | { 33 | public: 34 | SelectVolumeToolCmd1(); 35 | 36 | MStatus doIt( const MArgList &args ); 37 | MStatus redoIt(); 38 | MStatus undoIt(); 39 | bool isUndoable() const { return true; } 40 | MStatus finalize(); 41 | 42 | void setPrevSel( const MSelectionList &sel ) { prevSel = sel; } 43 | void setListAdjust( const MGlobal::ListAdjustment &la ) { listAdjust = la; } 44 | void addSphere( const MPoint &s ); 45 | 46 | static void *creator(); 47 | static MSyntax newSyntax(); 48 | static const MString commandName; 49 | 50 | private: 51 | MSelectionList prevSel; // Previous selection 52 | 53 | MGlobal::ListAdjustment listAdjust; 54 | MPointArray spheres; 55 | 56 | bool inVolume( const MPoint &p ) const; 57 | }; 58 | 59 | // 60 | // Context 61 | // 62 | class SelectVolumeContext1 : public MPxContext 63 | { 64 | public: 65 | SelectVolumeContext1(); 66 | 67 | virtual void toolOnSetup( MEvent &event ); 68 | virtual void toolOffCleanup(); 69 | 70 | virtual MStatus doPress( MEvent &event ); 71 | virtual MStatus doDrag( MEvent &event ); 72 | 73 | virtual void deleteAction(); 74 | virtual void completeAction(); 75 | virtual void abortAction(); 76 | 77 | virtual bool processNumericalInput( const MDoubleArray &values, 78 | const MIntArray &flags, 79 | bool isAbsolute ); 80 | virtual bool feedbackNumericalInput() const; 81 | virtual MSyntax::MArgType argTypeNumericalInput( unsigned index ) const; 82 | 83 | virtual void getClassName( MString &name ) const; 84 | 85 | private: 86 | short pressX, pressY; 87 | short releaseX, releaseY; 88 | bool addNewSphere; 89 | MSelectionList prevSel; 90 | MObject volumeLocatorObj; 91 | MGlobal::ListAdjustment listAdjust; 92 | MPointArray spheres; 93 | 94 | void updateViewport(); 95 | void addSphere( const MPoint &s, bool updateLocator=true ); 96 | void reset(); 97 | MPoint intersectGround( const MPoint &rayOrigin, 98 | const MVector &rayDir ); 99 | 100 | static const MString helpTxt; 101 | }; 102 | 103 | // 104 | // Context Command 105 | // 106 | class SelectVolumeContextCmd1 : public MPxContextCommand 107 | { 108 | public: 109 | virtual MPxContext *makeObj(); 110 | 111 | static void *creator(); 112 | static const MString commandName; 113 | }; 114 | 115 | #endif -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/SelectVolumeLocator1.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #ifndef SELECTVOLUMELOCATOR1_H 9 | #define SELECTVOLUMELOCATOR1_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class SelectVolumeLocator1 : public MPxLocatorNode 29 | { 30 | public: 31 | SelectVolumeLocator1(); 32 | 33 | virtual void draw( M3dView &view, 34 | const MDagPath &path, 35 | M3dView::DisplayStyle style, 36 | M3dView::DisplayStatus status ); 37 | 38 | virtual bool isBounded() const; 39 | virtual MBoundingBox boundingBox() const; 40 | 41 | static void *creator(); 42 | static MStatus initialize(); 43 | 44 | static const MTypeId typeId; 45 | static const MString typeName; 46 | 47 | void addSphere( const MPoint &s ); 48 | void setLastSphereRadius( const double rad ); 49 | void deleteLastSphere(); 50 | void refresh(); 51 | 52 | private: 53 | MPointArray spheres; 54 | 55 | MPointArray circlePts; 56 | void generateCircle( const unsigned int nCirclePts ); 57 | void drawSphere( const MPoint &s ) const; 58 | void drawTube( const MPoint &start, 59 | const MPoint &end ) const; 60 | 61 | static const int N_CIRCLEPTS; 62 | 63 | // Attributes 64 | static MObject tickle; 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/selectVolumeContext1Icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/animformed/complete-maya-programming-book-files/0d6037a4c6ad629c25c19b1af354cd264e502bad/Volume-2/Plugins/SelectVolumeContext1/selectVolumeContext1Icon.jpg -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/selectVolumeContext1Properties.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // www.davidgould.com 4 | // 5 | 6 | global proc selectVolumeContext1Properties() 7 | { 8 | if( !`control -exists selectVolume1` ) 9 | { 10 | setUITemplate -pushTemplate OptionsTemplate; 11 | 12 | string $parent = `toolPropertyWindow -query -location`; 13 | setParent $parent; 14 | 15 | columnLayout selectVolume1; 16 | frameLayout -collapsable true -collapse false 17 | -l "Select Volume Settings" selectVolume1Frame; 18 | columnLayout selectVolume1Options; 19 | $parent = `setParent -query`; 20 | 21 | separator -style "none"; 22 | 23 | text -align "center" 24 | -label "No options"; 25 | 26 | setParent ..; 27 | setParent ..; 28 | setParent ..; 29 | 30 | setUITemplate -popTemplate; 31 | } 32 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SelectVolumeContext1/selectVolumeContext1Values.mel: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2004 David Gould 3 | // www.davidgould.com 4 | // 5 | 6 | global proc selectVolumeContext1Values( string $ctxName ) 7 | { 8 | string $icon = "selectVolumeContext1.xpm"; 9 | string $helpTag = "Select Volume"; 10 | toolPropertySetCommon $ctxName $icon $helpTag; 11 | 12 | string $parent = (`toolPropertyWindow -q -location` + "|selectVolume1"); 13 | setParent $parent; 14 | 15 | toolPropertySelect selectVolume1; 16 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdCube/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SubdCubeCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | subdCube.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdCube/SubdCubeCmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class SubdCubeCmd : public MPxCommand 22 | { 23 | public: 24 | virtual MStatus doIt ( const MArgList& ); 25 | virtual MStatus redoIt(); 26 | virtual MStatus undoIt(); 27 | virtual bool isUndoable() const { return true; } 28 | 29 | static void *creator() { return new SubdCubeCmd; } 30 | 31 | private: 32 | // Subd object created 33 | MObject subdTransform; 34 | }; 35 | 36 | 37 | MStatus SubdCubeCmd::doIt ( const MArgList &args ) 38 | { 39 | return redoIt(); 40 | } 41 | 42 | 43 | MStatus SubdCubeCmd::redoIt() 44 | { 45 | const MPoint pts[8] = 46 | { 47 | MPoint( -0.5, -0.5, 0.5 ), 48 | MPoint( 0.5, -0.5, 0.5 ), 49 | MPoint( 0.5, 0.5, 0.5 ), 50 | MPoint( -0.5, 0.5, 0.5 ), 51 | MPoint( 0.5, -0.5, -0.5 ), 52 | MPoint( 0.5, 0.5, -0.5 ), 53 | MPoint( -0.5, 0.5, -0.5 ), 54 | MPoint( -0.5, -0.5, -0.5 ), 55 | }; 56 | 57 | const int faces[6][4] = 58 | { 59 | { 0, 1, 2, 3 }, 60 | { 1, 4, 5, 2 }, 61 | { 4, 7, 6, 5 }, 62 | { 7, 0, 3, 6 }, 63 | { 2, 5, 6, 3 }, 64 | { 0, 7, 4, 1 } 65 | }; 66 | 67 | MStatus stat; 68 | 69 | unsigned int i, j; 70 | MPointArray verts; 71 | for( i=0; i < 8; i++ ) 72 | verts.append( pts[i] ); 73 | 74 | MIntArray polyCounts, polyConnects; 75 | for( i=0; i < 6; i++ ) 76 | { 77 | polyCounts.append( 4 ); 78 | for( j=0; j < 4; j++ ) 79 | polyConnects.append( faces[i][j] ); 80 | } 81 | 82 | MFnSubd subdFn; 83 | subdTransform = subdFn.createBaseMesh( false, 8, 6, verts, polyCounts, polyConnects ); 84 | 85 | // Put the object into the initial shading group 86 | MString cmd( "sets -e -fe initialShadingGroup " ); 87 | cmd += subdFn.name(); 88 | MGlobal::executeCommand( cmd ); 89 | 90 | cmd = MString("select -r ") + subdFn.name(); 91 | MGlobal::executeCommand( cmd ); 92 | 93 | return stat; 94 | } 95 | 96 | MStatus SubdCubeCmd::undoIt() 97 | { 98 | MFnDagNode dagFn( subdTransform ); 99 | MObject child; 100 | 101 | // N.B. It is important to delete the child shape before 102 | // the transform node, otherwise Maya will crash. 103 | child = dagFn.child(0); 104 | MGlobal::deleteNode( child ); 105 | MGlobal::deleteNode( subdTransform ); 106 | 107 | return MS::kSuccess; 108 | } 109 | 110 | MStatus initializePlugin( MObject obj ) 111 | { 112 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 113 | 114 | MStatus stat; 115 | stat = plugin.registerCommand( "subdCube", 116 | SubdCubeCmd::creator ); 117 | if ( !stat ) 118 | stat.perror( "registerCommand failed"); 119 | 120 | return stat; 121 | } 122 | 123 | MStatus uninitializePlugin( MObject obj ) 124 | { 125 | MFnPlugin plugin( obj ); 126 | 127 | MStatus stat; 128 | stat = plugin.deregisterCommand( "subdCube" ); 129 | if ( !stat ) 130 | stat.perror( "deregisterCommand failed" ); 131 | 132 | return stat; 133 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdInfo1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SubdInfo1Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | subdInfo1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdToMesh/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SubdToMeshCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | subdToMesh.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdToNURBS/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SubdToNURBSCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | subdToNURBS.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SubdToNURBS/SubdToNURBSCmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class SubdToNURBS : public MPxCommand 25 | { 26 | public: 27 | virtual MStatus doIt ( const MArgList& ); 28 | virtual MStatus redoIt(); 29 | virtual MStatus undoIt(); 30 | virtual bool isUndoable() const { return true; } 31 | 32 | static void *creator() { return new SubdToNURBS; } 33 | 34 | private: 35 | // Selected subd objects 36 | MDagPathArray selSubds; 37 | 38 | // Resulting parent transforms of nurbs surfaces 39 | MObjectArray nurbsTransforms; 40 | }; 41 | 42 | MStatus SubdToNURBS::doIt ( const MArgList &args ) 43 | { 44 | // Get a list of currently selected objects 45 | MSelectionList selection; 46 | MGlobal::getActiveSelectionList( selection ); 47 | 48 | // Iterate over the subds 49 | MDagPath dagPath; 50 | MItSelectionList iter( selection, MFn::kSubdiv ); 51 | for ( ; !iter.isDone(); iter.next() ) 52 | { 53 | iter.getDagPath( dagPath ); 54 | selSubds.append( dagPath ); 55 | } 56 | 57 | if( selSubds.length() == 0 ) 58 | { 59 | MGlobal::displayWarning( "Select one or more subd surfaces." ); 60 | return MS::kFailure; 61 | } 62 | 63 | return redoIt(); 64 | } 65 | 66 | MStatus SubdToNURBS::redoIt() 67 | { 68 | MStatus stat; 69 | 70 | nurbsTransforms.clear(); 71 | 72 | MObjectArray nurbsSurfs; 73 | MDagPath dagPath; 74 | unsigned int i; 75 | for( i=0; i < selSubds.length(); i++ ) 76 | { 77 | dagPath = selSubds[i]; 78 | 79 | MFnSubd subdFn( dagPath ); 80 | subdFn.convertToNurbs( nurbsSurfs ); 81 | 82 | MFnDagNode dagFn; 83 | MObject transform; 84 | transform = dagFn.create( "transform", "subdivToNURBS" ); 85 | nurbsTransforms.append( transform ); 86 | 87 | dagFn.setObject( transform ); 88 | unsigned int j; 89 | for( j=0; j < nurbsSurfs.length(); j++ ) 90 | { 91 | dagFn.addChild( nurbsSurfs[j] ); 92 | 93 | // Put the object into the initial shading group 94 | MFnDependencyNode depFn( nurbsSurfs[j] ); 95 | MGlobal::executeCommand( MString("sets -e -fe initialShadingGroup ") + depFn.name() ); 96 | } 97 | } 98 | 99 | // Select transforms 100 | MString cmd( "select -r" ); 101 | for( i=0; i < nurbsTransforms.length(); i++ ) 102 | { 103 | MFnDagNode dagFn( nurbsTransforms[i] ); 104 | cmd += MString(" ") + dagFn.name(); 105 | } 106 | MGlobal::executeCommand( cmd ); 107 | 108 | return stat; 109 | } 110 | 111 | MStatus SubdToNURBS::undoIt() 112 | { 113 | unsigned int i; 114 | for( i=0; i < nurbsTransforms.length(); i++ ) 115 | { 116 | MFnTransform transformFn( nurbsTransforms[i] ); 117 | // N.B. It is important to delete the child shapes before 118 | // the transform node, otherwise Maya will crash. 119 | while( transformFn.childCount() ) 120 | MGlobal::deleteNode( transformFn.child(0) ); 121 | MGlobal::deleteNode( transformFn.object() ); 122 | } 123 | 124 | return MS::kSuccess; 125 | } 126 | 127 | MStatus initializePlugin( MObject obj ) 128 | { 129 | MFnPlugin plugin( obj, "David Gould", "1.0" ); 130 | 131 | MStatus stat; 132 | stat = plugin.registerCommand( "subdToNURBS", 133 | SubdToNURBS::creator ); 134 | if ( !stat ) 135 | stat.perror( "registerCommand failed"); 136 | 137 | return stat; 138 | } 139 | 140 | MStatus uninitializePlugin( MObject obj ) 141 | { 142 | MFnPlugin plugin( obj ); 143 | 144 | MStatus stat; 145 | stat = plugin.deregisterCommand( "subdToNURBS" ); 146 | if ( !stat ) 147 | stat.perror( "deregisterCommand failed" ); 148 | 149 | return stat; 150 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/SurfaceInfo1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SurfaceInfo1Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | surfaceInfo1.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SurfaceInfo1/SurfaceInfo1Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | DeclareSimpleCommand( surfaceInfo1, "David Gould", "1.0" ); 16 | 17 | MStatus surfaceInfo1::doIt( const MArgList& args ) 18 | { 19 | MStatus stat = MS::kSuccess; 20 | 21 | MSelectionList selection; 22 | MGlobal::getActiveSelectionList( selection ); 23 | 24 | MDagPath dagPath; 25 | MObject component; 26 | 27 | const char *formTxt[] = { "Invalid", "Open", "Closed", "Periodic", "Last" }; 28 | double startU, endU, startV, endV; 29 | unsigned int i, j, nCVsU, nCVsV, nKnotsU, nKnotsV; 30 | MPoint pt; 31 | MDoubleArray knots[2]; 32 | 33 | MString txt; 34 | MItSelectionList iter( selection ); 35 | for ( ; !iter.isDone(); iter.next() ) 36 | { 37 | iter.getDagPath( dagPath, component ); 38 | 39 | MFnNurbsSurface surfaceFn( dagPath, &stat ); 40 | if( stat ) 41 | { 42 | txt += dagPath.fullPathName() + "\n"; 43 | 44 | txt += MString("Area: ") + surfaceFn.area() + "\n"; 45 | txt += MString("Degrees: ") + surfaceFn.degreeU() + ", " + surfaceFn.degreeV() + "\n"; 46 | txt += MString("Spans: ") + surfaceFn.numSpansInU() + ", " + surfaceFn.numSpansInV() + "\n"; 47 | txt += MString("Forms: ") + formTxt[ surfaceFn.formInU() ] + ", " + formTxt[ surfaceFn.formInV() ] + "\n"; 48 | 49 | surfaceFn.getKnotDomain( startU, endU, startV, endV ); 50 | txt += MString("Parametric Ranges: [") + startU + ", " + endU + "], [" + startV + ", " + endV + "]\n"; 51 | 52 | nCVsU = surfaceFn.numCVsInU(); 53 | nCVsV = surfaceFn.numCVsInV(); 54 | txt += MString("CVs: ") + nCVsU + ", " + nCVsV + "\n"; 55 | 56 | for( i=0; i < nCVsU; i++ ) 57 | { 58 | for( j=0; j < nCVsV; j++ ) 59 | { 60 | surfaceFn.getCV( i, j, pt, MSpace::kWorld ); 61 | txt += MString(" (") + pt.x + ", " + pt.y + ", " + pt.z + ")"; 62 | } 63 | } 64 | txt += "\n"; 65 | 66 | nKnotsU = surfaceFn.numKnotsInU(); 67 | nKnotsV = surfaceFn.numKnotsInV(); 68 | txt += MString("Knots: ") + nKnotsU + ", " + nKnotsV + "\n"; 69 | 70 | surfaceFn.getKnotsInU( knots[0] ); 71 | surfaceFn.getKnotsInV( knots[1] ); 72 | 73 | for( i=0; i < 2; i++ ) 74 | { 75 | for( j=0; j < knots[i].length(); j++ ) 76 | { 77 | txt += MString(" ") + knots[i][j]; 78 | } 79 | txt += "\n"; 80 | } 81 | } 82 | } 83 | 84 | MGlobal::displayInfo( txt ); 85 | 86 | return MS::kSuccess; 87 | } 88 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SurfaceInfo2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = SurfaceInfo2Cmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | surfaceInfo2.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/Plugins/SurfaceInfo2/SurfaceInfo2Cmd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file accompanies the book "Complete Maya Programming (Volume 2)" 3 | // For further information visit http://www.davidgould.com 4 | // 5 | // Copyright (C) 2004 David Gould 6 | // All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | DeclareSimpleCommand( surfaceInfo2, "David Gould", "1.0" ); 16 | 17 | MStatus surfaceInfo2::doIt( const MArgList& args ) 18 | { 19 | MStatus stat = MS::kSuccess; 20 | 21 | MSelectionList selection; 22 | MGlobal::getActiveSelectionList( selection ); 23 | 24 | MDagPath dagPath; 25 | MObject component; 26 | 27 | const int nSegs = 3; 28 | double startU, endU, startV, endV; 29 | unsigned int segU, segV; 30 | double u, v, uIncr, vIncr; 31 | MPoint pt; 32 | MVector norm, tangU, tangV; 33 | 34 | MString txt; 35 | MItSelectionList iter( selection ); 36 | for ( ; !iter.isDone(); iter.next() ) 37 | { 38 | iter.getDagPath( dagPath, component ); 39 | 40 | MFnNurbsSurface surfaceFn( dagPath, &stat ); 41 | if( stat ) 42 | { 43 | txt += dagPath.fullPathName() + "\n"; 44 | 45 | surfaceFn.getKnotDomain( startU, endU, startV, endV ); 46 | uIncr = (endU - startU) / nSegs; 47 | vIncr = (endV - startV) / nSegs; 48 | 49 | for( segU=0, u=startU; segU < (nSegs+1); segU++, u+=uIncr ) 50 | { 51 | for( segV=0, v=startV; segV < (nSegs+1); segV++, v+=vIncr ) 52 | { 53 | surfaceFn.getPointAtParam( u, v, pt, MSpace::kWorld ); 54 | norm = surfaceFn.normal( u, v, MSpace::kWorld ); 55 | norm.normalize(); 56 | surfaceFn.getTangents( u, v, tangU, tangV, MSpace::kWorld ); 57 | tangU.normalize(); 58 | tangV.normalize(); 59 | 60 | txt += MString("Sample: (") + u + ", " + v + ")\n"; 61 | txt += MString(" Position: (") + pt.x + ", " + pt.y + ", " + pt.z + ")\n"; 62 | txt += MString(" Normal: (") + norm.x + ", " + norm.y + ", " + norm.z + ")\n"; 63 | txt += MString(" Tangent U: (") + tangU.x + ", " + tangU.y + ", " + tangU.z + ")\n"; 64 | txt += MString(" Tangent V: (") + tangV.x + ", " + tangV.y + ", " + tangV.z + ")\n"; 65 | } 66 | } 67 | } 68 | } 69 | 70 | MGlobal::displayInfo( txt ); 71 | 72 | return MS::kSuccess; 73 | } -------------------------------------------------------------------------------- /Volume-2/Plugins/Tube/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins 3 | # Copyright (c) 2005 David Gould (www.davidgould.com) 4 | # 5 | # Tested with Maya 6.0, but may work with other versions 6 | # 7 | 8 | C++ = c++ 9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4 10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords 11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include 12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS) 13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI 14 | 15 | OBJECTS = TubeCmd.o 16 | 17 | .SUFFIXES: .cpp .o .so 18 | 19 | .cpp.o: 20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $< 21 | 22 | .o.so: 23 | $(LD) -o $@ $< $(LIBS) 24 | 25 | .cpp.so: 26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS) 27 | 28 | tube.so: $(OBJECTS) 29 | $(LD) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | clean: 32 | -rm -f *.o *.so 33 | -------------------------------------------------------------------------------- /Volume-2/_notes/dwSiteColumnsMe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------