# Locating different models in a single scene

I have a curiosity.

Say I wanted to create a big forest using Blender, in this forest I'd like to have a campfire or several campfires. What I could do is create the entire scene in Blender with campfires included and of course in-engine I would add a fire effect to it. Now what I do not understand is how can I actually find the fireplaces' locations in the engine? Since it's all in one scene, I can't just say getLocation on the model.

I guess what I'm asking isn't how to do it per say, but what the "professional" way is. Do professional game developers fiddle around with coordinates until they find it? Do they load the campfire on top of the scene as a separate model and move it until it fits the scene? Just in case it is important, I am using jMonkeyEngine.

If you want easy ( and look professional to me ) way to find the fire place , do this simple thing :

1. In your game engine , put an invisible object / empty game object
2. Put the object in the middle of the fireplace at the map
3. Get the coordinate of the invisible object / empty game object through script
• That method still requires fiddling with coordinates. I've figured a way out anywho. Just simply run a graph traversing – Alex Leonardi Dec 10 '16 at 4:44
• it's alot easier to fiddling with coordinates than the non-ordered object – user6668201 Dec 10 '16 at 4:46
• I don't think so. Say you have a massive scene with thousands of trees and you want to set them all on fire. With your method it will take an age xD – Alex Leonardi Dec 10 '16 at 4:47
• maybe :p but it's the part of "building a game" xD – user6668201 Dec 10 '16 at 4:50
• But why not just read the coordinates directly instead? You waste waaaaay less time and even calculations for the invisible cubes. – Alex Leonardi Dec 10 '16 at 4:55

I would create a script that looks though the entire scene and finds the models that are campfires, then add the effect to them. Possibly have the exact offset from the center of the model set manually once then applied to all objects of the same type.

While this would work I don't want this to happen at runtime so when the game is being built this would get called and change the level as one of the first steps in the build process or even as the level is changed in source control depending on how it's implemented.

This way there would be no messing around with locations every iteration of the forest and it would mean that there is an extra step of security before releasing as any error would cause the build to fail meaning that I couldn't release. Couple this with a continuous integration server (like Jenkins) and as soon as someone messes with the Forest in the wrong way it tells the team what part failed and why so that the person responsible for the change has to go and fix it.

• I see. Thank you :) I wonder what I could use as a condition to identify campfires, though? – Alex Leonardi Dec 10 '16 at 0:02
• Never used blender but i imagine that when you export the models the campfires have the same name or at least the same vectors that make up the shape i'd just make a list of all the objects that are campfires them have the script run through every object looking for a match. Even checking the vertices wouldn't be a big issue since it's automated and can run on a separate computer. – user3797758 Dec 10 '16 at 9:43
• Yep I can traverse the scene graph :) – Alex Leonardi Dec 10 '16 at 12:57

In Blender you can [Tab] into your mesh, and select the vertices of a campfire if your campfire is a single mesh you can press [Ctrl+L] after selecting a single vertex to get the linked vertices.

Once you have all the vertices you can press [Space] then search for "snap cursor to selection".

If you [Tab] out of your mesh and create a new object lets say a "Cube", and name it "campfire" now you can press [Shift+S] and chose object to cursor, "repeating this process for each campfire".

I don't know if the SDK can import Empties but if it can that might be the better option insted of Cube.

When your done doing that you could just save your blender file, and convert it to j3o in the SDK. Then find your campfire cubes in the Scene Composer, and delete there geometry but leave there nodes.

Finally in your code all you would need to do is:

Node forestScene = (Node) assetManager.loadModel("Scenes/forest.j3o");

Vector3f campfireLocation = forestScene.getChild("campfire").getWorldTranslation();
//OR
Vector3f campfireLocation = forestScene.getChild("campfire").getLocalTranslation();


this would work great expecially if you are going to attach a particle emitter then all you would need to do is:

((Node)(forestScene.getChild("campfire")).attachChild(emitter);


Final Thoughts: I would probably suggest a hierarchy like the following for you campfire nodes:  scene(Node) + +- campfires(Node) + | + campfire.0(Node) | + campfire.1(Node) | + campfire.2(Node) | + campfire.3(Node) +- scene.geometry(Geometry) 

Witch would allow you to make one control to handle all the campfires.

In case you haven't looked here Blender Key Mapping