Want to pass 3D objects and textures from java to irrlicht

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
balrajbalraj007
Posts: 16
Joined: Sun Mar 27, 2011 3:53 pm

Want to pass 3D objects and textures from java to irrlicht

Post by balrajbalraj007 »

Hi,

I am facing a problem in passing multiple texture file name string array from java to irrlicht code.

Can anybody tell me how to pass string array from java code to irrlicht and use that string array to bind as multiple texture files.

I am able to send one string as we are already sending sdcard path but I don't know how to pass string array and then use it as path for adding multiple textures.

Please reply as soon as possible.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

How exactly are you sending that one string to irrlicht right now?
I assume you need some kind of IPC, because natively managed languages like Java and non-managed languages like C++ don't really like eachother that much

Also, maybe it'd help if you explain the context a bit more, what is the Java code needed for? Some kind of editor?
balrajbalraj007
Posts: 16
Joined: Sun Mar 27, 2011 3:53 pm

Post by balrajbalraj007 »

I am able to pass one string as shown below:

In java code i am passing the string through nativeEnvJ2C method which i have altered for this purpose:-

Code: Select all

nativeEnvJ2C(sdcardPath, "FighterJet.obj", ".MTL", "FighterJet");
and in C++ code i have changed the nativeEnvJ2C method as follows:-

Code: Select all

void Java_com_ellismarkov_irrlicht_IrrlichtTest_nativeEnvJ2C(JNIEnv*  env, jobject defaultObj, jstring jsdcardPath, jstring object3D, jstring textureTy, jstring textureNa)
{
    char ligne[1024+1];
    const char *msg = env->GetStringUTFChars(jsdcardPath,0);
    gSdCardPath = msg;

    const char *objectP = env->GetStringUTFChars(object3D,0);
       objectPath = objectP;

       const char *textuteT = env->GetStringUTFChars(textureTy,0);
       textureType = textuteT;

          const char *textuteNam = env->GetStringUTFChars(textureNa,0);
                    textureName = textuteNam;

    __android_log_print(ANDROID_LOG_INFO, "This the Path *** gently caress You Irrlicht", "not handled %s", gSdCardPath.c_str());
    env->ReleaseStringUTFChars(jsdcardPath,msg);
    env->ReleaseStringUTFChars(object3D,objectP);
    env->ReleaseStringUTFChars(textureTy,textuteT);
    env->ReleaseStringUTFChars(textureNa,textuteNam);
}
My purpose is as follows:-

I have a web service from which i will get a list of 3d objects whose name i will be displaying in a list, on clicking one 3D object from that list, 3Dobject will be downloaded with its texture which i am saving on sdcard and then have to display it. The problem is that 3D objects are of different format and same with the texture file hence i have to make the irrlicht code dynamic so that i may pass the path of the 3D objects and multiple texture files to display the 3D object.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

To be honest, I fail to see why you are going through the hassle of mixing Java and C++ to get this done, I've never written applications for android, so I could be missing something here, but why aren't you just using a networking infrastructure to send packets from your web service to your application directly? These can contain data of any size, and can be interpreted easily by any language without the need of trying to let non-managed code work with data coming from managed code

As I said, I could be missing something here, but this approach seems too complex for what you are trying to achieve
balrajbalraj007
Posts: 16
Joined: Sun Mar 27, 2011 3:53 pm

Post by balrajbalraj007 »

Thanks for your reply, but i have to do it in the same way as there is other android code which i have to integrate with so i have to use the same approach.

Please tell me how to solve the above problem in the way i have mentioned.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

This page contains a section on passing arrays from java to other languages, I'm not sure if this could be of any help to you though

http://java.sun.com/developer/onlineTra ... tring.html

I have to say that I would really advise against this way of working, mixing code like this could cause weird and frustrating bugs (eg. non-consistent primitive/data type sizes, different formatting, etc.), only use this if there's really no other way of getting the job done
balrajbalraj007
Posts: 16
Joined: Sun Mar 27, 2011 3:53 pm

Post by balrajbalraj007 »

Hi,
Thanks for you reply,
i have seen the link you have given but i can't find any string array in it, the closest which i can get is char array, but to change char array to stringc which is one of the data type of irrlicht is the problem.

So can any one tell me how to convert a char array into array of stringc.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

I don't know if irrlicht provides functions for this, but you could take the following approach:

A string can be represented as a null-terminated char array, so if you would want to represent a string holding the value "Hello World" using a char array, the array would look like this: "Hello World\0"
You could create one long char array containing all your null-terminated strings, and parse this later on in your application and split this array into multiple arrays for each null-character ('\0') found
This will provide you with a collection of null-terminated char-arrays which you can then convert to a collection of strings


EDIT:
Also remember that in Java, everything is inherited from the Object superclass, so if it's possible to send an Object array (which I believe it is) it should be possible to use this to send a String array
balrajbalraj007
Posts: 16
Joined: Sun Mar 27, 2011 3:53 pm

Post by balrajbalraj007 »

Hi,

i have tried to follow your approach the issue with this approach is that when i will pass a string array from java then there is not compatible format to accept it in C++, but if I use char array then the issue comes when i have to convert char array to stingc format.

As you can see that i am doing the same for strings.
So is there any direct approach to do the same in which i may not be having these issues.
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Post by gerdb »

Hi,

if you like to "stream 3D Objects and Textures" from Java to C/C++ use standardized Communication Protocols like TCP/IP/UDP or simply save from Java to File, read File with C++

Dont mix both languages that unwise, why using java anyway when programming Games with C++, I never had a 3D object hardcoded in java.

If you just want to manipulate Strings, then use C++ with STL Streams or irrlicht core::stringw or wxwidgets or 1000 other libs but no Java
Post Reply