Crystal Space
Welcome, Guest. Please login or register.
November 27, 2014, 02:57:22 am

Login with username, password and session length
Search:     Advanced search
9026 Posts in 2046 Topics by 9140 Members
Latest Member: Corrycrifford
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Factories of Thing Meshes?
« previous next »
Pages: [1] Print
Author Topic: Factories of Thing Meshes?  (Read 2710 times)
Panch
Jr. Member
**
Posts: 80


View Profile Email
« on: October 21, 2007, 03:47:32 pm »

It seems like Thing Meshes don't have/need a mesh factory; is that right?

Code to create the ThingMesh:
Code:
// Create an Aggro Box
bool Time::CreateAggroBox(const char* mesh, csVector3 minPos, csVector3 maxPos)
{
if (!loader->LoadTexture ("adversary_texture", "/lib/stdtex/misty.jpg"))
return ReportError ("Error loading 'misty' texture!");

iMaterialWrapper* upMaterial = engine->GetMaterialList ()
  ->FindByName ("adversary_texture");

aggroMesh = engine->CreateThingMesh (room, mesh);

iMeshObject* aggro_objects = aggroMesh->GetMeshObject ();
iMeshObjectFactory* aggro_factory = aggro_objects->GetFactory();
if (!aggro_factory)
return false;

csRef<iThingFactoryState> aggro_state =
scfQueryInterface<iThingFactoryState> (aggro_factory);

aggro_state->AddOutsideBox(minPos, maxPos);

aggro_state->SetPolygonMaterial (CS_POLYRANGE_LAST, upMaterial);
aggro_state->SetPolygonTextureMapping (CS_POLYRANGE_LAST, 3);
 
// Push the aggro sphere into the aggro array
    aggroList_object = aggroMesh->QueryObject(); 
aggroList.PushSmart(aggroList_object->GetName());

return true;

}

Code that returns false when attempting to query the mesh factory wrapper:
Code:
// Get the attachment meshes factory
iMeshFactoryWrapper* attach_factory = attachMesh->GetFactory();
if (!attach_factory) return false;

Thanks!
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: October 21, 2007, 06:24:25 pm »

It seems like Thing Meshes don't have/need a mesh factory; is that right?

No that's not. The only special thing is that with things the factories are created automatically if you don't do it yourselves.

Quote
Code to create the ThingMesh:
Code:
// Create an Aggro Box
bool Time::CreateAggroBox(const char* mesh, csVector3 minPos, csVector3 maxPos)
{
if (!loader->LoadTexture ("adversary_texture", "/lib/stdtex/misty.jpg"))
return ReportError ("Error loading 'misty' texture!");

iMaterialWrapper* upMaterial = engine->GetMaterialList ()
  ->FindByName ("adversary_texture");

aggroMesh = engine->CreateThingMesh (room, mesh);

iMeshObject* aggro_objects = aggroMesh->GetMeshObject ();
iMeshObjectFactory* aggro_factory = aggro_objects->GetFactory();
if (!aggro_factory)
return false;

csRef<iThingFactoryState> aggro_state =
scfQueryInterface<iThingFactoryState> (aggro_factory);

aggro_state->AddOutsideBox(minPos, maxPos);

aggro_state->SetPolygonMaterial (CS_POLYRANGE_LAST, upMaterial);
aggro_state->SetPolygonTextureMapping (CS_POLYRANGE_LAST, 3);
 
// Push the aggro sphere into the aggro array
    aggroList_object = aggroMesh->QueryObject(); 
aggroList.PushSmart(aggroList_object->GetName());

return true;

}

Code that returns false when attempting to query the mesh factory wrapper:
Code:
// Get the attachment meshes factory
iMeshFactoryWrapper* attach_factory = attachMesh->GetFactory();
if (!attach_factory) return false;

Thanks!

In this case there is still a factory but it is internal. That means there will be an internal iMeshObjectFactory but no iMeshFactoryWrapper.

Note that thing meshes shouldn't be used anymore. Genmesh is preferred now.

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #2 on: October 22, 2007, 03:23:11 am »

Quote
That means there will be an internal iMeshObjectFactory but no iMeshFactoryWrapper.
Which means I won't be able to socket without an iMeshFactoryWrapper. So i'll try and create my thing meshes with a specifically defined factory.

Quote
Genmesh is preferred now.
Won't work for me because in all my testing, collision detection is not polygon accurate with genmeshes; although it still is with thing meshes.

Thanks!

Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: October 22, 2007, 07:33:01 am »

Won't work for me because in all my testing, collision detection is not polygon accurate with genmeshes; although it still is with thing meshes.

That's certainly not true. Both thing and genmesh have the same polygon accurate collision detection.

Greetings,
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #4 on: October 22, 2007, 08:20:17 am »

Won't work for me because in all my testing, collision detection is not polygon accurate with genmeshes; although it still is with thing meshes.
That's certainly not true. Both thing and genmesh have the same polygon accurate collision detection.

Panch, so perhaps explain more specifically the issues you're getting with genmeshes and CD.
Logged
rvhaasen
Jr. Member
**
Posts: 62


View Profile
« Reply #5 on: October 22, 2007, 09:35:28 am »

Note that thing meshes shouldn't be used anymore. Genmesh is preferred now.
does this mean that in the current version of CS genmeshes can be used with lightmaps ?
This would be great, in that case i can refactor the 3dsmax exporter to only use genmeshes.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #6 on: October 22, 2007, 09:41:01 am »

Yes, using the lighter2 tool.

Greetings,
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #7 on: October 22, 2007, 09:44:19 pm »

Quote
Panch, so perhaps explain more specifically the issues you're getting with genmeshes and CD.

Sure. I create a spherical GenMesh using the same code from walktest:
Code:
// Create a GenMesh
bool Time::CreateGenMesh()
{
csRef<iGeneralFactoryState> fstate;

  // Create GenMesh Factory
  imeshfact = engine->CreateMeshFactory (
  "crystalspace.mesh.object.genmesh", "adversary");
  if (!imeshfact) return false;

  fstate = scfQueryInterface<iGeneralFactoryState> (
  imeshfact->GetMeshObjectFactory ());
  csEllipsoid ellips (
  csVector3 (0, 0, 0),
csVector3 (1, 1, 1));
  fstate->GenerateSphere (ellips, 10);

  if (!loader->LoadTexture ("adversary_texture", "/lib/stdtex/misty.jpg"))
    return ReportError ("Error loading 'misty' texture!");
  iMaterialWrapper* adversary_material = engine->GetMaterialList ()
  ->FindByName ("adversary_texture");
  imeshfact->GetMeshObjectFactory ()
    ->SetMaterialWrapper (adversary_material);

   //csRef<iMeshWrapper> adversary = view->GetEngine ()->CreateMeshWrapper (
  sprite = view->GetEngine ()->CreateMeshWrapper (
      imeshfact, "adversary",
room, csVector3 (0, 3, 3));

   return true;

}

When I try to detect collision detection with:
Code:
// Aggro for level 1
if(aggroList.GetSize()>0)
{
for (aggro_i; aggro_i<aggroList.GetSize(); aggro_i++)
{
string aggroName = aggroList.Get(aggro_i);
csRef<iMeshWrapper> aggroed = engine->GetMeshes()->FindByName(aggroName.c_str());

csReversibleTransform trans1 = hero->GetMovable()->GetFullTransform();
csReversibleTransform trans2 = aggroed->GetMovable()->GetFullTransform();
col_aggro = aggroed->QueryObject();

csRef <csColliderWrapper> hero_collider_wrapper =
csColliderWrapper::GetColliderWrapper (hero_object);

if(hero_collider_wrapper->Collide(col_aggro, &trans1, &trans2))
{
Print(col_aggro->GetName());
//aggroList.Delete(col_aggro->GetName());
//engine->RemoveObject(col_aggro);
}
}
}

The CD doesn't report properly, if you can imagine a circle around the circumference on the x-axis of the sphere, CD will work fine along that axis. However, it is not per polygon accurate.  It is however with Thing Meshes. I have my camera set a few marks behind my hero mesh for debugging purposes and I can see the hero mesh intersect with different pieces of the GenMesh with no response. However, if I jump up to the x-axis of the object I will collide properly. With Thing Meshes however I can collide against any polygon and return that collision accurately.

The idea is to create a sphere/cube around enemies that when collided with will let them know to attack me. I have nearly surrendered to the fact that I can not do it with the limitation of CS + ODE collision. It isn't too much of a big deal because I've come up with 2 very workable alternatives.

I would like to see the 'aggro' thing work though as I think my theory and code are sound!
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 7.293 seconds with 15 queries.