Dad72 Posted December 2, 2016 Share Posted December 2, 2016 Hi, I am looking to create a ramp system. But I do not succeed in making it. Is what anybody has of idea of how? At the moment, I raise summits which form a mountain and I wish that by choosing vertexes from top of the mountain, then the vertexes of the bottom of the mountain, this will create a ramp. I found a sample video that looks like what I would like to do: How can this be done? Thank you for your help Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted December 2, 2016 Share Posted December 2, 2016 Why not just model ramps in 3d modeler ? Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 It is for a terrain editor that I do. So I need to have this tool for my editor. But I do not know yet how. Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 I start a PG of what I have until the. There are two modes. One for the vertex elevation and another for the ramps. It changes to line: 43 and 44 (To be changed manually) By default elevation mode is actived The function to make the ramp is line 171 Currently I select the vertex on functions: line 129 and 150 and I save them in an array. This corresponds to the beginning of the ramp towards the end. But I'm not sure if what I have started is correct. I wanted to take inspiration from the function: line 279 coming from worldmonger on the site of Babylon http://www.babylonjs-playground.com/#RKPBE#13 I hope there is some expert on terrain sculpture that will help me. This is the last thing of complicate with my editor. Thank you for you help Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
getzel Posted December 2, 2016 Share Posted December 2, 2016 Waho the terrain editor looks promising. Dad72 and Kemal UÇAR 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 Yes, There are other tools with: I also intend to add different brushes too. But I still have the problem of ramps with which I really struggle. The other tools work. getzel and Kemal UÇAR 2 Quote Link to comment Share on other sites More sharing options...
Gugis Posted December 2, 2016 Share Posted December 2, 2016 You have 2 variables - topPoint (at the top of the mountain) and bottomPoint (at the bottom of the mountain). Now you have to caculate distance and height difference between these two points: var totalDistance = Math.sqrt((topPoint.x-bottomPoint.x) * (topPoint.x-bottomPoint.x) + (topPoint.z - bottomPoint.z) * (topPoint.z - bottomPoint.z)); var heightDifference = topPoint.z - bottomPoint.z; Next you have to select which vertices you need to update, for that use https://en.wikipedia.org/wiki/Bresenham's_line_algorithm Loop through all vertices and calculate how far from bottom point current vertex is (use first method): var currentVertexDistance = Math.sqrt((bottomPoint.x-currentVertex.x) * (bottomPoint.x-currentVertex.x) + (bottomPoint.z - currentVertex.z) * (bottomPoint.z - currentVertex.z)); For getting proper height of current vertex you have to calculate distance ratio between current vertex and bottom point: var heightRatio = currentVertexDistance/totalDistance; Finally height of current vertex: currentVertex.z = endPoint.z + heightRatio * heightDifference; I am not sure that i wrote everything 100% correctly, but it should be something like that. Dad72 and Kemal UÇAR 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 Woaw, I do not understand for the use of Bresenham's_line_algorithm. In any case, thank you for this theoris and sample code. Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
Gugis Posted December 2, 2016 Share Posted December 2, 2016 9 minutes ago, Dad72 said: Woaw, I do not understand for the use of Bresenham's_line_algorithm. In any case, thank you for this theoris and sample code. Here's javascript function of this algorithm: http://stackoverflow.com/questions/4672279/bresenham-algorithm-in-javascript/4672319#4672319 Dad72 and Kemal UÇAR 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 Thank you. It's complicated, I have a headache. Would you have time to help me reproduce this on this playground? http://www.babylonjs-playground.com/#RKPBE#13 Thanking you in advance Kemal UÇAR 1 Quote Link to comment Share on other sites More sharing options...
Gugis Posted December 2, 2016 Share Posted December 2, 2016 There's a lot of work to do. The most I can do is to guide you. Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted December 2, 2016 Share Posted December 2, 2016 And why not paint on a heightmap and update the terrain on live rather than directly "paint" mesh data ? Would it not be easier ? adam 1 Quote Link to comment Share on other sites More sharing options...
adam Posted December 2, 2016 Share Posted December 2, 2016 It would look cool. I don't think it would be easier, though. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 I try but I can not and I think I did absolutely anything. I modify the PG in ways to create a small mountain and automatically switch to ramp creation mode (when you can create more mountain) But what I did does not work for Ramp mode. I do not even understand what I do. http://www.babylonjs-playground.com/#RKPBE#16 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 2, 2016 Author Share Posted December 2, 2016 I try another approach that is also a total failure. I drop this feature that takes me too much head and I will finish no longer have hair on my head. I can not do it and I do not think I can do it tomorrow either. You can always create ramps manually by gradually elevating the tops at the moment. So I'll settle for that. I do not have the level for that kind of "chemistry mathematics". Quote Link to comment Share on other sites More sharing options...
gryff Posted December 2, 2016 Share Posted December 2, 2016 34 minutes ago, Dad72 said: I drop this feature @Dad72 I have known you on this forum for almost 3 years - not known you to give up easily. C'est mauvais cheers, gryff Wingnut and Dad72 2 Quote Link to comment Share on other sites More sharing options...
adam Posted December 2, 2016 Share Posted December 2, 2016 I'll give it an attempt over the weekend. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 2, 2016 Share Posted December 2, 2016 SO, now... hehe... gray scale image... used as a heightMap or displaceMap... that has a "quantized" number of available steps, yes? 256 colors of gray? So, ramps made from gray-scale... that use our displaceMap system... will get a "steppy" ramp... yes? But a modeled ramp... or a math-derived map... would give a much smoother ramp, yes? Ok, just checking. The granularity (subdivs) of the ground... will need consideration... (duh wingy). hmm. Can a ramp get wider or narrower... as it ascends/descends? (Wingy digs in his bag for some aspirin). Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 3, 2016 Author Share Posted December 3, 2016 Thank you Gryff, Adam and Wingnut for your support. Yes, Gryff I'm not the type to give up generally easily, but I feel like I run into a big wall. I do not know at all how to do and rather than do anything/to make bullshit, down I prefer to stop. My ideas exceed my skills sometimes. But thanks. If you get there, Adam, I would try to understand what you did for learn. Thank you for giving a try to this headache and do not you care if you do not succeed. Quote Link to comment Share on other sites More sharing options...
Gijs Posted December 3, 2016 Share Posted December 3, 2016 Hi, it's a fun challenge! I tried my best to make something like in the video, and here are the results: This is the standalone version. You can adjust the brush size. http://www.babylonjs-playground.com/#RKPBE#17 Tip: enable wireframe mode on the material to see the geometry better. This is your #13 mixed with my #17: http://www.babylonjs-playground.com/#RKPBE#18 I saw buttons in your demo very briefly, but for some reason they usually don't show. I made the middle mouse button for 'ramp' instead, left is to make mountains. Hopefully it is of some use to you. Good luck with your project! iiceman, getzel, adam and 3 others 6 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 3, 2016 Author Share Posted December 3, 2016 Woaw, it's really cool. Thank you so much Gijs. I will study what you have done to learn. Thanks again. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 3, 2016 Author Share Posted December 3, 2016 I studied the code you did. I'm impressed, I would never have done that. You made a quality system. This is really perfect. Great thank you for helping me with this. Quote Link to comment Share on other sites More sharing options...
Gijs Posted December 3, 2016 Share Posted December 3, 2016 30 minutes ago, Dad72 said: I studied the code you did. I'm impressed, I would never have done that. You made a quality system. This is really perfect. Great thank you for helping me with this. You're welcome, but I just thought of a more general method of doing such things, so if that works out, the ramp code may soon be obsolete Dad72 1 Quote Link to comment Share on other sites More sharing options...
getzel Posted December 3, 2016 Share Posted December 3, 2016 There are some coding heros on this forum ! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 3, 2016 Author Share Posted December 3, 2016 4 hours ago, Gijs said: but I just thought of a more general method of doing such things, so if that works out, the ramp code may soon be obsolete If there is one manners more general, I definitely want to see it. 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.