Basic concepts of Max SDK (2)

Source: Internet
Author: User

2. Basic concepts of SDK

2.1 three abstract base classes

3DS MAX plug-ins are mainly used for modeling, animation, and rendering. These plug-ins are mainly inherited from one of the following abstract base classes.

Anomatable-> referencemaker-> referencetarget

These basic classes provide a wide range of functions to implement functions such as those displayed in the track view or interactions between plug-ins.

(1) animatable

The most basic level of the class hierarchy is the abstract class about animation, which is the animatable class. The main method of this class is the function and memory management displayed in the track view. The two classes inherited from the animatable class are used in 3DS
Different parts of Max are used for interaction.

(2) referencemaker

When 3DS
When a reference in Max is created, the object to be referenced will be dependent on the object to be referenced. The reference creator is a dependent object and the reference target is an independent object. When a target is referenced
When the state changes, the referenced target must notify the referenced creator of the change. Any class belonging to the referenced creator must inherit from the referencemaker class of the abstract class.
(3) referencetarget

Any class that belongs to the reference target must inherit from the referencetarget class of the abstract class. See the referencemaker explanation above.

> Plug-ins not inherited from these classes

These plug-ins do not inherit from three abstract base classes. Generally, these classes are not directly related to animations. For example, the import and export plug-in only
Max, so they do not appear in the track view, and their functions are independent of other plug-ins.


2.2 plug-in system overview

Most classes in the SDK are inherited from the abstract base class.

The root class of the three abstract base classes is the animatable class, which defines most of the methods related to animation and trajectory view.

The class inherited from the animatable class is referencemaker, which allows reference to other objects.

The class inherited from the referencetarget class is referencetarget. A reference is a bidirectional connection between two objects in a scenario.
Create a formal dependency record between "referencemaker" and "referencetarget. Its main function is to enable a reference target to change its status. The notification depends on its reference.

Classes that do not inherit from animations are mainly those that are irrelevant to animations. For example, the interface class provides a series of methods to call 3DS
Max functions, and the interface class does not inherit from the animatable class.

Shows the inheritance diagram of the main public classes in the SDK. The most basic class (that is, the class without a parent class) is displayed at the top, with the inheritance hierarchy down and to the right.
Figure omitted (see SDK)



2.3 plug-ins in 3DS MAX


This section discusses how 3DS MAX calls the plug-in method and how the plug-in calls the methods provided by 3DS MAX.

(1) User Implementation Method

Each plug-in is inherited from a base class of 3DS MAX. For example, a plug-in that creates a geometric object can inherit from the simpleobject2 class.

Class mygeomobject: Public simpleobject2

{

//...
};

3DS
The header file defining simpleobject2 in Max is simpobj. h. The plug-in developer must implement some methods in the simpleobject2 class. In other words, the plug-in overwrites some methods of the parent class. 3DS
Max can call these methods in the plug-in.

For example, simpleobject2's buildmesh () method, 3DS
Max calls this method to obtain the triangular mesh of a geometric object. The plug-in must implement simpleobject2: buildmesh () to generate 3DS
The mesh required by Max.

(2) Basic Methods

Some methods are provided by the base class, that is, the base class itself implements some methods. These methods can be called by the plug-in. Extensions inherited from the base class can inherit these methods. For example, a basic geometric object may inherit from geomobject. This basic collection can call policydependents (), which is
A referencetarget method that inherits from the base class
(Geomobject-> Object-> baseobject-> referencetarget ).

(3) interface methods
The plug-in can also call 3DS
Max method, through the interface pointer provided by the interface class. An interface class is just a class that contains pure virtual functions without any member variables. A class like this is essentially a function pointer table.

The interface class is frequently used in 3DS MAX. The most frequently used interface class is interface. A pointer to this class can call many methods. The plug-in uses this pointer to implement 3DS
Some common operations provided by Max. For example, if a modifier plug-in wants to display a user interface on the Command Panel, you can call the addrolluppage () method of the interface, or the plug-in wants to get the 3DS
The gettime () method of the interface can be called at the current time specified by the Max frame slider.

2.4 communication between plug-ins-reference structure


In the object-oriented example, independent plug-in objects work together to implement all the functions of the system, so internal objects need to communicate. 3DS
Max uses the reference structure as the architecture for controlling communication.

(1) Case Study
Consider the following example to understand why internal communication is required.
The 3DS MAX animation controller has a look
The at plug-in (the gaze constraint plug-in) is a space transformation controller that can control its position, rotation, and scaling in the scenario. Look
The at controller rotates the project to which it belongs to so that it faces (or watches) another object. For example, create a free camera and specify a look
The at Controller acts as the camera's space transformation controller, and then selects a box as the look
At controller's target, which enables the free camera to rotate and orientation toward the box. Whenever the box moves, the Controller will reset the settings so that the camera still points to the box. Of course, if you delete a box from a scenario, the camera will be able to identify and remain unchanged.

Now consider these projects (camera, look
At controller, box) is a plug-in. Every plug-in has nothing to do with other plug-ins. How do they communicate? For example, how does a camera know to change its direction when the box is moved? Look
How does the at controller know that the box in the scenario is deleted? The answer for communication between these objects is references ).

(2) Reference

One reference is the method of associating two projects. In this case, one project is considered to be dependent on another project. In the above example, look
At controller depends on box, camera depends on look
At controller. That is to say, if a box changes, it needs to let other objects dependent on it know the changes. The Controller obtains the box change notification through reference. The Controller notifies its projects in the same way. When the Controller changes, it knows the project that depends on it, so the camera is notified.

An object establishes a dependency by creating a reference. When an object creates a reference, it is called the reference creator and those dependent objects are called reference targets. In the above example, the camera references the Creator, which references the look
At controller, the look at controller is the reference object of the camera.
At is also the reference Creator, which references box, and box is the reference target of the controller. In fact, box has its own reference, such as its space transformation controller.

3DS MAX has many internal references. In a simple scenario, there may be dozens of references (many
In a complex scenario, there may be hundreds of references.

2.5 relationship between nodes and objects in a scenario

In a scenario, each object is associated with a node, and there is a one-to-one correspondence between the node and the object in the scenario. The ball, grid, camera, light, and auxiliary objects are all objects in the scene. All these objects can be transformed, rotated, and so on.

In the scenario, the node manages the objects associated with it: Space Transformation controller, materials used, information about Parent and Child layers, group information, and so on.

(1) The spatial transformation controller of the node controls the position, rotation, and scaling of the object in the scene.

(2) The Renderer uses the node material to set the surface features of an object, such as color, texture, and concave and convex.
(3) hierarchical information is used to control the connection/unconnected state and Reverse dynamics (ik) of an object ).

Generally, you can obtain a node and extract the specified scene object. It is effective to encapsulate the scene object with the node. 2.6 process object

A process object is an object that you can create and control in a view. Such as cameras, lights, and geometric objects (cubes, balls, or more complex objects ).

Process objects are defined and created by custom attributes, such as radius (for balls) or length (rectangle ). Because of this, parameter objects are also considered to be synonymous with process exclusive.

Geometric objects must eventually be converted to triangular grids for rendering. 3DS MAX Renderer and Ray tracking rendering (Mental Ray
Renderer) all work at the mesh object level. Therefore, basic objects, Boolean objects, loots, particle systems, patch grids, and non-green surfaces must all be converted to triangular grids. Only one exception: Ray Tracing supports a specified basic body hair and is more effective than a triangular mesh.

For example, a basic body ball is defined by its radius, number of segments, and hemisphere settings, rather than its vertices and patches. However, the Triangle Mesh representing the ball is used for rendering. Therefore, in the running process, the vertex and patch of the grid are calculated using the ball parameters.
For a process object, 3DS
Max provides modifiers to extend objects. You can modify, modify, process, and Edit object application modifiers. You can also use the Space Bending plug-in to change the location of the World Space of the ry. For plug-in developers, the implementation of all these functions must understand the conversion process from the parameter object to the modifiable triangle surface model.

3DS
Max's geometric pipeline system is used to control these processes and transformations. The geometric pipeline system is used to make the parameter object modifiable, and finally generate a suitable triangular mesh model for rendering and display in the view.

2.7 time interval and event Interval


The plug-in developer needs to specify the time point and time interval to process the animation.

(1) Time Point

3DS
The basic unit of time in Max is timue. The SDK uses timue when any time point needs to be specified. 1timue equals 1/4800 seconds.

Timue is also a 3DS MAX Data Type.

For example, if the plug-in needs to know the current system time (in 3DS
In max), you can call interface: gettime (). This method returns the current time (in the unit of timue, that is, 1/4800 S ).

(2) Time Interval

In 3DS MAX, the interval class is usually used to define a time period during which objects do not change. To be as fast as possible, 3DS
Max avoids re-evaluating computing objects at any time. If an animation plug-in can specify how long it will not change, 3DS
Max knows that it does not need to re-evaluate the computing object during this period of time.

For example, 3DS
Max needs to know how long the modifier modification is valid. Take the bending modifier as an example in the animation of 100 frames. The user changes the bending angle and marks that the animation does not bend between 0th frames and 50th frames, and is bent 45 degrees at 50-frames. In the first 50 frames
Max does not need to reevaluate the computing modifier (after all, the first 50 frames are not bent ). 3DS
Max uses valid time intervals to identify the time period of deformation. The valid interval is a time period. For example, the valid interval returned at 23 frames may be forever, and the valid interval returned at 56 frames may be instantaneous.

2.8 animation Controller


All animations in 3DS MAX are called animtable
Controller (animation Controller) Plug-in management, or controller for short.

Some controllers are based on key frames. This means that you can set the Controller value at the key time point. Then, the Controller computes and sets the value of another time by interpolation between two key frames.

Other controllers are program-based and set their values in the programming state at specific time points (for example, the noise wave controller uses the irregular fragment function to calculate their values ).

There are six basic controller types, each of which controls a specific data type:

(1) floating point value (float)

(2) Three floating point values (point3)

(3) position (matrix3)

(4) rotate (quat)

(5) scalue)

(6) transformation (matrix3)

Plug-in developers can create a new controller type or use an existing controller type.

Many controllers use parameter variables, such as the radius parameter variable of a program ball. 3DS
Max provides tools for developers to use parameter variables for easier management .. The most important part is the parameter block. The parameter block provides a system that stores values for plug-in parameters and controllers (controllers that control interpolation or generate values.

2.9 parameter block

Parameter blocks are very important. They are used to store and display the variable values of the plug-in.

3DS
Max provides classes for storing, obtaining, and displaying the data. Most plug-ins display information in the form of a dialog box, and users can control the display information (such as defining the parameters of a program object ).

The variables used by the parameter block storage plug-in (usually called parameters), manage the Undo/Redo functions, automatically provide these parameters to maxscript, and manage message notifications that reference the system.

Parameter blocks automatically display data to the 3DS MAX User Interface in coordination with related classes, which frees developers from tedious underlying tasks.

2.10 graphic interface


Users are the same as 3DS
The interaction of Max is mainly through the control panel's scroll bar and dialog box, mouse (or WordPad), keyboard, and 3D view. The SDK provides developers with control over the interaction areas of each user.

Plug-ins usually display their user interaction control in the following ways:

(1) Volume display bar: displayed in the material editor, environment, and rendering dialog box.

(2) Modal Dialog Box

(3) Non-Modal Dialog Box

> Control

Many buttons in the dialog box or volume bar, fine-tuning control items, and editing areas all come from the 3DS MAX custom control. This helps 3DS
The graphic interfaces of each plug-in Max have the same appearance.

> Mouse

Use command modes (command mode) to control mouse-to-view interaction in the SDK.

> Keyboard

The keyboard accelerator allows you to bind functions and buttons to execute a plug-in function.

> View

The plug-in often needs to be drawn in a 3D view to display its content or other small objects. You can call the method provided by the interactive Renderer (graphicswindow class.

2.11 DLL Functions


This section describes the five functions required by each plug-in DLL. For more information, see required DLL.
Functions (detailed ).

Each plug-in developer needs to provide the dllmain code and four lib functions. The following describes these functions:
I. Function Initialization
Dllmain () is a hook program used by windows to initialize DLL. The 3DS MAX plug-in uses this function to initialize the general control library and 3DS
Max Custom Control.
2. functions used by 3DS MAX to manage and classify DLL plug-ins

These four functions describe the number and attributes of plug-ins provided by DLL.

(1) libnumberclasses ()
This function returns the number of plug-in classes in the DLL.

(2) libversion ()
This function allows the system to process the version of the DLL plug-in.

(3) libdescription ()
This function returns a text string if the DLL is unavailable.

(4) libclassdesc (I)
This function returns a pointer to a descriptor Class Object. This is a class descriptor. Each DLL plug-in class has this descriptor object. A Class descriptor has the following functions:

A) describes the attributes of each plug-in class;

B) Create a plug-in class;

C) destroy the plug-in class;

Developers can place multiple plug-ins in a DLL file. In this case, libclassdesc () will execute a switch statement and return different class descriptor pointers.

2.12 ID of the plug-in creation and running types


The descriptor class inherits from classdesc2 and has several important functions. But the two most important aspects are the classification of the plug-in and the allocation of memory for the plug-in instance.

A dll plug-in contains many plug-in classes.
Max calls the DLL through the libnumberclasses function to determine how many plug-in classes it contains. Then, based on the number of plug-in classes, call the static descriptor class cyclically (call libclassdesc (I )). After Max obtains the class descriptor, it allocates the plug-in instance by calling the CREATE () method of the class descriptor.

Each plug-in class must have a class ID (classid ).

Each plug-in object is associated with two class IDs, which are:

(1) Class ID uniquely identifies a plug-in class

(2) super class ID specifies the super class of the plug-in class.

For example, a ball object has a unique class.
ID. You can generate this ID through the program provided by the SDK, which uniquely identifies the plug-in class. (This program is in/maxsdk/help/gencid. EXE)

Its superclass ID is geomobject_class_id, because it belongs to the basic ry. Superclass IDs are defined by Max. Each plug-in must belong to one of the classes.

For example, all texture map extensions have the same superclass ID, which is texmap_class_id. Each texture map plug-in has its own unique class ID. Therefore, the superclass ID defines the category of the plug-in (texture map plug-in here), and the class ID uniquely identifies a specific plug-in class.

• Runtime type ID

Class descriptor method classdesc: superclassid () returns the superclass ID, classdesc: classid () returns the class ID.

• Create a plug-in

Another function of class descriptor is to allocate memory for the plug-in class instance. For example, when a 3DS MAX file is loaded, the file contains a program ball
Max needs to create an instance of the ball plug-in. It is implemented by calling the class descriptor classdesc: Create () of the ball.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.