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
vins
Posts: 51
Joined: Mon Aug 16, 2004 6:14 pm
Location: Sofia, Bulgaria
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by vins »

greenya, Kudos for the great .NET wrapper. I tried it today and I just love it. There is no way to express how much I like the fast compile times of .NET and the cool Debuging features. For example I added a Cube and set it's textute but it rendered black. I just paused and used the "Quick Watch" tool to set the "Lightning" of the material to false...

Your wrapper is defenetly doing my time with Irrlich more fun.
Not sure why we need the Reference Counter in Irrlicht under .NET;
What if the classes are inherited from IDisposable and decrease the reference countre in Irrlicht and then release the code. I don't have much experience with Irrlicht/.NET but just a guess - it might be possible.

Thanks alot for your work!
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by lester »

Hey greenya!
I'm the former maintainer of Irrlcht .NET CP project and I'm very glad to see that .net wrapper is not abadnoded!
Keep up a good work and prove Irrlicht is the very best engine across the all platforms and languages!

Cheers,
lester.
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by WaxyChicken »

this is really limiting my advanced GFX functions....

i need a LIME (VB.NET) translation for...

services->setVertexShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);

the closest i can come is...

services.SetVertexShaderVariable( ? , ? )

thanks if you can.
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

vins wrote:Not sure why we need the Reference Counter in Irrlicht under .NET;
What if the classes are inherited from IDisposable and decrease the reference countre in Irrlicht and then release the code. I don't have much experience with Irrlicht/.NET but just a guess - it might be possible.
IrrlichtLime.ReferenceCounted is a wrapping class for irr::IReferenceCounted. I need it to build all the hierarchy like Irrlicht has. Because Lime is a wrapper and not an engine. Internally ReferenceCounted is a ordinary wrapped class and i don't use its DebugName and ReferenceCounter members, but i allow read-only access to them for better debugging. It is useful to check ReferenceCounter value while debugging and see what native c++ Irrlicht is doing after each call.

While developing Lime i needed something that would indicate for any Lime.NativeValue object how it was created. NativeValue object is anything like vector3df, color3df, matrix and so on; so this is a structure in c++ that holds values and need to be freed after all properly. That is why Lime.NativeValue has 2 members: m_NativeValue (a pointer to our native c++ "anything") and m_DeleteOnFinalize (very important member that answers on question "should we actually call "delete m_NativeValue;" when we are in finalizer (c++ .net "destructor")?"). We need to know the answer, because if we will free everything, than soon or later we will get double-free (memory coruption exception), if we will not free m_NativeValue, memory will never get free (c++ allocated structures will be lost in memory; and out of memory will crash our app).

How this works and what actually end user (.net programmer which uses Lime) can benefit?
Lets look next code:

Code: Select all

Material a = new Material();
// a.m_DeleteOnFinalize == true -- this means that m is a copy and we can do anything with it. its not a reference that will influence on something inside;
Material b = a;
// now we created new reference on a; this is very fast created link. b just became a mirror of a; of couse now "b.m_DeleteOnFinalize == true" and if we do "b.DiffuseColor = Color.OpaqueCyan;" a also get DiffuseColor changed.
Material c = new Material(a);
// now we created new copy of a; this is slower than "c = a;" but this is a distinct copy and any changes on c won't reflect to a.
Material d = driver.Material2D;
// a.m_DeleteOnFinalize == false -- this means that we get an internal reference; we still can use "d.DiffuseColor = Color.OpaqueCyan;" but this will do direct change in proper Irrlicht' struct.
One more example:

Code: Select all

// we write
driver.GetTransform(TransformationState.World).Scale = new Vector3Df(0.111f);
// and this doesn't work; i mean no crashes, simply world matrix did not changes; and you may ask: why "node.GetMaterial(0).xxxx = xxxx;" works fine but "driver.GetTransform().xxxx = xxxx;" not works?
// it's because node.GetMaterial() specially returns a reference (an object with m_DeleteOnFinalize == false; which means this is an internal link), but driver.GetTransform() returns a copy, and you need to assign it to variable, make changes and then do SetTransform().
// node.GetMaterial() returns a reference to allow easy using it like we do in c++ all over the code;
// since .net doesn't allows syntax like "x.x() = x", we has SetMaterial() (it is .net only member for setting new material)
// and it has next view:
public void SetMaterial(int num, Material newMaterialToCopyFrom); // "newMaterialToCopyFrom" intentionally was named this long to get to user that material will be copied.
 
Last example:

Code: Select all

n.Scale.X = 10.0f; // also won't work; you can predict it by checking while you debugging "node.Scale.m_deleteOnFinalize ? this-is-copy : this-is-link"
WaxyChicken wrote:this is really limiting my advanced GFX functions....

i need a LIME (VB.NET) translation for...

services->setVertexShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);

the closest i can come is...

services.SetVertexShaderVariable( ? , ? )

thanks if you can.
I believe in terms of Lime this will become:

Code: Select all

float[] f = new float[4] { 1, 2, 3, 4 }; // this array must contain 4 or 8 or 12 ,... elements; number of elements in this array divided on 4 defines 3rd argument in c++' setVertexShaderConstant() - the number of registers to set; we calc it automatically since in .NET we can get number of elements in array and also since we know that one register consists of 4 floats (that is why we have 2 arguments, instead of 3).
services.SetVertexShaderRegisters(8, f);
Instead of "f" you can use construction like:
1) (new Vector3Df(0.2f, 0.4f, 0.6f)).ToArray() -- this one returns 4 floats (4th will be "0"; just like original vector3d<T>::getAs4Values() does)
2) (new Colorf(0.2f, 0.4f, 0.6f, 1.0f)).ToArray()
3) or anything that returns array of 4 floats.

lester wrote:Hey greenya!
I'm the former maintainer of Irrlcht .NET CP project and I'm very glad to see that .net wrapper is not abadnoded!
Keep up a good work and prove Irrlicht is the very best engine across the all platforms and languages!
Thank you :)
vins
Posts: 51
Joined: Mon Aug 16, 2004 6:14 pm
Location: Sofia, Bulgaria
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by vins »

Thank you for the detailed explanation.
kaostg
Posts: 3
Joined: Wed Dec 07, 2011 2:45 pm

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by kaostg »

Hi, I'm still with VS2008, so I suppose I can't use the latest version (0.9.1) and lookking at changes.txt I suppose I've to use version 0.8. Where I can found it? It's just for starting, because I already planned to jumo to VS2010, but the next year....

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

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

Yes. To use latest version you need VS2010.
Here you can download any release: http://sourceforge.net/projects/irrlich ... ht%20Lime/
kaostg
Posts: 3
Joined: Wed Dec 07, 2011 2:45 pm

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by kaostg »

Thanks a lot. I'll try with the vrsion 0.8
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

Version 1.0 has been released

New example:
L09.SimpleLOD // shows one way how LODing can be used;

Shot:
Image

Notes

~
SceneNode now has OnAnimate protected event. It is possible to handle it for own animation. It takes the time as an argument. ISceneNode::OnAnimate() is executed before your method: this makes work all assigned animators; you cannot control this (you do not explicity call it, its called internally).

~
GUIElement now can be inherited. You can handle OnDraw and OnEvent protected events using Environment prop. to create own simple GUI controls. When you handle OnEvent, you don't need to care about children, if your OnEvent returns false, base OnEvent (from IGUIElement) will be executed automatically.

Updated Irrlicht SDK to trunk rev. 4021.
See changes.txt for full list of changes.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

Besides Lime allows us to use irrlicht with IronPython (.NET python) out of the box:

Code: Select all

import clr
clr.AddReference('IronPython')
clr.AddReference('IrrlichtLime')
 
import IrrlichtLime
from IrrlichtLime import *
from IrrlichtLime.Core import *
from IrrlichtLime.Video import *
from IrrlichtLime.Scene import *
from IrrlichtLime.GUI import *
 
def main():
    device = IrrlichtDevice.CreateDevice(DriverType.Software, Dimension2Di(640, 480), 16, False, False, False)
    device.SetWindowCaption("Hello World! - Irrlicht Engine Demo")
 
    driver = device.VideoDriver
    smgr = device.SceneManager
    gui = device.GUIEnvironment
 
    gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", Recti(10, 10, 260, 22), True)
 
    mesh = smgr.GetMesh("data/sydney.md2")
    node = smgr.AddAnimatedMeshSceneNode(mesh)
 
    if node != None:
        node.SetMaterialFlag(MaterialFlag.Lighting, False)
        node.SetMD2Animation(AnimationTypeMD2.Stand)
        node.SetMaterialTexture(0, driver.GetTexture("data/sydney.bmp"))
 
    smgr.AddCameraSceneNode(None, Vector3Df(0, 30, -40), Vector3Df(0, 5, 0))
 
    while device.Run():
        driver.BeginScene(True, True, Color(100, 101, 140))
        smgr.DrawAll()
        gui.DrawAll()
        driver.EndScene()
 
    device.Drop()
 
if __name__ == '__main__':
    main()
 
Also for the curious - with a little bit of effort ironpython scripts can be compiled to .NET executables that decompiled look far worse than decompiled c#. Also performance-wise ironpython is on about same level as cpython. And as you have probably guessed - ironPython can use any .NET library without additional wrapping. Now just imagination is the limit ^_^

EDIT:
Not to mention sweet autocompletion:
Image
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

hmm im kind of struggling with SceneNode.OnAnimate. I wonder if you would have any interest in helping to solve this maybe. Basically class that inherits SceneNode still can not access OnAnimate. According to ironpython docs it should be able to access that, however AttributeError exception is raised, that means no OnAnimate is found. Or maybe you have some other ideas how to workaround this? I tried overloading Animate() with little success. For some reason it did not get called.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

You cannot find OnAnimate as protected method, because it is protected event.
OnAnimate can be used next way:

Code: Select all

                class MySceneNode : SceneNode
                {
                        MeshSceneNode[] meshNodes;
 
                        public MySceneNode(SceneNode parent)
                                : base(parent, parent.SceneManager)
                        {
                                meshNodes = new MeshSceneNode[8];
                                for (int i = 0; i < 8; i++)
                                {
                                        Mesh m = SceneManager.GeometryCreator.CreateSphereMesh(20 + 10 * i);
                                        SceneManager.MeshManipulator.SetVertexColors(m, new Color(40, 50 + i * 20, 140));
                                        meshNodes[i] = SceneManager.AddMeshSceneNode(m, this, -1, new Vector3Df((20 + i * 10) * 2, 0, 0));
                                        meshNodes[i].SetMaterialFlag(MaterialFlag.Lighting, false);
                                        m.Drop();
                                }
 
                                OnAnimate += new AnimateEventHandler(MySceneNode_OnAnimate);
                        }
 
                        void MySceneNode_OnAnimate(uint time)
                        {
                                // here we are changing Rotation property, which supposed not be used by class user,
                                // BUT if we need the Rotation to be freely use, we can avoid it many ways,
                                // for example simply add some proxy node between "this" and "meshNodes" and use its Rotation :)
 
                                Rotation = new Vector3Df(0, 0, time / 100.0f);
                        }
                }
Then our custom scene node can be used next way:

Code: Select all

MySceneNode n = new MySceneNode(smgr.RootNode);
n.Drop();
Image
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

oh thats right, a property... things look much clearer in the morning :] looks like in order to access properties from ironpython they must be public. to satisfy my needs i exposed them to the world. i wonder what you think about making them public in order to satisfy one more programming language for irrlicht ^_^
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

OnAnimate cannot be public, because it is designed specially for overloading when you derive from SceneNode.
The reason why i pick way of "event" not way of "method overriding" is because overrided method cannot be detected by base class (the fact is it overrided or not).
Lime' SceneNode also has Animate() method, which can be called directly. In native Irrlicht there is no difference between these two pieces (they both are the same single ISceneNode::OnAnimate()).
Post Reply