Animate (rotate) a model, needs to be instantiated

I’m working through the HelloLoop tutorial. I used this code, copied from HelloAsset, to place my model in the scene:

    Spatial rotor2 = assetManager.loadModel("Models/Rotor2/Rotor2.mesh.j3o");
    rotor2.scale(5f, 5f, 5f);
    rotor2.rotate(0.0f, -1.0f, 0.0f);
    rotor2.setLocalTranslation(0.0f, 0.0f, 0.0f);
    rootNode.attachChild(rotor2);
    // You must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

But to make the model rotate, apparently it needs to be instaniated, (like player = new Geometry(“blue cube”, b); ). But I don’t know what type to use for the object.
I’ve tried:

protected Material rotor2;
rotor2 = new Material(assetManager.loadModel("Models/Rotor2/Rotor2.mesh.j3o"));

or
Material rotor2 = new Material(assetManager.loadModel(“Models/Rotor2/Rotor2.mesh.j3o”));
and
protected Spatial rotor2;
rotor2 = new Spatial(assetManager.loadModel(“Models/Rotor2/Rotor2.mesh.j3o”));
and
protected Model rotor2;
rotor2 = new Model(assetManager.loadModel(“Models/Rotor2/Rotor2.mesh.j3o”));
and
protected Object rotor2;
rotor2 = new Object(assetManager.loadModel(“Models/Rotor2/Rotor2.mesh.j3o”));

Any help will be appreciated.

JME requires knowledge of Java programming or you really won’t get anywhere. It would be in your best interest to run through Java tutorials and get better at Java before attempting “one of the hardest things you can do in a language”, ie: writing a 3D game.

Firstly, “But to make the model rotate, apparently it needs to be instaniated”

…is a totally erroneous premise.

This:
Spatial rotor2 = assetManager.loadModel(“Models/Rotor2/Rotor2.mesh.j3o”);

Is creating an instance of a model. rotor2 will point to that instance. It cannot be otherwise.

rotor2 can either point to an instance or to null.

This is like the most fundamentally basic OOP programming stuff, though. You will struggle every minute going forward without some basic programming knowledge, really.

pspeed, thanks for your reply. Of course, a person can’t have too much knowledge and experience, but:

The short story: I understand the basics of Java programming. I started with Java about 6 weeks ago, and have a running application that creates a composite signal function from a series of sine functions defined by a ListArray of parameters. The app animates a “waveform” illustration of the function, calculates and displays the FFT of the function using the FastFourierTransformer class. I’m attempting to use JME to create an animation of the spinning rotor that would generate the signal. This is a teaching tool for training classes in signal analysis, not a game.

The HelloLoop class does almost what I need. Instead of the box geometry, I need my rotor object, (created in Sketchup and imported to .j30), to rotate. When I replace
Box b = new Box(2, 1, 1);
player = new Geometry(“blue cube”, b);
with
Spatial rotor1 = assetManager.loadModel(“Models/Rotor1/Rotor1.mesh.j3o”);
rotor1 = new Geometry(“myRotor”, rotor1);
and other appropriate changes, the errors imply a mismatch between Model and Geometery. Changing “new Geometry” to “new Spatial” also fails.

I expect to create more sophisticated animations as the needs develops, so any help you can offer will be appreciated.

This code:
Spatial rotor1 = assetManager.loadModel(“Models/Rotor1/Rotor1.mesh.j3o”);
rotor1 = new Geometry(“myRotor”, rotor1);

Here is what it’s doing in english:
-Load the rotor model and store a reference to it in rotor1
-blow that reference away with a bad Geometry object trying to treat rotor1 as a mesh…

The second step is completely unnecessary and I’m not sure why you felt the need to do it.

I think “the basics of Java programming” is perhaps not enough, here. 6 weeks is not really enough to learn proper Java programming, I guess. I’m not trying to be rude. We all have to start somewhere but your approach so far seems to be “try a bunch of random code-looking things until they work”. And for some very basic math/functional type stuff, that will work ok. As soon as you are doing object oriented programming (as you are now) it will be much more difficult.

Thanks, I appreciate the feedback, (really).

I have it working. I created a Node and attached the model as a child.

Now I need to work on the appearance and position.
I’m looking for a reference source that will provide the fundamentals of working with models, such as Materials, translations, etc. There seems to be a lot missing between what the tutorials provide and documentation references. Perhaps there is a reference textbook that someone could recommend?

@Torqued said: Thanks, I appreciate the feedback, (really).

I have it working. I created a Node and attached the model as a child.

You didn’t even need to do that. I’m not sure why you couldn’t just rotate the rotor1 directly. That was kind of my point about the second step being unnecessary in addition to being incorrect in your previous example.

@Torqued said: Now I need to work on the appearance and position. I'm looking for a reference source that will provide the fundamentals of working with models, such as Materials, translations, etc. There seems to be a lot missing between what the tutorials provide and documentation references. Perhaps there is a reference textbook that someone could recommend?

There is a JME book. There are also the help topics to the right of this page… like “Scene Graphs for Dummies”, etc… The tutorials tend to assume the reader has had some 3D graphics experience before. They are useful for learning the engine if you come from a different engine.

I think Materials are pretty well covered, though. You should do all of the tutorials and not just pick and choose… especially since you are still a Java beginner.