[2.1] How to draw as wire?

Problems building or running the engine, queries about how to use features etc.
Post Reply
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

[2.1] How to draw as wire?

Post by rrl »

I have a model that has been exported in blender, and then I use the OgreMeshTool as follows:

$ ./OgreMeshTool -e -O puqs -v2 car.mesh.xml ./car.mesh

This generates a *.mesh file. I then draw it in 2.1 like so.

Code: Select all

	Ogre::SceneManager *sm = mGraphicsSystem->getSceneManager();

        Ogre::Item *item = sm->createItem("car.mesh", 
		Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
            	Ogre::SCENE_DYNAMIC);
        item->setCastShadows(false);

        mSceneNode = sm->getRootSceneNode(Ogre::SCENE_DYNAMIC)->
            createChildSceneNode(Ogre::SCENE_DYNAMIC);
        mSceneNode->setPosition(Ogre::Vector3::ZERO);
        mSceneNode->setOrientation(Ogre::Quaternion::IDENTITY);
        mSceneNode->attachObject(item);
The problem is that I just want to draw the mesh as a wire frame. Currently it appears like the model, but solid black.

Thoughts?
Last edited by rrl on Sat Oct 14, 2017 3:05 am, edited 1 time in total.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

That is done via the material.

In code you set the PolygonMode in the datablock
https://bitbucket.org/sinbad/ogre/src/d ... lock.h-108

in script you set the polygon mode like this;

Code: Select all

    "macroblocks" :
    {
        "unique_name" :
        {
            "polygon_mode" : "wireframe"
        }
    },
Feanor16
Halfling
Posts: 46
Joined: Tue Feb 18, 2014 10:49 pm

Re: how to draw as wire?

Post by Feanor16 »

Or you can made your own macroblock by code like this after you made the datablock material

Code: Select all

Ogre::HlmsMacroblock macroblock = *datablock->getMacroblock();
macroblock.mPolygonMode = Ogre::PM_WIREFRAME; // define your mesh as wireframe
datablock->setMacroblock(macroblock);
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

I'm trying to work this using the scripts. Here is the mesh I'm trying to display as a wire.

Code: Select all

        Ogre::HlmsManager* hlmsManager =
            Ogre::Root::getSingleton().getHlmsManager();

        Ogre::MaterialPtr mat =
            Ogre::MaterialManager::getSingleton().getByName("my_wire");

        Ogre::HlmsDatablock* block =
            hlmsManager->getDatablockNoDefault("my_wire");

	// block is null at this point, doesn't find material I believe.

        Ogre::SceneManager *sm = mGraphicsSystem->getSceneManager();

        Ogre::Item *item = sm->createItem("my.mesh",
            Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
            Ogre::SCENE_DYNAMIC);
        item->setCastShadows(false);
        item->setMaterial(mat);

        mSceneNode = sm->getRootSceneNode(Ogre::SCENE_DYNAMIC)->
            createChildSceneNode(Ogre::SCENE_DYNAMIC);
        mSceneNode->setPosition(Ogre::Vector3::ZERO);
        mSceneNode->setOrientation(Ogre::Quaternion::IDENTITY);
        mSceneNode->attachObject(item);
And here is the material file which is in the resources2.cfg file in a FileSystem path.

Code: Select all

"macroblocks" :
{
    "my_wire" :
    {   
        "polygon_mode" : "wireframe"
    }
}.
However, I am unable to see the mesh show up as a wire, rather, it's just an all black model. Thoughts?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

Well you have 2 material types to choose from, PBS and unlit. This is a file that describes all possible settings for PBS, using this as a template you could do something as simple as this;

Code: Select all


{
    "macroblocks" :
    {
        "wireMacro" :
        {
            "polygon_mode" : "wireframe"
        }
    },
     "pbs" :
    {
        "my_wire" :
        {   
            "macroblock" : "unique_name"
        }
    }
}

rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

So my material script now looks like this, but I don't see any changes in the way my model is displayed.

Code: Select all

{   
    "macroblocks" :
    {
        "wireMacro" :
        {
            "polygon_mode" : "wireframe"
        }
    },
    "pbs" : 
    {   
        "my_wire"  :
        {
            "macroblock" : "unique_name"
        }
    }
}   
When running the app, it segfaults with

Code: Select all

Can't assign material mat13 because this Material does not exist. Have you forgotten to define it in a .material script?
The script is in my resources2.cfg FileSystem path and I can see that the script was parsed with the console msg "Parsing script wire.material" when initializing.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

2 things

firstly I made a mistake in my post,

Code: Select all

"macroblock" : "unique_name"
should be

Code: Select all

"macroblock" : "wireMacro"
Secondly you need or rename your material file to be (the file extension needs to be "material.json"

Code: Select all

"wire.material.json"
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

Ugh, I can't get this to work. The material file looks correct to me, as far as I can tell.

In order to render as a wire, my understanding is I have to do this using the HLMS (either PBS or Unlit). So I've added the registerHlms() call from the Samples into my project.

And I've added 'if (secName != "Hlms") ...' so that it doesn't add this section from resources2.cfg by calling addResourceLocation(...) within my initialize function.

My problem is that it's crashing on getDefaultPaths(...) from within registerHlms(), yet the arguments being passed into it are null. Should they be? I don't see how they get populated other than from getDefaultPaths() and I was unable to find this call in the docs.

Code: Select all

Ogre::String mainFolderPath;
Ogre::String libraryFoldersPaths;

Ogre::HlmsUnlit::getDefaultPaths(mainFolderPath, libraryFoldersPaths);
Thoughts? I'm just trying to display a wire mesh.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

Did not realise you had not setup HLMS, not sure how Ogre was even working at all!

It might be a little tricky trying to work out your issue with little info, but for starters libraryFoldersPaths should be a Ogre::StringVector not an Ogre::String. But I assume thats a typo in your post. If you can provide anything else, eg logs, stack trace, I might be able to help some more
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

Ah, yes, that was a typo. It's a StringVector. Let me provide some more info. The code that I'm using is directly from here.

http://www.ogre3d.org/tikiwiki/tiki-ind ... e+into+QT5

I needed QT5 so I ran with that and am adding registerHlms() which I got from GraphicsSystem.cpp from the 2.0 Samples. The only part from that I've changed is where I've added registerHlms() from just after the 'while (seci.hasMoreElements())' loop of the initialise function (completely after the while loop). So that section looks like this.

Code: Select all

    while (seci.hasMoreElements()) {
        secName = seci.peekNextKey();

        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();

        if (secName != "Hlms") {
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
            
            for (i = settings->begin(); i != settings->end(); ++i) {
                typeName = i->first;
                archName = i->second;
               
                Ogre::ResourceGroupManager::getSingleton().
                    addResourceLocation(archName, typeName, secName);
            }
        }
    }
    
    registerHlms();
Problem is, when I get within registerHlms(), the line it seg faults on is getDefaultPaths().

Code: Select all

    Ogre::String mainFolderPath;
    Ogre::StringVector libraryFoldersPaths;
    Ogre::StringVector::const_iterator libraryFolderPathIt;
    Ogre::StringVector::const_iterator libraryFolderPathEn;

    Ogre::ArchiveManager &archiveManager = Ogre::ArchiveManager::getSingleton();

    {   
        std::cout << "just before ..." << std::endl;

        Ogre::HlmsUnlit::getDefaultPaths(mainFolderPath, libraryFoldersPaths);

        std::cout << "just after ..." << std::endl;
And when I run it, the console shows 'Segmentation fault' on that line (getDefaultPaths) which I know because of the print statement before and not after. So mainFolderPath and libraryFoldersPaths hasn't even been set to anything that I can see, yet it's passed in.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

The only way it could crash in that function is if you have not initialised the rendersystem yet. (Ogre::Root::Initialise()), but that is quite literally the first thing you would do when working with Ogre!

I would suggest debugging it to see exactly where its falling over
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

Thank you for the help. I guess I was calling it too early. The results changed when I moved it down further within initialise(). Not running yet, but not crashing on this function any more.
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

Still wresting with trying to draw this as a wire. I've got things running, all except that the mesh is not being drawn as a wire. It segfaults at the point where I'm calling setMaterial. Not sure I've got that coded correctly.

Here's the code I'm using to draw the mesh.

Code: Select all

    Ogre::HlmsManager* hlmsManager =
        Ogre::Root::getSingleton().getHlmsManager();

    Ogre::MaterialPtr mat =
        Ogre::MaterialManager::getSingleton().getByName("my_wire");

    // commented out because doesn't seem to be in use.
    //Ogre::HlmsDatablock* block = hlmsManager->getDatablockNoDefault("my_wire");

    Ogre::Item *item = m_ogreSceneMgr->createItem("Cube_d.mesh", 
        Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
        Ogre::SCENE_DYNAMIC);
    item->setCastShadows(false);
    // seg faults at this line, am I using setMaterial correctly?
    item->setMaterial(mat);

    mSceneNode2 = m_ogreSceneMgr->getRootSceneNode(Ogre::SCENE_DYNAMIC)->
        createChildSceneNode(Ogre::SCENE_DYNAMIC);
    mSceneNode2->attachObject(item);
    mSceneNode2->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f));
And here is my material.json file ...

Code: Select all

                                                              
{
    "macroblocks" :
    {   
        "wireMacro" :
        {   
            "polygon_mode" : "wireframe"
        }
    },
    "pbs" :
    {   
        "my_wire" :
        {   
            "macroblock" : "wireMacro"
        }
    }
}
Any thoughts?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: how to draw as wire?

Post by al2950 »

Interesting I just tried that and it does indeed crash. I have not looked into why but it shouldnt and is a bug with Ogre.

The reason is that setMaterial is a hangover from Ogre 1.x and Ogre 2.1 deals more in blend, macro and data blocks.

Anyway its a much easier fix than you might think just delete your setMaterial code and replace it with

Code: Select all

item->setDatablock("my_wire")
That should work!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: how to draw as wire?

Post by dark_sylinc »

It's crashing because the user is doing:

Code: Select all

Ogre::MaterialPtr mat =
        Ogre::MaterialManager::getSingleton().getByName("my_wire");
// commented out because doesn't seem to be in use.
//Ogre::HlmsDatablock* block = hlmsManager->getDatablockNoDefault("my_wire");
item->setMaterial(mat);
Instead of doing:

Code: Select all

Ogre::HlmsDatablock* block = hlmsManager->getDatablockNoDefault("my_wire");
item->setDatablock(block);
But as al2950 said, this is cleaner:

Code: Select all

item->setDatablock("my_wire")
Cheers
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

So I changed to the following ...

Code: Select all

    Ogre::HlmsManager* hlmsManager =
        Ogre::Root::getSingleton().getHlmsManager();

    Ogre::HlmsDatablock* block =  
        hlmsManager->getDatablockNoDefault("my_wire");

    Ogre::Item *item = m_ogreSceneMgr->createItem("Sphere1000.mesh",
        Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
        Ogre::SCENE_DYNAMIC);
    //item->setCastShadows(false);
    item->setDatablock("my_wire");
    //item->setDatablock(block);
and after running, it doesn't crash, but does get this error.

Code: Select all

Can't find HLMS datablock material '[Hash 0xa40c7310]'. It may not be visible to this manager, try finding it by retrieving getHlms()->getDatablock()
And if I add ...

Code: Select all

    Ogre::HlmsDatablock* block =  
        hlmsManager->getDatablockNoDefault("my_wire");
    item->setDatablock(block);
I do get a segmentation fault.

Using item->setDatablock("my_wire"), could it be that it can't be found because I have these two in the same location in my resources2.cfg file? One loads as a resource, yet the "Hlms" does not? Maybe overriding the previous? I have the materials.json file inside /opt/test/resources.

Code: Select all

[General]
FileSystem=/opt/test/resources
[Hlms]
DoNotUseAsResource=/opt/test/resources
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: how to draw as wire?

Post by dark_sylinc »

Maybe Ogre wasn't built with JSON support?
In OgreBuildSettings.h you should see the following:

Code: Select all

#define OGRE_NO_JSON 0
If you see instead this:

Code: Select all

#define OGRE_NO_JSON 1
Then Ogre was built without JSON support.
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

So I removed the build dir, ran cmake, then changed the #define OGRE_NO_JSON to 0, and kicked off make, and got the following ...

Code: Select all

...
[ 11%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJsonCompute.cpp.o
/home/pepp/ogre-v2-1/OgreMain/src/OgreHlmsJson.cpp:42:32: fatal error: rapidjson/document.h: No such file or directory
compilation terminated.
make[2]: *** [OgreMain/CMakeFiles/OgreMain.dir/build.make:1479: OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJson.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/pepp/ogre-v2-1/OgreMain/src/OgreHlmsJsonCompute.cpp:42:32: fatal error: rapidjson/document.h: No such file or directory
compilation terminated.
make[2]: *** [OgreMain/CMakeFiles/OgreMain.dir/build.make:1503: OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJsonCompute.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: OgreMain/CMakeFiles/OgreMain.dir/all] Error 2
make: *** [Makefile:150: all] Error 2
Did I do something wrong?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: how to draw as wire?

Post by dark_sylinc »

Yeah, you can't just change it like that. CMake disabled it because it couldn't find rapidjson as a Dependency.

You can do so by using ogredeps.
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

Here's how I've been trying Ogre w/ ogredeps ...

Code: Select all

    $ hg clone https://bitbucket.org/sinbad/ogre/v2-1 ogre-v2-1
    $ hg branches
    $ hg update v2-1
    $ mkdir build

    $ hg clone https://bitbucket.org/cabalistic/ogredeps Dependencies
    $ cd Dependencies
    $ mkdir build
    $ cd build
    $ mkdir Release 
    $ cd Release
    $ cmake -D OGRE_DEPENDENCIES_DIR=Dependencies/build/ogredeps -D
    OGRE_BUILD_SAMPLES2=1 -D OGRE_USE_BOOST=0 -D OGRE_CONFIG_THREAD_PROVIDER=0
    -D OGRE_CONFIG_THREADS=0 -D CMAKE_BUILD_TYPE=Release ../..
    $ make
    # make install (not done, do not want system wide, just trying to get a local tree built)

    $ cd ../../../build
    $ cmake ..
    # edit build/include/OgreBuildSettings.h and set OGRE_NO_JSON to 0
    $ make -j8
And the above gives out tons of warnings and fails with the following.

Code: Select all

[ 46%] Building C object Dependencies/src/FreeImage/CMakeFiles/FreeImage.dir/Source/ZLib/zutil.c.o
[ 46%] Linking CXX static library libFreeImage.a
[ 46%] Built target FreeImage
make: *** [Makefile:150: all] Error 2
I think what I'll try next is to build the packages of ogredeps using my distro's package manager and see if that doesn't work a bit more. Unless anyone sees that I'm doing something majorly wrong here?
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: how to draw as wire?

Post by rrl »

So my issue was I needed to do the install. Anyways, got past building ogredeps and here's what I'm facing.

If OGRE_NO_JSON is set to 1, it builds.
If OGRE_NO_JSON is set to 0, I get the following error.

Code: Select all

...
[ 46%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJson.cpp.o
/home/pepp/ogre-v2-1/OgreMain/src/OgreHlmsJson.cpp:42:32: fatal error: rapidjson/document.h: No such file or directory
compilation terminated.
make[2]: *** [OgreMain/CMakeFiles/OgreMain.dir/build.make:1479: OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJson.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:490: OgreMain/CMakeFiles/OgreMain.dir/all] Error 2
make: *** [Makefile:150: all] Error 2
A second try results in the following ...

Code: Select all

...
[ 41%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreImage.cpp.o
/home/pepp/ogre-v2-1/OgreMain/src/OgreHlmsJson.cpp:42:32: fatal error: rapidjson/document.h: No such file or directory
compilation terminated.
/home/pepp/ogre-v2-1/OgreMain/src/OgreHlmsJsonCompute.cpp:42:32: fatal error: rapidjson/document.h: No such file or directory
compilation terminated.
make[2]: *** [OgreMain/CMakeFiles/OgreMain.dir/build.make:1479: OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJson.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [OgreMain/CMakeFiles/OgreMain.dir/build.make:1503: OgreMain/CMakeFiles/OgreMain.dir/src/OgreHlmsJsonCompute.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:490: OgreMain/CMakeFiles/OgreMain.dir/all] Error 2
make: *** [Makefile:150: all] Error 2
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: [2.1] How to draw as wire?

Post by dermont »

What distro are you using? Rapidjson is header only so you only need to include the header path, either:

1) check your package manager for the development package for rapidjson (on Ubuntu it's rapidjson_dev) and build using the
dependencies from your package manager.

2) Alternatively if your distro doesn't have a rapidjson dev package copy the rapidjson header files to the expected dir structure:

Code: Select all

cp -ax /media/sdb5/Libraries/OGRE/ogredeps/src/rapidjson/include <your-dir>/rapidjson


add the following to your cmake command or set Rapidjson_INCLUDE_DIR from the CMake gui.

Code: Select all

-DCMAKE_PREFIX_PATH:PATH=<your-dir>


3) Set your OGRE_DEPENDENCIES_DIR to where you installed the dependencies, you run the risk of header/lib mismatch.

4) Rename/copy ogredeps/src/rapidjson/include so that the contents of the include dir are in ogredeps/src/rapidjson and copy ogredeps to dependencies in your v2-1 source dir. Think dependencies is the name, not sure how it works on Linux.
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: [2.1] How to draw as wire?

Post by rrl »

Let me ask this ... is there another way to set materials for drawing wires instead of trying to add all this JSON support (a RPITA)? Maybe some way to do it programmatically?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] How to draw as wire?

Post by dark_sylinc »

Via the old material scripts:

Code: Select all

polygon_mode wireframe
Via C++:

Code: Select all

HlmsMacroblock macroblock = *datablock->getMacroblock();
macroblock.mPolygonMode = PM_WIREFRAME;
datablock->setMacroblock( macroblock );
Post Reply