Le Samedi 18 Février 2006 17:31, Jorrit Tyberghein a écrit :
> The easiest way is to use engine->CreateMeshWrapper(). This is
> actually documented in the manual. Check the using cs/engine/meshobj
> section where it is explained how you can in general create a mesh
> from a factory.
>
> Greetings,
I finally found my mistake: the 'particles' mesh object itself doesn't
provide the iParticleState interface, but rather iParticlesObjectState.
Here's the code I used to load the factory, set the particles_simple.xml
shader (only way to get a material instead some dots and get rid of some
visibility problem, it seems), then get the state interface:
// get the material and assign it the particle_basic shader as standard type
loader->LoadTexture ("nuage2", "/xd/textures/nuage2.png");
csRef<iMaterialWrapper> particlemat =
engine->GetMaterialList ()->FindByName ("nuage2");
if (!particlemat)
return ReportError ("Unable to load nuage2 material!");
if (!loader->LoadShader ("/shader/particle_basic.xml"))
return ReportError ("Unable to load /shader/particle_basic.xml!");
csRef<iStringSet> strings = CS_QUERY_REGISTRY_TAG_INTERFACE (
object_reg, "crystalspace.shared.stringset", iStringSet);
csRef<iShaderManager> shader_mgr = CS_QUERY_REGISTRY (object_reg,
iShaderManager);
if (!shader_mgr)
return ReportError ("Unable to get shader manager!");
iShader* particle_shader = shader_mgr->GetShader ("particle_basic");
if (!particle_shader)
return ReportError ("Unable to get particle_basic shader!");
particlemat->GetMaterial ()->SetShader (strings->Request ("standard"),
particle_shader);
// load the factory for particles from file
csRef<iMeshFactoryWrapper> factoryw = loader->LoadMeshObjectFactory (
"/xd/models/thrusterparticles");
if (!factoryw)
return ReportError ("Unable to load thrusterparticles!");
// Initialize the particles mesh object(s) used for thruster(s).
emitters.Empty ();
size_t i = 0;
csString pattern;
keybase = cfgkey + "ThrusterUnit.";
while (config->SubsectionExists (pattern.Format (keybase + "%d.", i)))
{
ThrustersInfos* infos = new ThrustersInfos (); // the csObject
csRef<iMeshObjectFactory> objectfactory =
factoryw->GetMeshObjectFactory ();
csRef<iParticlesFactoryState> factorystate =
scfQueryInterface<iParticlesFactoryState> (objectfactory);
if (!factorystate)
return ReportError ("Unable to get factory state!");
factorystate->SetMixMode (CS_FX_ADD);
infos->position = GetConfigVector (config, pattern + "PositionStart",
"0,0,2");
csString meshname;
infos->meshw = engine->CreateMeshWrapper (factoryw,
meshname.Format ("ThrusterEmitter%d", i),
pccamera->GetCamera ()->GetSector (),
infos->position);
if (!infos->meshw)
return ReportError ("Unable to create particle meshwrapper!");
infos->meshw->SetZBufMode (CS_ZBUF_TEST);
infos->meshw->SetRenderPriority (engine->GetRenderPriority ("alpha"));
infos->meshw->GetMeshObject ()->SetMaterialWrapper (particlemat);
// Set a name for the csObject so it's easier to find it later
infos->SetName (meshname.GetData ());
infos->state = SCF_QUERY_INTERFACE (infos->meshw->GetMeshObject (),
iParticlesObjectState);
[...]
Et voila.
Thank you
> On 2/18/06, Vincent Knecht <[EMAIL PROTECTED]> wrote:
> > Hi !
> >
> > I'm trying to create particle systems from code, using a factory from a
> > file... I've tried many combinations, but I'm lost.
> > How to do that ?
> >
> > The following code fails on getting iParticleState:
> >
> > csRef<iMeshFactoryWrapper> factoryw = loader->LoadMeshObjectFactory (
> > "/xd/models/thrusterparticles");
> > if (!factoryw)
> > return ReportError ("Unable to load thrusterparticles!");
> >
> > // Initialize the emitter mesh object(s) used for thruster(s).
> > emitters.Empty ();
> > size_t i = 0;
> > csString pattern;
> > keybase = cfgkey + "ThrusterUnit.";
> > while (config->SubsectionExists (pattern.Format (keybase + "%d.", i)))
> > {
> > ThrustersInfos* infos = new ThrustersInfos (); // a csObject
> > /* that doesn't work neither
> > csString meshname;
> > infos->meshw = engine->CreateMeshWrapper (factoryw,
> > meshname.Format ("ThrusterEmitter%d", i),
> > pccamera->GetCamera ()->GetSector (),
> > csVector3 (0.0f, 0.0f, 0.0f));
> > */
> > infos->meshw = factoryw->CreateMeshWrapper ();
> > if (!infos->meshw)
> > return ReportError ("Unable to create particle meshwrapper!");
> > ///engine->AddMeshAndChildren (infos->meshw);
> > //infos->SetName (meshname.GetData ());
> > // is messing with iMeshObject really needed ?
> > csRef<iMeshObject> meshobject =
> > factoryw->GetMeshObjectFactory ()->NewInstance ();
> > infos->meshw->SetMeshObject (meshobject);
> > engine->AddMeshAndChildren (infos->meshw);
> >
> > infos->state = SCF_QUERY_INTERFACE (infos->meshw->GetMeshObject (),
> > iParticleState);
> > if (!infos->state)
> > return ReportError ("Unable to get iParticleState!");
> > [...]
> >
> > just in case:
> > ===== /xd/models/thrusterparticles ===================
> > <!-- <library> -->
> > <meshfact name="thrusterFACT">
> > <plugin>crystalspace.mesh.loader.factory.particles</plugin>
> > <params>
> > <emitter type="sphere">
> > <time>300</time>
> > <innerradius>0.01</innerradius>
> > <outerradius>0.03</outerradius>
> > <force type="linear">
> > <direction x="0.5" y="1" z="0"/>
> > <amount>10</amount>
> > <range>3.0</range>
> > <falloff>linear</falloff>
> > </force>
> > </emitter>
> > <dampener>0.1</dampener>
> > <mass>5</mass>
> > <massvariation>2.5</massvariation>
> > <pps>50</pps>
> > <initial>0</initial>
> > <gravity x="0" y="-1" z="0"/>
> > <diffusion>0.1</diffusion>
> > <radius>0.1</radius>
> > <ttl>5</ttl>
> > <zsort>yes</zsort>
> > <timevariation>0.5</timevariation>
> > <colormethod type="linear">
> > <gradient>
> > <color red="0" green="0" blue="1"/>
> > <color red="0" green="0.5" blue="1"/>
> > <color red="1" green="1" blue="1"/>
> > </gradient>
> > </colormethod>
> > </params>
> > </meshfact>
> > <!-- </library> -->
> > ==================================
> >
> > TIA
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]