Physx2.8 Tutorial: Cooking

Source: Internet
Author: User
From: The physx SDK. chm/GUIDE/collision detection/meshes/cooking

To create a triangle mesh, you must first cook it into a fixed format. in this format, the SDK can efficiently perform conflict detection. The cooking process may be very slow. Therefore, the cooking operation is usually performed offline only once. After the process is completed, generated stream of the result data is saved as a document. The next time you load it, you only need to load it.

Use PPU for Cook. There are also some precautions. For details, see the mesh paging section. Practical Program Use the nxcooking library cook mesh. First, you must call the following interface to initialize an nxcooking library object:

 

Static Nxcookinginterface * Gcooking = Nxgetcookinglib (nx_physx_sdk_version );
Gcooking -> Nxinitcooking (); Then, use Nxtrianglemeshdesc The object describes a grid and passes it as a parameter to the function. Nxcooktrianglemesh () , This function will process the mesh description and use the stream -- Nxstream Physx requires the user to implement a read/write operation interface-then stream can write it into the file or memory. // Build physical model
Nxtrianglemeshdesc bunnydesc;
Bunnydesc. numvertices = Bunny_nbvertices;
Bunnydesc. numtriangles = Bunny_nbfaces;
Bunnydesc. pointstridebytes =   Sizeof (Nxvec3 );
Bunnydesc. trianglestridebytes =   3 * Sizeof (Nxu32 );
Bunnydesc. Points = Gbunnyvertices;
Bunnydesc. triangles = Gbunnytriangles;
Bunnydesc. flags =   0 ;
Gcooking -> Nxcooktrianglemesh (bunnydesc, userstream ( " C: \ cooked. Bin " , False )); Next, when the application needs to create a triangular mesh, load the mesh data stored by stream using the following function. Bunnytrianglemesh = Gphysicssdk -> Createtrianglemesh (userstream ( " C: \ TMP. Bin " , True )); Nxcookconvexmesh () / Nxcookclothmesh () And Nxcooktrianglemesh () The usage is the same. Note: : The cooking operation is greatly affected by the precision, and relies heavily on the FPU mode of the floating point operation unit. Cross-platform, ensure that the precision of FPU is consistent with the rounding method. In the preceding example, the flag Member is not set. Flag can be used to set some special flag. For example
    1. Nx_mf_flipnormals-Reverse Order of the three vertices in the index list (counter-clockwise by default), that is, reverse normal
    2. Nx_mf_16_bit_indices-The Data Length of the vertex index is 16 bits instead of 32 bits.
    3. Nx_mf_convex-Allows the mesh to be viewed as convex and automatically optimized
The normal line of the triangle surface is not explicitly described. It can calculate (V1-V0) x (v2-V0) v0, V1, and v2 as three vertices of the triangle. The counter-clockwise (right-hand rule right handed coordinate system) is clockwise. Algorithm They are all the same. Grid considerations:
    1. Ensure the orientation of the normal. Conflict Detection only correctly calculates the shape from the front.
    2. Do not repeat the vertex. If the two triangles share one vertex, This vertex can only appear once in the vertex list, but is indexed twice in the index list. Because duplicate vertices are two vertices for physx, which may cause conflict detection errors.
    3. Do not use t-joint or non-manifold edge. (Because both of these two items require the sharing points in the triangle to be regarded as two points .)
    4. Once the mesh Cook is complete, both the mass and inertia tensor are calculated.
    5. The materials of different triangles in the same mesh can be different. For details, see the material chapter.
Then you can use mesh to create a shape and actor. The key is to set the meshdata of the triangle mesh shape description to the mesh after the previous cooking. Nxtrianglemeshshapedesc bunnyshapedesc;
Bunnyshapedesc. meshdata = Bunnytrianglemesh;
Nxbodydesc bodydesc;
Nxactordesc actordesc;
Actordesc. shapes. pushback ( & Bunnyshapedesc );
Actordesc. Body =   & Bodydesc;
Actordesc. Density =   1.0f ;
Nxactor * Newactor = Gscene -> Createactor (actordesc );

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.