Jump to content

Getting 3D Positions From TerrainMaterial?


Raggar
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...