Hi guys, I really hope someone here can help me...

My problem relates to the simpleformer and bruteblock terrain mesh
object (not terrain2). I'm creating them programmatically (i.e. not
loaded from a world file) and providing them with heightmap and
materialmap data also generated programmatically. The heightmap works
fine, but no matter what I try, the materialmap is not working as expected.

I should be seeing a stochastically-generated pattern of 3 different
textures, but I'm only seeing one texture covering the entire terrain.
Which of the 3 textures I see seems to be random - for example, it'll be
red one time and green the next time - which suggests it might be using
the wrong scale or so. I've tried fiddling with the scale and all the
other options but nothing seems to help.

I don't think it's reverting to the base material, because it's a
different material each time, and because the LOD distance is set to a
million - much further than the distance from the camera.

>From looking at the plugins' source, it appears that the doxygen
comments in the interfaces are out of date; I've tried conforming to
them and also tried reading the source to see what the plugins actually
expect.

I've tried looking at the source code for the loader plugins, and as far
as I can tell, my code does just the same thing as what the loaders do,
and the loaders are working properly, as shown by "walktest terrain".

And I've verified that the materialmap image data I'm providing is correct.

I tried asking Dentoid and Fossi about it in IRC the other day, since
their names were mentioned in the relevant plugin source files, but my
internet connection was too intermittent to be of any use - sorry about
that, guys.

So the mailing list seems like my last hope. I've tried everything else
I can think of.

Here's the code I'm using. Thankyou very much in advance if you can give
me any clue of what's wrong.

csRef<iMeshFactoryWrapper> factWrap = engine->CreateMeshFactory
  ("crystalspace.mesh.object.terrain.bruteblock", "terrainFactory");
csRef<iMeshFactory> fact = factWrap->GetMeshObjectFactory();
csRef<iTerrainFactoryState> factState =
  scfQueryInterface<iTerrainFactoryState>(fact);

csRef<iTerraFormer> former = csLoadPlugin<iTerraFormer>
  (objreg, "crystalspace.terraformer.simple");
csRef<iSimpleFormerState> formerState =
  scfQueryInterface<iSimpleFormerState>(former);

formerState->SetHeightmap(heightmap, width, height);

formerState->SetScale(csVector3(256.0f, 0.1f, 256.0f));
formerState->SetMaterialScale(csVector2(1.0f, 1.0f));

factState->SetTerraFormer(former);
factState->SetSamplerRegion
  (csBox2(-256.0f, -256.0f, 255.0f, 255.0f));

csRef<iMeshWrapper> meshWrap = engine->CreateMeshWrapper
  (factWrap, "terrain", sector, csVector3(0, 0, 0));
csRef<iMeshObject> mesh = meshWrap->GetMeshObject();
csRef<iTerrainObjectState> meshState =
  scfQueryInterface<iTerrainObjectState>(mesh);

meshState->SetStaticLighting(false);
meshState->SetCastShadows(false);

mesh->SetMaterialWrapper(red);

csArray<iMaterialWrapper*> palette (6);
palette.Push(redMaterial);
palette.Push(greenMaterial);
palette.Push(blueMaterial);
meshState->SetMaterialPalette(palette);

csRef<iStringSet> strset = csQueryRegistryTagInterface<iStringSet>
  (objreg, "crystalspace.shared.stringset");

/*** Attempt (1) at setting materialmap ***/
meshState->SetMaterialMap(materialmap, width, height);
/******/

/*** Attempt (2) at setting materialmap ***/
meshState->SetMaterialAlphaMaps(alphamaps, width, height);
/******/

/*** Attempt (3) at setting materialmap ***/
csRGBpixel imgpal[256];
imgpal[0].Set(255,0,0);
imgpal[1].Set(0,255,0);
imgpal[2].Set(0,0,255);
for (uint i = 3; i < 256; i++) pal[i].Set(0,0,0);
csRef<iImage> image;
image.AttachNew(new csImageMemory (width, height,
  (void const*)materialmap, CS_IMGFMT_PALETTED8, pal));
former->SetIntegerMap(strset->Request("materialmap"), image);
/******/

/*** Attempt (4) at setting materialmap ***/
for (uint i = 0; i < alphamaps.GetSize(); i++)
{
  csString name ("alphamap ");
  name += i;
  simpleFormer->SetIntegerMap(strset->Request(name), alphamaps[i]);
}
/******/

terrMesh->SetLODValue("splatting distance", 1000000.0f);
engine->Prepare();
engine->ShineLights();

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to