[fixed]Particle De/Serialization; Min/MaxStartSize ignored

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

[fixed]Particle De/Serialization; Min/MaxStartSize ignored

Post by Ion Dune »

I noticed in the source code that both Box and Point emitters do not serialize either MinStartSize or MaxStartSize, which makes it impossible to set the size of emitted particles via an irr scene file. The bug is fairly easy to see in the code, just look at the "serialize" and "deserialize" functions at the bottom of Point Emitter and Box Emitter.

The fix should be fairly simple, the following code needs to be somewhere in the serialization functions:

Code: Select all

out->addFloat("MinStartSizeWidth", MinStartSize.Width);
out->addFloat("MinStartSizeHeight", MinStartSize.Height);
out->addFloat("MaxStartSizeWidth", MaxStartSize.Width);
out->addFloat("MaxStartSizeHeight", MaxStartSize.Height);
and the following code in the deserialization functions:

Code: Select all

MinStartSize.Width = in->getAttributeAsFloat("MinStartSizeWidth");
MinStartSize.Height = in->getAttributeAsFloat("MinStartSizeHeight");
MaxStartSize.Width = in->getAttributeAsFloat("MaxStartSizeWidth");
MaxStartSize.Height = in->getAttributeAsFloat("MaxStartSizeHeight");
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

At least those had some serialization - half of the other emitters and affectors didn't do anything. Thanks for reporting - I have fixed it in the 1.7 branch in svn.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

well it is not working.

after looking at sourcecode i thought it should work, but it simply doesnt show up anything.

here is a testcase:

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include "driverChoice.h"

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

#define READING
int main()
{
	video::E_DRIVER_TYPE driverType=driverChoiceConsole();
	if (driverType==video::EDT_COUNT)
		return 1;

	IrrlichtDevice *device =
		createDevice(driverType, core::dimension2d<u32>(640, 480),
		16, false, false);

	if (device == 0)
		return 1; // could not create selected driver.

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/room.3ds");

	smgr->getMeshManipulator()->makePlanarTextureMapping(mesh->getMesh(0), 0.004f);

	scene::ISceneNode* node = 0;

	node = smgr->addAnimatedMeshSceneNode(mesh);
	node->setMaterialTexture(0, driver->getTexture("../../media/wall.jpg"));
	node->getMaterial(0).SpecularColor.set(0,0,0,0);

	// create light

	node = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
		video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 800.0f);
	scene::ISceneNodeAnimator* anim = 0;
	anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),250.0f);
	node->addAnimator(anim);
	anim->drop();

	// create a particle system

	scene::IParticleSystemSceneNode* ps =
		smgr->addParticleSystemSceneNode(false);

#ifndef READING
	scene::IParticleEmitter* em = ps->createCylinderEmitter(
		core::vector3df(0,0,0), 20, core::vector3df(0,1,0), 10, false,
		core::vector3df(0.0f,0.06f,0.0f),   // initial direction
		80,100,                             // emit rate
		video::SColor(0,255,255,255),       // darkest color
		video::SColor(0,255,255,255),       // brightest color
		800,2000,0,                         // min and max age, angle
		core::dimension2df(10.f,10.f),         // min size
		core::dimension2df(20.f,20.f));        // max size

	ps->setEmitter(em); // this grabs the emitter
	em->drop(); // so we can drop it here without deleting it

	scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();

	ps->addAffector(paf); // same goes for the affector
	paf->drop();
#endif

	ps->setPosition(core::vector3df(-70,60,40));
	ps->setScale(core::vector3df(2,2,2));
	ps->setMaterialFlag(video::EMF_LIGHTING, false);
	ps->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
	ps->setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
	ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);

	io::IAttributes* attr = device->getFileSystem()->createEmptyAttributes(device->getVideoDriver());

#ifdef READING
	io::IXMLReader* reader = device->getFileSystem()->createXMLReader("derp.xml");
	attr->read(reader);
	ps->deserializeAttributes(attr);
	reader->drop();
#else
	io::IXMLWriter* writer = device->getFileSystem()->createXMLWriter("derp.xml");
	ps->serializeAttributes(attr);
	attr->write(writer, true);
	writer->drop();
#endif
	attr->drop();

	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	camera->setPosition(core::vector3df(-50,50,-150));

	// disable mouse cursor
	device->getCursorControl()->setVisible(false);

	s32 lastFPS = -1;

	while(device->run())
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, 0);

		smgr->drawAll();

		driver->endScene();

		const s32 fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw str = L"Irrlicht Engine - SpecialFX example [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}

	device->drop();

	return 0;
}
first run it with commenting the #define READING to save the effect.
then run it with uncommenting it, and ull see nothing.
It actually loads the particlesystemscenenode, but not the emitters? maybe

PS: used the latest SVN branch
PPS: as far as i tested, it only works with box emitter
PPPS: it would be nice if we could get those private members to let us serialize by ourself ^^ (or to make nice particle editors ;) )
Image
Image
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Thanks for the test-case. This is a new problem - seems the particlesystemscenenode doesn't yet create all emitter types.

But I must look at this when I'm more awake then now. It seems to use some small hand-coded factory to create emitters and affectors in the serialization, but I must take a longer look if this really works that way when more than one affector is used.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

hey
yeah, yesterday my net went off, so i couldnt post.
So after digging more the code, found it just ignores emitters except the box and point.
tried to give them default values, and it seems like to work.
putting this in works for me:

Code: Select all

	switch(type)
	{
	case EPET_POINT:
		Emitter = createPointEmitter();
		break;
	case EPET_BOX:
		Emitter = createBoxEmitter();
		break;
	case EPET_CYLINDER:
		Emitter = createCylinderEmitter(core::vector3df(0,0,0),1, core::vector3df(0,1,0), 1);
		break;
	case EPET_ANIMATED_MESH:
		Emitter = createAnimatedMeshSceneNodeEmitter(0);
		break;
	case EPET_MESH:
		Emitter = createMeshEmitter(0);
		break;
	case EPET_RING:
		Emitter = createRingEmitter(core::vector3df(0,0,0), 1, 1);
		break;
	case EPET_SPHERE:
		Emitter = createSphereEmitter(core::vector3df(0,0,0), 1);
		break;
	default:
		break;
	}
except the animatedmesh animator, and maybe the mesh animator too (this one isnt confirmed)
they arent handle if the mesh pointer is null. that needs a fix (fortunately i dont use them in my project XD)

other ones works great for me. as i see, the affectors not importing either (only the gravity, the fade out, and the attractor)
Image
Image
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ok, I did fix it now that way for the 1.7 branch. Not perfect but will fix the obvious problem.

Can't do much about mesh and animatedmesh for now - I don't know yet how to handle those with the current attribute-system.

And well - also can't handle serialization of user-emitters and affectors that way. As in other places in the engine this would need real factories. But I'm still not sure if it's a good way to add another factory for each type (we need the same for fonts, skins for example) or if there is another way (for example one factory for all serializable types).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

thanks for quick fix~
Image
Image
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

no cloning method for particlesystemscenenode?
Image
Image
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

B@z wrote:no cloning method for particlesystemscenenode?
Hm, yes, seems so. Thanks for noticing. Btw. don't be afraid of opening a new thread for a new problem, it makes it easier to see which stuff got fixed and which is still open.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

oh ok, got it :D
thanks~
Image
Image
Post Reply