Map made with 3DS MAX

ulDuc

23-02-2010 10:45:06

Hi all !

i didn't found the french forum for NxOgre so here i am !

with a friend, we are trying to do a 3D game using Ogre3D and recently NxOgre PhysX for the physics engine.

so we have a map of about 15 000 polygons composed of some objets like a bridge, some barriers, a house cave etc... some trees may be added and some more.

i succeded importing the scene, after having it exported with OgreExporter in .scene with all the .mesh, using DotScene Script.

After that achievement, we wanted to add physics in our world. I succeded having some test to work with simple objets made myself like cubes, and all needed in the tutorials.

However, i don't see how i can combine DotScene script and NxOgre. I would like just an idea on how to use our map has a terrain.
We don't want to use heightfield at all because our 3D Graphist is a crack, a very goob worker.

thank you for you help, do not hesitate to ask for some details

ul.Duc

betajaen

23-02-2010 10:57:10

I think there is a PhysX exporter for 3DS Max, you'd find it on the NVIDIA/PhysX website somwhere, otherwise you could convert your map into Blender, then use the flower/flour exporter written by me.

This will convert just the meshes only, and so when you load in your dotScene map, make sure you create the required static actors with the same positional/orientation as the dotScene nodes do.

ulDuc

23-02-2010 11:05:59

Hey Betajean !

thanks for that explaination.

i used Flour for the tutorials but the problem was until now that for the whole scene, there were more than 200 meshes exported... so flour on these would have take a very long time.

i'll try to export with the physX exporter for 3DS MAX, i don't think that the graphist want to use blender whereas he has the greatest ^^

you are saying that with flour, i will only convert mesh to mesh and be able to use still DotScene script ? i will maybe have to add some lines in the script so that it creates the static actors during the creation of the scene.

ul.Duc, thank you for the quick answer :)

betajaen

23-02-2010 11:51:51

Yep. You'll need a .mesh for Ogre, and a .nxs for PhysX/NxOgre.

The 3DS Max PhysX Exporter should be pretty easy to use. You only want the NXS files, any extra collada or NxuStream file aren't required. As you'll be loading in the meshes via dotScene anyway (for which you'll have to add a line or two to create any static geometries at the same time).

ulDuc

23-02-2010 13:04:49

Now i tried to export the scene with physX exporter...

i just have choice between XML, nxb and dae...
as you said, dae(collada) is not supported.

however, the exporter is based on NxuStream 2... is that want i need or i have to pass every mesh with flour, a small batch script should do it, but is there another way to so that more easily ?

ul.Duc

betajaen

23-02-2010 13:09:56

Ugh.

If you do an export to dae/nxb/nxustream, are there any NXS files exported to?

ulDuc

23-02-2010 13:11:49

nope no NXS files, i tested them all...

only a xml, a dae and a nxb.

ul.Duc, what can i do ?

betajaen

23-02-2010 13:14:30

Your going to have to Flower it I'm afraid.

But Flower 0.4 is pretty robust, I pretty sure you can export them all in one go.

ulDuc

24-02-2010 17:55:57

Hi again, i have some more problems, not related to the map itself.

i succeded having my map with physics, i had to use flour 0.3.2 i think, to convert mesh to nxs. so anyway, that is working.

now, i'am trying to have my character, which is by now the example ninja, so i converted it in convex nxs. i insert it in the scene using the tutorials on the wiki and so i create a convex model after having loaded the .nxs ninja.

then, i look at it in the scene and i see it falling on the map and everything is ok !

now, i found a lot of examples on my problem in the forum but your explanations weren't as clear as i could imagin. I want to attach my camera (i have a Ogre::SceneNode for the character, the pitchNode and the Camera itself) to the ninja Node.

without the physics part, it was fine, i had my camera behind the ninja, the ninja was moving in function of the mouse on the yaw axis and the keybord for the movement on the XY plane. what i wanted to add with NxOgre was that the ninja, in that configuration falls and the camera stays behind him.

so i try with a OGRE3DKinematicBody but the createKinematicBody method ask for a shape. In every tutorial, it is primitive shape. But for my ninja, i'd need a more advanced shape.

If you could help me on that problem i'm having, that'd be great !

ul.Duc

EDIT : here is the basic stuff that makes the ninja falling down on the map. the camera juste fly around freely

// ##### MAP ##### //
// creation du mesh de la map en utilisant le modele physX nxs
NxOgre::Mesh* mapMesh = NxOgre::MeshManager::getSingleton()->load("media:map.nxs");
// creation de la geometrie pour l'associer a la scene physique
NxOgre::TriangleGeometry* mapGeometry = new NxOgre::TriangleGeometry(mapMesh);
// association de la geometrie de la map a la scene physique
mScene->createSceneGeometry(mapGeometry, NxOgre::Matrix44(NxOgre::Vec3(0, 0, 0)));

// creation de l'entité pour l'affichage de la Map
Ogre::Entity* mapEntity = mSceneMgr->createEntity("map", "map.mesh");
Ogre::SceneNode* mapNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("map");
mapNode->attachObject(mapEntity);
// on ajuste le mesh graphique a la position du mesh physique
mapNode->setPosition(Vector3::ZERO);

// #### ninja #### //

// creation du mesh du ninja en utilisant le modele physX nxs
NxOgre::Mesh* ninjaMesh = NxOgre::MeshManager::getSingleton()->load("media:ninja.nxs");
// creation de la geometrie du ninja en physique
NxOgre::Convex* ninjaGeometry = new NxOgre::Convex(ninjaMesh);
// creation du body du ninja en fonction de sa position et de sa geometrie et de son mesh :/
OGRE3DBody* ninjaBody = mRenderSystem->createBody(ninjaGeometry, NxOgre::Vec3(0, 2500, 0), "ninja.mesh");

betajaen

24-02-2010 18:42:42

If I remember correctly the Ninja is a really large mesh, in NxOgre scale several KMs high.

Anyway, You'll have to represent him as a Convex, Capsule (or a collection of primitives that represent his legs/arms/etc) as TriangleMeshes do not collide with each other.

ulDuc

24-02-2010 19:13:57

the convex is already there, the ninja collide fine enough for my learning.

the probleme is on the camera. i wasn't so explicit ^^

for the scale, the map is 150metre wide and around 60 metres height, the ninja is perfectly propotionned in our map.

however, do you have some links to learn about character with NxOgre or just how to attach a camera to the NxOgre Actor or OGRE3DBody.

i tried to move the camera at the same time as the ninja KinematicBody, but i had some troubles with the move method combined with

ninjaNode->translate(ninjaNode->getOrientation() * mDirection * evt.timeSinceLastFrame);
NxOgre::Vec3 mDirNx(mDirection.x, mDirection.y, mDirection.z);
mKB->moveGlobalPosition(mKB->getGlobalOrientationQuat() * mDirNx * evt.timeSinceLastFrame);


and it can't compile cause of the Vec3 not compatible with Quaternion. With Ogre i do like that and it is pretty simple.

any idea of an easier way to make the camera move at the sime time as the Kinematicbody... maybe, i may use other class than kinematicbody...
sorry for being such a noob :/

ul.Duc

ulDuc

24-02-2010 20:16:44

i've tried some stuff but i think that everything like .as<Ogre::Vector3>() is depreciated...

do you have a way to make the KinematicBody according to its orientation ?

as with the node using getOrientation() * mDirection * time

ul.Duc

betajaen

24-02-2010 20:32:00

Vec3::as<T> should exist, and Quat::as<T> as well.

Either way; you would want to update the Physics first, then set the graphics second (from the Physics).

Roughly:
NxOgre::Vec3 trans = (orientation * mDirection) * evt.timeSinceLastFrame;
kb->moveGlobalPosition(kb->getGlobalPosition() + trans);
ninjaNode->setPosition(kb->getGlobalPosition().as<Ogre::Vector3>());
ninjaNode->setOrientation(kb->getGlobalOrientation().as<Ogre::Quaternion>());

ulDuc

24-02-2010 20:36:29

i have the git version of NxOgre and

.\src\myListener.cpp(50) : error C2039: 'as' : is not a member of 'NxOgre::Matrix33'

where am i getting wrong ?

ulDuc

24-02-2010 20:53:26

I found it.. sorry about that.
i try to understand what i have where and normally it should do it.

thanks, i'll come back if i have another trouble :)

ul.Duc

ulDuc

24-02-2010 22:12:29

ok, now i have my KinematicBody just how i wanted it in front of the camera but

the kinematicBody doesn't collide anymore... i can pass through every thing. However, i use the visual debbuger(which i think is very well done) and so i see every triangles from the flour conversion.

Vector3 trans = ninjaNode->getOrientation() * mDirection * evt.timeSinceLastFrame;
mKB->setGlobalPosition(mKB->getGlobalPosition().as<Vector3>() + trans);

ninjaNode->setPosition(mKB->getGlobalPosition().as<Vector3>());


the ninja is well a convex model loaded as follows :

// creation du mesh du ninja en utilisant le modele physX nxs
NxOgre::Mesh* ninjaMesh = NxOgre::MeshManager::getSingleton()->load("media:ninja.nxs");
// creation de la geometrie du ninja en physique
NxOgre::Convex* ninjaGeometry = new NxOgre::Convex(ninjaMesh);
// creation du body du ninja en fonction de sa position et de sa geometrie et de son mesh :/
mKB = mRenderSystem->createKinematicBody(ninjaGeometry, NxOgre::Vec3(0, 2400, 0), "ninja.mesh");


Where the lack of collision could come from ?

betajaen

24-02-2010 22:38:54

That's how they work, it's a one-way collision. More technically; every frame the momentum is cancelled out, so if/when you move through something it doesn't react because it has "forgotten" too. Character Controllers are Kinematic Actors too, but they have an extra step to pre-calculate the collisions, and act accordingly.

You can do the same thing; or you could use a normal Actor/Body, but carefully control it (reduce momentum, help with collisions, cancel out frictional forces, stop unwanted turning, etc.)

ulDuc

01-03-2010 18:47:59

Hi betajean and the others :)

now, i've got my model(i use the ninja while my graphist didn't made one of his own) and the problem is now that either i put him a mass enormous and he falls fast enough, then he doesn't move or almost when he collides or i let the gravity of -9.8 on Y axis and a mass of 80 (kilograms i suppose) but when he is at the top of a hill, he goes in the air because he dosent follow exactly the height of the map.

i tought about adding 9.8 on the Y axis in my force that i use to move the model, but at the top of the hill, he goes strait still cause the gravity is cancelled until the key is released.

here is my code :

void Application::setupScene(){

// initialisation de NxOgre
mWorld = NxOgre::World::createWorld();

// description de la scene dont le jeu fera parti
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0, -9.8f, 0);
sceneDesc.mName = "SceneMonde";

// creation de la scene dont le jeu fera parti
mScene = mWorld->createScene(sceneDesc);

// quelques valeur de configuration de la scene
mScene->getMaterial(0)->setStaticFriction(1.0f);
mScene->getMaterial(0)->setDynamicFriction(1.0f);
mScene->getMaterial(0)->setRestitution(0.0f);
(...)
rbDesc.mMass = 80;
rbDesc.mName = "cylindreBody";
mB = mRenderSystem->createBody(cylindreGeometry, NxOgre::Vec3(0, 2400, 0), "ninja.mesh", rbDesc);
mB->setAngularMomentum(NxOgre::Vec3::ZERO);
mB->setLinearMomentum(NxOgre::Vec3::ZERO);
mB->setAngularDamping(1.0f);
mB->setLinearDamping(1.0f);
(...)
}

bool MyFrameListener::frameStarted(const FrameEvent &evt) {
mTimeController->advance(evt.timeSinceLastFrame);

if(mMouse)
mMouse->capture();
if(mKeyboard)
mKeyboard->capture();

Vector3 force2(ninjaNode->getOrientation() * force * evt.timeSinceLastFrame);
NxOgre::Vec3 force3(force2.x, force2.y, force2.z);
mB->setLinearVelocity(NxOgre::Vec3(0, -9.8f, 0) + force3);
Quaternion ninOr = ninjaNode->getOrientation();
NxOgre::Quat orien(ninOr.w, ninOr.x, ninOr.y, ninOr.z);
mB->setGlobalOrientationQuat(orien);

ninjaNode->setPosition(mB->getGlobalPosition().as<Vector3>());

mVisualDebugger->draw();
mVisualDebuggerNode->needUpdate();

return mContinue;
}

bool MyFrameListener::keyPressed(const OIS::KeyEvent &e)
{
switch (e.key)
{
case OIS::KC_ESCAPE:
mContinue = false;
break;

case OIS::KC_UP:
case OIS::KC_W:
force.z = -mMove;
break;

case OIS::KC_DOWN:
case OIS::KC_S:
force.z = +mMove;
break;

case OIS::KC_LEFT:
case OIS::KC_A:
force.x = -mMove;
break;
(...)
}


i just tried to play with the friction effect, even at 0.8f, the model slide at the top of the hill because it's goind down... :/
i don't know what to try.

thank you

ul.Duc