Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Zurzaza,
there are 2 examples: L02.WinFormsWindow and L04.ParticleEmitterViewer which use handle of a panel for rendering, you can check how its done there.

In general, when you specify params->WindowID a real handle (not 0), then Irrlicht will use that handle for rendering, if its 0 (better use IntPtr.Zero) than Irrlicht will create new window for rendering.

Please check L02.WinFormsWindow example, or its main source file here:
http://irrlichtlime.svn.sourceforge.net ... iew=markup

P.S.: if you still have problems, then post your source (as short as possible) that reproduces the problem and i will check it.
Zurzaza
Posts: 153
Joined: Fri Mar 26, 2010 9:41 pm
Location: Filo (FE), Italy
Contact:

Post by Zurzaza »

Yes, i followed the 2nd tutorial (I Simply converted from c# to c++).
This is my code snippet:

Code: Select all

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 IrrlichtLime::Core::Dimension2Di di(100,100);
			IrrlichtLime::IrrlichtCreationParameters ^pa = gcnew IrrlichtCreationParameters();
			
			pa->WindowID = this->panel1->Handle;
			pa->DriverType = IrrlichtLime::Video::DriverType::OpenGL;
			backgroundRendering->RunWorkerAsync(pa);
			 }
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				 InitializeComponent();
			 }
	
private: System::Void backgroundRendering_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
			 
			 BackgroundWorker ^ worker = reinterpret_cast<BackgroundWorker^>(sender);
			 IrrlichtLime::IrrlichtCreationParameters ^ pa = reinterpret_cast<IrrlichtCreationParameters^>(e->Argument);
			// IrrlichtLime::IrrlichtCreationParameters ^ pa = (IrrlichtCreationParameters^)e;

			//pa.WindowSize = di;a

			IrrlichtDevice  ^dev = IrrlichtDevice::CreateDevice(pa);
			IrrlichtLime::Video::VideoDriver ^ drv = dev->VideoDriver;
			IrrlichtLime::Scene::SceneManager ^ smgr = dev->SceneManager;
			smgr->AddCameraSceneNode();
			smgr->AddAnimatedMeshSceneNode(smgr->GetMesh("sydney.md2"));
			dev->GUIEnvironment->AddStaticText("Ti tiro una ceppa",gcnew Core::Recti(10,10,100,30));
			IrrlichtLime::Scene::CameraSceneNode ^ cam = smgr->AddCameraSceneNode();
			
			cam->Target = gcnew IrrlichtLime::Core::Vector3Df(0);

			IrrlichtLime::Scene::SceneNodeAnimator ^ anim = smgr->CreateFlyCircleAnimator(gcnew IrrlichtLime::Core::Vector3Df(0, 15, 0), 30.0f);
			cam->AddAnimator(anim);
			anim->Drop();

			SceneNode ^ cube = smgr->AddCubeSceneNode(20);
			cube->SetMaterialTexture(0, drv->GetTexture("../media/wall.bmp"));
			cube->SetMaterialTexture(1, drv->GetTexture("../media/water.jpg"));
			cube->SetMaterialFlag(IrrlichtLime::Video::MaterialFlag::Lighting, false);
			cube->SetMaterialType(IrrlichtLime::Video::MaterialType::Reflection2Layer);
			int lastFPS = -1;
			while(dev->Run())
			{
				dev->VideoDriver->BeginScene(true,true,gcnew IrrlichtLime::Video::Color(0,0,0));
				smgr->DrawAll();
				dev->GUIEnvironment->DrawAll();
				dev->VideoDriver->EndScene();
				int fps = drv->FPS;
				if (lastFPS != fps)
				{
					
					worker->ReportProgress(fps, drv->Name);
					lastFPS = fps;
				}
			}
			dev->Drop();
		 }
		 private: void backgroundRendering_ProgressChanged(System::Object^  sender, System::ComponentModel::ProgressChangedEventArgs^  e)
		{
			// process reported progress

			int f = e->ProgressPercentage;
				System::String ^d = (System::String^)e->UserState;

			labelRenderingStatus->Text = System::String::Format("Rendering {1} fps using {0} driver",d, f);
		}
irrBP - an Irrlicht - Bullet Physics Wrapper.
The only irrlicht-physics wrapper that uses multithread technology.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I didn't found nothing special in your code, and don't really know why you get different result than me.
I am using VS2008, next code:

Code: Select all

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				IrrlichtCreationParameters ^pa = gcnew IrrlichtCreationParameters();

				pa->WindowID = this->panel1->Handle;
				pa->DriverType = DriverType::OpenGL;
				backgroundWorker1->RunWorkerAsync(pa);
			 }

	private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
				BackgroundWorker ^ worker = reinterpret_cast<BackgroundWorker^>(sender);
				IrrlichtCreationParameters ^ pa = reinterpret_cast<IrrlichtCreationParameters^>(e->Argument);

				IrrlichtDevice ^dev = IrrlichtDevice::CreateDevice(pa);

				dev->GUIEnvironment->AddStaticText("Ti tiro una ceppa", gcnew Recti(10,10,100,30));

				CameraSceneNode ^cam = dev->SceneManager->AddCameraSceneNode();
				cam->Target = gcnew Vector3Df(0);

				SceneNodeAnimator ^anim = dev->SceneManager->CreateFlyCircleAnimator(gcnew Vector3Df(0, 15, 0), 30.0f);
				cam->AddAnimator(anim);
				anim->Drop();

				SceneNode ^cube = dev->SceneManager->AddCubeSceneNode(20);
				cube->SetMaterialFlag(MaterialFlag::Lighting, false);

				while(dev->Run())
				{
					dev->VideoDriver->BeginScene(true, true, gcnew Video::Color(0,100,200));
					dev->SceneManager->DrawAll();
					dev->GUIEnvironment->DrawAll();
					dev->VideoDriver->EndScene();
				}
				dev->Drop(); 
			 }
produces next result (after i click on button1):
Image

P.S.: maybe something out of this code, so if you want, you can PM me a link to zip with all the project, so i will open it in IDE and check.
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

Code: Select all

            topMesh = scene.GetMesh("face_top.ms3d");
            bottomMesh = scene.GetMesh("face_bottom.ms3d");
            northMesh = scene.GetMesh("face_north.ms3d");
            eastMesh = scene.GetMesh("face_east.ms3d");
            southMesh = scene.GetMesh("face_south.ms3d");
            westMesh = scene.GetMesh("face_west.ms3d");
------->
Could not load mesh, because file could not be opened: : f
Could not load mesh, because file could not be opened: : f
Could not load mesh, because file could not be opened: : f
Could not load mesh, because file could not be opened: : f
Could not load mesh, because file could not be opened: : f
Could not load mesh, because file could not be opened: : f
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

pixartist,

looks like your MS3D files located in wrong folder. If you do not specify the path (and didn't added any virtual file systems, like path to media folder or ZIP archive), then your MS3D files must be located in the same directory with your applications EXE, Irrlicht.dll and IrrlichtLime.dll.
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

they are...

Image
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Please test loading one of your models from IrrlichtLime's example OR send me a PM with zip with one of your ms3d files (i will test it myself).
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I've got your archive.

Looks like you are using IrrlichtLime.dll with the lates released version - 0.8. BUT Irrlicht.dll is something that you took from other place. The problem is in this wrong dlls. Your Irrlicht.dll is 1.7.2, with file size = 2,670,592 bytes (looks like this is release build).

Lime with 0.8 uses Irrlicht 1.8.0-alpha. You can take release or debug dlls from (\irrlicht\dll\ of Lime SDK archive) its sizes 2,221,568 and 5,119,488 bytes respectively. If you use Lime, you must use only Irrlicht' DLLs provided with it OR you must rebuild all the Lime with new Irrlicht sources manually -- this is the only correct way.
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

oh, okay thanks !

any idea about the mesh combining question ?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

This is just a wrapper around some (alot i believe so :) ) functionality of native Irrlicht. Its almost has nothing more than just an ability to be used in managed language (like c# and vb.net). Lime doen't have batching either as native Irrlicht. You can find some working solutions here (in Project Announcements and Code Snippets), but this is all for C++ native engine. In Lime you need to implement something yourself.

I think, most real to implement is do drawing (of main big batch(s)) manually between BeginScene() and EndScene() using VideoDriver' DrawVertexPrimitiveList(). This way is most fast. Anyway, using SceneManager for really alot number of nodes is wrong way (either for implementaion in native Irrlicht).
Last edited by greenya on Fri Apr 15, 2011 12:16 pm, edited 2 times in total.
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

greenya wrote:This is just a wrapper around some (alot i believe so :) ) functionality of native Irrlicht. Its almost has nothing more than just an ability to be used in managed language (like c# and vb.net). Lime doen't have batching either as native Irrlicht. You can find some working solutions here (in Project Announcements and Code Snippets), but this is all for C++ native engine. In Lime you need to implement something yourself.

I think, most real to implement is do drawing (of main big batch(s)) manually between BeginScene() and EndScene() using VideoDriver' DrawVertexPromitiveList(). This way is most fast. Anyway, using SceneManager for really alot number of nodes is wrong way (either for implementaion in native Irrlicht).
thanks, that helped a LOT :D
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

Hmm, why doesn't my program render vertex colors ?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

03.CustomSceneNode uses vertex colors for rendering.
Or post small piece of code where you set up you material, setup vertex colors and do actually rendering.
pixartist
Posts: 25
Joined: Thu Apr 14, 2011 4:58 pm

Post by pixartist »

Creating vertices:

Code: Select all

         private void addTopFace(int x, int y, int z)
        {
            uint i = (uint)vertexIndices.Count;
            float gx = (x + chunkX * World.chunkSize) * Render.blockSize;
            float gy = y * Render.blockSize;
            float gz = (z + chunkZ * World.chunkSize) * Render.blockSize;
            float hb = Render.blockSize / 2;
            vertices.Add(new Vertex3D(
                gx - hb,
                gy + hb,
                gz - hb));
            vertices[vertices.Count - 1].Color = new Color(0, 255, 0);
            vertexIndices.Add(i);

            vertices.Add(new Vertex3D(
                 gx - hb,
                 gy + hb,
                 gz + hb));
            vertices[vertices.Count - 1].Color = new Color(0, 255, 0);
            vertexIndices.Add(i + 1);

            vertices.Add(new Vertex3D(
                gx + hb,
                gy + hb,
                gz + hb));
            vertices[vertices.Count - 1].Color = new Color(0, 255, 0);
            vertexIndices.Add(i + 2);

            vertices.Add(new Vertex3D(
                gx + hb,
                gy + hb,
                gz - hb));
            vertices[vertices.Count - 1].Color = new Color(0, 255, 0);
            vertexIndices.Add(i + 3);
        }
Rendering:

Code: Select all

while (device.Run())
            {
                //device.SetWindowCaption(driver.FPS.ToString() + " FPS");
                driver.BeginScene(true, true, new Color(100, 100, 255, 140));
                //
                //driver.DrawVertexPrimitiveList();
                for (int i = 0; i < World.worldSize / World.chunkSize; i++)
                {
                    for (int j = 0; j < World.worldSize / World.chunkSize; j++)
                    {
                        World.worldChunks[i][j].doRedraw();
                        
                        if(World.worldChunks[i][j].getVertexIndices().Count > 0)
                            driver.DrawVertexPrimitiveList(World.worldChunks[i][j].getVertexList(), World.worldChunks[i][j].getVertexIndices(), PrimitiveType.Quads);
                    }
                }
                scene.DrawAll();
                gui.DrawAll();
                driver.EndScene();
            }
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

First) of all never do drawing before scene->drawAll(), unless you really need it. Do all your manual drawing before EndScene().

Second) I'm going to show 2 ways how to see vertex colors in action. Remember, vertex has color, but has no material (which defines how to use it), vertex has position, but has no transformation matrix, which inform VideoDriver where to move to draw your vertices, because they are part of the mesh, and only then - mesh part of the scene. So:

next code will draw the cube with different vertex colors (this code supposed to be entered before your device->Run loop):

Code: Select all

			// ----------------------------------------------------------
			// USING SCENE NODE
			// ----------------------------------------------------------
			MeshSceneNode X = scene.AddCubeSceneNode(100);
			X.Position = new Vector3Df(-400, 0, -400);
			X.GetMaterial(0).Lighting = false;
			Vertex3D[] V = (Vertex3D[])X.Mesh.GetMeshBuffer(0).Vertices;
			for (int k = 0; k < V.Length; k++) V[k].Color = new Color(140 + k * 10, k * 20, k * 5);
			X.Mesh.GetMeshBuffer(0).UpdateVertices(V, 0);
			// ----------------------------------------------------------
This cube is only draws because of scene->drawAll() call. SceneNode is such high level thing, which takes care about transformation matrix for us and the material (actualy material is a part of the meshbuffer, which we are accessing in the code above).

next code will draw a single triangle with different vertex colors (this code consist of two parts: initalization (before device->Run loop) and actually drawing (before driver->EndScene)):

Code: Select all

			// ----------------------------------------------------------
			// USING OWN VERTICES
			// ----------------------------------------------------------
			List<Vertex3D> VERTICES = new List<Vertex3D>();
			VERTICES.Add(new Vertex3D(-500, 0, -400, 0, 0, 0, new Color(100, 200, 120))); // using 3 different
			VERTICES.Add(new Vertex3D(-700, 0, -400, 0, 0, 0, new Color(60, 240, 120))); // colors, because
			VERTICES.Add(new Vertex3D(-600, 200, -400, 0, 0, 0, new Color(160, 140, 220))); // we want
			List<uint> INDICES = new List<uint>();
			INDICES.AddRange(new uint[] { 0, 2, 1 });
			// ----------------------------------------------------------
and drawing:

Code: Select all

				driver.SetTransform(TransformationState.World, Matrix.Identity);
				Material m = new Material();
				m.Lighting = false;
				driver.SetMaterial(m);
				driver.DrawVertexPrimitiveList(VERTICES, INDICES);
take careful look at the code just before DrawVertexPrimitiveList call. What it does? Right! We just sew a legs to our vertices, so they can run just like SceneNode do. We said to video driver that it must use material without lighting, and he must move "drawing pensil" to the origin. If you do not do SetTransform() - you will have some transformation from what scene->DrawAll() has left (you cannot predict). The same with the material.

Add FPS camera fly around and check.
This code produces:
Image
Post Reply