From 3D Studio Max to Direct 3D: Introduction to plugin Development

Source: Internet
Author: User

If a programmer can translate an artist's work into a real-time 3D environment, the game will be that much better. for program programmers, 3D Studio Max is the tool of choice for pre-calculating and real-time 3D scenes. and, in the opinion of this author, Microsoft's DirectX API is the most efficient API for games on Windows Platforms

This article explains how to create a 3DS MAX plugin to export the artist's work into your real-time 3D engine. my instructions will take you through both the max and direct3d APIs. while no experience is necessary, you shoshould be familiar with Visual C ++, windows, direct3d (using the Immediate Mode's draw primitives) as well as computer graphics basics.

I'll start with the Max's API and cover how to use it to create a new plugin. with this knowledge, we can implement the plugin's project using Visual C ++. for real concrete stuff, for instance mesh and material exportation, you'll have to wait for the next articles.

Introduction to Max plugin Development

3DS MAX primarily deals with Meshes concerning the realization of 3D objects. patches and OpenGL are also managed, but because the powerful geometry pipeline makes it possible to convert them into meshes, it shouldn't be a problem. the exportation of OpenGL-based objects wowould have made things very difficult and inappropriate for real-time 3d. this flexibility is the reason why 3DS MAX is becoming the standard as far as game development is concerned. if you already own the second version, you'll enjoy its performance compared to the first version. except changes were made in this second version, and as a result, there is an incompatibility of plugins between the two versions. getting around this incompatibility requires only a recompilation and maybe a few changes. so, with that in mind, techniques explained in this article will work, regardless of the Max SDK version you have.

What do I need?

On the software side, you'll need Microsoft Visual C ++. while the 4.0 version is good enough to create plugins for the first version of 3DS MAX, You'll imperatively need the 5.0 version if you use the max2 SDK. as for APIS, You'll of course need a version of Max's SDK and DirectX 5.

While CPU speed is not extremely important on the hardware side as it doesn' t have any incidence on the compilation/testing time, I stronugly recommend you at least 64 MB RAM. if you have less, Max, Visual C ++ and your project won't be able to stay in memory. when this happens, Compilation Time will be multiplied by 5, and Max will take at least 20 seconds to load. this, needless to say, can be maddening.

128 mb ram is sufficient, if your plugins project is inside a workspace which already contains projects such as your 3D Game Engine.

The max SDK gives developers the possibility to create your kinds of plugins, from procedural objects to video post processing. A plugin's type called "File Export" is of particle interest. however it's not the type I wowould recommend. export plugins are made to export a whole Max scene, without any interactions with the user, which is, in our present case, not what we want. the utility plugin is more flexible just in case you want to select scene components to export, and how you want to export them.

Max Philosophy

As a max plug-ins developer you'll have to understand Max's internal structure. the rest of this article will introduce you to fundamental concepts such as the geometry pipeline, the manipulation of the scene's nodes, calculus implementation and the Plugins 'interface. if you like oriented object programming, you'll love Max's API: Everything has been made according to the OOP philosophy, you'll Nd classes for almost everything you can think about (mesh, face, point, matrix ...).

Nodes manipulation

What's a node? In Max, a node is a visual representation of an object (here, the term 'object' means 3D object, light, camera, shape, etc ...). Nodes are linked to each other to make a hierarchy. the root node of this hierarchy is the max scene. to realize a max exporter plugin, it's important to be familiarized with the manipulation of nodes, as they're the starting point of your conversion.

What can we do with a node? A node is created and controlled from the Max's class inode. i'm not going to detail this class, the max's help file will do it better than me, but I'll just comment on a few things that will be useful for our exporter.

The main function of a node is to reference the object it is associated. this object's state can be evaluated in the world (its representation in the viewport) at a given time. see the geometry pipeline, for more information. once this object is evaluated, you can retrieve all of its specific data, we'll see later how to do that.

Concerning the hierarchy... From a node, you can get its parent node, the number of its children and a specific child node, using the inode: getparentnode (), inode: numberofchildren and inode :: getchildnode () methods. to scan the whole scene, you just have to get the root node (using a function of the Plugins 'interface), and then using the functions given below.

Other properties like the node's transformation matrix (a transformation matrix is made of a position, an orientation and a scale factor), the transformation matrix of the object, its reference and its name can be retrieved.

Now you know how a node basically works, Let's explain how objects work with the help of the geometry pipeline.

The geometry Pipeline

This is the most fundamental concept and Innovation of Max. if you have already worked with 3D Studio/DOS, you know how the creation of meshes work. you cocould start by creating 2D shapes with the 2D shaper and then create a 3D object based on those shapes using the 3D lofter. to apply modifications (vertices displacement, Boolean operations, mapping, etc ...) On it You cocould use the 3D editor. each time you made a modification on a 2D shape or 3D object, the previous state was lost as the modification was directly applied on the entities (faces, vertices, 2D spline) that made up the 2D shape or 3D object.

Max uses another approach to create geometric components called a "procedural approach ". each node contains a node pipeline. at the beginning of this pipeline there is the base object. each time you apply a modification to your node, the modifier you used is referenced in the node pipeline, with the parameters you set. then, the geometry pipeline evaluates the node's pipeline to create the world space state of the node's object. this world space state is what you can see in the Max's viewport.

OK, let's take model what a "TOP". Don't expect CT a nice one, I'm just a programmer!

This model can be made in two steps: the creation of a sphere and the application of a taper on it.

When you create a sphere, a new node is also created and inserted into the max scene. the object referenced by the node is the node's base object (the sphere ). as it is a procedural object, the Sphere object is not made of faces and vertices at this stage. this object can be generated into a mesh, depending of the parameters you specified.

Figure 1 below is the geometry pipeline representation of the node at this stage and its World Space state.

In step two, a taper modifier was applied on our node, you can see the result in figure 2 (I 've also assigned a texture map ). the node now points on what we call the 'derived object '. this derived object is the result of the node's pipeline interpreted by the geometry pipeline.

Following the derived object is the taper modifier, and finally, our base object: The Sphere.

Suppose that you apply a bend to the object. this modifier will appear in the pipeline right after derived object and before the taper. with the help of Max's modifier stack you can change parameters of any modifiers you want (even the base object ). you can also remove or insert modifiers anywhere you want in the stack. anytime the object's World Space state will be recomposed: That's the job of the geometry pipeline.

The World Space State object of a node can be evaluated using the inode: evalworldstate () method. this method returns a C ++ object of the class objecstate. from this object, you can retrieve the object evaluated by the geometry pipeline. the evaluated object is also a C ++ object of a class that is derived from the object class. max implements attributes classes that are derived from the object class.

Later in this series, we will see classes such:

Triobject: defines a mesh object made of triangles
Cameraobject: defines either a free or target camera
Lightobject: defines either an omni, directional, target spot or free spot light

A bit of Calculus

Max's API offers a set of classes and functions to make the utilization of matrices, points and quaternions easier. since the manipulation of points is not really a big challenge, I'm not going to overview the point3 class. talking about quaternions wocould go beyond the scope of this article, as they are mostly used when dealing with animation. so only fundamentals of matrices are explained. here we go.

Transformation matrices.

Transformation matrices are used to switch from one given coordinate system to another; for example, to transfer the coordinates of an object's vertices from local to the world space coordinate system. transformation matrices are also used to position nodes in the scene. the transformations provided by these matrices are: translation, rotation and scaling. such matrices can be created and used with the matrix3 class of Max.

In max, matrices have 4 rows of 3 columns. usually, 3D matrices are 4x4 instead of 4x3. it's also the case for Max, but as the last column is always [0 0 0 1] for such matrices, it's implicitly managed by the class and functions dealing with it.

The coordinate system used by Max is a right-handed one, with counter-clockwise angles when looking to the positive way of an axis, as shown in Figure 3 below.

Now let's see how the identity, translation, rotation and scaling are encoded. an identity matrix has the property to keep a vector or a matrix unchanged during a vector/matrix or matrix multiplication. it's encoded as follows:

You can initialize a matrix to the identity by passing 1 to the constructor of matrix3 class or by calling the method matrix3: identitymatrix ().

Translation is stored in the matrix this way:

Translation can be set using matrix3: settrans (), retrieved using matrix3: gettrans (), set to null using matrix3: notrans ().

The matrices for rotations around the three axes are shown below. The rotation's angle is always given in radians.

X rotation:

Y rotation:

Z rotation:


These matrices can be created using global functions rotatexmatrix (), rotateymatrix (), rotatezmatrix (). an incremental rotation around und one specific axis can be performed med using the matrix3's methods matrix3: rotatex (), matrix3: rotatey (), matrix3: rotatez ().

A Method of the matrix3 class is also provided to create a yaw/pitch/roll angles matrix (using the rule of Euler's angles): matrix3: rotateyprmatrix ().

Scale factors are encoded like this:

Scaling factor can be set using matrix3: setscale (), or reset to 1 using matrix3: noscale ().

For the last part of this article we're re going to take a brief look at how the plugin can get access to Max features.

The plugin's Interface

The plugin's interface is a C ++ interface retrieved during the plugin's initialization. the term interface signifies that a C ++ object contains methods only. the plugin's interface is used to provide APIs that the max offers to the plugin. from the list of Apis it provides, the following pertains to our exporter.

Command Panel-rollup PAGE Method

As the plugin's type we will use is a utility plugin, we'll have to design a dialog that will appear during the plugin's initialization in the utility plugin's pan. this dialog will appear under the form of a rollup page. methods of the plugin's interface will be used to add and delete this rollup page dialog.

Nodes related methods

By using functions of this API, we can access the root node of the scene, accessing a node from its name.

Node picking

Provides functions to call the interactive nodes selection dialog of Max. useful to select nodes we want to export.

Standard Max Dialog

The track View Pick dialog, material browse dialog can be called using this API.

Last words

Next time, we'll see how to create a plugin's project, how to integrate MFC inside the plugin, how to debug it, and check out a simple example of a utility plugin.

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.