├── 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 |
12 |
13 |
14 |
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