University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Simplesmartbody question. | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Simplesmartbody question.
November 6, 2015
5:20 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
November 5, 2015
sp_UserOfflineSmall Offline

Hello everyone,

It's the first time I visit here.

So I have my Smartbody setup, and try to run the simplesmartbody test application,

I wonder why the "Jtroot" position is always located at 0,0,0 after a 100 iterations that I see in the log console?

I am using the D3DX library, therefore I need the simplesmartbody type of interfaces to work with.

Thanks in advance

Jack

November 6, 2015
9:57 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Ok, it looks like simplesmartbody.cpp needs a couple of changes:

Under the line that says:

int numMotions = scene->getNumMotions();
LOG("Loaded %d motions...", numMotions);

add the following code to load up a motion that would show some movements:

scene->loadAssetsFromPath("behaviorsets/MaleMocapLocomotion/motions/ChrMarine@RunCircleRt01.skm");

The idling poses don't move the feet, so the root joint won't show any difference.

then change the animation to the one that was loaded:

// make the character do something
scene->getBmlProcessor()->execBML("mycharacter", "<body posture=\"ChrMarine@RunCircleRt01\"/>");

You should be seeing different values (the animation has the character running in part of a circle, repeatedly).

 

I've made changes to the simplesmartbody.cpp file, so if you are checking out the data from SVN, you can update the code.

Ari

November 7, 2015
3:12 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
November 5, 2015
sp_UserOfflineSmall Offline

I wonder if I can draw stuff like this...

Sorry, still haven't got used to use the source code tag, I start the source code editor and embrace the source code inside it

and it clears out my contents...

 

SrModel model = character->getActiveMesh()->getDeformableMesh()->getStaticModel();

model.V

November 7, 2015
4:15 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Can you repost? You can try using the preformatted, instead of the paragraph mode for code if it's easier.

November 8, 2015
4:32 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
November 5, 2015
sp_UserOfflineSmall Offline

Do I have to do something like this in order to render the character on the screen?

[code]

    scene->loadAssetsFromPath("behaviorsets/MaleMocapLocomotion/motions/ChrMarine@RunCircleRt01.skm");

    // create a character
    LOG("Creating the character...");
    character = scene->createCharacter("mycharacter", "");      
    
    //character->update(0.0f);

    model = character->getActiveMesh()->getDeformableMesh()->getStaticModel(0);

    std::vector<VertexPositionColor> verts;    

    for (int i = 0; i < model.V.size(); i++)
    {
        SrPnt pt = model.V.get(i);
        SrMaterial mat = model.getMaterial(i);        
        D3DXCOLOR newColor(mat.ambient.r, mat.ambient.g, mat.ambient.b, mat.ambient.a);
        VertexPositionColor newVert(pt.x, pt.y, pt.z, newColor);
        verts.push_back(newVert);
    }

    m_pDevice3D->CreateVertexBuffer(model.V.size() * sizeof(VertexPositionColor), 0,
        VertexPositionColor::FVF, D3DPOOL_MANAGED, &VB, NULL);

    VOID* pVerts;
    // put stuff into vertex buffer
    VB->Lock(0, sizeof(verts), (void**)&pVerts, 0);
    memcpy (pVerts, &verts, sizeof(verts));
    VB->Unlock();

    
    std::vector<int> indices;
    m_pDevice3D->CreateIndexBuffer(model.F.size() * 3,
        D3DUSAGE_WRITEONLY,
        D3DFMT_INDEX16,
        D3DPOOL_MANAGED,
        &IB,
        NULL);

    for (int i = 0; i < model.F.size(); i++) {
        indices.push_back(model.F.get(i).a);
        indices.push_back(model.F.get(i).b);
        indices.push_back(model.F.get(i).c);
    }

    VOID* pIndices;
    IB->Lock(0, sizeof(indices), (void**)&pIndices, NULL);
    memcpy (pIndices, &indices[0], sizeof(indices));
    IB->Unlock();

[/code]

November 8, 2015
4:35 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
November 5, 2015
sp_UserOfflineSmall Offline

Hello Ari,

Here I come again.

First off,

The data directory is located under ../data where the root directory is at . (the vcxproj file)

The data directory contains all the initial data provided in the SmartBody package

So like this

TestProject 

  |_TestProject

  |     |_ .vcxproj

  |_ Data

That's the first stuff

The second stuff is just wondering why the following code has no mesh in it.

 [code]
#include
#include  
#include "vhcl.h"
#include <sb/SBScene.h>
#include <sb/SBCharacter.h>
#include <sb/SBSkeleton.h>
#include <sb/SBPython.h>
#include <sb/SBSimulationManager.h>
#include <sb/SBBmlProcessor.h>
#include <sb/SBSceneListener.h>
#include <sb/SBAssetManager.h>
#include <sb/SBJointMap.h>
#include <sbm/gpu/sbmtexture.h>
#include <sr/sr_camera.h>
#include <sr/sr_gl_render_funcs.h>
#include <sr/sr_light.h>  
#include <gl/glut.h>

SmartBody::SBScene* scene;
SmartBody::SBCharacter* character;
SmartBody::SBSkeleton* skeleton;
SmartBody::SBSimulationManager* sim;

 

void initialize(void);

 
class SimpleListener : public SmartBody::SBSceneListener
{
   public:
       SimpleListener() {}
       ~SimpleListener() {}
     
      virtual void OnLogMessage( const std::string & message )
      {
#ifdef WIN32
        LOG("%s", message.c_str());
#else
        std::cout << message << std::endl;
#endif
      }
};

SimpleListener listener;

void initialize() {
 
    std::string mediaPath = "../data";

    // add a message logger to stdout
    vhcl::Log::StdoutListener* stdoutLog = new vhcl::Log::StdoutListener();
    vhcl::Log::g_log.AddListener(stdoutLog);

    LOG("Loading Python...");

    // initialize the Python libraries
    initPython("../Python27/Libs");

    // get the scene object
    scene = SmartBody::SBScene::getScene();    

    scene->addSceneListener(&listener);

    // set the mediapath which dictates the top-level asset directory
    scene->setMediaPath(mediaPath);

    // indicate where different assets will be located
    // "motion" = animations and skeletons
    // "script" = Python scripts to be executed
    // "mesh" = models and textures
    scene->addAssetPath("motion", "ChrBrad");         

    // load the assets from the indicated locations
    LOG("Loading Assets...");    
    scene->loadAssets();    
    int numMotions = scene->getNumMotions();
    LOG("Loaded %d motions...", numMotions);

    //scene->loadAssetsFromPath("behaviorsets/MaleMocapLocomotion/motions/ChrMarine@RunCircleRt01.skm");
    scene->loadAssetsFromPath("mesh/ChrBrad/ChrBrad.dae");

    scene->loadAssetsFromPath("behaviorsets/MaleMocapLocomotion/motions/ChrMarine@RunCircleRt01.skm");

    // create a character
    LOG("Creating the character...");
    SmartBody::SBCharacter* character = scene->createCharacter("mycharacter", "");               

    // load the skeleton from one of the available skeleton types
    SmartBody::SBSkeleton* skeleton = scene->createSkeleton("ChrBrad.sk");

    // attach the skeleton to the character
    character->setSkeleton(skeleton);

    // create the standard set of controllers (idling, gesture, nodding, etc.)
    character->createStandardControllers();

    LOG("Character %s's skeleton added to the scene.", "mycharacter");        
    character->dMeshInstance_p =  new DeformableMeshInstance();
    character->dMeshInstance_p->setPawn(character);
    LOG("Character %s's deformable mesh reset.", "mycharacter");

    std::string dMeshAttrib = character->getStringAttribute("deformableMesh");
    character->setStringAttribute("deformableMesh", "mesh/ChrBrad/ChrBrad.dae");

    character->update(0.0f);

    sim = scene->getSimulationManager();

    
    bool useRealTimeClock = true;
    if (useRealTimeClock)
    {
        sim->setupTimer();
    }
    else
    {
        // otherwise, the time will run according
        sim->setTime(0.0);
    }

    // make the character do something
    scene->getBmlProcessor()->execBML("ChrBrad", "");
    
    LOG("Starting the simulation...");    
    sim->start();
}

/* GLUT callback Handlers */
static void resize(int width, int height)
{
    const float ar = (float)width / (float)height;

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

    float camera[3] = { 0, 30, 0 };    
    gluLookAt(camera[0], camera[1], camera[2], /* look from camera XYZ */
        0, 0, 0, /* look at the origin */
        0, 0, 1); /* positive Y up vector */

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
}

static void display(void)
{
 
    glBegin(GL_QUADS);
    glClearColor(1.0,0.0,0.0,1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    
     // draw a ground plane
    float planeSize  = 300.f;
    SrVec quad[4] = { SrVec(planeSize, 0.f, planeSize), SrVec(-planeSize, 0.f, planeSize), SrVec(-planeSize,0.f,-planeSize), SrVec(planeSize, 0.f, -planeSize) };
    SrVec quadN[4] = { SrVec(0.f, 1.f, 0.f), SrVec(0.f, 1.f, 0.f), SrVec(0.f, 1.f, 0.f), SrVec(0.f, 1.f, 0.f) };
    GLfloat quadColor[16] = { 0.2f,0.2f, 0.2f, 1.f , 0.3f,0.3f,0.3f, 1.f, 0.5f,0.5f,0.5f,1.f, 0.25f,0.25f,0.25f,1.f };
    unsigned short indices[] = {0,1,2, 0,2,3};

    glShadeModel(GL_SMOOTH);
    glDisable(GL_CULL_FACE);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, (GLfloat*)&quad[0]);
    glColorPointer(4, GL_FLOAT, 0, quadColor);
    glNormalPointer(GL_FLOAT, 0, (GLfloat*)&quadN[0]);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
    glDisableClientState(GL_COLOR_ARRAY);

    //glEnable(GL_LIGHTING);    

    const std::vector& pawns = SmartBody::SBScene::getScene()->getPawnNames();
    for (std::vector::const_iterator pawnIter = pawns.begin();
        pawnIter != pawns.end();
        pawnIter++)
    {
        SmartBody::SBPawn* pawn = SmartBody::SBScene::getScene()->getPawn((*pawnIter));
        if(pawn->dMeshInstance_p)
        {            
            pawn->dMeshInstance_p->setVisibility(1);
            pawn->dMeshInstance_p->update();
            SrGlRenderFuncs::renderDeformableMesh(pawn->dMeshInstance_p);
            //LOG("Rendering");
        }
    }     

    glEnd();
    glutSwapBuffers();
}

 
static void idle(void)
{
    glutPostRedisplay();
}

/* Program entry point */
int main(int argc, char* argv[])
{    
    glutInit(&argc, argv);
    glutInitWindowSize(800, 600);
    glutInitWindowPosition(10, 10);

    initialize();

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT quadPoly");

    glutReshapeFunc(resize);
    glutDisplayFunc(display); 
    glutIdleFunc(idle); 

    glutMainLoop();

    sim->stop();

    return EXIT_SUCCESS;
}

[/code]

Here I use the glut library again. Sorry, I need time to adapt the interfaces offered by Smartbody,

For the time being, this makes me easier to understand the library.

When I step into the Update function of pawn->dMeshInstance_p

It exits out immediately which means there was no mesh inside the pawn?

BTW, opengl is z-up, right, if I put the camera at 0,5,0. It should be a little bit out of the screen, right?

Thanks

Jack
 

November 8, 2015
5:55 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

You don't want to use this code:

 

 LOG("Character %s's skeleton added to the scene.", "mycharacter");        
    character->dMeshInstance_p =  new DeformableMeshInstance();
    character->dMeshInstance_p->setPawn(character);
    LOG("Character %s's deformable mesh reset.", "mycharacter");

std::string dMeshAttrib = character->getStringAttribute("deformableMesh");
character->setStringAttribute("deformableMesh", "mesh/ChrBrad/ChrBrad.dae");

 

   

use these lines of code instead:

# loads the necessary media from the path

scene.loadAssetsFromPath("mesh/ChrBrad")

# assigns the ChrBrad.dae to the character

character->setStringAttribute("deformableMesh", "ChrBrad.dae");

 

Coordinates are y-up (right handed coordinate system). 0,5,0 will put the camera 5 units up.

Ari

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: Jamesnuh, gotselyuk1987mon, koenig62ramos, krygerhagen69, coxgeorge3, doyle68bekker, ludvigsen62abbott, shortstext78, cormierhopper5
67 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

jwwalker: 80

jyambao: 52

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 67

Members: 100502

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 460

Posts: 2403