www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on July 26, 2011, 08:04:49 pm

Title: object pivot
Post by: Thomas. on July 26, 2011, 08:04:49 pm
I set the object's pivot in 3ds max and when I rotate object in engine pivot is in the center of this object... Is it normal?
Title: Re: object pivot
Post by: EgonOlsen on July 26, 2011, 08:11:16 pm
The loader doesn't care for any pivot set in 3ds Max.
Title: Re: object pivot
Post by: Thomas. on July 26, 2011, 09:02:05 pm
I see, so could you implement this, please? :)
Title: Re: object pivot
Post by: EgonOlsen on July 27, 2011, 09:18:56 am
Rather not. The rotation pivot is calculated by jPCT when calling build(). Getting it from the file instead would break every application that loads 3ds files.
Title: Re: object pivot
Post by: Thomas. on July 27, 2011, 10:08:09 am
and what Config.keepOriginalPivot(boolean keep) ... default false
Title: Re: object pivot
Post by: EgonOlsen on July 27, 2011, 08:47:01 pm
If you can send me a 3ds file with pivot and the pivot value itself, i'll look at it...
Title: Re: object pivot
Post by: Thomas. on July 27, 2011, 10:08:37 pm
here is 3ds file http://dl.dropbox.com/u/26148874/object.3DS and position of pivot is 0,0,0 ... thank :)
Title: Re: object pivot
Post by: EgonOlsen on July 27, 2011, 11:55:13 pm
Don't you have anything with a pivot unlike 0,0,0? 0,0,0 is rather...pointless.
Title: Re: object pivot
Post by: Thomas. on July 28, 2011, 02:20:42 am
file updated with new pivot in 2.699, 1.206, 2.525
Title: Re: object pivot
Post by: EgonOlsen on August 02, 2011, 08:53:07 pm
Oh, the joys of the 3ds format. One could expect that the pivot is part of the object defition, right? Like the camera is, for example (which i don't understand either). No, my friend...why should it? It's part of the keyframe definitions, which contain a tree that orders the objects. This tree references the objects by name (so the names are stored at least twice in the file) and as a sub-chunk, there's a hardly documented bunch of floats (8 to be exact) where the last 3 float seem to contain the pivot. The first 5 ones contain...something...nobody knows. At least that's what i'm guessing and it seems to be correct for your test file. So get this jar: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar), set Config.useRotationPivotFrom3DS=true; and see what happens...
Title: Re: object pivot
Post by: Thomas. on August 02, 2011, 09:21:25 pm
Thank you :) I'll try it tomorrow. Now I'm tired a lot because I was a bike ride with my girlfriend...
edit: 3ds has been proposed by some drunks?  ;D
Title: Re: object pivot
Post by: EgonOlsen on August 02, 2011, 09:47:21 pm
Just like .OBJ. I think it's that way for historical reasons. They might have added that tree/name/keyframe/pivot later and couldn't fit it into the actual object-chunks because that would break some third-party software...but that's just a guess.
Title: Re: object pivot
Post by: Thomas. on August 03, 2011, 09:44:01 pm
So, I just tested pivot from 3ds file and ... working without problem, excellent work ;)
Title: Re: object pivot
Post by: nico_r_a on August 04, 2011, 12:13:35 pm
i try to turn an object, and i load 3 object in 3ds (i think the problem is to define each object)
but in my log cat i have this

08-04 10:15:41.234: WARN/dalvikvm(395): threadid=9: thread exiting with uncaught exception (group=0x40014760)
08-04 10:15:41.234: ERROR/AndroidRuntime(395): FATAL EXCEPTION: GLThread 10
08-04 10:15:41.234: ERROR/AndroidRuntime(395): java.lang.NullPointerException
08-04 10:15:41.234: ERROR/AndroidRuntime(395):     at com.mm.Ovip$MyRenderer.onSurfaceChanged(Ovip.java:359)
08-04 10:15:41.234: ERROR/AndroidRuntime(395):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1422)
08-04 10:15:41.234: ERROR/AndroidRuntime(395):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1184)
08-04 10:15:41.285: WARN/ActivityManager(81):   Force finishing activity com.mm/.Ovip
08-04 10:15:41.297: WARN/WindowManager(81): Failure taking screenshot for (230x135) to layer 21015
Title: Re: object pivot
Post by: EgonOlsen on August 04, 2011, 05:42:35 pm
The nullpointer is in your code, not in the engine. I can't comment on that without seeing the code.
Title: Re: object pivot
Post by: stownshend 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
Title: Re: object pivot
Post by: stownshend 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.
Title: Re: object pivot
Post by: K24A3 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);
Title: Re: object pivot
Post by: EgonOlsen 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 (http://jpct.de/download/beta/jpct-ae.jar)
Title: Re: object pivot
Post by: stownshend 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);
Title: Re: object pivot
Post by: EgonOlsen 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.
Title: Re: object pivot
Post by: stownshend 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.
Title: Re: object pivot
Post by: stownshend 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
Title: Re: object pivot
Post by: Tishu 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).

(http://www.freeimagehosting.net/t/ba660.jpg) (http://www.freeimagehosting.net/ba660)

Thanks
Nicolas

[attachment deleted by admin]
Title: Re: object pivot
Post by: EgonOlsen on January 07, 2012, 11:39:54 pm
Can you post the log from the loading process?
Title: Re: object pivot
Post by: Tishu 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:

Regards
Nicolas
Title: Re: object pivot
Post by: EgonOlsen 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?
Title: Re: object pivot
Post by: Tishu 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]
Title: Re: object pivot
Post by: EgonOlsen 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?
Title: Re: object pivot
Post by: EgonOlsen 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.
Title: Re: object pivot
Post by: Tishu on January 29, 2012, 01:52:26 pm
Hi

Thanks for your last message, it helped me resolve the issue by looking at the python script used by Blender to export 3DS. Here is what I did, I hope this can help someone...

Firstly, all the keyframe export section was commented out in my version with the following comment
Code: [Select]
# COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX

I uncommented all the relevant sections, and then checked the flags used. I noticed that the script is using different conventions, and here are the relevant ones:

Code: [Select]
#------ Main Chunks
OBJECTINFO   =      long("0x3D3D",16);      #This gives the version of the mesh and is found right before the material and object information
VERSION      =      long("0x0002",16);      #This gives the version of the .3ds file
KFDATA       =      long("0xB000",16);      #This is the header for all of the key frame info

#>------ sub defines of KFDATA
KFDATA_KFHDR            = long("0xB00A",16);
KFDATA_KFSEG            = long("0xB008",16);
KFDATA_KFCURTIME        = long("0xB009",16);
KFDATA_OBJECT_NODE_TAG  = long("0xB002",16);

#>------ sub defines of OBJECT_NODE_TAG
OBJECT_NODE_ID          = long("0xB030",16);
OBJECT_NODE_HDR         = long("0xB010",16);
OBJECT_PIVOT            = long("0xB013",16);
OBJECT_INSTANCE_NAME    = long("0xB011",16);
POS_TRACK_TAG = long("0xB020",16);
ROT_TRACK_TAG = long("0xB021",16);
SCL_TRACK_TAG = long("0xB022",16);

I checked what values are set for these, and the one that is interesting here POS_TRACK_TAG (0XB020) was forced to zero, as the author of this script uses it as a position and not a rotation center:

Code: [Select]
# meshes have their transformations applied before
# exporting, so write identity transforms here:
if ID==POS_TRACK_TAG:
    # position vector:
    #track_chunk.add_variable("position", _3ds_point_3d((0.0,0.0,0.0)))

I changed the last line to

Code: [Select]
track_chunk.add_variable("position", _3ds_point_3d(obj.getLocation()))

And all is good now!

Code: [Select]
01-29 12:46:32.024: I/jPCT-AE(23839): Name in hierarchy found: balancier
[...]
01-29 12:46:32.034: I/jPCT-AE(23839): Setting rotation pivot of object balancier_jPCT0 to (0.3,-0.3,0.0025380924)

The conventions used in the original python script and in the JPCT loader are questionable as there does not seem to be an "official" 3DS specification, but this works great for Blender/JPCT-AE usage.

Regards
Nicolas
Title: Re: object pivot
Post by: kkl on December 11, 2013, 01:55:26 pm
Hi,

How did you make it work? I un-commented the code and it still crashed on Blender v2.69. A lot of errors after that.