I was wondering how I could locate all the different objects in a scene. A single, .j3o scene made in Blender that has multiple objects on it. Say it had campfires in it, for example. How would I get the location of these campfires so as to attach a fire effect to them in-engine? Thanks
Blender scenes import as a scene graph and TL;DR answer is you traverse the graph.
A more useful answer is that note nodes have names and blender has names on its nodes as well. So you name things in your blend file. This is how i do it, i have a formal naming convention. But note that blender has quite a bit of scene graph structure in its own data. So a object contains a mesh. Both can be named. it pays to inspect the scene in the SDK and get very familiar with how things import.
I see. Is there a tutorial somewhere? Because I donât quite know how to use this name. How do I call it? Do I store it in a sub-spatial that is a child of my main scene? ._.
The name of the Object in blender. As in you set it in the object pannel in blender. This will be the node name in jME. The SDK import blender tuts and examples are best. I recommend you try the sdk.
You need to know some blender here. Otherwise that is a good place to start. Also go over the scene graphs for dummies in the jME docs from the front page if your not familiar with scene graphs.
I see. BlenderLoader wonât get recognized by my SDK. I see in the Docs that itâs a plugin, but the SDK canât communicate with plugins server, so I went and looked up about downloading it manually but I saw a thread which said the BlenderLoader was now default for JME3. /confused
No I mean the Java Monkey Engine SDK. It is stuck for now with jME 3.0. But the blender stuff is fine and its great for playing around. It imports blender files directly and you get a nice view of the scene and tree UI for exploring how the data is arranged after import.
Sorry to keep asking these understandably silly questions, but itâs hard to find this info. The docs donât really have a guide, they just semi-explain what it can do, not how to do so (at least not the âBlenderâ side of the docs). I see the importer has all the objects loaded but how exactly do I access those? I created a node for one of the objects, for example:
But how do I actually âgetâ this Node? What can I access it through? Thanks
this shows the scene graph. Typically you would transverse this graph programatically. Also i understand the SDK will let you delete/save parts of the sub graph you want. So you can explicitly save your fireplace as a asset in the much faster jME native formats.
If you donât know how to transverse the scene graph. I would take a step back. And try and make something simple with geometry you can make directly. Put this into the scene graph and manipulate it. There is a lot of little details you will just have to learn on the way.
Also for a blender object i typically group all the meshes into a single mesh. I forget the command. J or something. Splitting and joining meshes in blender is easy. I just constantly forget the commands.
To be more explicit. The loading code is something like this:
Node node=assetLoader.load(blenderResource);
This node has children like you see above. The node also has a name. So you can get to the children via
node.getChild(i);
you can check the name etc.
But like i said. If you donât know scene graphs or blenders internal data management. It will be fairly overwhelming. I would STRONGLY recommend starting with something far simpler.
With blenderResource here do you mean the scene.j3o?
I tried using the SceneGraphVisitor and SceneGraphVisitorAdapter to traverse the scene and itâs simple enough, I can get all the names of the objects I have. The issue is still the same I had at the start. This only gives me the name. Iâve tried fiddling around with its methods but Iâm probably just stupid because I canât find anything that will say âHey, give me the location of that object right there called âWeaponsShopââ!
Well I already read up on those before I started delving into the engine. From what I gathered theyâre graphs based on a tree-structure where you have parent-child relationships between nodes. the rootNode for example is the parent node every other node in my program. But how does this tell me what method to use to âcatchâ my objects?
We are simply not going to make progress this way. This is really way back at how to program. Traversing a tree structure IS catching your object. When you have the node that you named in your blender file that is the object.
Sorry but i am at a loss on where the misunderstanding is. And typically means is a lot further back.
Write something very simple in jME with no assets outside say some boxes. have some Boxes move in a group. This will go a long way to finding the gaps in knowledge i think.
Well⌠Iâm confused because I have the traversing working i.e it gets the names of all spatials. But again, thereâs a really tiny gap of knowledge: I donât know the method to get the location. I tried to do all sorts of things like
doesnât work (NullPointerException). I tried node.getChild(0); that just gives me an ArrayIndexOutOfBounds. I am looking through all the docs and found a tutorial but I still donât understand very well how to get the location of the object maybe Iâve been going at it too much. Itâs 5 am here and Iâve been programming all day. Perhaps a fresh start tomorrow could helpâŚ
Yes because you in fact DONâT know how to traverse a graph, this is not a small gap. You are using a visitor pattern and you probably shouldnât, if you in fact even know what it is. Your probably cutting and pasting code. Sorry but you NEED to work with something MUCH simpler.
It is fairly clear you are new to programming.
Why wonât you follow the suggestion of doing something much simpler with putting a cube in a scene. Then have a set of cubes move together?
I feel youâre underestimating my programming abilities just because I donât know how to use jMonkeyEngine. Iâm not stupid and Iâm frankly offended youâd think Iâm new to programming, because Iâve been putting a crap ton of effort into it for a few years nowâŚ
Iâm sorry if I offended you in any way, too. Iâve however solved the issue. It was a very silly oversight on my part, too. I was trying to get the local translation + the name at the same time without realising it. I realise now how stupid that was, probably due to my tiredness at the moment. Here is the code in case anybody were interested in it:
I donât mean to offend. But you clearly donât know how to traverse tree or graph data structures. That is not a jME thing. It is a basic programming thing that should come up very early in learning to code.
Also Why wonât you do the simple example i suggest? It will help. Start at the start.
I will definitely look better into graph traversals, thank you. As for the example you suggested, isnât that just attaching models to a central node and rotating the node?