MAX SDK Grid feature

Source: Internet
Author: User
Tags array length visibility
MAX SDK Grid feature2013-11-20 00:20 473 People read review (0) Favorite Report Category: Max Programming (13)

Grid Topics

first, the mesh geometric structure

1.1 vertices (Vertex)

The model vertices in max still use the usual vertex array, the Mesh vertex array member is a one-dimensional array with verts,verts as the vertex three-dimensional coordinates, and mesh::numverts the number of vertices.

[C-sharp] view plain copy int getnumverts ();   Returns the number of current vertices bool mesh::setnumverts (int ct, bool keep = FALSE, bool Synchsel = TRUE);   This method is used to set the number of mesh vertices, which is responsible for reallocating the vertex array to the grid, while keep identifies whether the previous vertex data is retained, and the Synchsel identifies whether to reset the length of the vertex selection state bit array, which is usually true. void Setvert (int i, const point3& XYZ); Set vertex coordinates void Setvert (int i, float x, float y, float z); Set vertex coordinates point3& getvert (int i); Get vertex coordinates point3* getvertptr (int i); Get pointers to vertex coordinates

1.2 patch (FACE)

Patches in mesh meshes are triangles with a special face class description, and the face class records the index of a patch's three vertices in the vertex array, the visibility of three edges, the visibility of the polygon, the smoothing group to which it belongs, and the associated material ID. In the mesh class, the patch array is faces, which is an array of face types, and the array length is determined by mesh::numfaces. The associated methods are:

int mesh::getnumfaces () const//return number of mesh patches

BOOL mesh::setnumfaces (int CT, bool keep=false, bool synchsel=true); Set the number of patches and assign an array of patches

After the patch array is allocated, you can set the vertex index for the patch, which is provided by the face class:

void Face::setverts (int a, int b, int c);

Of course, the face class provides access to set the edge visibility, polygon visibility, smoothing group, and associated material ID. In the mesh class, there is only such a face array, and the specific information about the patch is completely recorded by the faces class.

1.3 Sides (Edge)

In addition to the vertex and polygon information, of course, there are wildest information, of course, there are wildest information in Max, but the edge information is "virtual". Why is it. Because polygon information naturally contains edge information, mesh does not need to record the edge set, but creates a list of edges when needed. The Edge class is the class that describes the edge, which contains the index of two endpoints and the index of the associated triangle patch.

1.4 The state of the Geometry element

In the mesh class, there are three selection status flags array, namely vertex selection state bit array (Vertsel), patch selection state bit array (Facesel), Edge Select State bit Array (Edgesel), all of them are BitArray type (bit array). Obviously, the length of the Vertsel bit array is numverts,facesel bit array length is numfaces. But as we have just said, the edge set does not exist, so how to determine the index of the edge. In fact, the length of the Edgesel here is 3*numfaces, how this should be very clear, a triangle three side, so the first triangle corresponding to the three sides in Edgesel respectively edgesel[i*3], edgesel[i*3+1], and EDGESEL[I*3+2].

There is also an array of bits that record the display/hide state of the vertex, which is verthide, length numverts, and if Verthide[i] is 1 indicates that the vertex is hidden.

1.5 acquisition of geometrical information

The mesh class provides a number of ways for us to get the relevant geometry information, not just vertices and patch information, including other geometric information built on it, such as we can get the face normals or vertex normals, we can find the angle between two faces and so on. Or, the mesh class has implemented a lot of geometry-based computations, and all we have to do is invoke the method it provides. Here are some common ways to get information:

• Bounding box information (bounding box): the so-called bounding box is usually a box in Max, which is determined by two inflection points in the local coordinate system, namely the lowest and highest point. Don't be confused here, think two points how can describe a box. If you think about it, you'll think it's enough. box is parallel to the local axis, the popular point is "positive" on the coordinate system, so record a low point (here the lowest is said X, Y, z three components are the smallest) and the highest (x, Y, z three components are the largest) is sufficient to determine the location and size of a bounding box. The Mesh::getboundingbox () method can obtain the current bounding box information.

• Normal information (Normals): Getnormal ()/setnormal () can get the normals of a vertex (note that the normals here may not be computed based on the geometry information, because Rvertex normals can be specified manually); Getfacenormal ()/ Setfacenormal () Gets and sets the normals of the triangular patches (of course, the face normals can also be specified manually).

Elemental Information (Element): If you can get a connected patch element, it is easier to understand the element selection tool in edit mesh. The Elementfromface () method can get the element information in the specified range.

• Patch Center (center of Face): that is, the triangle center of gravity. Although it is easier to calculate, however mesh has already provided the Facecenter () method.

• Two face angle (Angle between Faces): This is more difficult than the triangle center of gravity to express some, fortunately mesh (anglebetweenfaces ()) also help us to calculate well. When you take some kind of smoothing algorithm, the calculation of the two-face angle is very frequent.

• Triangle Weights (bary coordinates): Such translation may not be accurate enough, its practical meaning is to use the three vertices of the triangle to represent any point on the plane of the triangle, and barycoords () can return a little bit of the weights of each vertex represented by the triangle Vertex, The popular point is that P = k1*v0 + K2*v1+k3*v2, the method returns (K1, K2, K3). This method is quite useful under certain requirements.

• Border Edge (Open Edges): Maybe here I have to reiterate what Max should be aware of when creating a mesh, such as two triangles per edge, one at a time or the other, or even the definition of "boundary edge" is problematic. The so-called boundary side is said to relate only to the edge of a triangle. The Findopenedge () method can always identify all boundary edges in the Edgesel bit array.

• Isolated points (Isolated Verts): These points are useless and keep them.

• Morbid Triangles (Llegal Faces): Out of bounds ah, useless.

• Degenerate triangles (degenerate Faces): as useless as an outlier, a triangle with a repeating vertex index that has degenerated to a straight line or point.

Ray intersection (Intersect Ray): This thing itself is still more troublesome, mesh provides the Intersectray () method not only can find the intersection of Ray and mesh, but also the extent of the intersection with which patch, the intersection of the discovery is how much, the intersection in the triangle position weights. It also says that all the information that can be obtained after finding the intersection is thrown out.

In fact, you can get a lot of useful information, especially in the introduction of Mnmesh can calculate the information more, here simple example, just want to say, want to get what information, do not rush to write, first look at the SDK there is no, I think so many versions after The algorithm that Max implements should be more robust than your own writing most of the time. (Although Max jumps from time to time with a baffling mistake)

second, mesh texture map

We've even introduced texture textures and stuff like that, but it's still a bit of a turn. The material in Max is at the node level, each node is associated with a material, and the material can also be a multi-material (multi-material) type, and in the actual rendering process, the mesh matches the type of material defined on its corresponding node, including texture textures, and so on.

2.1 Map channel (map Channels)

Again, Max can support multiple channels, with the exception of 0 identifying vertex colors and 1-99 identifying texture map channels. It should be said that there are few ways to present mesh details with vertex colors, and most of the time the mesh details are represented in a variety of texture maps, such as diffuse maps.

The number of supported channels in the mesh is determined by the Nummaps property, which by default is 2, which means that the vertex color channel and a default texture map channel are supported, but you can change the number of support channels as needed, Getnummaps ()/setnummaps () The number of supported channels can be set, and Mapsupport () is used to determine if the channel is supported.

It is important to note that if an extra texture map channel is supported, then the corresponding texture vertex and texture coordinates of the channel are stored somewhere. You have to introduce the maps members of the mesh, maps is just a meshmap type of pointer, each of its instances records a channel corresponding texture vertex and texture patch information, that is, when adding a texture map channel, will create a new Meshmap instance, And the instance stores the channel mapping information. The maps members of the mesh class only maintain pointers to these instances, allowing them to get texture mapping information for any channel when needed. This allows the mesh class to support the use of multiple channels of switching. (I have guessed that this is probably convenient for multiple artists at the same time mapping a model, each produced a different UV distribution map, and then based on their own UV distribution map to draw a number of texture maps, and then difficult to sub-par or as an alternative way, so that you can switch freely in max)

2.2 Texture Vertex (UV verts)

The texture vertices are stored in the same way as the mesh geometry vertices, in arrays. Don't get me wrong. The number of texture vertices will be the same as the number of geometric vertices, which is completely two concepts, the texture vertices exist in the texture space, and the geometric vertices do not have the necessary correspondence, even when the texture mapping is completely not used to some texture vertices. The number of texture vertices is determined by mesh::numtverts, and if you want to manually set the texture vertices and assign the texture vertex position yourself, setnumtverts () can help you complete the allocation of the texture vertex array, getnumtverts () returns the number of texture vertices. Although the art is through the plug-in tool to automatically semi-automatic or even manual UV expansion, but for programmers, these methods are often needed. The simplest example is to import a plug-in, which is bound to be used when importing texture coordinates from some kind of 3D file.

I seem to forget to say that UV coordinates do not mean that it is a two-dimensional coordinate that corresponds to a planar image, and that the UV coordinates are actually three-dimensional coordinates. In addition to the planar expansion of UV, cylindrical expansion, spherical expansion is also very common.

2.3 Textured Patch (UV Faces)

Just said that the texture vertex and mesh geometric vertices have no correspondence, but the texture patch is not the same, it must be corresponding to the mesh patch one by one. We must not have found a mesh class there is a member such as "numtvfaces" to identify the number of texture patches. This is of course not necessary, the number of texture patches is not only the same as the number of geometric patches, but also on the index is one by one corresponding relationship. Tvface is the texture patch array, obviously faces[i] corresponding texture patch is tvface[i].

The structure of the texture patch is determined by the Tvface class, which is a simple structure that records the index of the texture vertices corresponding to the three vertices in the texture vertex array. This is similar to the face class, except that the face class also records additional information. Tvface provides a way to set and get the texture vertex index.

2.4 UV Expansion (UV Unwrap)

The mesh class even provides several UV expansion methods. Makemapplanar () only for a map channel to provide planar expansion, UV plane expansion only need to put the geometric vertices projected onto the plane can be UV expanded. Usually we do not use this method, for complex models we often difficult to automate the implementation of UV expansion, because it may also require "peeling" and other complex operations as well as some artistic perception, which is why there are so many UV-assisted expansion plug-in tools. Although mesh also provides several other methods of UV expansion: the Applyuvwmap () method provides a number of expansion modes, including planar, cylindrical, spherical, and even can be set for tiling, mirroring parameters, but the actual development may not be easy to use.

2.5 vertex color (Vertex color)

As we have already said, vertex color channels are rarely used because of the heavy use of texture maps, but consider their application in the early days of graphics and are supported by the various versions of Max.

The vertex color channel differs from the texture map channel in that it first maintains a color vertex array vertcolor (corresponding to the texture vertex tverts in the texture map) to define a color patch vcface for each patch triangle of the mesh (corresponding to the texture patch tvface in the texture map). The color value of each point in a triangular patch is determined by the corresponding color interpolation of its three vertices, which is a more common method in the early stages.

Vertices color vertex is a set of Vertcolor type color values, in fact, this type is POINT3, three components are RGB components respectively. Mesh maintains a color vertex array vertcolor, the number is determined by Numcverts, Getnumvertcol ()/setnumvertcol () to return and set the number of color vertices.

• The color patch (color Faces) color patch storage type is still tvface, because its structure is just as simple as recording three vertices corresponding to the color index. Obviously, the same texture patch, the color patch and mesh geometry is one by one corresponding relationship. Mesh maintains a color patch array vcface,setnumvcfaces () to set the size of the color patch array.

After version 4.0, the data organization of color vertices was enhanced by the so-called enhancement that the color vertex array/color patch array could point to an external array. Curvcchan identifies the color channel being used.

[CPP] view plain copy vertcolor *vertcoloarray;     The array pointer still points to a default internal array, which is the previous vertcol;      Vertcolor *curvcarray;              Point to an external array, default to null int curvcchan;         Identifies the mapped channel being used, which defaults to 0 tvface *vcfacedata; The vcface array is used by default, and is used when other mapping channels are used

third, grid topology editing

Max provides a modifier plugin for editing the grid edit mesh, which corresponds to the function of the edit mesh, and the SDK contains methods to implement these functions, and further enhancements can be achieved through the SDK. Before you introduce these editing features, you have to repeat some of the rules of the grid.

1. An edge can be quoted at most once in the same direction;
2. Avoid the self-intersecting of the patches;
3. When creating a patch, the vertex of the patch appears coincident;
4. Do not use a point to join two different mesh parts;
5. Decompose the mesh into more easily understandable sub-elements (correspondingly, if it appears to be an element, then it should be an element);
6. Close the grid at any convenient time;

These rules are again mentioned because Max has no limitations when creating meshes, and you can create meshes that do not conform to any of the rules here, and some of the models I download from the Web are obviously the result of a challenge to these rules. Although a non-conforming grid is not constrained by Max, it can be cumbersome to use the SDK to handle this type of mesh. The special emphasis here is on the 1 and 42 specifications, which are a geometric basis for some of the algorithms in the SDK. In other words, if these specifications are not met, many of the plug-in features of the grid may have incorrect results. In that case, why do you have to create these hard-to-handle meshes? Fortunately, I noticed that some of the formal 3D production company's model requirements are very consistent with these specifications, on the one hand, these specifications are easy to follow and suitable for use on a variety of plug-ins, on the other hand, because they often need to use the SDK to write some small plug-ins to achieve some specific effects.

As an example, if a grid does not meet the 1 or 4 criteria, then the SELECT element in the edit mesh will be problematic, and the select Open edges will also have weird results. So here are some of the features of the editing grid that we've mentioned below, all for these more compliant grids.

3.1 Mesh class related methods

Mesh class, as the entity class of the grid, provides many basic editing methods. The following is a selection of common editing methods to be introduced.

• Find/Select/Hide/delete elements

(1) Vertex elements

◇findvertsusedonlybyfaces (): Finds the vertices to use for the specified patch set. This feature is often used in certain situations, similar to the "Convert face to Vertex" in Unwarp UVW. Mainly used for a set of patches that have been selected, but want to know the set of vertices that are currently selected in the patch.

◇getisoverts (): Find outliers, these points are not used by any patches.

◇vertsel (): Returns the selection state bit array of the vertex, or sets the selection state of any one vertex by this bit array.

◇verthide: This bit array identifies whether the vertex is hidden.

◇deleteisoverts (): Delete orphaned vertices, there is no need for orphaned vertices.

◇deleteselected (): If the selection level is at the vertex level, the selected vertices are deleted. At the same time, the patches associated with these vertices will also be deleted.

◇deletevertset (): Deletes the specified set of vertices. The vertex set can be any specified set of vertices, and the patches associated with them will be deleted.

(2) Patch elements

◇doesfaceexist (): Finds the presence of a patch for the specified vertex.

◇elementfromface (): Finds all patches connected to the specified patch. That is, the Select element function in the edit mesh.

◇polyfromface (): Finds the polygon that contains the specified patch. This concept is necessary to explain that the so-called polygon containing the patch refers to a set of patches, these patches share these hidden edges, and the angle of these hidden edges (that is, the edge-related patches of the two-sided corner) is less than a threshold value, the patches are still not composed of a polygon. That is, the Select Polygon function in the edit mesh.

◇facesel (): Returns the selection state bit array of the patch, or it can be used to set the selection state of any patch.

◇face_hidden: This identifier is the flags tag of the face class to identify whether the patch is hidden, and you can hide the patch by setting the identity.

◇removedegeneratefaces (): Removes all degraded patches.

◇removeillegalfaces (): Removes all errors of patches (index out of bounds, etc.).

◇deleteselected (): If the selection level is at the patch level, the selected patch will be deleted. At the same time, only the vertices associated with these patches will be deleted.

◇deletefaceset (): Deletes the specified patch set. Can be any of the specified patches, and only the vertices associated with this deletion will be deleted.

◇deleteflaggedfaces (): Removes the marked patch.

(2) Edge element

◇findopenedges (): Finds all border edges. Boundary edge refers to an edge that is associated with only one triangular patch.

◇displayalledges (): Whether all edges are displayed.

◇e

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.