Save model .j3o and "normalize" scale to 1

@pspeed said: Well, the problem I have is that I'm not sure why you go through all of this work to avoid setting a scale at runtime. Seems like a lot of effort for little to no gain.

Well… What I’m doing is (I think I said it before) an external editor for my game. That editor is thought to be used by “graphic modelers” that doesn’t know anything of code so I want to give them a tool to generate final .j3o files to the game loading on that editor an external model (on 3ds, blender, …), scaling them and leaving them to fit great on the game.

I could just them scaled but then I have to have this in mind on all controllers that I add to them so I see to ways on that case:

  1. if I add them a custom camera control I have to multiply distances on it by it spatial’s scale.
  2. I could create another node (making the model have this node as parent) and add the camera control to it.

But I just wanted to have the code as clean, structured and simple as possible (just loading models and adding to them controllers, this models just have geometry childs normally).

I know I could do it on other ways… but I wanted to do this like that and so, I wasn’t afraid about complexing a little bit the external utility if that is making the game code “better”. But just now it remains a little problem on all that… and is that I don’t know how to resize the animations. Now I have:

Model:

  • geometries: resized
  • skeleton: resized
    - animation: couldn’t find how

So if you know how to resize the animation without appliying an scale to the entire model I would be really thankful.

@NemesisMate said: 1. if I add them a custom camera control I have to multiply distances on it by it spatial's scale.

This part I don’t understand.

Maybe the problems you are having with using regular scaling are not really problems but just misunderstandings?

Taking scale into consideration is not particularly hard and may already be done automatically if you do things right. All of that sounds way simpler than what you are doing… but then again you seem to already be almost done.

@pspeed said: This part I don't understand.

Maybe the problems you are having with using regular scaling are not really problems but just misunderstandings?

Taking scale into consideration is not particularly hard and may already be done automatically if you do things right. All of that sounds way simpler than what you are doing… but then again you seem to already be almost done.

My camera control makes use of a pivot that is added as a child to the model when added and removes it when done (Actually it changes between different camera modes, and the pivot one makes problems). Maybe the optimization gaining is not really useful but to be honest, I’m not really pressed on other things and I wanted to try to just make the resize manually and so, remove possible future problems if I want to attach more things to that node (maybe not xD).

Anyway… It’s never bad to learn new things ;).

Yes… it is almost done… but I can’t resize the animations :S. Resizing the geometries and the bones I get a resized model but it animations are too “big” or too “small” for the resized model, so if normally it moves on “Idle” just a little bit to the right and to the left, if I make the model small resizing it manually, it just really “moves” from side to side. I looked almost all the animation docs and I think that my experiment ends here :S, maybe it can’t be done on jme3.

Anyway, thanks for your time :D.

I didn’t read the whole thread but why don’t you just scale down the main node that the model is attached to? That works fine for me, including animations. If you scale the single geometries and bones by themselves they obviously won’t play the animation data correctly anymore.

@NemesisMate said: My camera control makes use of a pivot that is added as a child to the model when added and removes it when done (Actually it changes between different camera modes, and the pivot one makes problems). Maybe the optimization gaining is not really useful but to be honest, I'm not really pressed on other things and I wanted to try to just make the resize manually and so, remove possible future problems if I want to attach more things to that node (maybe not xD).

But this is where I’m confused because every way I can think of doing this properly, scale wouldn’t be an issue. So maybe you are just not doing it right.

@normen said: I didn't read the whole thread but why don't you just scale down the main node that the model is attached to? That works fine for me, including animations. If you scale the single geometries and bones by themselves they obviously won't play the animation data correctly anymore.

Yes… that works, but I just wanted to scale all but the main node.

@pspeed said: But this is where I'm confused because every way I can think of doing this properly, scale wouldn't be an issue. So maybe you are just not doing it right.

I think I’m doing it right, I’m doing just like in a tutorial I found (I don’t remember the exact link) on the site:

pivot = new Node("CamTrack");
      
cameraNode = new CameraNode(name, cam);
cameraNode.setControlDir(com.jme3.scene.control.CameraControl.ControlDirection.SpatialToCamera);
	
pivot.attachChild(cameraNode);
cameraNode.setLocalTranslation(new Vector3f(0, 0, followDistance));
pivot.setLocalTranslation(new Vector3f(0, 1f, 0));
cameraNode.lookAt(pivot.getLocalTranslation(), Vector3f.UNIT_Y);
pivot.getLocalRotation().fromAngleAxis(-verticalAngle, Vector3f.UNIT_X);

Once de control is added to the model node I do:

((Node)spatial).attachChild(pivot);

(I dettach it from the old spatial too). And, because of the scale of the node, to get it right I have to do:

pivot.setLocalScale(Vector3f.UNIT_XYZ.divide(spatial.getLocalScale()));

If the model node is scaled then the pivot is too (On the moment I attach it to the model), isn’t it?. That’s why I have to do that fix and that’s why I wanted to make a manual resize on the external editor so I can avoid that kind of things. As I said, I’m not afraid about doing an extra work to have the external editor doing that kind of things but I saw too that there is no way to scale an animcontrol (no scale function or buffer resizes or any other way to do it) without scaling the main node.

As you said… that isn’t really an issue… but just a thing I wanted to change and I was trying to find a way to do it as I said (manually).

I guess so often the models I load are not offset the way I want and not scaled the way I want, so I always have some code that normalizes them by placing them under a node and then moving + scaling + rotating them as needed so all is the same. And at that point, attaching a pivot to the outer node would require no special treatment.

Are you going to bake in rotation fixes and position fixes also? Some models have the origin at the waist, some at the head, some at the feet. Some look down the X axis, some look down -Z. Some models are Y-up and some are Z-up.

@pspeed said: I guess so often the models I load are not offset the way I want and not scaled the way I want, so I always have some code that normalizes them by placing them under a node and then moving + scaling + rotating them as needed so all is the same. And at that point, attaching a pivot to the outer node would require no special treatment.

Are you going to bake in rotation fixes and position fixes also? Some models have the origin at the waist, some at the head, some at the feet. Some look down the X axis, some look down -Z. Some models are Y-up and some are Z-up.

That that you do is just what I wanted to say with:

2. I could create another node (making the model have this node as parent) and add the camera control to it.

And… yes, I was thinking on doing all that fixes to the model on the external editor. I’m just allowing anyone to add a model to my scene, doing it as simple as open them on the external editor and fitting it. Whatever… I think I’ll have to attach it to another node as it is regularly done instead of all the changes I wanted because of the animation independent resizing impossibility. But, if someone just know how to resize that animation without creating additional nodes or scaling it parent node, I’ll be glad to read the way to :D.