How do you: .blend to j3o without materials and textures, but then assigning them in code

I am trying to import a plane from Blender to which i am going to attach an image as texture. This plane will serve the purpose of a background image of space (universe). I know that i could just use a Box and that the box texture vertices are properly aligned for the image, but i am wondering how this could be done for a mesh (plane) that came out of a j3o blendered file using loadModel.



Also i am not interested in workarounds to this question, but really dealing with it this way, as i want to understand how mesh/texturing is done in jme3 with blender.



For example i want to load a different background to my plane each time. I don’t wan’t it to be a box though.


  1. Created a plane in Blender
  2. Converted it to j3o
  3. loaded it in using loadModel
  4. assigned material with texture (space image) to the loaded model
  5. It is not properly aligned to the mesh/plane so i can see that it’s trying to do it (the colors are of the image), but the texture coordinates are not right so the texture looks like you’ve zoomed into the image by x100.



    I tried that one Flip flag (true/false) didn’t help.



    I tried playing with the materials and texture in Blender but when converting the .blend file to j3o i get an error that it cannot find the TextureAssets (TextureHelper null pointer, something like that). I think i read somewhere of a way to have the blender file properly reference the texture image, but can’t find it any more. Anyways even if it could i want to do this part programatically, not in Blender.



    I think the problems is with setting the mesh’s texture coords, but the model from Blender does not have the textcoords at all (since i can’t convert from .blender to .j3o if it does). I tried looking into how to set them manually, but it seems difficult (BufferFloat or something) .



    Bottom line is there a link to a tutorial with “.blender-j3o” topic? This might be the latest stuff so it might not be available yet.



    I’d like to design my model in Blender, and assign the material (and texture) with code (due to code logic). Please let me know of the best way to do this!



    Thanks!

https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:model_loader_and_viewer



found this article, but i am not using Ogre at all - just Blender and .blend files. I always add them to the assets folder and then i right-click-convert-to-j3o and then i reference this j3o when loading models with loadModel.



However i seem to be having some issues if the .blend model has textures…the conversion to j3o seems to fail with.



Also how would one add a texture to a .j3o that has been loaded with loadModel?

Personally I remove the materials from blender, then convert to j3o (file size is smaller, unless the blender importer has been updated to reference the images, I haven’t checked). Then in code you’ll do something like this, depending on what material definition (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:materials_overview) you wanna use:



[java]

Spatial spatial = assetManager.loadModel(“Models/Objects/object.j3o”);

Material m2= new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

m.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/diffuse.png”));

m.setColor(“Color”, ColorRGBA.Green);

spatial.setMaterial(m);

rootNode.attachChild(spatial);[/java]



then if you need to change something after you can do (assuming spatial is a geometry, most likely its a node):

[java]

((Geometry) spatial).getMaterial().setColor(“Color”, ColorRGBA.Red);

[/java]

1 Like

Thanks for the reply wezrule, i was on the same path so i am glad i see i’m not missing something, but now i realize that adding image texture to a more complex model would best be done in Blender, do you agree? For now my model is a simple cone, and i wanted to put checkers (red-white) around it, but the method above stretches out the image…i mean it makes sense that this is what happens since the default code can’t know exactly how the texture should be applied.



I guess my only path from here is to use Blender material/texture for more complex models. However i am unable to get Blender to work with Ogre (not being recognized as an export method), so i was hoping to use the new .blend convert to .j3o method and just work like that as to materials and textures.



Do you know how stable and functional is the .blend to .j3o conversion?

Yeh make the model in the blender, create UV’s, create a texture, and map the UV’s to it, make sure it looks good. Then remove all materials, then convert to .j3o. Not too sure on stability, its been improved a lot recently. I don’t use ogre (except once for an animation in blender 2.49b), i mainly use .blender/.obj, so im not sure about that sorry



yeh thats a typo sorry :stuck_out_tongue: (edited).

1 Like

cool, i’ll keep learning about this stuff, for some reason i thought it was as simple as drawing in Blender, converting into j3o, and loadModel-ing it in :stuck_out_tongue:



thanks :wink:

I am having similar problems. A simple cylinder shape with a texture on top results in a j3o file where the texture is projected from the wrong axis. What I really want is just a simple cylinder where I can have a texture on the top and another on the bottom as well as another one along the sides. How would I go about doing that? I am very new to blender also so its quite a learning curve, but at least I was able to add a texture and normal map using simple generated mapping coords with a flat projection (top and bottom). I guess to get another texture on the cylinder circumference I need to do full UV image editing?



What is the preferred routine people have when working with 3d models in blender and want to use them in jme3? I’d love to hear how people go about with this. Do you create your UV texture maps in blender and save those so you can reload them in jme3?



I did try a bit of modelling in Google sketchup which is very simple to work with, and my exported ogre mesh created two separate geometries, one for the top and bottom and another for the circumference surfaces. But I had problems getting the cylinder smooth around as Sketchup shows them as smooth but the j3o created from the mesh/material results in surfaced sides. I also have this problem in blender as it wants to smooth the top an bottom as well which ruins the point. Somehow I got to get that smooth function to work only on the sides. Haha, yes I am stuck at getting a cylinder to look right so I guess there will be some time before I can model something real. :slight_smile:

You simply create your uv unwrapped model in blender and when you export it to jme, jme automatically import its uv text coordinates.

http://www.blender.org/development/release-logs/blender-234/uv-unwrapping/

I was able to get it working. Created the model in Blender, made a UV map (actually opened a saved template and edited it in Paint.net and reloaded that, Blender fortunately has a reload button so its fast to test out), converted to j3o in jMonkey (only worked if the UV map image was in the same directory as the model) and created a material for it where I could choose the same UV map texture (that had to be flipped), and voila the j3o loaded easily as a one liner.



I noticed however that the hierarchy of the geometry created one extra node level which was unexpected, but I got around that too. When I did ray picking testing I got a geometry where the parent wasnt the j3o node (which I set the name for in code), a secondary container child node of this, so I had to get parent of parent on all j3o type loaded files to reach the node where I attached object user data (name, etc). I just simplified this to look backwards in parent hierarchy to find the node with my user data attribute that indicated it was up for “picking”. :slight_smile:

1 Like

:? :? :? :? :? :? :? :? :? :? :? :? :? :? :?

:smiley:

@nardev said:

I tried playing with the materials and texture in Blender but when converting the .blend file to j3o i get an error that it cannot find the TextureAssets (TextureHelper null pointer, something like that). I think i read somewhere of a way to have the blender file properly reference the texture image, but can't find it any more.


Quick question, does anybody know what's up with this? I got the same error importing a model:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.scene.plugins.blender.textures.TextureHelper.blendTexture(TextureHelper.java:250)
at com.jme3.scene.plugins.blender.materials.MaterialContext.(MaterialContext.java:154)
at com.jme3.scene.plugins.blender.materials.MaterialHelper.toMaterial(MaterialHelper.java:198)

Obviously I'm not loading textures correctly from my blend file, but I have no idea how to fix it and this is all I could find in the forums. Using Blender 2.59 by the way.

Thanks!

Did you save the textures in same folder of the model as well?

Yeah, the textures have to be inside the assets folder as well or in the same (or a sub-) folder of the model when using the Model Import Tool.

1 Like

YES! finally got it - i was missing texture image in the same folder as the model. jMonkey is sweet! Great stuff…just the last piece of the puzzle i was missing. Thanks to all of you above for the help - much appreciated.



To sum up for next guy that get’s stuck on this:


  1. Open Blender
  2. Create an object
  3. Create material
  4. Create texture from image (in blender it’s hard to notice it, but it’s in the list of texture types)
  5. Assign texture from image to the material
  6. Hit render to view your textured object
  7. Save as .blend into your jmonkey project models folder
  8. Save the textured image to that same folder
  9. Right-click on the .blend file in jMonkey and convert it to j3o
  10. View it using the scene viewer (you should now have the beautiful texture and material on the object)
  11. Use the assetmanager to load up the model:

    assetManager.loadModel(“some.j3o”);
  12. Go and make your game now :slight_smile:



    Once again, thanks!
1 Like

You should also be able to store the textures in the “Textures” folder and the model in the “Models” folder. If the blend file correctly references the textures in the Texture folder you should be able to convert it as well. Important thing is that all files are in the assets folder.

Ah, I got it now. Knew it was something simple.