Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creation of PxHeightField Geometry #40

Open
im-esteban opened this issue Nov 30, 2024 · 5 comments
Open

Creation of PxHeightField Geometry #40

im-esteban opened this issue Nov 30, 2024 · 5 comments

Comments

@im-esteban
Copy link

Hi there Mr. fabmax, again thanks for always answering my small issues and helping everyone out, even my whole game idea is reliant on your library to a very high degree, anyways, the issue that brought me here once more is that there are some things i see missing, like this: github.com/fabmax/physx-jni/issues/74

Here you are telling someone that they should use PxHeightFieldSample.SIZEOF,
so what do you think should be the answer for us in the JS side?

let heightFieldDesc = new PhysX.PxHeightFieldDesc()
heightFieldDesc.samples.stride = 12 //PxHeightFieldSample 8 bytes? 12 bytes?

i tried going through your physx-jni and kool-engine (such cool engine) and the only piece i'm missing is that one,
even tried setting the stride value from 5 to 52(there is no way it is more than 16) and testing every number generating a flat height map but every time the collisions weren't right which makes me think that there is something else wrong, i should have hit the size, right?

Truly yours, your biggest fan, this is Stan.

@im-esteban
Copy link
Author

oh and real quick tell me if there is something wrong here, i tried to simplify it so you can take a quick look

let sampleArray = new PhysX.PxArray_PxHeightFieldSample()
let heightFieldDesc = new PhysX.PxHeightFieldDesc()
heightFieldDesc.nbColumns = numberOfColumns
heightFieldDesc.nbRows = numberOfRows
heightFieldDesc.format = PhysX.PxHeightFieldFormatEnum.eS16_TM
                                                                                
heightFieldDesc.samples.stride = 0 // placeholder, i have no idea

for (let i = 0; i < heights.length; i++) {

    let sample = new PhysX.PxHeightFieldSample()

    sample.height = heights[i]
    sampleArray.set(i, sample)
}

heightFieldDesc.samples.data = sampleArray

let hf = PhysX.PxTopLevelFunctions.prototype.CreateHeightField(heightFieldDesc)
let flags = new PhysX.PxMeshGeometryFlags(0)
geometry = new PhysX.PxHeightFieldGeometry(hf, flags, 1, 100, 100)

@im-esteban
Copy link
Author

went through the whole deal of compiling PhysX, and building a program with it, the answer is 4, the thing is that still it doesn't work well for me, if i find out why i post an update

@im-esteban
Copy link
Author

Fixed it, you have to call .begin() on the array (or .data() if is a vector) like this:
heightFieldDesc.samples.data = sampleArray.begin()

@fabmax
Copy link
Owner

fabmax commented Dec 1, 2024

Hi! Yeah 4 is correct. I haven't yet found a way how to get these values in a nice way in JS. I usually check what the SIZEOF value in the java version returns and simply use that. Here I did that in kool

The desc.samples.data = samples.begin() is there as well 😄

Anyway, glad you figgered it out!

@im-esteban
Copy link
Author

im-esteban commented Dec 1, 2024

I was pretty close, was zooming through those files too, also your code is very clear to read.

Good night and thank you, fabmax!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants