Author Topic: object pivot  (Read 6078 times)

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: object pivot
« Reply #15 on: October 09, 2011, 03:08:33 am »
Hi Egon,

I want to use the pivot set in 3DS Max or Blender for some .3ds and .obj model files.

The reason being - my colleague has created a scene for me which contains 6 object files. I want to import them and have them stay in their relative positions to each other when I rotate them to accommodate for the change in coordinate system.

I've tried Config.useRotationPivotFrom3DS but this doesn't appear to be included in my version of jpct-ae.jar. Was this method/property made part of the main branch of code or was it a one off which can only be accessed by using that specific JAR file you created for Thomas?

Many thanks,

Stephen

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: object pivot
« Reply #16 on: October 09, 2011, 03:52:54 am »
Update: I tried using the Object3DsetOrigin() method because what I want is the pivot to be 0,0,0 in world space (so when I rotate all these objects they rotate around the same spot and keep their relative positions).

That didn't work. I thought perhaps it failed because I needed to do the rotation and set the origin after I added it to the world, but changing the order didn't have a noticeable impact.

The only solution I've found is to import all the objects - add them to an array of Object3D's, then create a new Object3D using the Object3D.mergeAll() method - and then rotate this new "super" object. However because it calculates the geometric centre of this new object I've lost track of its world position and when I go to place my active objects (tiles) they're no longer in the correct place.

I'm going to try my old approach (mergeAll) but then find the object centre, and then translate it to the world origin. Better approaches/ideas are most welcome.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: object pivot
« Reply #17 on: October 09, 2011, 08:01:49 am »
@stownshend,

One option is to align each object to the center yourself using rotateMesh().

Code: [Select]
player.translate(10, 12, -2);
player.rotateMesh();
world.addObject(player);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #18 on: October 09, 2011, 01:54:26 pm »
The pivot-reading is in the alpha/beta of 1.24, not in the "official" 1.23 release. Get the latest beta here: http://jpct.de/download/beta/jpct-ae.jar

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: object pivot
« Reply #19 on: October 11, 2011, 08:52:17 am »
Does the pivot reading work for .OBJ files too or just .3DS?

I tried it with OBJ files and it didn't throw any error but they appear to have calculated object origins as before. The line of code I changed was:

Code: [Select]
// Configure JPCT to import object origins from model files.
Config.useRotationPivotFrom3DS = true;

If not, is there any chance this could be included? OBJ is for us a much better format because of the exporting functions in Max which allow us to strip out all transformations and get just the mesh data.

Just in-case I'm doing my rotations wrong here is my code:

Code: [Select]
// Load models - each one has object origin/pivot set to world origin (0,0,0).
honeyTop = new Object3D(loadModel(HONEY_TOP_MODEL_FILE, HONEY_TOP_TEXTURE_NAME));
honeyWall = new Object3D(loadModel(HONEY_WALL_MODEL_FILE, HONEY_WALL_TEXTURE_NAME));
honeyTrap = new Object3D(loadModel(HONEY_TRAP_MODEL_FILE, HONEY_TRAP_TEXTURE_NAME));
honeyOutline1 = new Object3D(loadModel(HONEY_OUTLINE1_MODEL_FILE, HONEY_OUTLINE_TEXTURE_NAME));
honeyOutline2 = new Object3D(loadModel(HONEY_OUTLINE2_MODEL_FILE, HONEY_OUTLINE_TEXTURE_NAME));
honeyOutline3 = new Object3D(loadModel(HONEY_OUTLINE3_MODEL_FILE, HONEY_OUTLINE_TEXTURE_NAME));

// Rotate to accommodate for coordinate system
honeyTop.rotateX(PI / -2f);
honeyWall.rotateX(PI / -2f);
honeyTrap.rotateX(PI / -2f);
honeyOutline1.rotateX(PI / -2f);
honeyOutline2.rotateX(PI / -2f);
honeyOutline3.rotateX(PI / -2f);

// Add to world
world.addObject(honeyTop);
world.addObject(honeyWall);
world.addObject(honeyTrap);
world.addObject(honeyOutline1);
world.addObject(honeyOutline2);
world.addObject(honeyOutline3);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #20 on: October 11, 2011, 09:22:15 am »
No, it's 3DS only for now. If you can confirm that the pivot is actually in the OBJ-file and you have a test file available (in both formats if possible), i'll have a look at it.

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: object pivot
« Reply #21 on: October 11, 2011, 09:42:21 am »
Hi Egon,

Will have a look at the OBJ format and see if it has pivots and if so will provide you a test case.

We found a solution just now - he imported our OBJ files into Max, exported them as 3DS, and doing this has stripped out all the transformation information which was causing them to get messed up before.

So no urgency on the OBJ pivots!

Thanks for your patience.

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: object pivot
« Reply #22 on: October 11, 2011, 10:01:37 am »
Looks like OBJ doesn't have any concept of a "pivot" like .3ds files do.

The file just contains:

- vertices
- texture co-ordinates
- polygons
- vertex normals

Really interesting, I didn't know it was just plain text.

I don't know enough about modelling, geometry, and the OBJ file formats to study it further. If anyone else has the same requirement (to have an object pivot imported from a modelling program) but also wants to strip out transformation information I recommend exporting to OBJ, then importing and re-exporting to 3DS in the meantime.

http://people.sc.fsu.edu/~jburkardt/txt/obj_format.txt

Offline Tishu

  • byte
  • *
  • Posts: 32
    • View Profile
Re: object pivot
« Reply #23 on: January 07, 2012, 11:30:34 pm »
Hi

great to read that 3DS pivot support has been added. This will be a really useful feature. Unfortunately I could not get it to work properly. If I load the attached .3DS file into JPCT-AE 1.24 beta (the url above), and set the flag correctly:

Code: [Select]
private static Object3D[] loadModel(InputStream is)
{
Config.useRotationPivotFrom3DS = true;
return Loader.load3DS(is, 1);
}

I get a (0,0,0) rotation center. I am not sure whether the issues comes from the 3DS file though, as I do not have any tool to look into it, but in Blender it rotates around (-0.409, -0.179, -0.036).



Thanks
Nicolas

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #24 on: January 07, 2012, 11:39:54 pm »
Can you post the log from the loading process?

Offline Tishu

  • byte
  • *
  • Posts: 32
    • View Profile
Re: object pivot
« Reply #25 on: January 08, 2012, 12:00:45 am »
Sure:

Code: [Select]
01-07 22:55:51.995: INFO/jPCT-AE(7558): Static references cleared...
01-07 22:56:10.284: INFO/jPCT-AE(7558): Loading file from InputStream
01-07 22:56:10.303: INFO/jPCT-AE(7558): Expanding buffers...16384 bytes
[...]
01-07 22:56:10.533: INFO/jPCT-AE(7558): Expanding buffers...409600 bytes
01-07 22:56:10.533: INFO/jPCT-AE(7558): File from InputStream loaded...337755 bytes
01-07 22:56:10.563: INFO/jPCT-AE(7558): Processing new material Material.005!
[...]
01-07 22:56:10.583: INFO/jPCT-AE(7558): Processing new material Material.001!
[...]
01-07 22:57:43.843: INFO/jPCT-AE(7558): Processing object from 3DS-file: break
01-07 22:57:43.993: INFO/jPCT-AE(7558): Object 'break_jPCT9' created using 228 polygons and 122 vertices.
[...]

I have used [...] to strip some lines:
  • Expanding other buffers on the first one
  • Processing other materials on the second one
  • Processing other objects with the same log on the two last ones

Regards
Nicolas

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #26 on: January 08, 2012, 04:55:49 pm »
If that's all, then there's no output about the object hierarchy in the file which means that there's no pivot in it...or at least not stored in a way that i know of. There are no Name in hierarchy found:-messages?

Offline Tishu

  • byte
  • *
  • Posts: 32
    • View Profile
Re: object pivot
« Reply #27 on: January 08, 2012, 05:40:13 pm »
Hi

No there is no such message.

It's definitely stored somewhere though. I exported two 3DS files, one with pivot in (0,0,0) and one with the pivot I mention above. When I load them back into Blender from the 3DS files, the loaded objects have the correct distinct pivots. I attached the two files.
Do you use some external software to parse the 3DS? I'm happy to have a look if you can help me browse the file.

Also is there a way on runtime or in the jar file to confirm which version of JPCT I am using? JAR files do not seem versioned.

Thx
Nicolas

[attachment deleted by admin]
« Last Edit: January 08, 2012, 05:46:44 pm by Tishu »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #28 on: January 08, 2012, 08:25:07 pm »
No, no external software is used. I'm parsing the file based on some inofficial format specs. In these specs (as well as in all the others that i could find...), there's a list of object names in an object hierarchy in a chunk flagged with 0xB010. Then there's a sub-chunk 0xB020 which contains the pivot. These values have to be matched to the actual objects after loading based on the objects' names, i.e. the pivot isn't part of the actual object definition but part of a hierarchy definition.

In your files, none of these chunks is present. I've no idea where the pivot should be stored in your files instead. I tried to import and re-export them with DeepExploration hoping that this can somehow "restore" the pivot information...it didn't work. After saving them as 3ds again, the hierarchy was present but the pivot has been set to (0,0,0) even for the non-zero file.

Are you 100% sure that what you are setting there really is the rotation pivot? Not some camera position or object translation?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: object pivot
« Reply #29 on: January 09, 2012, 11:37:55 pm »
Also is there a way on runtime or in the jar file to confirm which version of JPCT I am using? JAR files do not seem versioned.
Config has some version information.