[SOLVED] Getting location of objects in a scene?

Hello everyone,

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 :slight_smile:

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 :cry:

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 :slight_smile:

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


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’”! :frowning:

Yea, you clearly don’t understand the scene graph. You don’t understand tree data structures. Start there.

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 :frowning: 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?

BTW i did teach programming to biologists for quite a few years. And many people think i am pretty good at it.

The trick is to start at the start.

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:

private SceneGraphVisitorAdapter visAdapt = new SceneGraphVisitorAdapter(){
    public void visit(Node node){
    private void searchSpatialTranslations(Spatial spatial){
        System.out.println(spatial.getName() + ": " + spatial.getLocalTranslation());

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?