Question about converting user submitted textures into .j3m files?

Hello all,

I allow users to provide their own images to use as textures, but the issue is I have 3 images to create six sides (i.e., front and back are the same, top and bottom, left and right) that I want to store and use multiple times, as well as convert these images from their current format into either a jpg or png depending if they have an Alpha Channel. The problem with this is the read/write of so many objects takes the IDE 130+ seconds, and about 30 seconds when deployed, this is terrible.

The thing is since they provide these images the only way I see to do this is creating custom mesh’s as 2d rectangles, then creating a node from the 6 sides to make a box, and adding those node into the rootNode. I figured that I should then use the node multiple times instead of redoing the mesh’s, so I haven’t tried that yet.

Everything is static so I assumed that creating .j3m files would be the best approach, but can I do that with user submitted images? Can I create these .j3m files from using multiple materials? Or if not is there a way to convert all of these 6 mesh’s into 1, without using an external editor?

I also read up in 3.0 there is a Texture Atlas built in, but it looked like it was only in Scene Composer, so it seemed you can only do it with images you have? Or can we use it with user submitted images?

Again everything will be static, so I just need to find the approach that wont last a long time(130 seconds for a world that wasn’t completely filled is bad).

Thanks,

~KZ

The oddest thing to me is why you’d want to convert the images to another format. Most of the time will be taken there.

Otherwise, just create a Material and set its textures. Share the instance around if you want to.

Of course, if this is really a block world and you just aren’t saying then the whole approach is already wrong.

Well the thing is according to the docs I’ve seen you can only have a Jpg or Png. The files most people will have are a random filetype, so I am converting it so that it can be read as an asset.

This isn’t a blockword per-say, just somethings are going to be boxes with multiple faces on them.

With setting multiple textures to a Material it will just be one texture over another right? Users will have different textures for each sides, so I want to account for that.

I also believe that the conversion is taking up the most time, and then the creation of my mesh’s, but since the assetManager cannot read in the filetype I have to convert it seems.(Unless there is a way to register a filetype, but the last time I asked about that it, it seemed I was confused, or was confusing others).

Here is the topic in question http://hub.jmonkeyengine.org/forum/topic/reading-in-a-file-type-that-isnt-a-standard-extension-i-e-file-1-file-2-etc/

Maybe there’s a better way to do this than I think.

In the end I would like to have new user submitted data be formatted into a better readable file so that I can call it much faster next time.

Well, you could make the users convert them to a usable format. Then you don’t get blamed for the conversion time. Also, your conversion code might be slow, too. I can’t see it so I don’t know.

A standard Lighting or Unshaded material can only have one texture. You will have to use an atlas or separate quads. If there is only one of these custom objects then separate quads should not be too big of a deal.

@pspeed said: Well, you could make the users convert them to a usable format. Then you don't get blamed for the conversion time. Also, your conversion code might be slow, too. I can't see it so I don't know.

A standard Lighting or Unshaded material can only have one texture. You will have to use an atlas or separate quads. If there is only one of these custom objects then separate quads should not be too big of a deal.

Yeah I was thinking about converting everything as an option in the main menu, then they can start after.

I basically buffer it in, write it out into a new file, make my material, then pass the info into another method that creates the boxes.

s = s.substring(0, s.length()-2);

               BufferedImage i1 = null;
               BufferedImage i2 = null;
               BufferedImage i3 = null;
               try
               {
                  i1 = ImageIO.read(new File(s.concat(".1")));
                  i2 = ImageIO.read(new File(s.concat(".2")));
                  i3 = ImageIO.read(new File(s.concat(".3")));

               }
                catch(IOException e) {}





                   File f1 = new File(s.concat(".1.png"));
                   File f2 = new File(s.concat(".2.png"));
                   File f3 = new File(s.concat(".3.png"));

               
                   ImageIO.write(i1,"png",f1);
                   ImageIO.write(i2,"png",f2);
                   ImageIO.write(i3,"png",f3);


                   Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                   Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                   Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");



                   mat1.setTexture("ColorMap", assetManager.loadTexture(f1.getName()));
                   mat2.setTexture("ColorMap", assetManager.loadTexture(f2.getName()));
                   mat3.setTexture("ColorMap", assetManager.loadTexture(f3.getName()));
                   
                   Node node = multiFace(i,j,mat1,mat2,mat3);
                   node.rotate(new  Quaternion().fromAngleAxis(FastMath.DEG_TO_RAD*-180, new Vector3f(1,0,0)));
                   n.attachChild(node);

There are a lot of these custom objects, as well as multiple of a single object, so I figured since I put them into a node I would just create copies of that node and reuse them(I believe that will work)??? Am I able to store these are .j3m objects/can I create a single mesh out of the 6 sides internally, without an external editor?

Thanks for the help pspeed!

If its only for a few cubes, i would go with a build them from single quads, then batch/atlas them with the atlas tool thingy somewhere in the tests.That way after this is done the runtime performance after generation gets no penalty.

For the conversion, this might indeed a usecase for a second thread, conver the images, when everything is done enqueu the task that creates the cube out of the new ones.

Btw you mgiht safe tons of conversion time by checking if its a jpg or png before, so that only the more exotic formats are actually penalized.

And if you are converting i would probably go for dds, while not as small it can be used by the graficcards without further processing.

@Empire Phoenix said: If its only for a few cubes, i would go with a build them from single quads, then batch/atlas them with the atlas tool thingy somewhere in the tests.That way after this is done the runtime performance after generation gets no penalty.

For the conversion, this might indeed a usecase for a second thread, conver the images, when everything is done enqueu the task that creates the cube out of the new ones.

Btw you mgiht safe tons of conversion time by checking if its a jpg or png before, so that only the more exotic formats are actually penalized.

And if you are converting i would probably go for dds, while not as small it can be used by the graficcards without further processing.

I’ll have to go look for the tool, or would you happen to know where I might be able to find it? I definitely just want to do this one per set of data.

I’ll look into a second thread, I figured I should probably use one.

I do check to make sure that it isn’t a png or jpg, but the “exotic formats” are most likely going to be more of them.

how does dds work?

Thanks for the help!

Feel free to use google for searching

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:texture_atlas?s[]=atlas

@Empire Phoenix said: Feel free to use google for searching

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:texture_atlas?s[]=atlas
DirectDraw Surface - Wikipedia

Gotcha thanks, I couldn’t find anything pertaining to dds in jmonkey besides a bunch of topics about “SkyBox.” I guess It would be smart to convert it to that type of file then(I’ll have to see if there is a special convert needed, or if the ioWrite will work).

I didn’t see that topic when searching texture atlasses, thanks, so I guess you can do it internally, this should help out a ton! Then It seems from this https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:save_and_load I can create an .j30 object and just reuse it…

Thanks!