Jump to content

Problems reading texture layer for per-layer footstep sounds


rgresko

Recommended Posts

Hi there - I'm working on adding different footstep sounds to correspond with the different texture layers placed on a Gaia terrain by a texture spawner. I'm using a method similar to the video below for reading the splatMapData from the terrain to determine which sound set to use. When I run, I'm only getting a single layer returned, which happens to be the last layer rule in my texture spawner (this happens at all positions on the terrain). Is there a different way to read the terrain texturing performed by the Gaia spawners?

 

Thanks-

 

This is a code snippet from the example that shows how the relative texture mix is read from the terrain:

 

 private float[] GetTextureMix(Vector3 playerPos, Terrain t)
 {
            Vector3 tPos = t.transform.position;
            TerrainData tData = t.terrainData;

 

            // Get Player's X and Z position relative to terrain
            int mapX = Mathf.RoundToInt((playerPos.x - tPos.x) / (tData.size.x * tData.alphamapWidth));
            int mapZ = Mathf.RoundToInt((playerPos.z - tPos.z) / (tData.size.z * tData.alphamapHeight));

            float[,,] splatMapData = tData.GetAlphamaps(mapX, mapZ, 1, 1);

            float[] cellmix = new float[splatMapData.GetUpperBound(2) + 1];


            for(int i=0; i<cellmix.Length; i++)
            {
                cellmix[i] = splatMapData[0, 0, i];
            }

            return cellmix;

}

 

 

 

Link to comment
Share on other sites

You could look in the GaiaAPI. 
The GaiaAPI class is the official API, and in there each function is described in the source code.
 

Link to comment
Share on other sites

my mistake, had a math bug in the code, this is working perfectly now.

 

bad parens in this code:

int mapX = Mathf.RoundToInt((playerPos.x - tPos.x) / (tData.size.x * tData.alphamapWidth));
int mapZ = Mathf.RoundToInt((playerPos.z - tPos.z) / (tData.size.z * tData.alphamapHeight));

 

should be:

int mapX = Mathf.RoundToInt(((playerPos.x - tPos.x) / tData.size.x) * tData.alphamapWidth);
int mapZ = Mathf.RoundToInt(((playerPos.z - tPos.z) / tData.size.z) * tData.alphamapHeight);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...