Making better use of Ogre's capbilities?

Everything about development and the OpenMW source code.
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Making better use of Ogre's capbilities?

Post by lgromanowski »

jhooks1 wrote:Having problems.
MSVC complained about
usleep()
boost/thread/tss.hpp missing
____PRETTY_FUNCTION_____
__PRETTY_FUNCTION__ could be changed to __FUNCTION__ ("pretty" is gcc extension).
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

I am thinking now that the reason the creature looks wrong is I am making the skeleton inside the mesh NIFLoader. Maybe if I made it with the SkeletonManager it would work.
Chris
Posts: 1626
Joined: 04 Sep 2011, 08:33

Re: Making better use of Ogre's capbilities?

Post by Chris »

jhooks1 wrote:Having problems.
MSVC complained about
usleep()
boost/thread/tss.hpp missing
____PRETTY_FUNCTION_____
Add

Code: Select all

#define usleep(x) Sleep((x)/1000)
somewhere. Not sure about "pretty function", seems to be a boost issue.
jhooks1 wrote:I am thinking now that the reason the creature looks wrong is I am making the skeleton inside the mesh NIFLoader. Maybe if I made it with the SkeletonManager it would work.
Yes, you should use separate loaders for the skeleton and mesh(es). Just make sure the skeleton is loaded before trying to use it to get bones (call skel->load()). Probably set the skeleton name on the mesh(es) just after creating them, too.
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

I made the skeletons load through the skeleton loader. At this time things are not going good. As soon as I try to apply animation to a creature (an ash zombie) things go haywire and parts fly back and forth all over the place.
Chris
Posts: 1626
Joined: 04 Sep 2011, 08:33

Re: Making better use of Ogre's capbilities?

Post by Chris »

jhooks1 wrote:I made the skeletons load through the skeleton loader. At this time things are not going good. As soon as I try to apply animation to a creature (an ash zombie) things go haywire and parts fly back and forth all over the place.
Are you trying to load and run the animation using Ogre? Do you have any code I could look at?
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

Yes, I am trying to use ogre's animation system. Code is up on my animexperimental branch. I have not tested any cells with npcs yet, they may crash it (dunno yet). I would recommend Ainab, it has one ashzombie.
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

Also I need to get rid of std::vector<bool> vertexPosAbsolut in handleNiTriShape(). I think it may be causing a problem.
Chris
Posts: 1626
Joined: 04 Sep 2011, 08:33

Re: Making better use of Ogre's capbilities?

Post by Chris »

Haven't had much time to go through everything, but I do notice that you're specifying initial positions for the bones when loading the skeleton. You shouldn't be doing that since the nif animation deltas are relative to untransformed bones, while the skeleton seems to specify some initial pose.

It means you also need to "untransform" the mesh vertices to be squished up around the untransformed bones, instead of around the bone's bind pose. Niflib has a 4x4 matrix for each bone in NiSkinData which represents the transformation back to the skeleton's root from the bone's bind pose (for openmw's nif code, I believe you would use NiSkinData's bones[idx].trafo). In my code, it's handled with this:

Code: Select all

NiTriShapeDataRef data = DynamicCast<NiTriShapeData>(shape->GetData());
    NiSkinInstanceRef skin = shape->GetSkinInstance();
    std::vector<Vector3> srcVerts = data->GetVertices();
    std::vector<Vector3> srcNorms = data->GetNormals();
    if(skin != NULL)
    {
        // Convert vertices and normals back to bone space
        std::vector<Vector3> newVerts(srcVerts.size(), Vector3(0,0,0));
        std::vector<Vector3> newNorms(srcNorms.size(), Vector3(0,0,0));

        NiSkinDataRef data = skin->GetSkinData();
        const std::vector<NiNodeRef> &bones = skin->GetBones();
        for(size_t b = 0;b < bones.size();b++)
        {
            Matrix44 mat = data->GetBoneTransform(b);

            const std::vector<SkinWeight> &weights = data->GetBoneWeights(b);
            for(size_t i = 0;i < weights.size();i++)
            {
                size_t index = weights[i].index;
                float weight = weights[i].weight;

                if(newVerts.size() > index)
                    newVerts[index] += (mat*srcVerts[index]) * weight;
                if(newNorms.size() > index)
                {
                    for(size_t j = 0;j < 3;j++)
                    {
                       newNorms[index][j] += mat[j][0]*srcNorms[index][0] * weight;
                       newNorms[index][j] += mat[j][1]*srcNorms[index][1] * weight;
                       newNorms[index][j] += mat[j][2]*srcNorms[index][2] * weight;
                    }
                }
            }
        }
        srcVerts = newVerts;
        srcNorms = newNorms;
    }
With the mesh loaded all squished up around the skeleton's root along with the bones, what should happen is that the animations move the bones out to its proper pose. With the proper bone assignments in place, moving the bones away from the skeleton's root and into a proper pose will also expand the mesh vertices into a proper form.
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

Thank you, will try the recommendations you gave me soon.
jhooks1
Posts: 780
Joined: 06 Aug 2011, 21:34

Re: Making better use of Ogre's capbilities?

Post by jhooks1 »

Yes, it works! Now to make it look smoother.

EDIT: For shapes without skins, the best solution at this time may be to just modify buffer positions. Most creatures/npc parts containing a skeleton do not have a shape like this, so it shouldn't slow us down to much
Post Reply