Jump to content

[SOLVED] Extending a mesh with a dummy triangle


photo

Recommended Posts

Hello,

 

I would like to add a dummy triangle to an existing surface of a mesh.

The dummy triangle shouldn't be connected to the mesh and it should be hidden by other geometry (so it can use any normals and texcoords).

I will explain at the end of my posting why i need that.

 

I do the following steps in a unigine script .usc command line script:

Mesh mesh = new Mesh();
mesh.load(getArg(1));

int nVerticesBefore = mesh.getNumVertex(0);
mesh.addVertex(vec3(0.0f, 0.0f, -10000.0f), 0);
mesh.addVertex(vec3(1.0f, 1.0f, -10000.0f), 0);
mesh.addVertex(vec3(0.0f, 1.0f, -10000.0f), 0);

mesh.addCIndex(nVerticesBefore, 0);
mesh.addCIndex(nVerticesBefore+1, 0);
mesh.addCIndex(nVerticesBefore+2, 0);

mesh.addTIndex(0, 0);
mesh.addTIndex(1, 0);
mesh.addTIndex(2, 0);

mesh.save(....);


What I would expect is an isolated triangle at around (0, 0, -10000), but instead I get a triangle which is connected to some existing vertex:

 

post-990-0-26629100-1473757714_thumb.png

 

Here is an Image of the original geometry before I add the triangle:

 

post-990-0-22623100-1473757706_thumb.png

 

 

Background Information:

 

I need to extend the bounding box of some meshs because they get culled away during shadow map generation. We have got a camera running on a circle, which looks at (0, 0, 0). When the camera is between the wall (you can see in the screenshots) and origin, occassionally a jump in the shadow is visible, which I believe is a result from switching shadow map generation on or off for the respective object.

Two solutions come to my mind:

1.: Replacing every affected geometry with an ObjectMeshDynamic, where I can set the bounding box size per surface manually.

2.: Adding a dummy triangle which is invisible but extends the bounding box.

 

This posting results from my attempt to implement number 2.

 

Thanks in advance for any help

 

cheers

 Helmut

 

 

 

Link to comment

Hi Helmut,

 

At first glance the idea of replacing each affected mesh with ObjectMeshDynamic and setting custom bounds looks like the proper solution. With IMMUTABLE_ALL flag performance will be the same.

Adding invisible triangles is very complex and ineffective solution.

 

We can tell more if you can give us some video or small test scene where we can see the exact problem. Maybe adding method for changing bounding box of the MeshStatic objects will be also enough for such use cases. Or even increasing Shadow distance in Rendering Settings -> Common tab.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hello Silent,

 

the only reason for me for preferring the "hidden triangle" approach was because it would allow us to keep our content update workflow simple.

Some of the meshs in question are stored directly in the world file, some others are stored in a .node file.

Tweaking the shadow distance would be the easiest way I guess, but it is already configured together with the cascade offsets, I will check if I can change it.

 

Thank you Silent, I will have a second lookt at the ObjectMeshDynamic solution.

 

Cheers

 Helmut

Link to comment

Hi Helmut,

 

Have you solved the problem?
I've tried to add a new invisible triangle to the existing surface and successfully did it.

 

Here is an example that I wrote in init() of the world script:

// load the material ball
Mesh mesh = new Mesh("meshes/mb.mesh"); 
// get the number of mesh indices
int i = mesh.getNumIndices(0);

// add vertices of the triangle to the existing surface with 0 index
mesh.addVertex(vec3(15.0f,15.0f,15.0f),0);
mesh.addVertex(vec3(15.0f,15.0f,16.0f),0);
mesh.addVertex(vec3(15.0f,16.0f,15.0f),0);

// add indices 
mesh.addIndex(i++,0);
mesh.addIndex(i++,0);
mesh.addIndex(i++,0);

// create bounds for the mesh including new vertices
mesh.createBounds();

// save the mesh
mesh.save("meshes/mb2.mesh");

And in the REditor I got the following:

post-1513-0-17583700-1474618534_thumb.png

Well, this code works, but it seems like it's a workaround for your case and not a solution :)

 

Link to comment

Hello koshachy,

 

thank you very much, your code works perfectly and indeed it solves the problematic cases (actually I discovered that I need to fix not only geometry which is behind the camera but also all power poles, which cast very long shadows at dusk/dawn).

Generally I think it would be great to have some kind of a "no-frustum-culling" flag per object or per material.

But I'm totally happy with your script code. Typically we have an orbiting camera in our projects, so adding a dummy triangle at the center under the ground surface will always work for us.

 

Thank you and cheers

 Helmut

Link to comment
×
×
  • Create New...