Jump to content

intersectsMesh() doesn't work


Uniform
 Share

Recommended Posts

Quote

And to begin with I'd like to  ask you why the heck is the ball becoming red even after the commented out bounding boxes? 

@Uniform : You are not commenting out the actual bounding boxes of the two planes. That code is actually just showing you what/where the bounding boxes are that are being used by the two conditions

(balloon1.intersectsMesh(plan1, false))
and
(balloon2.intersectsMesh(plan1, true))

cheers, gryff :)

Link to comment
Share on other sites

On 12/07/2016 at 2:27 AM, gryff said:

@Uniform : You are not commenting out the actual bounding boxes of the two planes. That code is actually just showing you what/where the bounding boxes are that are being used by the two conditions


(balloon1.intersectsMesh(plan1, false))
and
(balloon2.intersectsMesh(plan1, true))

cheers, gryff :)

Thank you a lot @gryff

 

It is really strange because i feel like the bounding box has been designed for me and I have no word to say, quite strange.

But anyway it still doesn't resolve my issue.

Here is the code: http://www.babylonjs-playground.com/#1GHPEG (open the console and press run)

 

Basically, I am trying to map the terrain into a 2 dimension matrix of 0 for non walkable and 1 for walkable. (for further pathfinding use)

I am planning to use an abstract mesh as a pointer but for visual purposes i am using a mesh. Every frame this mesh will move by incrementations of 0.5 units on the x axis. When it reaches the border of the ground the pointer will increment the z axis until it reaches the top right corner of the terrain. I use the intersectMesh() function to detect wether the pointer mesh encounters another mesh, in this case the big red box.

I am printing the matrix into the console and i am limiting the computing to the 3 first frames because everything is similar after it.

This is the algorithm:

 var pathMatrix = []; // initializing an array
        function computeMatrix(){
            var begin = [-7.5,-7.5]; // bottom left corner of the ground
            var end = [7.5,7.5]; // top right corner of the ground
            var incr = 0.5; // Incremental value, crashes if set to 0.1... strange!
            pointer.position = new BABYLON.Vector3(begin[0],0.3, begin[1]);

            var tempArray = []; // temp array representing each row of the Matrix
            var stop = false;
            while(stop == false){
                if(pointer.intersectsMesh(box,true)){
                    tempArray.push(0);
                }
                else{
                    tempArray.push(1);
                }

                // Condition of stop
                if (pointer.position.x == end[0] && pointer.position.z == end[1]){
                    pathMatrix.push(tempArray);
                    tempArray = [];
                    stop = true;
                }
                else if (pointer.position.x == 7.5){
                    pathMatrix.push(tempArray);
                    tempArray = [];
                    pointer.position.x = -7.5;
                    pointer.position.z += incr; // go to next row
                }
                pointer.position.x += incr; // go to next column
            }
            // Print each row of the array in console
            for(var i = 0; i<30;i++){
                console.log(pathMatrix[i]);
            }
            pathMatrix = []; // reset the matrix arrau
        }

 

 

I would be very grateful if anyone can help me to resolve this issue. Basically I am trying to obtain a 2dimension matrix based on the abstract representation of the ground mesh. This matrix represents a collision mask that I will be able to use with my pathfinding library.

If you have other suggestions of how I can do this because this might be a bit overkill (especially moving an object several times per frame)

 

Thanks, 

Uniform

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

I'm sorry but I did not get the problem here ;)

can you try to explain me with a simple playground where the problem is?

Wow didn't expect an answer from the mighty creator :D

Well if you look at the matrix output the first frame I obtain only zero's. It is okay because the first frame everything is created.

But then the next frames I get matrices only 1's.

mini_324971Capture.png

 

 

So because there is this big red box in the middle of the ground the matrix should have some 0 in the place of 1's because that means that the pointer encountered some collision and thus there is a mesh in the way.

Which is not the case here because I only get an array of 1.

Link to comment
Share on other sites

ok gotcha:) Not a big deal then. This is because the internal bounding info are only updated when a frame is rendered for performance reason.

Just add this code:

pointer.computeWorldMatrix(true); // true to force all inner values to get updated RIGHT NOW :)
if(pointer.intersectsMesh(box,true)){
                    tempArray.push(0);
                }
                else{
                    tempArray.push(1);
                }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...