lianlab / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

btTriangleIndexVertexArray has problems with double precisiom mode and single-precision meshes #213

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile Bullet with double precision
2. Use the btTriangleIndexVertexArray to create a collision shape that re-uses
a rendering mesh using single precision
3. Bullet assumes the mesh has double precision too, and the resulting shape
is invalid as the striding fails completely.

What is the expected output? What do you see instead?
It's not possible to define a single precision mesh when using double precision,
even though render meshes mostly are in single precision.

What version of the product are you using? On what operating system?
It's SVN 1649 on Linux 32 bit, but this seems to be a general problem.

Please provide any additional information below.
I've made a patch that fixes this. It changes 3 files:
btTriangleIndexVertexArray.h: 
Added PHY_ScalarType m_vertexType to the btIndexedMesh struct. 
Added a constructor to the struct that sets a default value for the type 
depending
on if the BT_USE_DOUBLE_PRECISION flag is defined or not. The default gives the
current Bullet behaviour.

btTriangleIndexVertexArray.cpp:
Removed the hardcoded setting for "type" and replaced it with setting type from
m_vertexType in the btIndexedMesh struct.

btStridingMeshInterface.cpp:
Allthough type is passed in the getLockedReadOnlyVertexIndexBase function, it
has been completely ignored. Instead a cast to the btScalar was used to get the
vertex coordinates. Now in the patch there is a switch statement checking the
type, and casting to either float or double. 

This might create an additional small performance hit due to the extra switch
statement. If this is too bad, I suggest having an #ifdef
BT_USE_DOUBLE_PRECISION for the whole block using the new code, and #else
with the old code, as it probably would be safe to assume that no-one would run 
in
single-precision mode using double-precision meshes.

Also, I am unsure about alignment in the btIndexedMesh struct. Please check if I
messed it up after adding the extra variable. :-)

Best regards,
Ola Røer Thorsen

Original issue reported on code.google.com by olaroert...@gmail.com on 1 Apr 2009 at 9:59

Attachments:

GoogleCodeExporter commented 9 years ago
Forgot to mention that the patch is relative to the src/ directory, not the 
base directory. 

Original comment by olaroert...@gmail.com on 1 Apr 2009 at 10:00

GoogleCodeExporter commented 9 years ago
good point, we'll look into fixing this.

Thanks a lot for the patch!

Original comment by erwin.coumans on 1 Apr 2009 at 9:23

GoogleCodeExporter commented 9 years ago

It has been applied, with the #ifdef
BT_USE_DOUBLE_PRECISION, so it doesn't hurt performance in single precision 
builds.

http://code.google.com/p/bullet/source/detail?r=1650

Thanks for the report and patch!
Erwin

Original comment by erwin.coumans on 6 May 2009 at 7:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Unfortunately the patch seems to have broken multiple-index-mesh support:

http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3657

Need to fix this (or revert) before 2.75 release.

Original comment by erwin.coumans on 2 Jun 2009 at 6:16

GoogleCodeExporter commented 9 years ago
Small fix for multiple-index-mesh issue, needs testing
http://code.google.com/p/bullet/source/detail?r=1691

Original comment by erwin.coumans on 11 Jun 2009 at 1:26

GoogleCodeExporter commented 9 years ago

Original comment by erwin.coumans on 10 Sep 2009 at 11:53