Mesh Decals

lanevorockz

11-01-2007 19:54:52

I'm getting an error when trying to create a PagingLandScapeMeshDecal.
OgrePagingLandScapeAxisAlignedBoxSceneQuery.cpp:308: void Ogre::LodTracker::SetPage(int, int): Assertion `false' failed.

sklug

12-01-2007 05:19:29

Hrm, that will happen if your decal is on a page that isn't currently loaded. It's possible that that assert() could be removed. I haven't done much experimentation with pages that are loading and unloading. Let me know if it does "the right thing" if you just remove the assert (or run in debug). It's a piece of reminder code to look at it later. Later just hasn't come along yet.

sklug

lanevorockz

12-01-2007 14:56:25

That's it.

Got it working now. Just solving some problems with the conflics with the terrain, even with depth bias set as 1

lanevorockz

12-01-2007 18:41:01

I'm Creating the Texture in RealTime, but It think that something wrong with the u,v because the texture is applied in a strange way. I created a dynamic texture that should have a cross in it. Can somebody enlight me ?

This is the code that I use to print the Texture


// Create the texture
TexturePtr texture = TextureManager::getSingleton().createManual(
"DynamicTexture", // name
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
TEX_TYPE_2D, // type
256, 256, // width & height
0, // number of mipmaps
PF_BYTE_BGRA, // pixel format
TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
// textures updated very often (e.g. each frame)

// Get the pixel buffer
HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();

// Lock the pixel buffer and get a pixel box
pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);

// Fill in some pixel data. This will give a semi-transparent blue,
// but this is of course dependent on the chosen pixel format.
for (size_t j = 0; j < 256; j++)
for(size_t i = 0; i < 256; i++)
{
bool selected=true;

if(j==128 || i==128){
selected=false;
}

if(selected){
*pDest++ = 255; // B
*pDest++ = 0; // G
*pDest++ = 0; // R
*pDest++ = 127; // A
}
}

// Unlock the pixel buffer
pixelBuffer->unlock();

// Create a material using the texture
MaterialPtr material = MaterialManager::getSingleton().create(
"DynamicTextureMaterial", // name
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture");
material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
material->getTechnique(0)->setDepthBias(1);

// Create object MeshDecal
NameValuePairList params;
params["materialName"] = "DynamicTextureMaterial";
params["width"] = StringConverter::toString( 256 );
params["height"] = StringConverter::toString( 256 );
params["sceneMgrInstance"] = ogreSystem->getSceneManager()->getName();

MovableObject* entity = ogreSystem->getSceneManager()->createMovableObject(
"testeObject",
"PagingLandScapeMeshDecal",
&params );

// Add MeshDecal to Scene
SceneNode* node = ogreSystem->getSceneManager()->createSceneNode("SelectedTerrain");
node->attachObject(entity);
//node->setPosition(Ogre::Vector3(0,600,0));
node->setPosition(Ogre::Vector3(0,0,0));
node->setScale(1,1,1);

ogreSystem->getSceneManager()->getRootSceneNode()->addChild(node);


sklug

13-01-2007 04:46:55

Keep in mind the mesh decals still do not have hooks into lod change events. So if you change lod from when you first place the object (i.e., you move the camera so the position the decal is at changes LOD) the mesh will no longer be correct. To test to see if this is what's going on, you could re-create the decal every frame, or move it.

sklug

lanevorockz

13-01-2007 17:36:57

Thanks sklug that was it. the fighting with the terrains is ok, but I still haven't figure out what's happening with the texture.

I want to create a polygon decal in real time. I was thinking about building a texture and apply that in the MeshDecal. Does this is the better solution or I should try to get the vertex data from the entity and cut the mesh in the polygon form ??

Both Screenshot were producing with the same code. It's strange because both texures are the same. Even so the result are rather different, as if the u,v was no evenly applied.



sklug

13-01-2007 20:49:14

I would suggest trying it with a regular bitmap texture first and see if that works. Then you'll know for sure if it's your texture generation that's the problem. I'm using a bitmap with an alpha channel here and it seems to work fine.

sklug

lanevorockz

15-01-2007 13:44:36

I created a material with a texture. But I ended up messed up when was applied. Same as the dynamic texture problem

sklug

15-01-2007 17:17:58

How is that material messed up? It looks ok from the screenshot. I'm confused.

sklug

lanevorockz

15-01-2007 17:30:46

I was thinking that the u,v mapping would be mapped to fit the start of the texture in one of the corners.
Maybe I got wrong, I started to use mesh decals to create a highlight during a terrain selection. That would consist of getting a mesh decal and applying a transparent texture above it.
This is the best way to do it ? If I need more precision than tiles what would be the right way ?

Thanks a Lot, and sorry for any trouble

lanevorockz

20-01-2007 20:14:26

I have fixed the mapping of my texture using terrain decals inside the mesh decal. But with the terrain decals I got a strange problem with the pixel that is streched troughout the whole terrain. like in the screenshot

sklug

22-01-2007 00:48:53

Use tex_border_color with a 0.0 alpha rather than clamping the color on your texture. This is caused by having your texture go right up to the edges of your UV's. When you clamp it will take any color on the edge and repeat it infinitely.

I imagine there are other ways to solve this as well, but using the above is easy.

sklug

Creajeux_Progs

24-01-2007 10:14:57

I've got a problem with mesh decals : i think its a problem with the tiles..

when i construct a building, the decals apear on the whole tile (you can see bouding boxes of tiles on screenshots), if i construct on the middle of 2 tiles, the decals appears differently.
I want the decals to appear only on the bouding box shown (which is the BB of the decals itself....strange :? )

As anyone encounter the same problem ?..can you help me on this ?



sklug

26-01-2007 03:51:14

Creajeux_Progs

If I understand your problem correctly, I believe the issue is that the mesh generated by the decal system will be larger (usually) than the bounding box. The reason for this is that the decal system does not create any new vertices, it only uses the ones already in the terrain (it doesn't actually use the same vertex buffer, though that might be possible with some optimization). If your texture is the translucent blue in the images above, that's easily solved by using tex_border_color 0.0 0.0 0.0 0.0 in the material script. This will limit your texture to the size of your bounding box.

This does bring up a bit of a limitation though, in that if you wanted to repeat your texture within the space of the bounding box, the current mesh decals wouldn't work for that. It doesn't look like that's what you're trying to do here though.

sklug

Creajeux_Progs

26-01-2007 10:38:49

Thanks for your reply.

You have pointed the problem, it doesn't create vertices and only used th terrain vertices which already exists.

But your solution doesn't seem to work..First i didn't used any texture as it's only a color..i tried to put one to test your solution with tex_border but it still doesn't work :/

Here is my material
material 13_-_Default
{
technique
{
pass
{
//ambient 0.0 0.0 1.0 0.5
//diffuse 0.0 0.0 1.0 0.5
//specular 0.0 0.0 1.0 0.5
//emissive 0.0 0.0 0.0 0.0

scene_blend alpha_blend
depth_bias 1
texture_unit
{
texture Echafaux_buildable.tga
tex_border_color 0.0 0.0 0.0 0.0
}

}
}
}


i don't use ambient/diffuse... alpha is directly in the tga texture

Creajeux_Progs

26-01-2007 10:58:01

well i just find the answer.."colour" instead of "color" ^^

here is the code for the material

tex_address_mode border
tex_border_colour 0.0 0.0 0.0 0.0

sklug

27-01-2007 18:09:19

Ack! Sorry for misleading you with an American typo. :)

Glad you got it working!

sklug