[SOLVED] Trouble rendering GuiObject in a scene


photo

Recommended Posts

Hello,

I am trying replicate some of the behavior from the gui_06 sample to attach a GuiObject to a node in the world.  I have everything in my script set up exactly the same as the example script (including importing and referencing the same material library as the script), but for some reason the label isn't showing up in the main world.

Object obj = our_custom_class.rootObject;
ObjectGui dragHandle = add_editor(new ObjectGui(2.0f, 2.0f));
dragHandle.setWorldTransform(obj.getTransform());
dragHandle.setBillboard(1);
dragHandle.setBackground(0);
dragHandle.setMaterial("objects_gui", "*"); // Imported from the sample material library
dragHandle.setProperty("surface_base", "*");
dragHandle.setScreenSize(96, 96);
			
Gui gui = dragHandle.getGui();
WidgetLabel label = new WidgetLabel(gui, "Some example text");
label.setFontSize(48);
gui.addChild(label);
obj.addWorldChild(dragHandle);

Thoughts on why my label isn't showing up?

 

Thank you,

Andrew

Link to post

Yes I am still having this problem.  I can post a minimum working example tomorrow.

Link to post

Here's a minimum working example of the world script we're using:

#include <core/unigine.h>
#include <core/scripts/utils.h>
#include <core/scripts/primitives.h>

Node add_editor(Node node) {
	engine.editor.addNode(node);
	return node_remove(node);
}

void remove_editor(Node node) {
	engine.editor.removeNode(node);
}

int init() {
	PlayerSpectator camera = new PlayerSpectator();
	camera.setPosition(Vec3(420.f, -2.f, 12.f));
	camera.setDirection(Vec3(1.f, -1.f, 0.f));
	camera.setMinVelocity(5.f);
	camera.setMaxVelocity(15.f);
	engine.game.setPlayer(camera);
	engine.app.setMouseGrab(1);
	engine.controls.setMouseEnabled(1);
	engine.controls.setButtonPressCallback("OnButtonPressed");
 	engine.gui.setMouseEnabled(0);

	return 1;
}

int shutdown() {
	return 1;
}

int update() {
	return 1;
}

int OnButtonPressed(int button){
	if(engine.controls.isMouseEnabled())
	{
		switch (button)
		{
		case APP_BUTTON_LEFT:
		case APP_BUTTON_DCLICK:

			break;
		case APP_BUTTON_RIGHT:
			// Get a reference to the node we're attaching this label to
			Node wall = engine.world.getNode(1704072469);

			log.message("Tattletail - Attempting to assign a label to the node %s\n", wall.getName());
			log.message("Tattletail - Wall children before add: %d\n", wall.getNumChilds());

			// Make a label to stick above the wall
			ObjectGui object_gui = add_editor(new ObjectGui(2.0f, 2.0f));

			mat4 defaultTransform = mat4(0.0f, 0.0f, 10.0f);

			object_gui.setTransform(defaultTransform);
			object_gui.setBillboard(1);
			object_gui.setBackground(0);
			object_gui.setMaterial("objects_gui", "*");
			object_gui.setProperty("surface_base", "*");
			object_gui.setScreenSize(96, 96);

			Gui gui = object_gui.getGui();
			WidgetLabel label = new WidgetLabel(gui, "This is a wall, I really hope you can see this");
			label.setFontSize(100);
			gui.addChild(label);

			wall.addChild(object_gui);

			mat4 ogt = object_gui.getWorldTransform();
			mat4 wt = wall.getWorldTransform();
			log.message("Tattletail - object_gui transform: x: %f, y: %f, z: %f\n", ogt.m03, ogt.m13, ogt.m23);
			log.message("Tattletail - wall transform: x: %f, y: %f, z: %f\n", wt.m03, wt.m13, wt.m23);
			log.message("Tattletail - Wall children after add: %d\n", wall.getNumChilds());
			break;
		default:
			break;
		}
	}
	return 0;
}

int flush() {
	
	return 1;
}

Printing the translation vectors indicates that, in world coordinates, the Gui object should be a few meters from the "wall" node, and I've followed the gui sample code very closely, including importing the sample object material file that contains the "objects_gui" material.  Instead, I can see the "wall" node, but the label that should be 10 units in the z direction above it doesn't appear.

 

My world file is 550 lines long, shall I paste that here as well or is there a way to attach a .world file to a post?

 

Thank you for your time,

Andrew

Link to post

Hi, Andrew.

 

You are trying to transform object gui in relative to wall node coordinates, so you have to set wall.addChild(ogject_gui) before calling setTransform method.

Link to post

Setting the transform after adding the ObjectGui as a child to the wall node doesn't seem to make a difference.  The GUI object still doesn't appear.  Furthermore, inspecting the WorldTransform of the Gui object indicates that it should be right next to the wall node.  They are only offset by a few units.  Is there some subtlety about world transforms that I'm not grasping?

Link to post

Hi, Andrew,

 

This code draws label above the wall node correctly:

int id = 1704072469;
Node wall = engine.world.getNode(id);
if(wall != NULL) {
	// Make a label to stick above the wall
	ObjectGui object_gui = add_editor(new ObjectGui(2.0f, 2.0f));
	wall.addChild(object_gui);
	
	Mat4 defaultTransform = Mat4(0.0f, 0.0f, 1.0f);
	
	object_gui.setTransform(defaultTransform);
	object_gui.setBillboard(1);
	object_gui.setBackground(0);
	object_gui.setMaterial("objects_gui", "*");
	object_gui.setProperty("surface_base", "*");
	object_gui.setScreenSize(96, 96);
	
	Gui gui = object_gui.getGui();
	WidgetLabel label = new WidgetLabel(gui, "This is a wall, I really hope you can see this");
	label.setFontSize(48);
	gui.addChild(label);
	
	mat4 ogt = object_gui.getWorldTransform();
	mat4 wt = wall.getWorldTransform();
}

You also can use setWorldTransfororm in global coordinates:

Mat4 defaultTransform = wall.getWorldTransform() * Mat4(0.0f,0.0f,1.0f);
object_gui.setWorldTransform(defaultTransform);

Link to post

Structuring my code exactly as you have presented still yields no label.  Is there a setting in a .word file or unigine.cfg that effects the way ObjectGui nodes are rendered?  I feel like there's a setting somewhere I'm missing if my code is identical to yours.

 

Thank you for your time,

Andrew

Link to post

Hi, Andrew,

 

Try this example scene. Pay attention, that engine.controls.isMouseEnabled() returns false in editor mode, you have to unload it (editor_quit in console)

test.zip

Link to post

I have tested the world and cpp files you provided and I still can't see the label.  Could there be something wrong with my Unigine install?  What could cause gui objects to not be rendered?

 

Andrew

Link to post

Hi Andrew,

Could you please tell us what SDK version, API (DX11 / OpenGL) and OS are you using?

 

We can confirm that this sample is working fine with the latest 2.0beta2 SDK with OpenGL / DX11 setup under Windows platform.

 

test_cpp.png

 

Thanks!

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

Link to post

SDK 2.0beta, Windows 8, DX11.

 

Also, when I try to load the editor I receive an error that says "core/systems/widgets/widget_menubox.h:91: Interpreter::parse_extern_class_begin(): unknown "WidgetMenuBox" class member "setItemMenu"

 

Could this error be related to my troubles rendering widget labels?

 

Also, I tried rebuilding, "core.ung," and, "editor.ung," to no avail.  I tried adding several other kinds of widgets to the object_gui (like buttons) and couldn't get any of them to render either.

 

Andrew

Link to post

Aha!  Rebuilding the Unigine dlls and *.ung files from the latest version did the trick.  I can see labels now.

 

Thank you for your time,

Andrew

Link to post