University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Simplified interface to SmartBody help required | 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
Simplified interface to SmartBody help required
November 19, 2014
5:21 am
Avatar
Member
Members
Forum Posts: 20
Member Since:
November 18, 2014
sp_UserOfflineSmall Offline

Hello,

I am going through the SmartBody documentation and am stuck at "Using the SmartBody library" on pages 26-27 (code below). I am using the standalone version of SmartBody (i.e. I am running the sbgui application). I am going File->Load from Script. The result is "could not find Python script [name of file]". Can you anyone suggest what I'm doing wrong?

Thanks. 

#include Smartbody.dll

#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>

class SimpleListener : public SmartBody::SBSceneListener {
public:
SimpleListener() {}
~SimpleListener() {}

virtual void OnLogMessage(const std::string & message) {
#ifdef WIN32
LOG(message.c_str());
#endif
}
};

int main(int argc, char** argv) {
//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
SmartBody::SBScene* scene = SmartBody::SBScene::getScene();
SimpleListener listener;
scene->addSceneListener(&listener);

//set the media path which dictates the top-level asset directory
scene->setMediaPath("../data");

//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);

//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();

//get the simulation object
SmartBody::SBSimulationManager* sim = scene->getSimulationManager();

//if you want to use a real-time clock do the following:
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("mycharacter", "<body posture=\"ChrBrad@Idle01\"/>");

LOG("Starting the simulation...");
double lastPrint = 0;
sim->start();

//run for 100 simulation seconds
while(sim->getTime() < 100.0) {
scene->update();
if(!useRealTimeClock)
// update at 1/60 of a second when running in simulated time
sim->setTime(sim->getTime() + 0.16);
else
sim->updateTimer();

if(sim->getTime() > lastPrint) {
LOG("Simulation is at time: %5.2f
", sim->getTime());
lastPrint = sim->getTime() + 10;
}

const std::vector<std::string>& characterNames = scene->getCharacterNames();

for(size_t c = 0; c < characterNames.size(); c++) {
SmartBody::SBCharacter* character = scene->getCharacter(characterNames[c]);
SmartBody::SBJoint* joint = character->getSkeleton()->getJoint(0);
SrVec position = joint->getPosition();
LOG("Character %s first joint is at position (%f, %f, %f)", character->getName().c_str(), position.x, position.y, position.z);
}
}
sim->stop();
return 0;
}

November 19, 2014
4:20 pm
Avatar
Member
Members
Forum Posts: 29
Member Since:
September 30, 2014
sp_UserOfflineSmall Offline

Hi Dilbert,

For you to get help on that, I think it would be more usefull that you gave us the content of the Python script you are trying to load from instead of the code you copy-pasted from the manual.

This code is an example on how to use the simplified API to SmartBody to create your own SmartBody-enabled application. If you want to use the sbgui application, I suggest that you read carefully pages 8 to 24, the Tutorials section (pages 31-45) and the Using SmartBody with Python section (starting page 50). The latest tells you what you need to know about the API for Python scripts to get started.

I have encountered this error before, inside some of the example scripts. In your script, there probably are one or several call to scene.run('name_of_the_script.py'). When this instruction is called, SmartBody looks for a script named "name_of_the_script.py" in the path that was given for scripts by the following instruction:

assetManager.addAssetPath('script', 'path/to/scripts')

Followed by:

assetManager.loadAssets()

If the script called inside the script you try to load your scene setup from is not in this directory, SmartBody cannot find it.

The path "path/to/scripts" is relative to the media path that can be changed using the following line :

scene.setMediaPath('path')

So you can try the following:

1) Make sure that the path to any script that is run during the execution of your main script is properly specified.

2) Make sure the media path variable is properly set.

3) You can add as many paths to scripts as you need provided that the loadAssets method is called after.

I hope it helps.

Cheers,

Pierre

 

November 19, 2014
8:23 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

If you are using sbgui, are you saying that you choode: File->Load from script... and the script doesn't load?

If so, make sure there is a file called:

 

.smartbodysettings

in the same directory as the sbgui executable, and make sure that there is a line in that file that looks like this:

mediapath=../../../../data

where the path (../../../../data in this case) leads to the 'data' directory.

 

Ari

November 20, 2014
8:27 am
Avatar
Member
Members
Forum Posts: 20
Member Since:
November 18, 2014
sp_UserOfflineSmall Offline

Thanks for your replies.

I have .smartbodysettings in the same directory at the sbgui application. The .smartbodysettings file includes mediapath=../data. I replaced ../data with the path of my data directory and got the same result.

I don't have a Python script. I was trying to load the .cpp file from the SmartBody documentation directly into the sbgui.

After reading your posts, I looked online for a way to call a c++ script in Python and found a couple solutions for small bits of code but none for an entire c++ script. Can you suggest a way to run a c++ script in Python and on the sbgui?

Thanks.  

November 22, 2014
12:15 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

When running sbgui, you cannot call c++ functions directly. However, you can call Python functions which are very similar to the C++ functions (the Python API is directly based on the C++ API).

 

For example, in C++ you would write:

 

scene->getCharacters();

 

whereas in Python the same code looks like this:

scene.getCharacters()

 

Ari