*
Login | forgot password | register | register with OpenID Click here to register with OpenID
X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

(what is OpenID?)

Forums

45 Posts in 15 Topics by 16 members

Jump to:

General Discussion

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Imaginary Game Engine » Forums » General Discussion » Can not create NxTriangleMesh
Page: 1 go to end Reply
Author Topic: Can not create NxTriangleMesh 813 views
  • LeshaVH
    LeshaVH's avatar
    Community Member
    2 posts

    Can not create NxTriangleMesh

    Here is sample code that threw access viloation exception. Could u please point to problem?

     
    Vector3[] vertices = new Vector3[3];
    vertices[0] = Vector3.Zero;
    vertices[1] = Vector3.UnitX;
    vertices[2] = Vector3.UnitY;
     
    int[] indices = new int[3];
    indices[0] = 0;
    indices[1] = 1;
    indices[2] = 2;
     
    NxTriangleMeshDesc meshDesc = new NxTriangleMeshDesc();
     
    // unsafe part
    unsafe
    {
    fixed (int* pIndices = indices)
    {
    meshDesc.triangles = new IntPtr((void*)pIndices);
    }
     
    fixed (Vector3* pVertices = vertices)
    {
    meshDesc.points = new IntPtr((void*)pVertices);
    }
     
    meshDesc.pointStrideBytes = (uint)sizeof(Vector3);
    }
     
    meshDesc.numVertices = (uint)vertices.Length;
    meshDesc.numTriangles = (uint)indices.Length / 3;
    meshDesc.triangleStrideBytes = 3 * sizeof(int);
    meshDesc.flags = 0;
    meshDesc.heightFieldVerticalAxis = NxHeightFieldAxis.NX_Z;
    meshDesc.heightFieldVerticalExtent = -1000.0f;
     
    NxCookingInterface cooking = PhysXLoader.NxGetCookingLib(PhysXLoader.NX_PHYSICS_SDK_VERSION);
    NxStream stream = new NxStream();
    bool cooked = cooking.NxCookTriangleMesh(meshDesc, stream);
     
    NxTriangleMesh mesh = sdk.createTriangleMesh(stream);
     
    cooking.Dispose();
    cooking = null;
     
    meshDesc.Dispose();
    meshDesc = null;
     

    Last edited: 18 July 2008 at 10:37pm

  • SeaEagle1
    SeaEagle1's avatar
    Administrator
    16 posts

    Re: Can not create NxTriangleMesh

    I can't tell exactly what your problem is, but one of them is that you assign pointers in the meshDesc in the fixed{ } part, but immediatly 'free' them by leaving fixed{ } while PhysX will use those pointers when you call NxCookTriangleMesh(). So it should be something like

     
    // create stream
    NxStream stream = new NxStream();
     
    // go unsafe
    unsafe
    {
    // fix pointers
    fixed (int* pIndices = indices)
    fixed (Vector3* pVertices = vertices)
    {
    // assign pointers
    meshDesc.triangles = new IntPtr((void*)pIndices);
    meshDesc.points = new IntPtr((void*)pVertices);
     
    meshDesc.pointStrideBytes = (uint)sizeof(Vector3);
     
    meshDesc.numVertices = (uint)vertices.Length;
    meshDesc.numTriangles = (uint)indices.Length / 3;
    meshDesc.triangleStrideBytes = 3 * sizeof(int);
    meshDesc.flags = 0;
    meshDesc.heightFieldVerticalAxis = NxHeightFieldAxis.NX_Z;
    meshDesc.heightFieldVerticalExtent = -1000.0f;
     
    // create mesh
    NxCookingInterface cooking = PhysXLoader.NxGetCookingLib(PhysXLoader.NX_PHYSICS_SDK_VERSION);
    bool cooked = cooking.NxCookTriangleMesh(meshDesc, stream);
    }
    }
     
    NxTriangleMesh mesh = sdk.createTriangleMesh(stream);
     

    Last edited: 18 July 2008 at 10:47pm

  • LeshaVH
    LeshaVH's avatar
    Community Member
    2 posts

    Re: Can not create NxTriangleMesh

    Thanks for reply!

    However your code does not work too...
    I try to check and figure out that NxCookTriangleMesh() does not write to stream anything....

    As I check it in C++ all is fine (stream must containt about 300 bytes for 2 trianlges), except at least 2 triangles should be passed to NxCookTriangleMesh()...

    Could u please check it in ะก#?

    813 views
go to top Reply

Currently Online:

There is nobody online.

Welcome to our latest member: jfreie