Raggar Posted January 5, 2018 Share Posted January 5, 2018 I was wondering whether or not it's possible to get the world/3D positions of different textures using the TerrainMaterial. Let's use the TerrainMaterial PG as an example: https://www.babylonjs-playground.com/#E6OZX#7 Now, let's say I want to place meshes wherever the rock texture is used on the ground mesh, programmatically and automatically. I don't seem to find any relevant references or functions in the object, and can't think of a proper way without loading the image separately and somehow map those colors to the ground positions. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 5, 2018 Share Posted January 5, 2018 Hello, there is no automatic way per se but you can read the content of your mix map to get UV coordinates where the rock texture will be applied. Using this UV coordinates you can then deduce XZ coordinates on your ground. Then you will need to get the Y coordinates (you can also get this value by reading at UV coordinates in the ground texture) Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 5, 2018 Share Posted January 5, 2018 Ehhhhh, yes but not inherently. And not on the GPU. This will take some math. So you have your mix map, which will be they key. Lets say any area that is rocks is coded red on the mix map, what you are going to need to do is first create some control logic for the analysis of a section of terrain and then some sort of pseudo random method. First Step: Create an array of usable meshes to be placed; 2: Load the Terrain's mixmap into a function that iterates over areas of the map at a certain fidelity. 3: If at that terrain mixmap location it meets the conditions (so much red is present) do step 4 else continue iterations 4: Pass location of test into the pseduo random method and see if the point validates for example if you could test if the locations value creates a psudeo random number greater then lets say 0.8 then go to step 5 else continue iterations; 5: Pass location again into pseudo random method in range equal to length of your mesh array, floor the value and place mesh from array that returns from the random result; YOU ARE done or continue to step 6; 6: Pass location into pseudo random method to get values for mesh rotation/scaling/position offset. I would also recommend doing this recursively, so its propagates in async. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 5, 2018 Share Posted January 5, 2018 https://www.babylonjs-playground.com/#CD2RHZ#13 Here is the majority of the work for you, needs a bit of refinement (an there are better logic chains then this).. I would take advantage of a flood fill algo as well to make it more efficient on the testing instead of a x/y loop. 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.