elkyu Posted June 30, 2015 Share Posted June 30, 2015 Hi, Yes, me again ... So, I still have my plane with some face (triangle) compose by 3 vertex. I can get the face ID, get the 3 vertex which compose a face, get the normal of each vertex but now, I would like to find how to get the normal of a face (not the all plane, just one face) .. I try with the function getNormal() (pickingInformation) but each time that return x=0 y=1 z=0, but some face are inverted and the function return the same result I don't know why Quote Link to comment Share on other sites More sharing options...
jahow Posted June 30, 2015 Share Posted June 30, 2015 Hey again, This is where it's done in the BJS code (used for converting mesh to flat shaded): https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.mesh.ts#L1102 Basically the normal of a face is the cross product of two of its three sides, but you have to compute it yourself (this data is not stored, unlike vertices normals). Good luck elkyu and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
elkyu Posted June 30, 2015 Author Share Posted June 30, 2015 Thank you ! It's done and it's working var positions = plane.getVerticesData(BABYLON.VertexBuffer.PositionKind);scene.onPointerDown = function(evt, pickResult){ if(pickResult.hit){ faceId = pickResult.faceId; var vertex1 = BABYLON.Vector3.FromArray(positions, indices[faceId * 3] * 3); var vertex2 = BABYLON.Vector3.FromArray(positions, indices[faceId * 3 + 1] * 3); var vertex3 = BABYLON.Vector3.FromArray(positions, indices[faceId * 3 + 2] * 3); var p1p2 = vertex1.subtract(vertex2); var p3p2 = vertex3.subtract(vertex2); var normal = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(p1p2, p3p2)); }} jahow 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 30, 2015 Share Posted June 30, 2015 You can also call pickResult.getNormal() Quote Link to comment Share on other sites More sharing options...
elkyu Posted June 30, 2015 Author Share Posted June 30, 2015 You can also call pickResult.getNormal() Like I said, it's not working . Each time that return x=0 y=1 z=0 , but some face are inverted .. Quote Link to comment Share on other sites More sharing options...
jahow Posted July 1, 2015 Share Posted July 1, 2015 That's because this method uses the vertices normals to compute the face normal: https://github.com/BabylonJS/Babylon.js/blob/master/src/Collisions/babylon.pickingInfo.ts#L21 The difference between both type of computations should probably be documented somewhere... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 1, 2015 Share Posted July 1, 2015 Correct Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 1, 2015 Share Posted July 1, 2015 I updated pickingInfo.getNormal to allow both versions:getNormal(useWorldCoordinates = false, useVerticesNormals = true) jahow, MinsuKim and c75 2 1 Quote Link to comment Share on other sites More sharing options...
MinsuKim Posted August 9, 2018 Share Posted August 9, 2018 On 2015. 7. 2. at 오전 12시 48분, Deltakosh said: 두 버전 모두 허용하도록 pickingInfo.getNormal을 업데이트했습니다. getNormal (useWorldCoordinates = false, useVerticesNormals = true) this code is work for me!! Quote Link to comment Share on other sites More sharing options...
jerome Posted August 9, 2018 Share Posted August 9, 2018 http://doc.babylonjs.com/how_to/how_to_use_facetdata getFacetNormal() 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.