Jump to content

Hide default ground plane from WidgetSpriteNode


photo

Recommended Posts

Hi,

 

We have created a WidgetSpriteNode and added a dynamic mesh to it (setNode()) but the plane mesh (the one used in most of the samples as ground) is also visible.

 

How can we disable/hide that?

 

Link to comment

Silent,

 

I'm trying to do the same thing and then save the image to disk - but whenever I use sprite.setEnvironmentTextureName("null.dds"); it creates a black image instead.

 

the code goes something like this:

 

m_sprite.setBlendFunc( GUI_BLEND_SRC_ALPHA, GUI_BLEND_ONE_MINUS_SRC_ALPHA );

m_sprite.setWidth( spriteSize );
m_sprite.setHeight( spriteSize );

m_sprite.setNode( m_compass.GetMesh() );
m_sprite.setEnvironmentTextureName("null.dds");
Image testImage = new Image("alpha_16x16.dds");
m_sprite.renderImage(testImage);
testImage.save("myTestImage.png");

 

myTestImage.png then goes black.

 

It's like it's reading the alpha value for each pixel as black instead.  Is there some flag I'm missing or something?

Link to comment

Silent - it's still not working.  I think the problem is that it isn't rendering the node/mesh at all.

 

Is there something else - maybe to do with a filter flag/viewport setting that I'm missing?

 

Thanks!

Link to comment

Hi, Simon.Anderson!

 

It is related to asynchronous loading of meshes and textures in the engine. In the init() method, they just don't have a time to be loaded and you get a black screen instead of a model. Sometimes it is caused by the Spatial Trees. It didn't have enough time to be updated after nodes were moved or created.

So, you should use this:

   // disable async loading of meshes and textures (and backup previous values)
   int m = engine.console.getInt("render_manager_create_meshes");
   int t = engine.console.getInt("render_manager_create_textures");
   engine.console.setInt("render_manager_create_meshes", 1);
   engine.console.setInt("render_manager_create_textures", 1);

   // update node just in case
   engine.world.updateSpatial();
   engine.world.addUpdateNode(node);

   ... paste your code with WidgetSpriteNode and Image here ...

  // return default values
  engine.console.setInt("render_manager_create_meshes", m);
  engine.console.setInt("render_manager_create_textures", t);
Link to comment

I think I figured out the underlying problem.  Please copy and paste the code below into the node_00.cpp demo file and read my comments.

 

Basically I think the projection and modelview are handled automatically in Unigine 1.0, but in 2.3.1 you have to set them manually in order for the image to get written to disk?

 

Does this sound correct?

 

#include <samples/render/common/render.h>

Node node;
WidgetSpriteNode sprite;

/*
*/
void update_scene() {

int size = 256;
float angle = 0.0f;

while(1) {
 
  angle += engine.game.getIFps();
  mat4 projection = perspective(60.0f,1.0f,0.1f,100.0f);
  Mat4 modelview = lookAt(Vec3(14.0f),Vec3(0.0f,0.0f,8.0f),vec3(0.0f,0.0f,1.0f)) * rotateZ(angle * 32.0f);
 
  if(sprite == NULL) {
   sprite = new WidgetSpriteNode(engine.getGui(),size,size);
   engine.gui.addChild(sprite,GUI_ALIGN_OVERLAP | GUI_ALIGN_RIGHT);
   sprite.setBlendFunc(GUI_BLEND_SRC_ALPHA,GUI_BLEND_ONE_MINUS_SRC_ALPHA);
   sprite.setNode(node);
            sprite.setViewportMask(2);
  }

        // Below code can be commented out for Unigine 1.0 and an image will get written to disk, but doesn't work for 2.3.1
        // It seems the projection and modelview are handled automatically in 1.0 so you don't need to set them but you do in 2.3.1
        // Is this correct?
        //sprite.setProjection(projection);
        //sprite.setModelview(modelview);

        Image testImage = new Image();
        sprite.renderImage(testImage);
        testImage.save("myTestImage.png");

  wait;
}
}

/*
*/
void create_scene() {

int size = 3;
float space = 16.0f;

for(int y = -size; y <= size; y++) {
  for(int x = -size; x <= size; x++) {
   ObjectMeshStatic mesh = add_editor(new ObjectMeshStatic("samples/common/meshes/statue.mesh"));
   mesh.setWorldTransform(translate(Vec3(x,y,0.0f) * space));
   mesh.setMaterial(get_phong_mesh_material(x ^ y),"*");
   mesh.setProperty("surface_base","*");
            mesh.setViewportMask(2,0);
   if(x == 0 && y == 0) node = mesh;
  }
}

return "WidgetSpriteNode";
}

Link to comment

Basically I think the projection and modelview are handled automatically in Unigine 1.0, but in 2.3.1 you have to set them manually in order for the image to get written to disk?

 

I don't know. But now default values are:

Projection: fov=60, znear=0.1, zfar=10000, aspect_ratio=1

Modelview: identity (zero position and rotation).

Link to comment

Finally found the problem - the projection matrix is incorrect.  I defaulted it to the original default settings from Unigine 1.0 and it works fine now.

Unigine 1.0 default:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Unigine 2.0 default

1 0 0 0
0 1 0 0
0 0-1 0
0 0-1 0

Not sure if this is a bug - I'd assume the behaviour should be consistent though as the user is now forced to set up the projection matrix themselves, while the modelview is fine? 

Thought I'd let you know anyway.

Thanks for you help,

Simon

Link to comment
×
×
  • Create New...