Collsion with irr file
Collsion with irr file
i have seen all the collision related topic in this forum,and i find one,but that code is only apllicable for one and only one single octtree mesh...what about other meshes that i include in the file..............
............
.....
give plz me complete code from
smgr->loadscene(string);
to
drop
is .irr is best for level or .bsp
if .bsp best then tell a compiler for Maya to create BSP"S or an export plugin or an mel ..
.....
...
ofcourse there is alternative....
from MAya to Ac3d to quakemsp to gradient to gmax tempest
it's is very lenghty process..........and i don't create any single cube bsp
.......
.....
............................
..................................................................
............
.....
give plz me complete code from
smgr->loadscene(string);
to
drop
is .irr is best for level or .bsp
if .bsp best then tell a compiler for Maya to create BSP"S or an export plugin or an mel ..
.....
...
ofcourse there is alternative....
from MAya to Ac3d to quakemsp to gradient to gmax tempest
it's is very lenghty process..........and i don't create any single cube bsp
.......
.....
............................
..................................................................
You have to setup collision information for everything that is collidable. There is no other option. The nice thing is that you only have to write a few functions for setting up the collisions, and then you just call those functions for every node in the scene graph. It is not like you need to write pages of code.
Travis
Travis
i have seen this level example from this forum only,he just assin collision for octree mesh ,but not,but collision is applied all other meshes ..how is it
is possible..................
note :-i have to found that all object's are inside the octree .obj mesh,not the child nodes to octree
here is the code
smgr->loadScene("media/levels/ship.irr");
/*
That was it already. Now add a camera and draw the scene
*/
// add a user controlled camera
ISceneNode* scene_node = smgr->getSceneNodeFromName("SpaceShip");
scene::ICameraSceneNode* camera;
if (scene_node && scene_node->getType() == ESNT_OCT_TREE)
{
irr::io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes();
if (attribs)
{
scene_node->serializeAttributes(attribs);
// get the mesh name out
core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
const c8 *meshName = mesh_name.c_str();
attribs->drop();
// get a mesh from the name
IAnimatedMesh* mesh = smgr->getMesh(meshName);
ITriangleSelector* selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), scene_node, 128);
scene_node->setTriangleSelector(selector);
camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(-30,15,4));
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(3,3,3),
core::vector3df(0,-1,0),
core::vector3df(0,6,0));
camera->addAnimator(anim);
anim->drop();
selector->drop();
}
}
.........plz can any 1 tell me a single function which is applicable to all meshes that include in .irr..................
..and bye the way ,plz treat me as baby in irrlicht and C++
is possible..................
note :-i have to found that all object's are inside the octree .obj mesh,not the child nodes to octree
here is the code
smgr->loadScene("media/levels/ship.irr");
/*
That was it already. Now add a camera and draw the scene
*/
// add a user controlled camera
ISceneNode* scene_node = smgr->getSceneNodeFromName("SpaceShip");
scene::ICameraSceneNode* camera;
if (scene_node && scene_node->getType() == ESNT_OCT_TREE)
{
irr::io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes();
if (attribs)
{
scene_node->serializeAttributes(attribs);
// get the mesh name out
core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
const c8 *meshName = mesh_name.c_str();
attribs->drop();
// get a mesh from the name
IAnimatedMesh* mesh = smgr->getMesh(meshName);
ITriangleSelector* selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), scene_node, 128);
scene_node->setTriangleSelector(selector);
camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(-30,15,4));
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(3,3,3),
core::vector3df(0,-1,0),
core::vector3df(0,6,0));
camera->addAnimator(anim);
anim->drop();
selector->drop();
}
}
.........plz can any 1 tell me a single function which is applicable to all meshes that include in .irr..................
..and bye the way ,plz treat me as baby in irrlicht and C++
Like I said, there is no single function. You have to write the code. Well, I guess now I've written the code...
Now you can create a triangle selector for most scene node types. I would probably split that function up a bit and maybe write some code to see if the nodes were supposed to get collision information generated at all, but you should be able to figure it out on your own. Now all you need to do now is create a meta selector for those selectors.
And you'd use the code like this...
Travis
Code: Select all
void ISceneNode_assignTriangleSelector(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
if (!node || !smgr || !ifs)
return;
if (node->getType() == scene::ESNT_OCT_TREE)
{
io::IAttributes* attribs = ifs->createEmptyAttributes();
if (attribs)
{
node->serializeAttributes(attribs);
// get the mesh name out
core::stringc name = attribs->getAttributeAsString("Mesh");
attribs->drop();
// get the animated mesh for the object
scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
if (mesh)
{
scene::ITriangleSelector* selector =
smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();
}
}
}
else if (node->getType() == scene::ESNT_MESH)
{
scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)node;
if (msn->getMesh())
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelector(msn->getMesh(), msn);
msn->setTriangleSelector(selector);
selector->drop();
}
}
else if (node->getType() == scene::ESNT_ANIMATED_MESH)
{
scene::IAnimatedMeshSceneNode* msn = (scene::IAnimatedMeshSceneNode*)node;
scene::IAnimatedMesh* am = msn->getMesh();
if (am)
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelector(am->getMesh(0), msn);
msn->setTriangleSelector(selector);
selector->drop();
}
}
else if (node->getType() == scene::ESNT_TERRAIN)
{
scene::ITerrainSceneNode* tsn = (scene::ITerrainSceneNode*)node;
scene::ITriangleSelector* selector =
smgr->createTerrainTriangleSelector(tsn, 0); // probably don't want lod 0 all the time...
tsn->setTriangleSelector(selector);
selector->drop();
}
else if (node->getType() == scene::ESNT_CUBE)
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelectorFromBoundingBox(node);
node->setTriangleSelector(selector);
selector->drop();
}
else
{
// not something we want to collide with
}
}
void ISceneNode_assignTriangleSelectors(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
// assign a selector for this node
ISceneNode_assignTriangleSelector(node, smgr, ifs);
// now recurse on children...
core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
core::list<scene::ISceneNode*>::ConstIterator end = node->getChildren().end();
for (/**/; begin != end; ++begin)
ISceneNode_assignTriangleSelectors(*begin, smgr, ifs);
}
void ISceneManager_assignTriangleSelectors(scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
ISceneNode_assignTriangleSelectors(smgr->getRootSceneNode(), smgr, ifs);
}
Code: Select all
void ISceneNode_gatherTriangleSelectors(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta)
{
scene::ITriangleSelector* selector = node->getTriangleSelector();
if (selector)
meta->addTriangleSelector(selector);
// now recurse on children...
core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
core::list<scene::ISceneNode*>::ConstIterator end = node->getChildren().end();
for (/**/; begin != end; ++begin)
ISceneNode_gatherTriangleSelectors(*begin, meta);
}
void ISceneManager_gatherTriangleSelectors(scene::ISceneManager* smgr, scene::IMetaTriangleSelector* meta)
{
ISceneNode_gatherTriangleSelectors(smgr->getRootSceneNode(), meta);
}
Code: Select all
// recursively assign selectors to nodes
ISceneManager_assignTriangleSelectors(smgr, device->getFileSystem());
// recursively gather triangle selectors into a meta selector
scene::IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
ISceneManager_gatherTriangleSelectors(smgr, meta);
// add a user controlled camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
// create collision response using all objects for collision detection
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(meta, camera, core::vector3df(30,30,30), core::vector3df(0,-1,0), core::vector3df(0,6,0));
camera->addAnimator(anim);
anim->drop();
// drop the meta selector. it is owned by the animator
meta->drop();
Last edited by vitek on Sun Jul 06, 2008 3:08 am, edited 3 times in total.
-
hybrid
- Admin
- Posts: 14144
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
kiranmaya, dou you have a braille translator in your browser, or do you use very small letters? You r posts are full of dots that don't make any sense to me. So pardon me if it's indeed an accessibility enhancement, but otherwise it would save lots of space and make your posts at least a little more readable if you just leave them out.
I am in the middle of trying to port your code to C#, but I have ran into major problems.
- There is no equivalence of ESNT_OCT_TREE.
- There is no Attributes class and no CreateEmptyAttributes in FileSystem.
- There is no MeshSceneNode, only AnimatedMeshSceneNode.
Am I blind or is it so that these have not been ported over to Irrlicht.NET (using Irrlicht .NET CP)?
Update: also found out that it is not possible to convert a SceneNode to an AnimatedMeshSceneNode for some dang reason...
Update: I vote that the LoadScene() function returns a reference/pointer to an Irr class/structure. Would make things so much easier.
- There is no equivalence of ESNT_OCT_TREE.
- There is no Attributes class and no CreateEmptyAttributes in FileSystem.
- There is no MeshSceneNode, only AnimatedMeshSceneNode.
Am I blind or is it so that these have not been ported over to Irrlicht.NET (using Irrlicht .NET CP)?
Update: also found out that it is not possible to convert a SceneNode to an AnimatedMeshSceneNode for some dang reason...
Update: I vote that the LoadScene() function returns a reference/pointer to an Irr class/structure. Would make things so much easier.
I'm guessing that most of this stuff isn't in the .net version. Is there a reason that you can't add it yourself?
Travis
Really? Why? What makes you think this would make anything easier. The loadScene method loads the scene into the scene manager's scene graph. All you need to do to get that scene graph is get the root scene node from the scene manager.I vote that the LoadScene() function returns a reference/pointer to an Irr class/structure. Would make things so much easier.
Travis
It is strange to me, but this code don't working properly:
(I used Vitek's collision code):
I tried everything (?), but result the same - no collision at all.
PS I'm appologizing for my bad English.
(I used Vitek's collision code):
Code: Select all
smgr->loadScene("MainTown.irr",0); //my irr file, it contains only static meshes (.3ds), but I tried also example.irr - the same result
ISceneManager_assignTriangleSelectors(smgr, device->getFileSystem()); //Although all meshes have type ESNT_MESH, "else if (node->getType() == scene::ESNT_ANIMATED_MESH) " skiped
scene::IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
ISceneManager_gatherTriangleSelectors(smgr, meta);
scene::ICameraSceneNode* camera = smgr-> addCameraSceneNodeFPS(0,50,10);
camera->setPosition(core::vector3df(20,4,30));
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(meta, camera,
core::vector3df(3,3,3),
core::vector3df(0,0,0),
core::vector3df(0,6,0));
camera->addAnimator(anim);
anim->drop();
meta->drop();
PS I'm appologizing for my bad English.
But if I execute directly
"Unhandled exception at 0x100bc75d in 15.LoadIrrFile.exe: 0xC0000005: Access violation reading location 0x00720069." appeared. What can I do?
Code: Select all
scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)node;
scene::ITriangleSelector* selector =
smgr->createTriangleSelector(msn->getMesh(), msn);
msn->setTriangleSelector(selector);
selector->drop();
Last edited by Chemist on Wed Apr 04, 2007 1:43 pm, edited 1 time in total.
Well, unless you know with 100% certainty that node is actually an IMeshSceneNode you cannot cast the pointer like that. If it is actually some other type, then you will get a crash, just like you say you are getting.
If you are unable to fix the problem yourself, or use the SVN version of Irrlicht, I suggest you go back to using Irrlicht 1.2.
Travis
If you are unable to fix the problem yourself, or use the SVN version of Irrlicht, I suggest you go back to using Irrlicht 1.2.
Travis