Skip to main content

How to measure a loaded model

9 replies [Last post]
gzdillon
Offline
Joined: 2010-10-18

I can load a .3ds or .obj model now. The problem is the size of model is so large that the viewpoint will be inside the model. I have to use keynavbehavior to "walk" a long time to see the whole model. My question is how to measure the size of models and resize it to fit the viewpoint, or relocate the viewpoint by the size.
Any reply will be appreciated!
Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
neil1988
Offline
Joined: 2010-09-13

When I did something like this, I just used mutiple scenes and each scene loaded an object. And then add all the scenes to one branch group. I didn't know a way you can solve your problem without letting Java 3D automatically resize your objects.

I used to have same requirement just like you, want the size of each object is critical. But that means you have to resize your objects by yourself. This is what I cannot do because I don't know I should shrink my transform group by how many times.

gzdillon
Offline
Joined: 2010-10-18

I guest your suggestion is the com.sun.j3d.loaders.objectfile.resize(), but it returns void.
Meanwhile I want to keep the actual size, because all the model I use are designed in real size, i.e., a person with 1.8 meters, a train with length of 25 meters. The comments of com.sun.j3d.loaders.objectfile.resize() is "Center the object and make it (-1,-1,-1) to (1,1,1)", that is not what I want.
Any help?

gzdillon
Offline
Joined: 2010-10-18

I found an old message, I will try it.
http://forums.java.net/jive/post!reply.jspa?messageID=473470

neil1988
Offline
Joined: 2010-09-13

This is the code:

int flags = ObjectFile.RESIZE;

ObjectFile f = new ObjectFile(flags, (float) (creaseAngle * Math.PI / 180.0));

Scene s1 = null;

s1 = f.load(filename1);

Hope this will help you.

gzdillon
Offline
Joined: 2010-10-18

Your reply is about viewing the whole object, thanks.
I saw this in the demo codes.
But I want to put many different objects into my scene, then the size of each object is still critical.

Any comments?

gmrolf
Offline
Joined: 2005-01-26

Hi,
1) checkout the coordinatespace of your Objects e.g. if they're normalized (|-, 1 |) or if their dimension is metrical - which will be the same as the j3d space is. If you're working with metrical-geodata a bit more of things has to be checked...if so tell us....
2.) scale the contentBranch of your geometries by using a Transform,Groups using a scaling as desired e.g. 0.1
3) load the Objects to your desired place

in general: setup your own viewEnvironment will be helpfull for several further things Back/FrontClipping more control for viewport-relevant behaviors....

regards
rolf

gzdillon
Offline
Joined: 2010-10-18

By the way, the large model is pruned by java3D, it seems the viewpoint has a short sight, then the far terminal of the model will be invisible. even if I set a large bound:
BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0), Double.MAX_VALUE);

This made me crazy!
Help me!

neil1988
Offline
Joined: 2010-09-13

Before you load the object, try this:

int flags = ObjectFile.RESIZE;

gzdillon
Offline
Joined: 2010-10-18

Could you please give more information? The "RESIZE" is a method or a member? of whom? After the flag, how to use it?
Thanks!

My code is like this:
String sFile = "E:/workspace/Java3D-prac/CHAPTER4/747.3DS";
Load3DS l = null;
try {
l = new Load3DS( sFile, this,
new Hashtable(), new Hashtable(),
new Properties() );
} catch (IOException e) {
e.printStackTrace();
}
BranchGroup obj = l.root();
tfAll.addChild(obj);

Message was edited by: gzdillon