Crystal Space
Welcome, Guest. Please login or register.
September 18, 2014, 08:59:24 am

Login with username, password and session length
Search:     Advanced search
9018 Posts in 2051 Topics by 8477 Members
Latest Member: Rochellealvarado
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  [SOLVED] Help with Coding for Particles
« previous next »
Pages: [1] Print
Author Topic: [SOLVED] Help with Coding for Particles  (Read 1891 times)
Hannofcart
Newbie
*
Posts: 14


View Profile Email
« on: November 30, 2008, 04:12:59 pm »

I have modeled a mesh complete with smoke and fire coming out of it . I have exported the inn and the particle meshes (the fire and smoke) into a library using b2cs.

Now the issue is that while I am able to load the inn (a genmesh) into another map I can't seem to get the smoke and fire (particle meshes) to load, at any location in the map.

I have used minimal code to do this ofcourse:

Code:
          vfs->PushDir ();
    vfs->ChDir ("/Glob/globInn");
    if  (!loader->LoadLibraryFile ("library"))
    {
       csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
           "globulation.error",
           "Error loading inn!");
      return false;
   }
  vfs->PopDir ();

iMeshFactoryWrapper* iSmokeFact = engine->FindMeshFactory ("partsmoke");
smoke = engine->CreateMeshWrapper (iSmokeFact, "chimmneySmoke", room, csVector3 (3, 2, 3));

  smoke->SetZBufMode (CS_ZBUF_TEST);
smoke->SetRenderPriority (engine->GetObjectRenderPriority ());


This doesn't do the job as it does for genmesh. Evidently I am missing some particle system specific initialization. I can't figure out what. I have been digging into the documentation as well as code in the mazing tutorial as well as walktest app. I have also checked out this related previous post:
http://www.crystalspace3d.org/forum/index.php/topic,968.0.html

All the aforementioned sources (except walktest) talk about progrmatically creating the mesh factories and getting hold of the factory state to modify it. Clearly, I dont want to do that. I can't make out what to do to load from a library. As for the walktest source code, well, I just don't know where to start looking. As far as I can see the only files which mention particles are the walkdemo.cpp and walkcmd.cpp . Obviously,walktest does load the particle objects from my library but I am at a loss trying to find the code snippet that does this from amidst the massive tangle of code.

Is the problem that I am not adding an emitter to the particle system? But then, the mesh factory xml file seems to have the emitter detailed in it. How must I pass this emitter to the particle system?

If this isnt it, then what am I doing wrong?
CS Version 1.2.1
« Last Edit: December 11, 2008, 07:32:23 pm by Hannofcart » Logged
Hannofcart
Newbie
*
Posts: 14


View Profile Email
« Reply #1 on: December 11, 2008, 06:09:36 pm »

Sorry for the repeated posts, but after perusing the API for hours this is how far I have got (only relevant code added)

Code:
class MyApp{
 
...
 
csRef<iParticleSystem> pbase;
  iMeshFactoryWrapper* SmokeFact;
 
...
 
}
 
void MyApp::CreateFactories(){
...
 
       //SMOKE ATTEMPT
vfs->PushDir ();
  vfs->ChDir ("/Glob/globInn");
  if (!loader->LoadLibraryFile ("library"))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
        "myapp.error",
        "Error loading inn library!");
    return false;
  }
  vfs->PopDir ();
 
SmokeFact = engine->FindMeshFactory ("partsmoke.001");
smoke = engine->CreateMeshWrapper (SmokeFact, "chimmneySmoke", room, csVector3 (3, 2, 3));
pbase = scfQueryInterface<iParticleSystem> (SmokeFact->GetMeshObjectFactory ());
 
if (!smoke)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    "crystalspace.application.globGUI",
      "Can't get smoke going!");
 
return false;
  }
  smoke->SetZBufMode (CS_ZBUF_TEST);
smoke->SetRenderPriority (engine->GetObjectRenderPriority ());
smoke->GetMeshObject()->SetMixMode (CS_FX_ADD);
 
  ...
}
void MyApp::UpdateFrame(){
...
         pbase->Advance(vc->GetElapsedTicks ());
...
}

So far I get a runtime error saying segmentation fault. I have a feeling that the problem is that I am not loading the iParticleSystem plugin using the csInitializer::RequestPlugins function.
Logged
Hannofcart
Newbie
*
Posts: 14


View Profile Email
« Reply #2 on: December 11, 2008, 07:27:53 pm »

I got a fix to my problem thanks to Vincent ('knecht') and Andres Freund ('andres') on the IRC.

Basically, the code mentioned in the previous template is correct except for the following two changes.

1) The iParticleSystem must query the Mesh and not the factory.

    i.e:
Code:
pbase = scfQueryInterface<iParticleSystem> (SmokeFact->GetMeshObjectFactory ());

must be replaced with

   
Code:
pbase = scfQueryInterface<iParticleSystem> (smoke);

2) No need to call the Advance in the Update() function

   i.e: Remove this line
Code:
pbase->Advance(vc->GetElapsedTicks ());

Hope this saves someone some trouble.
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #3 on: December 11, 2008, 09:19:12 pm »

These are actually coding style notes but:
  • At least in the code you pasted the only remaining use of pbase is the assignment from the scfQueryInterface. You may want to remove that member altogether if not used otherwise at all.
  • If you only use SmokeFact in CreateFactories it's better to move it out of the class into that method, as a local variable,
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 5.276 seconds with 16 queries.