Jump to content

Create mesh like plane (side not visible)


benjydel
 Share

Recommended Posts

Hi !

I have to create a room in babylon js. I have used 4 plane for the walls and a ground for the ground. With that, we can see all the time on the room because some side are visible and some not.

I would like to know if we can do that with some other mesh like ligne. I have to do a grid on the wall and the ground.

 

Tkanks !

Link to comment
Share on other sites

12 hours ago, adam said:

If you need one side of the LineSystem to be invisible, you can do something like this:

http://www.babylonjs-playground.com/#1DKDYG#3

The sideOrientation property doesn't work for LineSystem or LinesMesh.

Thank you very much 

I try to understand how your solution works but i am blocked at this lines :
 

var mat = camera.getWorldMatrix();
		
		camVec.x = mat.m[8];
		camVec.y = mat.m[9];
		camVec.z = mat.m[10];

How do you know which coordonate is the "camVec" ?
Because i need to repeat this on other planes

An other question : 
Can i add several  registerBeforeRender() ?? I mean, if y iterate this again won't it be erase ??

Thank you very much again ;)

Link to comment
Share on other sites

It appears as though you can add several registerBeforeRender functions.

http://www.babylonjs-playground.com/#1DKDYG#4

1 hour ago, benjydel said:

How do you know which coordonate is the "camVec" ?
Because i need to repeat this on other planes

You can do this instead:

http://www.babylonjs-playground.com/#1DKDYG#6

If the dot product of the camera direction vector and the normal of the plane is negative, then the plane should be facing you.

I'm not sure why it isn't working perfectly though if the plane is translated like this:

http://www.babylonjs-playground.com/#1DKDYG#5

Maybe someone else here will know what the issue is.

 

Link to comment
Share on other sites

Thank you @adam I finally found the issue.

But i can't explain how it work, I have been inspired of your solution:

    var VecteurNormal;
    var camVec = BABYLON.Vector3.Zero();
    
            VecteurNormal = BABYLON.Vector3.Cross(new BABYLON.Vector3(0,-1,0), new BABYLON.Vector3(0,0,-1));
           
    scene.registerBeforeRender(function () {
        var mat = camera.getWorldMatrix();
        camVec.x = mat.m[12];
        camVec.y = mat.m[13];
        camVec.z = mat.m[14];
        var dot = BABYLON.Vector3.Dot(camVec, VecteurNormal);
        if (dot > 0) {
            ligne.visibility = 1;
        } else {
            ligne.visibility = 0;
        }
    });

And if there is a translation :

camVec.x = mat.m[12]+xTranslation;
camVec.y = mat.m[13]+yTranslation;
camVec.z = mat.m[14]+zTranslation;

 

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...