[2.1] set wireframe color

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] set wireframe color

Post by rrl »

I create HlmsDatablock, then create an HlmsMacroblock with mPolygonMode set to PM_WIREFRAME. Then I create a mesh, createItem from the mesh, then set the datablock and add it to a scene node. I'm not using material scripts, this is all via C++. This renders my mesh.

What I haven't' yet gotten is how to set the color of the wireframe. Can anyone comment on how this would be done?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] set wireframe color

Post by xrgo »

wireframe uses the colour of the datablock itself, so if you are using Pbs you must set the diffuse colour or add a diffuse texture, it even react to lights the same way that when is not wireframe
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: [2.1] set wireframe color

Post by rrl »

I've been using the sample DynamicGeometry for help and have since added a light source as can be seen towards the end of this code snippet. This is how I'm currently doing it and has resulted in my wireframe turning white. I have registered HLMS, but am not using material scripts, and so I think I am using PBS, but have not quite gotten how to add diffuse colour.

Also, by adding this light source, when I rotate my mesh, it has become very jerky and delayed as opposed to before where it would rotate smoothly.

Thoughts?

Code: Select all


void QtOgreWindow::createScene()
{
    static bool called = false;

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

    Ogre::HlmsDatablock* block = hlmsManager->getDefaultDatablock();

    Ogre::HlmsMacroblock macroblock = *block->getMacroblock();
    macroblock.mPolygonMode = Ogre::PM_WIREFRAME;
    block->setMacroblock(macroblock);

    if (called == false) {
        // 'if called' because we can only call createManual once (the main mesh) once
        the_mesh = Ogre::MeshManager::getSingleton().createManual("The Mesh", 
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

        for (/* ... */) {
            createStaticMesh(the_mesh, xtra);
        }
        
        called = true;
    }

    Ogre::Item *item = ogreSceneManager->createItem(the_mesh, Ogre::SCENE_DYNAMIC);
    item->setDatablock(block);

    mSceneNode = ogreSceneManager->getRootSceneNode(Ogre::SCENE_DYNAMIC)->
        createChildSceneNode(Ogre::SCENE_DYNAMIC);
    mSceneNode->attachObject(item);
    mSceneNode->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f));
    mSceneNode->setScale(Ogre::Vector3(2.0f, 2.0f, 2.0f));

    // recently added the following resulting in jerky rotations
    Ogre::Light *light = ogreSceneManager->createLight();
    Ogre::SceneNode *lightNode = 
        ogreSceneManager->getRootSceneNode()->createChildSceneNode();
    lightNode->attachObject(light);
    light->setPowerScale(Ogre::Math::PI);
    light->setType(Ogre::Light::LT_DIRECTIONAL);
    light->setDirection(Ogre::Vector3(-1, -1, -1).normalisedCopy());
}
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] set wireframe color

Post by xrgo »

first you need to register the Pbs Hlms implementation, see GraphicsSystem.cpp in samples/2.0/common method registerHlms
then you can create a pbs datablock like this:

Code: Select all

Ogre::HlmsPbsDatablock* myDatablock = static_cast<Ogre::HlmsPbsDatablock*>(hlmsPbs->createDatablock( "MyDatablockName", "MyDatablockName", Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec()) );
        
and then you can set a diffuse colour:

Code: Select all

myDatablock ->setDiffuse( Ogre::Vector3(1,0,0) );
then use this datablock for your item. And of course you have to set the macroblock with the wireframe option for this datablock.
rrl wrote: Sun Jan 14, 2018 10:56 pm Also, by adding this light source, when I rotate my mesh, it has become very jerky and delayed as opposed to before where it would rotate smoothly.
I am not so sure about this... maybe its not the rotation the problem, maybe your mesh don't have proper normals and the light just reacts weirdly, you should try without wireframe first to see how it looks solid.
Post Reply