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/SelectVolumeContext1/selectVolumeContext1Properties.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | // www.davidgould.com
4 | //
5 |
6 | global proc selectVolumeContext1Properties()
7 | {
8 | if( !`control -exists selectVolume1` )
9 | {
10 | setUITemplate -pushTemplate OptionsTemplate;
11 |
12 | string $parent = `toolPropertyWindow -query -location`;
13 | setParent $parent;
14 |
15 | columnLayout selectVolume1;
16 | frameLayout -collapsable true -collapse false
17 | -l "Select Volume Settings" selectVolume1Frame;
18 | columnLayout selectVolume1Options;
19 | $parent = `setParent -query`;
20 |
21 | separator -style "none";
22 |
23 | text -align "center"
24 | -label "No options";
25 |
26 | setParent ..;
27 | setParent ..;
28 | setParent ..;
29 |
30 | setUITemplate -popTemplate;
31 | }
32 | }
--------------------------------------------------------------------------------
/Volume-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/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-2/Plugins/Tube/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = TubeCmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | tube.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule4/Molecule4Node.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #ifndef MOLECULE4NODE_H
9 | #define MOLECULE4NODE_H
10 |
11 | #include
12 | #include
13 |
14 | class Molecule4Node : public MPxNode
15 | {
16 | public:
17 | virtual MStatus compute( const MPlug &plug, MDataBlock &data );
18 | static void *creator();
19 | static MStatus initialize();
20 |
21 | static MObject radius;
22 | static MObject segments;
23 | static MObject ballRatio;
24 | static MObject inMesh;
25 | static MObject outMesh;
26 |
27 | static MTypeId id;
28 |
29 | static MDistance radiusDefault();
30 | static int segmentsDefault();
31 | static double ballRatioDefault();
32 | };
33 |
34 | #endif
--------------------------------------------------------------------------------
/Volume-2/Plugins/SubdCube/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SubdCubeCmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | subdCube.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/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/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/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/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/MeshInfo4/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = MeshInfo4Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | meshInfo4.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/MeshInfo5/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = MeshInfo5Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | meshInfo5.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/MeshInfo6/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = MeshInfo6Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | meshInfo6.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SubdInfo1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SubdInfo1Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | subdInfo1.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SubdToMesh/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SubdToMeshCmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | subdToMesh.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/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/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/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/SubdToNURBS/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SubdToNURBSCmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | subdToNURBS.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SurfaceInfo1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SurfaceInfo1Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | surfaceInfo1.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SurfaceInfo2/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SurfaceInfo2Cmd.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | surfaceInfo2.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/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/Molecule1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = Molecule1Cmd.o MoleculeUtils.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | molecule1.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule2/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = Molecule2Cmd.o MoleculeUtils.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | molecule2.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule3/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = Molecule3Cmd.o MoleculeUtils.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | molecule3.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SelectRingContext1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SelectRingContext1.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | selectRingContext1.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SelectRingContext2/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = SelectRingContext2.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | selectRingContext2.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule4/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = Molecule4Cmd.o Molecule4Node.o MoleculeUtils.o PluginMain.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | molecule4.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/SelectVolumeContext1/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Linux makefile for "Complete Maya Programming (Volume 2)" example plugins
3 | # Copyright (c) 2005 David Gould (www.davidgould.com)
4 | #
5 | # Tested with Maya 6.0, but may work with other versions
6 | #
7 |
8 | C++ = c++
9 | CFLAGS = -O3 -pipe -D_BOOL -DLINUX -mcpu=pentium4
10 | C++FLAGS = $(CFLAGS) $(WARNFLAGS) -Wno-deprecated -fno-gnu-keywords
11 | INCLUDES = -I. -I$(MAYA_LOCATION)/include -I/usr/X11R6/include
12 | LD = $(C++) -shared $(NO_TRANS_LINK) $(C++FLAGS)
13 | LIBS = -L$(MAYA_LOCATION)/lib -lOpenMaya -lOpenMayaAnim -lOpenMayaUI
14 |
15 | OBJECTS = Plugin.o SelectVolumeContext1.o SelectVolumeLocator1.o
16 |
17 | .SUFFIXES: .cpp .o .so
18 |
19 | .cpp.o:
20 | $(C++) -c $(INCLUDES) $(C++FLAGS) $<
21 |
22 | .o.so:
23 | $(LD) -o $@ $< $(LIBS)
24 |
25 | .cpp.so:
26 | $(LD) -o $@ $(INCLUDES) $< $(LIBS)
27 |
28 | selectVolumeContext1.so: $(OBJECTS)
29 | $(LD) -o $@ $(OBJECTS) $(LIBS)
30 |
31 | clean:
32 | -rm -f *.o *.so
33 |
--------------------------------------------------------------------------------
/Volume-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-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-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/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-2/Plugins/Molecule2/MoleculeUtils.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | MStatus genBall(
14 | const MPoint ¢re,
15 | const double radius,
16 | const unsigned nSegs,
17 |
18 | int &nPolys,
19 | MPointArray &verts,
20 | MIntArray &polyCounts,
21 | MIntArray &polyConnects,
22 |
23 | const bool genUVs,
24 | MFloatArray &uCoords,
25 | MFloatArray &vCoords,
26 | MIntArray &fvUVIDs
27 | );
28 |
29 | MStatus genRod(
30 | const MPoint &p0,
31 | const MPoint &p1,
32 | const double radius,
33 | const unsigned nSegs,
34 |
35 | int &nPolys,
36 | MPointArray &verts,
37 | MIntArray &polyCounts,
38 | MIntArray &polyConnects,
39 |
40 | const bool genUVs,
41 | MFloatArray &uCoords,
42 | MFloatArray &vCoords,
43 | MIntArray &fvUVIDs
44 | );
45 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule3/MoleculeUtils.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | MStatus genBall(
14 | const MPoint ¢re,
15 | const double radius,
16 | const unsigned nSegs,
17 |
18 | int &nPolys,
19 | MPointArray &verts,
20 | MIntArray &polyCounts,
21 | MIntArray &polyConnects,
22 |
23 | const bool genUVs,
24 | MFloatArray &uCoords,
25 | MFloatArray &vCoords,
26 | MIntArray &fvUVIDs
27 | );
28 |
29 | MStatus genRod(
30 | const MPoint &p0,
31 | const MPoint &p1,
32 | const double radius,
33 | const unsigned nSegs,
34 |
35 | int &nPolys,
36 | MPointArray &verts,
37 | MIntArray &polyCounts,
38 | MIntArray &polyConnects,
39 |
40 | const bool genUVs,
41 | MFloatArray &uCoords,
42 | MFloatArray &vCoords,
43 | MIntArray &fvUVIDs
44 | );
45 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule4/MoleculeUtils.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | MStatus genBall(
14 | const MPoint ¢re,
15 | const double radius,
16 | const unsigned nSegs,
17 |
18 | int &nPolys,
19 | MPointArray &verts,
20 | MIntArray &polyCounts,
21 | MIntArray &polyConnects,
22 |
23 | const bool genUVs,
24 | MFloatArray &uCoords,
25 | MFloatArray &vCoords,
26 | MIntArray &fvUVIDs
27 | );
28 |
29 | MStatus genRod(
30 | const MPoint &p0,
31 | const MPoint &p1,
32 | const double radius,
33 | const unsigned nSegs,
34 |
35 | int &nPolys,
36 | MPointArray &verts,
37 | MIntArray &polyCounts,
38 | MIntArray &polyConnects,
39 |
40 | const bool genUVs,
41 | MFloatArray &uCoords,
42 | MFloatArray &vCoords,
43 | MIntArray &fvUVIDs
44 | );
45 |
--------------------------------------------------------------------------------
/Volume-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-2/Plugins/SelectRingContext2/selectRingContext2Properties.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | // www.davidgould.com
4 | //
5 |
6 | global proc selectRingContext2Properties()
7 | {
8 | if( !`control -exists selectRing2` )
9 | {
10 | setUITemplate -pushTemplate OptionsTemplate;
11 |
12 | string $parent = `toolPropertyWindow -query -location`;
13 | setParent $parent;
14 |
15 | columnLayout selectRing2;
16 | frameLayout -collapsable true -collapse false
17 | -l "Select Ring Settings" selectRing2Frame;
18 | columnLayout selectRing2Options;
19 | $parent = `setParent -query`;
20 |
21 | separator -style "none";
22 |
23 | checkBoxGrp -ncb 3
24 | -l "Components:"
25 | -l1 "Vertices"
26 | -l2 "Edges"
27 | -l3 "Faces"
28 | selectRing2Components;
29 |
30 | radioButtonGrp -nrb 2
31 | -l "Type:"
32 | -l1 "Ring"
33 | -l2 "Loop"
34 | selectRing2Type;
35 |
36 | setParent ..;
37 | setParent ..;
38 | setParent ..;
39 |
40 | setUITemplate -popTemplate;
41 | }
42 | }
--------------------------------------------------------------------------------
/Volume-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/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/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/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-2/Plugins/SelectRingContext2/selectRingContext2Values.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | // www.davidgould.com
4 | //
5 |
6 | global proc selectRingContext2Values( string $ctxName )
7 | {
8 | string $icon = "selectRingContext2.xpm";
9 | string $helpTag = "Select Ring";
10 | toolPropertySetCommon $ctxName $icon $helpTag;
11 |
12 | string $parent = (`toolPropertyWindow -q -location` + "|selectRing2");
13 | setParent $parent;
14 |
15 | int $selVerts = `selectRingContext2 -q -selectVertices $ctxName`;
16 | int $selEdges = `selectRingContext2 -q -selectEdges $ctxName`;
17 | int $selFaces = `selectRingContext2 -q -selectFaces $ctxName`;
18 |
19 | checkBoxGrp -e
20 | -v1 $selVerts
21 | -cc1 ("selectRingContext2 -e -selectVertices #1 " + $ctxName)
22 | -v2 $selEdges
23 | -cc2 ("selectRingContext2 -e -selectEdges #1 " + $ctxName)
24 | -v3 $selFaces
25 | -cc3 ("selectRingContext2 -e -selectFaces #1 " + $ctxName)
26 | selectRing2Components;
27 |
28 | int $selType = `selectRingContext2 -q -selectType $ctxName`;
29 |
30 | radioButtonGrp -e
31 | -on1 ("selectRingContext2 -e -selectType 0 " + $ctxName)
32 | -on2 ("selectRingContext2 -e -selectType 1 " + $ctxName)
33 | -select (!$selType ? 1 : 2)
34 | selectRing2Type;
35 |
36 | toolPropertySelect selectRing2;
37 | }
--------------------------------------------------------------------------------
/Volume-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/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/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/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/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/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-2/Plugins/Molecule4/Molecule4Cmd.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #ifndef MOLECULE4CMD_H
9 | #define MOLECULE4CMD_H
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | class Molecule4Cmd : public MPxCommand
29 | {
30 | public:
31 | virtual MStatus doIt( const MArgList& );
32 | virtual MStatus redoIt();
33 | virtual MStatus undoIt();
34 | virtual bool isUndoable() const { return true; }
35 |
36 | static void *creator() { return new Molecule4Cmd; }
37 | static MSyntax newSyntax();
38 |
39 | private:
40 | // Command options
41 | MDistance radius;
42 | int segs;
43 | double ballRodRatio;
44 |
45 | // Utility members
46 | MDagModifier dagMods[2];
47 | MObjectArray moleculeNodes;
48 | MObjectArray meshShapeNodes;
49 | };
50 |
51 | #endif
--------------------------------------------------------------------------------
/Volume-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/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-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-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-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-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-2/Plugins/Molecule3/molecule3CreateUI.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | //
4 |
5 | global proc molecule3CreateUI()
6 | {
7 | global string $gMainPolygonsMenu;
8 |
9 | if (`menu -exists $gMainPolygonsMenu`)
10 | {
11 | setParent -menu $gMainPolygonsMenu;
12 | menuItem -divider true molecule3DividerItem;
13 | menuItem -label "Molecule3"
14 | -command "molecule3MenuItemCallback 0"
15 | -annotation "Molecule: Create ball-rod model"
16 | molecule3Item;
17 | menuItem -optionBox true
18 | -command "molecule3MenuItemCallback 1";
19 | }
20 | else
21 | error "molecule3: Unable to get the \"Polygons\" menu";
22 | }
23 |
24 | global proc molecule3SetupOptions( int $reset )
25 | {
26 | if( $reset || !`optionVar -exists "molecule3Radius"` )
27 | optionVar -floatValue "molecule3Radius" 0.1;
28 | if( $reset || !`optionVar -exists "molecule3Segments"` )
29 | optionVar -intValue "molecule3Segments" 6;
30 | if( $reset || !`optionVar -exists "molecule3BallRatio"` )
31 | optionVar -floatValue "molecule3BallRatio" 2.0;
32 | }
33 |
34 | global proc molecule3MenuItemCallback( int $showOptions )
35 | {
36 | molecule3SetupOptions(0);
37 | if( $showOptions )
38 | molecule3Window();
39 | else
40 | molecule3Execute();
41 | }
42 |
43 | global proc molecule3Execute()
44 | {
45 | // Retrieve the option variables
46 | float $rad = `optionVar -q "molecule3Radius"`;
47 | int $segs = `optionVar -q "molecule3Segments"`;
48 | float $br = `optionVar -q "molecule3BallRatio"`;
49 |
50 | evalEcho( "molecule3 -radius " + $rad + " -segments " + $segs + " -ballRatio " + $br );
51 | }
--------------------------------------------------------------------------------
/Volume-2/Plugins/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-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-2/Plugins/Molecule4/molecule4CreateUI.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | //
4 |
5 | global proc molecule4CreateUI()
6 | {
7 | global string $gMainPolygonsMenu;
8 |
9 | if (`menu -exists $gMainPolygonsMenu`)
10 | {
11 | // Force creation of Polygons menu
12 | string $postMenuCmd = `menu -query -postMenuCommand $gMainPolygonsMenu`;
13 | catch( eval( $postMenuCmd ) );
14 |
15 | setParent -menu $gMainPolygonsMenu;
16 | menuItem -divider true molecule4DividerItem;
17 | menuItem -label "Molecule4"
18 | -command "molecule4MenuItemCallback 0"
19 | -annotation "Molecule: Create ball-rod model"
20 | molecule4Item;
21 | menuItem -optionBox true
22 | -command "molecule4MenuItemCallback 1";
23 | }
24 | else
25 | error "molecule4: Unable to get the \"Polygons\" menu";
26 | }
27 |
28 | global proc molecule4SetupOptions( int $reset )
29 | {
30 | if( $reset || !`optionVar -exists "molecule4Radius"` )
31 | optionVar -floatValue "molecule4Radius" 0.1;
32 | if( $reset || !`optionVar -exists "molecule4Segments"` )
33 | optionVar -intValue "molecule4Segments" 6;
34 | if( $reset || !`optionVar -exists "molecule4BallRatio"` )
35 | optionVar -floatValue "molecule4BallRatio" 2.0;
36 | }
37 |
38 | global proc molecule4MenuItemCallback( int $showOptions )
39 | {
40 | molecule4SetupOptions(0);
41 | if( $showOptions )
42 | molecule4Window();
43 | else
44 | molecule4Execute();
45 | }
46 |
47 | global proc molecule4Execute()
48 | {
49 | // Retrieve the option variables
50 | float $rad = `optionVar -q "molecule4Radius"`;
51 | int $segs = `optionVar -q "molecule4Segments"`;
52 | float $br = `optionVar -q "molecule4BallRatio"`;
53 |
54 | evalEcho( "molecule4 -radius " + $rad + " -segments " + $segs + " -ballRatio " + $br );
55 | }
--------------------------------------------------------------------------------
/Volume-2/Plugins/MeshInfo4/MeshInfo4Cmd.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | DeclareSimpleCommand( meshInfo4, "David Gould", "1.0" );
15 |
16 | MStatus meshInfo4::doIt( const MArgList& args )
17 | {
18 | MStatus stat = MS::kSuccess;
19 |
20 | MSelectionList selection;
21 | MGlobal::getActiveSelectionList( selection );
22 |
23 | MDagPath dagPath;
24 | MObject component;
25 |
26 | MColor c;
27 |
28 | MString txt;
29 | MItSelectionList iter( selection );
30 | for ( ; !iter.isDone(); iter.next() )
31 | {
32 | iter.getDagPath( dagPath, component );
33 |
34 | MItMeshFaceVertex fvIter( dagPath, component, &stat );
35 | if( stat == MS::kSuccess )
36 | {
37 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n";
38 |
39 | for( ; !fvIter.isDone(); fvIter.next() )
40 | {
41 | int vertId = fvIter.vertId();
42 | int faceId = fvIter.faceId();
43 | int faceVertId = fvIter.faceVertId();
44 |
45 | txt += MString(" Face ") + faceId + ": mesh-relative-vertexID (" + vertId + "), face-relative-vertexID (" + faceVertId + ")\n";
46 | if( fvIter.hasColor() )
47 | {
48 | fvIter.getColor( c );
49 | txt += MString(" Color: ") + c.r + ", " + c.g + ", " + c.b + "\n";
50 | }
51 | else
52 | txt += MString(" no color\n");
53 | }
54 | }
55 | }
56 |
57 | MGlobal::displayInfo( txt );
58 |
59 | return MS::kSuccess;
60 | }
61 |
--------------------------------------------------------------------------------
/Volume-2/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/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/Molecule4/PluginMain.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include "Molecule4Cmd.h"
9 | #include "Molecule4Node.h"
10 | #include
11 |
12 | MStatus initializePlugin( MObject obj )
13 | {
14 | MFnPlugin plugin( obj, "David Gould", "1.0" );
15 |
16 | MStatus stat;
17 | stat = plugin.registerCommand( "molecule4",
18 | Molecule4Cmd::creator,
19 | Molecule4Cmd::newSyntax );
20 | if( !stat )
21 | {
22 | MGlobal::displayError( MString( "registerCommand failed: " ) + stat.errorString() );
23 | return stat;
24 | }
25 |
26 | stat = plugin.registerNode( "molecule4",
27 | Molecule4Node::id,
28 | Molecule4Node::creator,
29 | Molecule4Node::initialize );
30 | if( !stat )
31 | {
32 | MGlobal::displayError( MString( "registerNode failed: " ) + stat.errorString() );
33 | return stat;
34 | }
35 |
36 | stat = plugin.registerUI( "molecule4CreateUI", "molecule4DeleteUI");
37 | if( !stat )
38 | {
39 | MGlobal::displayError( MString( "registerUI failed: " ) + stat.errorString() );
40 | return stat;
41 | }
42 |
43 | return stat;
44 | }
45 |
46 | MStatus uninitializePlugin( MObject obj )
47 | {
48 | MFnPlugin plugin( obj );
49 |
50 | MStatus stat;
51 | stat = plugin.deregisterCommand( "molecule4" );
52 | if ( !stat )
53 | {
54 | MGlobal::displayError( MString( "deregisterCommand failed: " ) + stat.errorString() );
55 | return stat;
56 | }
57 |
58 | stat = plugin.deregisterNode( Molecule4Node::id );
59 | if ( !stat )
60 | {
61 | MGlobal::displayError( MString( "deregisterNode failed: " ) + stat.errorString() );
62 | return stat;
63 | }
64 |
65 | return stat;
66 | }
--------------------------------------------------------------------------------
/Volume-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-2/Plugins/MeshInfo3/MeshInfo3Cmd.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | DeclareSimpleCommand( meshInfo3, "David Gould", "1.0" );
15 |
16 | MStatus meshInfo3::doIt( const MArgList& args )
17 | {
18 | MStatus stat = MS::kSuccess;
19 |
20 | MSelectionList selection;
21 | MGlobal::getActiveSelectionList( selection );
22 |
23 | MDagPath dagPath;
24 | MObject component;
25 |
26 | int i, polyCount, polyIndex, vertCount;
27 | MPoint p;
28 |
29 | MString txt;
30 | MItSelectionList iter( selection );
31 | for ( ; !iter.isDone(); iter.next() )
32 | {
33 | iter.getDagPath( dagPath, component );
34 |
35 | MItMeshPolygon polyIter( dagPath, component, &stat );
36 | if( stat == MS::kSuccess )
37 | {
38 | txt += MString( "Object: " ) + dagPath.fullPathName() + "\n";
39 |
40 | polyCount = polyIter.count();
41 | txt += MString("# Polygons: ") + polyCount + "\n";
42 |
43 | for( ; !polyIter.isDone(); polyIter.next() )
44 | {
45 | polyIndex = polyIter.index();
46 | txt += MString("Poly ") + polyIndex + "\n";
47 |
48 | vertCount = polyIter.polygonVertexCount();
49 | txt += MString(" # Verts: ") + vertCount + "\n";
50 |
51 | for( i=0; i < vertCount; i++ )
52 | {
53 | p = polyIter.point( i, MSpace::kWorld );
54 | txt += MString(" (") + p.x + ", " + p.y + ", " + p.z + ")";
55 | }
56 |
57 | txt += "\n";
58 | }
59 | }
60 | }
61 |
62 | MGlobal::displayInfo( txt );
63 |
64 | return MS::kSuccess;
65 | }
66 |
--------------------------------------------------------------------------------
/Volume-2/Plugins/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/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/SelectVolumeContext1/SelectVolumeLocator1.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #ifndef SELECTVOLUMELOCATOR1_H
9 | #define SELECTVOLUMELOCATOR1_H
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | class SelectVolumeLocator1 : public MPxLocatorNode
29 | {
30 | public:
31 | SelectVolumeLocator1();
32 |
33 | virtual void draw( M3dView &view,
34 | const MDagPath &path,
35 | M3dView::DisplayStyle style,
36 | M3dView::DisplayStatus status );
37 |
38 | virtual bool isBounded() const;
39 | virtual MBoundingBox boundingBox() const;
40 |
41 | static void *creator();
42 | static MStatus initialize();
43 |
44 | static const MTypeId typeId;
45 | static const MString typeName;
46 |
47 | void addSphere( const MPoint &s );
48 | void setLastSphereRadius( const double rad );
49 | void deleteLastSphere();
50 | void refresh();
51 |
52 | private:
53 | MPointArray spheres;
54 |
55 | MPointArray circlePts;
56 | void generateCircle( const unsigned int nCirclePts );
57 | void drawSphere( const MPoint &s ) const;
58 | void drawTube( const MPoint &start,
59 | const MPoint &end ) const;
60 |
61 | static const int N_CIRCLEPTS;
62 |
63 | // Attributes
64 | static MObject tickle;
65 | };
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/Volume-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/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-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/SurfaceInfo2/SurfaceInfo2Cmd.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | DeclareSimpleCommand( surfaceInfo2, "David Gould", "1.0" );
16 |
17 | MStatus surfaceInfo2::doIt( const MArgList& args )
18 | {
19 | MStatus stat = MS::kSuccess;
20 |
21 | MSelectionList selection;
22 | MGlobal::getActiveSelectionList( selection );
23 |
24 | MDagPath dagPath;
25 | MObject component;
26 |
27 | const int nSegs = 3;
28 | double startU, endU, startV, endV;
29 | unsigned int segU, segV;
30 | double u, v, uIncr, vIncr;
31 | MPoint pt;
32 | MVector norm, tangU, tangV;
33 |
34 | MString txt;
35 | MItSelectionList iter( selection );
36 | for ( ; !iter.isDone(); iter.next() )
37 | {
38 | iter.getDagPath( dagPath, component );
39 |
40 | MFnNurbsSurface surfaceFn( dagPath, &stat );
41 | if( stat )
42 | {
43 | txt += dagPath.fullPathName() + "\n";
44 |
45 | surfaceFn.getKnotDomain( startU, endU, startV, endV );
46 | uIncr = (endU - startU) / nSegs;
47 | vIncr = (endV - startV) / nSegs;
48 |
49 | for( segU=0, u=startU; segU < (nSegs+1); segU++, u+=uIncr )
50 | {
51 | for( segV=0, v=startV; segV < (nSegs+1); segV++, v+=vIncr )
52 | {
53 | surfaceFn.getPointAtParam( u, v, pt, MSpace::kWorld );
54 | norm = surfaceFn.normal( u, v, MSpace::kWorld );
55 | norm.normalize();
56 | surfaceFn.getTangents( u, v, tangU, tangV, MSpace::kWorld );
57 | tangU.normalize();
58 | tangV.normalize();
59 |
60 | txt += MString("Sample: (") + u + ", " + v + ")\n";
61 | txt += MString(" Position: (") + pt.x + ", " + pt.y + ", " + pt.z + ")\n";
62 | txt += MString(" Normal: (") + norm.x + ", " + norm.y + ", " + norm.z + ")\n";
63 | txt += MString(" Tangent U: (") + tangU.x + ", " + tangU.y + ", " + tangU.z + ")\n";
64 | txt += MString(" Tangent V: (") + tangV.x + ", " + tangV.y + ", " + tangV.z + ")\n";
65 | }
66 | }
67 | }
68 | }
69 |
70 | MGlobal::displayInfo( txt );
71 |
72 | return MS::kSuccess;
73 | }
--------------------------------------------------------------------------------
/Volume-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/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-2/Plugins/Molecule3/molecule3Window.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | //
4 |
5 | global proc molecule3Window()
6 | {
7 | string $layout = getOptionBox();
8 | setParent $layout;
9 | setUITemplate -pushTemplate DefaultTemplate;
10 | waitCursor -state 1;
11 |
12 | // Retrieve the option variables
13 | float $rad = `optionVar -q "molecule3Radius"`;
14 | int $segs = `optionVar -q "molecule3Segments"`;
15 | float $br = `optionVar -q "molecule3BallRatio"`;
16 |
17 | // Create the controls for the options
18 | string $parent = `columnLayout -adjustableColumn 1`;
19 | floatSliderGrp -label "Radius" -value $rad -min 0.00001 -max 100 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule3Radius;
20 | intSliderGrp -label "Segments" -value $segs -min 1 -max 60 -fieldMinValue 1 -fieldMaxValue 10000 molecule3Segments;
21 | floatSliderGrp -label "Ball-Rod Ratio" -value $br -min 0.00001 -max 10 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule3BallRatio;
22 |
23 | waitCursor -state 0;
24 | setUITemplate -popTemplate;
25 |
26 | string $applyBtn = getOptionBoxApplyBtn();
27 | button -edit -label "Create"
28 | -command ("molecule3SaveOptions( \"" + $parent + "\" ); molecule3Execute();")
29 | $applyBtn;
30 | string $saveBtn = getOptionBoxSaveBtn();
31 | button -edit
32 | -command ("molecule3SaveOptions( \"" + $parent + "\");")
33 | $saveBtn;
34 | string $resetBtn = getOptionBoxResetBtn();
35 | button -edit
36 | -command "molecule3SetupOptions(1); molecule3UpdateWindow();"
37 | $resetBtn;
38 |
39 | setOptionBoxTitle( "Molecule3 Options" );
40 |
41 | showOptionBox();
42 | }
43 |
44 | global proc molecule3SaveOptions( string $parent )
45 | {
46 | // Get values of controls
47 | setParent $parent;
48 | float $rad = `floatSliderGrp -query -value molecule3Radius`;
49 | int $segs = `intSliderGrp -query -value molecule3Segments`;
50 | float $br = `floatSliderGrp -query -value molecule3BallRatio`;
51 |
52 | // Update option variables
53 | optionVar -floatValue molecule3Radius $rad;
54 | optionVar -intValue molecule3Segments $segs;
55 | optionVar -floatValue molecule3BallRatio $br;
56 | }
57 |
58 | global proc molecule3UpdateWindow()
59 | {
60 | // Retrieve the option variables
61 | float $rad = `optionVar -q "molecule3Radius"`;
62 | int $segs = `optionVar -q "molecule3Segments"`;
63 | float $br = `optionVar -q "molecule3BallRatio"`;
64 |
65 | floatSliderGrp -edit -value $rad "molecule3Radius";
66 | intSliderGrp -edit -value $segs "molecule3Segments";
67 | floatSliderGrp -edit -value $br "molecule3BallRatio";
68 | }
--------------------------------------------------------------------------------
/Volume-2/Plugins/Molecule4/molecule4Window.mel:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2004 David Gould
3 | //
4 |
5 | global proc molecule4Window()
6 | {
7 | string $layout = getOptionBox();
8 | setParent $layout;
9 | setUITemplate -pushTemplate DefaultTemplate;
10 | waitCursor -state 1;
11 |
12 | // Retrieve the option variables
13 | float $rad = `optionVar -q "molecule4Radius"`;
14 | int $segs = `optionVar -q "molecule4Segments"`;
15 | float $br = `optionVar -q "molecule4BallRatio"`;
16 |
17 | // Create the controls for the options
18 | string $parent = `columnLayout -adjustableColumn 1`;
19 | floatSliderGrp -label "Radius" -value $rad -min 0.00001 -max 100 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule4Radius;
20 | intSliderGrp -label "Segments" -value $segs -min 1 -max 60 -fieldMinValue 1 -fieldMaxValue 10000 molecule4Segments;
21 | floatSliderGrp -label "Ball-Rod Ratio" -value $br -min 0.00001 -max 10 -fieldMinValue 0.00001 -fieldMaxValue 10000000 molecule4BallRatio;
22 |
23 | waitCursor -state 0;
24 | setUITemplate -popTemplate;
25 |
26 | string $applyBtn = getOptionBoxApplyBtn();
27 | button -edit -label "Create"
28 | -command ("molecule4SaveOptions( \"" + $parent + "\" ); molecule4Execute();")
29 | $applyBtn;
30 | string $saveBtn = getOptionBoxSaveBtn();
31 | button -edit
32 | -command ("molecule4SaveOptions( \"" + $parent + "\");")
33 | $saveBtn;
34 | string $resetBtn = getOptionBoxResetBtn();
35 | button -edit
36 | -command "molecule4SetupOptions(1); molecule4UpdateWindow();"
37 | $resetBtn;
38 |
39 | setOptionBoxTitle( "Molecule3 Options" );
40 |
41 | showOptionBox();
42 | }
43 |
44 | global proc molecule4SaveOptions( string $parent )
45 | {
46 | // Get values of controls
47 | setParent $parent;
48 | float $rad = `floatSliderGrp -query -value molecule4Radius`;
49 | int $segs = `intSliderGrp -query -value molecule4Segments`;
50 | float $br = `floatSliderGrp -query -value molecule4BallRatio`;
51 |
52 | // Update option variables
53 | optionVar -floatValue molecule4Radius $rad;
54 | optionVar -intValue molecule4Segments $segs;
55 | optionVar -floatValue molecule4BallRatio $br;
56 | }
57 |
58 | global proc molecule4UpdateWindow()
59 | {
60 | // Retrieve the option variables
61 | float $rad = `optionVar -q "molecule4Radius"`;
62 | int $segs = `optionVar -q "molecule4Segments"`;
63 | float $br = `optionVar -q "molecule4BallRatio"`;
64 |
65 | floatSliderGrp -edit -value $rad "molecule4Radius";
66 | intSliderGrp -edit -value $segs "molecule4Segments";
67 | floatSliderGrp -edit -value $br "molecule4BallRatio";
68 | }
--------------------------------------------------------------------------------
/Volume-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-2/Plugins/SurfaceInfo1/SurfaceInfo1Cmd.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file accompanies the book "Complete Maya Programming (Volume 2)"
3 | // For further information visit http://www.davidgould.com
4 | //
5 | // Copyright (C) 2004 David Gould
6 | // All rights reserved.
7 | //
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | DeclareSimpleCommand( surfaceInfo1, "David Gould", "1.0" );
16 |
17 | MStatus surfaceInfo1::doIt( const MArgList& args )
18 | {
19 | MStatus stat = MS::kSuccess;
20 |
21 | MSelectionList selection;
22 | MGlobal::getActiveSelectionList( selection );
23 |
24 | MDagPath dagPath;
25 | MObject component;
26 |
27 | const char *formTxt[] = { "Invalid", "Open", "Closed", "Periodic", "Last" };
28 | double startU, endU, startV, endV;
29 | unsigned int i, j, nCVsU, nCVsV, nKnotsU, nKnotsV;
30 | MPoint pt;
31 | MDoubleArray knots[2];
32 |
33 | MString txt;
34 | MItSelectionList iter( selection );
35 | for ( ; !iter.isDone(); iter.next() )
36 | {
37 | iter.getDagPath( dagPath, component );
38 |
39 | MFnNurbsSurface surfaceFn( dagPath, &stat );
40 | if( stat )
41 | {
42 | txt += dagPath.fullPathName() + "\n";
43 |
44 | txt += MString("Area: ") + surfaceFn.area() + "\n";
45 | txt += MString("Degrees: ") + surfaceFn.degreeU() + ", " + surfaceFn.degreeV() + "\n";
46 | txt += MString("Spans: ") + surfaceFn.numSpansInU() + ", " + surfaceFn.numSpansInV() + "\n";
47 | txt += MString("Forms: ") + formTxt[ surfaceFn.formInU() ] + ", " + formTxt[ surfaceFn.formInV() ] + "\n";
48 |
49 | surfaceFn.getKnotDomain( startU, endU, startV, endV );
50 | txt += MString("Parametric Ranges: [") + startU + ", " + endU + "], [" + startV + ", " + endV + "]\n";
51 |
52 | nCVsU = surfaceFn.numCVsInU();
53 | nCVsV = surfaceFn.numCVsInV();
54 | txt += MString("CVs: ") + nCVsU + ", " + nCVsV + "\n";
55 |
56 | for( i=0; i < nCVsU; i++ )
57 | {
58 | for( j=0; j < nCVsV; j++ )
59 | {
60 | surfaceFn.getCV( i, j, pt, MSpace::kWorld );
61 | txt += MString(" (") + pt.x + ", " + pt.y + ", " + pt.z + ")";
62 | }
63 | }
64 | txt += "\n";
65 |
66 | nKnotsU = surfaceFn.numKnotsInU();
67 | nKnotsV = surfaceFn.numKnotsInV();
68 | txt += MString("Knots: ") + nKnotsU + ", " + nKnotsV + "\n";
69 |
70 | surfaceFn.getKnotsInU( knots[0] );
71 | surfaceFn.getKnotsInV( knots[1] );
72 |
73 | for( i=0; i < 2; i++ )
74 | {
75 | for( j=0; j < knots[i].length(); j++ )
76 | {
77 | txt += MString(" ") + knots[i][j];
78 | }
79 | txt += "\n";
80 | }
81 | }
82 | }
83 |
84 | MGlobal::displayInfo( txt );
85 |
86 | return MS::kSuccess;
87 | }
88 |
--------------------------------------------------------------------------------
/Volume-1/Plugins/Posts2/posts2Cmd.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2001 David Gould
3 | //
4 | #include
5 | #include
6 | #include
7 | #include