NVIDIAGameWorks / PhysX

NVIDIA PhysX SDK
Other
3.11k stars 793 forks source link

(double) vertex error. #590

Open mandusulrungtang opened 1 year ago

mandusulrungtang commented 1 year ago

I I used (double) vertices. Used UE5 LARGE_WORLD_COORDINATES

    PxTriangleMeshDesc meshDesc;
    meshDesc.points.count = mesh->getVertCount();
    meshDesc.points.data = mesh->getVerts();
    meshDesc.points.stride = sizeof(double) * 3;
    meshDesc.triangles.count = mesh->getTriCount();
    meshDesc.triangles.data = mesh->getTris();
    meshDesc.triangles.stride = sizeof(int) * 3;

    PxDefaultMemoryOutputStream writeBuffer;
    PxTriangleMeshCookingResult::Enum result;
    bool ok = m_Cooking->cookTriangleMesh(meshDesc, writeBuffer, &result);

I think this code Wrong.; Cooking.h - 73 Line

PX_FORCE_INLINE static void     gatherStrided(const void* src, void* dst, PxU32 nbElem, PxU32 elemSize, PxU32 stride)
{
    const PxU8* s = reinterpret_cast<const PxU8*>(src);
    PxU8* d = reinterpret_cast<PxU8*>(dst);
    while(nbElem--)
    {
        PxMemCopy(d, s, elemSize);
        d += elemSize;
        s += stride;
    }
}

elemSize = 12 stride = 24

PxMemCopy . (float, float, float) <- (double , double , double)

nvtw commented 1 year ago

Hi, it looks like you would like to use the gatherStrided method to convert your data from double to float. That is not the purpose of this method. The method only copys data from different layouts into a dense array without doing data type conversions. E. g. it copies an array of PxVec4 into a dense array of PxVec3 but the data type is already float. In your case, you probably need to create a PxArray (or other array type) out of your data in mesh->getVerts() and store the vertex information as float instead of doubles. Unfortunately PhysX does not offer methods for that conversion out of the box. Hope that solves your problem.