dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
412 stars 57 forks source link

3D Heightfield: Runtime: unreachable #138

Closed a-type closed 2 years ago

a-type commented 2 years ago

No matter what I provide to the collider description, 3d heightfields always seem to throw this error:

0050af16:0xffe45 Uncaught (in promise) RuntimeError: unreachable
    at 0050af16:0xffe45
    at 0050af16:0x1303c4
    at 0050af16:0xfb6c1
    at Function.heightfield (rapier_wasm3d.js:3585:26)
    at oI.intoRaw (shape.ts:969:33)
    at aI.createCollider (collider_set.ts:65:35)
    at FI.createCollider (world.ts:342:31)
    at terrainCollider.ts:29:28
    at Generator.next (<anonymous>)
    at Effect.ts:79:37

last line of JS code before the exception is thrown:

        const ret = wasm.rawshape_heightfield(nrows, ncols, ptr0, len0, scale.ptr);

My heightfield is 257x257, the Float32Array of heights is correspondingly 66049 entries in size. But I've also tried a 2x2 heightfield full of 0s, same error.

I'm using @dimforge/rapier3d-compat Version is 0.8.1.

jcyuan commented 2 years ago

https://github.com/viridia/demo-rapier-three/blob/main/src/terrain/TerrainShape.ts#L108 check this out and try.

a-type commented 2 years ago

Thanks - it appears my error was because the heightmap height array should be (width + 1) * (height + 1) in length, not width * height as I assumed. It's working now!