freignat Posted April 7, 2018 Share Posted April 7, 2018 Hello, I'm trying to update a box mesh, in order to be able to deform it, for that, i create a box a regular way: let myBox = BABYLON.Mesh.CreateBox(name, size, scene, true); and then in the main loop, i tried to update the box, mesh, for now to be simple, i just tried to move it with a dx translation let pos = myBox.getVerticesData(BABYLON.VertexBuffer.PositionKind) for (let index=0; index<pos.length; index=index+3) { pos[index] = pos[index]+dx } myBox.updateVerticesData(BABYLON.VertexBuffer.PositionKind, pos); of course, i could use myBox.position, to do the same, but later i want to update mesh in a more complicated way than just a translation and first i would this simple translation works updating directly the Vertices data. So, it works well, i see that my box is moving in the x axe direction, but on some camera angles the box disappears and be back visible on other angles. So i certainly forget to update something important for the raycaster. I tried, to update also normal vectors the same way than the position vertexes, with the same result, the box disappear on some angles. What's happening ? how update a mesh the right way to make it visible on all camera angles? Thanks Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 7, 2018 Share Posted April 7, 2018 Hiya freignat, welcome to the forum. This almost sounds like a lighting problem. (normals) I would use a hemisphericLight for tests... (they usually aim to the sky) and maybe a hemisphericLight.groundColor = BABYLON.Color3.Gray(); ( a little reflected ground-light on the bottom of the mesh. ) Maybe hemisphericLight.diffuse = BABYLON.Color3.Red(); Get some lighting/colors activated... then you can "see" the affect of adjusting mesh normals. Our boxes are 24 vert boxes, so there should be 24 normal directions, I suppose. do: myBox.showBoundingBox = true; Does the bounding box also disappear at certain camera angles? Also, you might want to set camera.minZ = .001 or some other little number... just for kicks. If you can reproduce the same problem... using our playground app... that would be cool. Oh wait... we have a playground that is similar... https://www.babylonjs-playground.com/#1UHFAP#198 Maybe that will help-out... except... that is a 8-vertice box. Your box is a 24 vert. *shrug*. (The BJS default 24-vert box... allows per-face colors and textures... nice feature.) Stay tuned for more ideas/comments from others... likely coming soon. Quote Link to comment Share on other sites More sharing options...
freignat Posted April 7, 2018 Author Share Posted April 7, 2018 Hi Wingnut, Yes, i use a hemisphericLight for my tests: let light0 = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene); light0.diffuse = new BABYLON.Color3(1, 1, 1); light0.specular = new BABYLON.Color3(1, 1, 1); light0.groundColor = new BABYLON.Color3(0, 0, 0); Then, i tried, with more lights as let light2 = new BABYLON.PointLight("light", new BABYLON.Vector3(10, 10, 0), scene); but, same result, the box disappear at the same angles than before I set myBox.showBoundingBox = true, as you propose, and yes, the bounding box disappear also at some camera angle same with camera.minZ = .001 I'll try to have the simpe page of code for playground to show that on a better way... Thanks for help and ideas! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
freignat Posted April 7, 2018 Author Share Posted April 7, 2018 Hi again; I have prepare a page code for playground, very close from the way i'm updating the box vertexes and ... it works well under playground. I don't have the box disappearing on the camera angle, so i''ll try to find out what's wrong in my full code... this is the playground code: var createScene = function () { let scene = new BABYLON.Scene(engine); scene.collisionsEnabled = true; let camera = new BABYLON.FreeCamera("MainCamera", new BABYLON.Vector3(0, 2.5, 5), scene); camera.speed = 0.5; camera.angularSensibility = 1000; camera.minZ = .001 scene.activeCamera.attachControl(canvas, true); let light0 = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene); light0.diffuse = new BABYLON.Color3(1, 1, 1); light0.specular = new BABYLON.Color3(1, 1, 1); light0.groundColor = new BABYLON.Color3(0, 0, 0); let myBox = BABYLON.Mesh.CreateBox(name, 2, scene, true); window.setInterval(function() { let pos = myBox.getVerticesData(BABYLON.VertexBuffer.PositionKind) for (let index=0; index<pos.length; index=index+3) { pos[index] = pos[index]+0.01 } myBox.updateVerticesData(BABYLON.VertexBuffer.PositionKind, pos); }, 100); return scene } Quote Link to comment Share on other sites More sharing options...
freignat Posted April 7, 2018 Author Share Posted April 7, 2018 Hey, after a while, i begging to have to same issues on playground with the code in my previous node. On, some angles the box disappears, but it needs to spend a little time, let the box go, and turn around the box to find the bad angles. So, i'm pretty sure that the way i update vertexes is not good. Quote Link to comment Share on other sites More sharing options...
JohnK Posted April 9, 2018 Share Posted April 9, 2018 Hi @freignat and welcome to the forum from me. First of all it is helpful if you save the playground and provide a link to it rather than just giving a copy of the code. https://www.babylonjs-playground.com/#VB9KDE#1 It is not simply that you are turning the camera so that the box is out of view of the camera, is it? Does the same thing happen if you do not update the vertex data (ie comment out line 23), if so it cannot be an updateVertexData problem. What happens of you change to an arc rotate camera. This will keep the box in view until it move outside the camera orbit. https://www.babylonjs-playground.com/#VB9KDE#2 Have you read about how the different cameras work? http://doc.babylonjs.com/babylon101/cameras Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 10, 2018 Share Posted April 10, 2018 Ahhhh... it DOES happen in the #1 playground. I see it. Firefox 52 ESR on Win 7 Inspiron desktop. Use various arrow keys... while holding down left mouse button for aiming. Perhaps wait for the mesh to move for 10-15 seconds, then pan the cam to make mesh go off-screen on either side. Sometimes/Often.... it appears to "pop" out of view... too soon. I think its gets worse... with more time or larger move-increments. Exact procedure... hold left arrow for 3 secs, then LMB-pan camera left and right, watching mesh as it disappears from both sides of screen. Re-center mesh... repeat procedure. Soon, mesh will be disappearing at the wrong time, or even disappearing with up/down arrow moves. (simpler, keep panning cam hard left/right, while occasionally holding some arrow keys) Again, it might be easier to see happen... after you let the mesh move for some time, or maybe move the mesh in larger increments. ----------- BUT... I THINK... this is a boundingBox NOT-updating... thing... which is fooling the FOV. The mesh is leaving its bounding area... behind, when it moves! (maybe) I put a myBox.refreshBoundingInfo(); at line 24 of #3 version, and it seems to work better. This might be the solve. I did some nav testing with the arrows and the panning, and I haven't been able to repeat the problem. Help me test this possible solve, gang. Freignat... you're not going insane. I have seen what you have seen. Yay! Good catch/report, F! Interesting issue! Quote Link to comment Share on other sites More sharing options...
freignat Posted April 15, 2018 Author Share Posted April 15, 2018 Hello, Sorry, i could not answer for days because of work, but i'm back now. JohnK, yes i'll save the playground and provide a link next time. Happy, that Wingnut could see the issue, i was about the provide another playground more clear. I added refreshBoundingInfo(), in my code and YES! it works well. Thanks very much for your help to you two. I'm trying to have a physique engine working with different kind of matter, steal, stone, wood, plastic, ... and have cube deformation/collision considering the real matter technical parameters (Young module, elasticity,....). Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.