ozRocker Posted August 6, 2017 Share Posted August 6, 2017 Does anyone know of a way to get the circumference of a mesh at any point on the Y-axis in realtime? I've attached an image below as an example. I'd like to find the circumference around the shoulders, like I wrapped string around it then measured that length of string. I suppose you could measure the distance from one point to the next, then add them all up for total circumference but there's 2 things I'm unsure of: how to get points from exactly the same place on the Y-axis how to take into account smooth-shading Quote Link to comment Share on other sites More sharing options...
ozRocker Posted August 6, 2017 Author Share Posted August 6, 2017 I played with Blender to create an edge-loop at the area I want to measure. I figured that I could somehow save that as a vertex group, but the Babylon.js exporter doesn't store that info. I tried separating those vertices into a separate mesh, but I think Babylon.js exporter will only save mesh data if it creates a polygon, 'cos that separate mesh just ended up as an empty array. I don't think its possible with Blender to store a set of vertices as a "group" which the exporter will also convert Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 7, 2017 Share Posted August 7, 2017 Hi Oz. Um... at any level of Y, surround the model with tiny planes... positioned and Y-rotated into a circle. Perhaps 16 of them, and you can scale their X-axes so that they DON'T OVERLAP each other. As you reduce the diameter of the circle-of-planes, you will need to down-scale each plane's X. IF they overlap whatsoever, you will not get an accurate circumference at the end of the procedure. Keep reducing the diameter of the circle-of-planes until one of them has an intersectsMesh with the model. Then "undo"... positioning/scaling planes at the previous diameter/scale of the circle-of-planes, when there was NO intersect. You are seeking "just barely NOT intersecting" with the primary model. Next, merge all the tiny planes together, and make sure you have good refreshBoundingInfo() (probably automatically done in merge code). Then... use mergedMesh.getBoundingInfo().boundingBox.extendsSizeWorld to get a diameter. (You can also subtract primary model position... from ANY tiny-plane position, and that will be circle radius. Double it for diameter, of course.) Then, circumference = diameter * PI. How's that for a ridiculous way of doing it? Edge-loop, the hard way. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted August 7, 2017 Author Share Posted August 7, 2017 20 minutes ago, Wingnut said: Hi Oz. Um... at any level of Y, surround the model with tiny planes... positioned and Y-rotated into a circle. Perhaps 16 of them, and you can scale their X-axes so that they DON'T OVERLAP each other. As you reduce the diameter of the circle-of-planes, you will need to down-scale each plane's X. IF they overlap whatsoever, you will not get an accurate circumference at the end of the procedure. Keep reducing the diameter of the circle-of-planes until one of them has an intersectsMesh with the model. Then "undo"... positioning/scaling planes at the previous diameter/scale of the circle-of-planes, when there was NO intersect. You are seeking "just barely NOT intersecting" with the primary model. Next, merge all the tiny planes together, and make sure you have good refreshBoundingInfo() (probably automatically done in merge code). Then... use mergedMesh.getBoundingInfo().boundingBox.extendsSizeWorld to get a diameter. Then, circumference = diameter * PI. How's that for a ridiculous way of doing it? Edge-loop, the hard way. That's an interesting way of doing it. Isn't diameter * PI for circles only? I will have meshes of all kinds of shape Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 7, 2017 Share Posted August 7, 2017 Ohhhh, you need non-circular circumference? Okay, never mind me, then. Sorry, I misunderstood. You need a cloth tape measure that can follow model contours precisely. Yuh, yuh, yuh. hmm. Like a tiny police skid-measuring wheel... that you can roll-around the mesh at any Y-point. Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 7, 2017 Share Posted August 7, 2017 (The term should be perimeter not circumference but no nit picking among friends). At first I thought I had a solution but it does not seem to generalize. Using raycasting I obtained an acceptable result. Taking a box of side 4 I got 15.9 as the circumference which is pretty close to 16. The lower the increment the more accurate the result. Here is the PG, check console for circumference. https://www.babylonjs-playground.com/#KNE0O#48 However when I tried to do the same thing with the skull the individual picked point results and the circumference do not make sense. According to the boundingInfo the skull is about 46 across which gives a ball park figure of 90 for the circumference at the chosen Y point but I get 9.7. Perhaps I am on the right track and just do not know enough about raycasting to do it properly or maybe it is not the way to do it. Anyway here is PG with skull for what it is worth. (by the way with the skull an increment of 0.01 for the skull locks the browser for a long time). https://www.babylonjs-playground.com/#KNE0O#51 EDIT When I showed the rays I found the mistake, the rays were not in the direction I expected. I had modified another playground but found to get rays in right direction I should just use the forward vector not the calculated direction vector. So this might work https://www.babylonjs-playground.com/#KNE0O#52 Wingnut, ozRocker and Pryme8 3 Quote Link to comment Share on other sites More sharing options...
SvenFrankson Posted August 7, 2017 Share Posted August 7, 2017 Hi, As far as I've tried, it might be expensive to cast multiple rays each frame on a high-poly mesh (it loops through triangles when the ray hit the bounding box). A solution in cases you may take an approximation as a result is to use a low-poly (very low-poly) version of your mesh to do it. For example, draw your skull with 60 vertices on Blender, attach the Mesh to the high-poly skull, hide it, and raycast on the low poly version. (also, once you have a 60 triangles mesh, it's not that expensive to loop through the vertices to evaluate the diameter, and you may drop the use of raycast, you have an "exact result based on approximate mesh", which might be better than "approximate result on exact mesh"). Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 7, 2017 Share Posted August 7, 2017 1 hour ago, SvenFrankson said: once you have a 60 triangles mesh, it's not that expensive to loop through the vertices Presuming you mean at least a 60 triangles mesh since in that case the facet triangles are small enough to give a good approximation then how expensive is it to determine the the vertices with a y value close enough to the given y value and that the vertices are consecutive by increasing angle. Remember that the contour of the slice at y may not be anywhere close to a circle and so just finding the diameter is not good enough. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 7, 2017 Share Posted August 7, 2017 why not just get its bounding box then? circumference is for ellipsoids I believe. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted August 8, 2017 Author Share Posted August 8, 2017 On 07/08/2017 at 2:10 PM, JohnK said: (The term should be perimeter not circumference but no nit picking among friends). At first I thought I had a solution but it does not seem to generalize. Using raycasting I obtained an acceptable result. Taking a box of side 4 I got 15.9 as the circumference which is pretty close to 16. The lower the increment the more accurate the result. Here is the PG, check console for circumference. https://www.babylonjs-playground.com/#KNE0O#48 However when I tried to do the same thing with the skull the individual picked point results and the circumference do not make sense. According to the boundingInfo the skull is about 46 across which gives a ball park figure of 90 for the circumference at the chosen Y point but I get 9.7. Perhaps I am on the right track and just do not know enough about raycasting to do it properly or maybe it is not the way to do it. Anyway here is PG with skull for what it is worth. (by the way with the skull an increment of 0.01 for the skull locks the browser for a long time). https://www.babylonjs-playground.com/#KNE0O#51 EDIT When I showed the rays I found the mistake, the rays were not in the direction I expected. I had modified another playground but found to get rays in right direction I should just use the forward vector not the calculated direction vector. So this might work https://www.babylonjs-playground.com/#KNE0O#52 This seems to work best. Thanx mate! Quote Link to comment Share on other sites More sharing options...
ozRocker Posted August 8, 2017 Author Share Posted August 8, 2017 @JohnK using your method here http://punkoffice.com/measurements If you compare to the stats on the right it seems pretty accurate. JohnK 1 Quote Link to comment Share on other sites More sharing options...
TimT77 Posted June 22, 2018 Share Posted June 22, 2018 @JohnK: i wanna do this (https://www.babylonjs-playground.com/#KNE0O#52) with simple meshes (like a MeshBuilder Box), but i ran into an error: https://www.babylonjs-playground.com/#KNE0O#93 What's the problem? Best regards Tim Quote Link to comment Share on other sites More sharing options...
SvenFrankson Posted June 22, 2018 Share Posted June 22, 2018 Your hit variable is never null, there's a boolean property hit.hit telling you wheter your ray touched something or not https://www.babylonjs-playground.com/#KNE0O#94 Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 22, 2018 Share Posted June 22, 2018 @ozRocker You always have interesting challenges. However, if this were my challenge, I would use a small texture of a known length to wrap around any specific area of the mesh. Then since it's tiled and I know the PX length, I can handle the rest of the calculations based upon how many times the image is tiled. You can attach this to any event, and hide the texture when you don't need it. That's my thought of the day ('night'). DB Quote Link to comment Share on other sites More sharing options...
TimT77 Posted June 25, 2018 Share Posted June 25, 2018 @SvenFrankson Hi! Many thanks for your advice! That was the solution! Best regards Tim SvenFrankson 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.