reading alphamaps in JS

how can I call this in js …

var terrainAlphamaps = Terrain.GetAlphamaps(0,0,myTerrain.alphamapResolution,myTerrain.alphamapResolution);

then access ‘terrainAlphamaps’ without getting the error “ArgumentException: Only single dimension arrays are supported.” ?
it seemed to work fine in 2.6 but not anymore in 3.0

Can you post the code where you access the temp variable (ie, the bit that gives the error)?

var biggestAlpha=-1.0;
for (var splatCount = 0; splatCount < numTerrainTex; splatCount++)
{

var index : int = offset + splatCount;
var intens = terrainAlphamaps[index]; // error on this line

trying this… var result : float[ ]= terrainAlphamaps;
results in error, cant cast from source type to destination type…

trying this… var result=terrainAlphamaps.map(Number);
results in ‘map’ not supported

trying this… heh… var result = new Array(terrainAlphamaps);
crashes unity everytime… interesting…

trying this…
var result = new Array();
for (var value in terrainAlphamaps)
result.Add(value);
gets the usual result… “Only single dimension arrays are supported”

any other crazy ideas ?

it seems like if you call Terrain.GetAlphamaps() from JS, it should return a single dimension array, but it doesn’t.

I wan’t find all “alpha” type maps,set it to models,how to do?

The message is misleading. You just have to provide indices for all three dimensions.

var alphaValue = terrainAlphamaps[0, 0, 0];

Rodrigo

thanks Rodrigo,
I tried that…

var intens = terrainAlphamaps[xx,yy,splatCount];

…but just get this error instead…

MissingFieldException: Field ‘System.Single[,].’ not found.

I think unity JS only supports single dimension arrays, but the GetAlphamaps() function returns a multi dimention array
it was still accessible in 2.6 as a single dimension array (you’d have to calculate your own index) but I think in 3.0 probably some warnings turned to errors, and now it doesnt work, I guess its impossible.
Which means I’ll probably have to port the whole project to C# or scrap the project, as my whole project relies on being able to read the type of terrain texture you are on.

anyone know of another way of reading that from the terrain ?

ok, the solution was to give up with js, just write it in cs as a function, and put the cs script, in the standard or pro assets folder, so its compiled first and the functions can be called from js.