Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - K24A3

#151
Support / Re: ClearRotation resets the scale
December 22, 2011, 04:51:00 PM
Ok thanks for that. Calling setScale after clearRotation solves the problem

Another issue I ran into is that setScale throws an exception when a negative value or 0 is parsed. Perhaps jPCT could ignore these invalid values and simply set the scale to the lowest possible scale.

The problem being I am scaling objects to zero to 'hide' it and constantly running into exceptions.
#152
Support / ClearRotation resets the scale
December 22, 2011, 04:34:05 PM
Is Object3D.clearRotation() supposed to reset the scaling of the object?

If yes, perhaps we can add a note to the docs mentioning that it will clear the scaling as well.
If not, it may be a bug because scaling gets reset when calling clearRotation() even after I build the object3D before cloning it. I believe the original object3D is also affected so build->clone is irrelevant.

This was driving me nuts for an hour until I traced it to clearRotation()  :P
#153
Support / Re: some question about "Collision detection"
December 15, 2011, 08:01:48 AM
There are a few good code examples posted in this forum, click on Search at the top left (don't use the search field at the top right since that only searches the current forum section), search for 'checkForCollisionEllipsoid'
#154
Yeah I noticed the file size difference. 100KB vs 357KB, but if it only increases the APK, it's not a problem for me since my objects are mostly low poly anyway. The APK format is actually a ZIP file so it shouldn't make much difference, zipping that 357KB serialized file shrunk it to 130KB (compared to 78KB using the 7zip format :p).
#155
Wow serialized objects make a big difference in load time, loading just three serialized 100KB objects shaved off another 500ms. The RAM usage appears to have dropped a bit as well (yet to confirm).

I can't seem to get Eclipse to auto serialize the folder unless I go into the Project Properties and click Apply again. Clicking Refresh and changing the folder contents does nothing.

The mesh bounding box is also different (offset is wrong) now that I need to call Scale() and translateMesh().
EDIT: I found a solution, removing translateMesh() and scaling the bounding box values manually gives me the correct values.
#156
That made quite a difference, I managed to decrease the load time from 6 seconds to 4.
Cheers.
#157
Is there a faster or more memory efficient way of loading the same 3D file into multiple Object3D's with each Object3D having an independent animation?

At the moment I'm using Load3DS for every object 3D. How can I load the 3D file just once and then copy the mesh to the other Object3D's?
Does mesh.cloneMesh() actually copy the mesh or does it use the same mesh?

Here's the current code:

for(int n=0;n<MAX_CLONES;n++)
{
obj = Object3D.mergeAll(Loader.load3DS(myContext.getResources().openRawResource(R.raw.obj3s), 2f));
obj2 = Object3D.mergeAll(Loader.load3DS(myContext.getResources().openRawResource(R.raw.obj3l), 2f));
obj3 = Object3D.mergeAll(Loader.load3DS(myContext.getResources().openRawResource(R.raw.obj3r), 2f));
obj.setTexture("obj3tex");
obj.setSpecularLighting(true);
obj.calcCenter();
obj2.calcCenter();
obj3.calcCenter();
obj.calcNormals();
obj2.calcNormals();
obj3.calcNormals();
obj.calcBoundingBox();
obj2.calcBoundingBox();
obj3.calcBoundingBox();
obj2.strip();
obj3.strip();

Animation anim = new Animation(3);
               anim.createSubSequence("anim1");
               anim.addKeyFrame(obj2.getMesh());
               anim.addKeyFrame(obj.getMesh());
               anim.addKeyFrame(obj3.getMesh());
               anim.setClampingMode(Animation.USE_CLAMPING);
               obj.setAnimationSequence(anim);
               //obj.compile();
world.addObject(obj);

               // Save object reference
               myObjects3[n] = obj;

anim = null;
obj  = null;
obj2 = null;
obj3 = null;

}
#158
To remove an Object3D I believe you need to remove it from the world then null all references to the Object3D so the garbage collector frees it.

world.removeObject(myObject);
myObject = null;

Cloning objects wont work with objects that have different animations (every object will have the same animation timings because they use the same mesh), but you can remove triangle information from the animations by calling Animation.strip().
#159
Support / Re: Inconsistency in collision detection
December 06, 2011, 08:09:41 AM
It appears to be working now after your suggestions, all three different objects completely sit flush on the ground. The offset is incorrect if I clone and rescale the objects, but I can take care of that  (I'll just scale the offset accordingly).

Here's the code if anyone is wandering:

Mesh mesh = object.getMesh();
float[] fBounds = mesh.getBoundingBox();      
fAutoOffset = -fBounds[3];
ObjectToGround(object, fAutoOffset);


Appreciate the help, thanks :)
#160
Support / Re: Inconsistency in collision detection
December 05, 2011, 11:44:06 AM
Ok so theoretically if the center is 0,0,0,  the lower value of the meshes bounding box should be the offset. I tried that but I'm still needing a corrective offset.

I can't seem to figure out a trending value to use. I'm guessing that calcBoundingBox() is not calculating the boundary exactly at the lowest vertex for performance reasons perhaps.


OBJECT 1
--------
Scale = 40f
Center = 0,0,0
LowerBoundingBox = -77
UpperBoundingBox = 50
Wants Offset = -10
Mesh BoundingBox 0 = -62.069466 1=51.452503 2=-33.44815 3=9.098154 4=-78.36731 5=49.07093

Scale = 80f
Center = 0,0,0
LowerBoundingBox = -67
UpperBoundingBox = 18
Wants Offset = -20
Mesh BoundingBox 0 = -124.13893 1=102.90501 2=-66.8963 3=18.196308 4=-156.73462 5=98.14186



OBJECT 2
--------
Scale = 95f
Center = 0,0,0
LowerBoundingBox = -550
UpperBoundingBox = -9
Wants Offset = 10
Mesh BoundingBox 0 = -80.026985 1=96.586525 2=-550.9481 3=-9.235985 4=-89.274704 5=144.33151

Scale = 35f
Center = 0,0,0
LowerBoundingBox = -202
UpperBoundingBox = -3.4
Wants Offset = 5
Mesh BoundingBox 0 = -29.483627 1=35.58451 2=-202.98088 3=-3.4027314 4=-32.890682 5=53.17477



By the way, there is no scaling being done loading the 3D file, there are no axis rotations (all objects point up natively), there are no animations.

obj = Object3D.mergeAll(Loader.load3DS(myContext.getResources().openRawResource(R.raw.obj7), 40f));
//obj.calcCenter();
//obj.getMesh().compress();
obj.calcBoundingBox();
obj.setTexture("obj7tex");
obj.setSpecularLighting(true);
obj.compile();
//obj.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
world.addObject(obj);
obj.translate(mainArea.getRandomPos());
ObjectToGroundAuto(obj);

The offset seems to follow the scale so I may just calculate the offset manually at scale 100f, then scale that master offset in ratio when scaling the cloned objects.
#161
Support / Re: Inconsistency in collision detection
December 04, 2011, 11:37:15 PM
Sorry I meant the starting point of the collision detection, does calcMinDistance start measuring from the exact center of the object? Or does it start from the closest polygon?
#162
Support / Re: Inconsistency in collision detection
December 04, 2011, 02:17:09 AM
QuoteI use a fixed height which is guaranteed to be always above the ground, calculate the distance and apply the offset to that value.

That is how I am doing it but I needed to manually supply the offset. The problem is that I have multiple instances of the object with different scales, so the offset is different each time.


private void ObjectToGround(Object3D object, float nYOffset)
{
if(terrain==null) return;

SimpleVector sv = new SimpleVector();

// Make sure object is above the terrain
object.translate(0, -200, 0);

// Get object position
sv.set(object.getTranslation());

// Determine height above terrain
float terrHeight = terrain.calcMinDistance(sv, new SimpleVector(0,1,0));
if(terrHeight == Object3D.COLLISION_NONE)
{
//Log.v(TAG, "COLLISION_NONE" );
// Drop back down
object.translate(0, 200, 0);
}
else
{
Log.v(TAG, "COLLISION terrHeight = "+terrHeight );
if(terrHeight>1000)  {object.translate(0, 200, 0); return;}
terrHeight += nYOffset;
sv.set(0, terrHeight, 0);
object.translate(sv);
}
}


And here's my current attempt to automatically get the offset, assuming calcMinDistance is based on the center of the object rather than the bounding box.

private void ObjectToGroundAuto(Object3D object)
{
if(terrain==null) return;

float fAutoOffset  = 0;


// Get mesh
Mesh mesh = object.getMesh();

// Get Bounding Box
float[] fBounds = mesh.getBoundingBox();

// Get the middle of the bounds
float fMid = fBounds[3] - fBounds[2];


fAutoOffset = fMid / 2; //(fMid * object.getScale()); // Always 1.0

Log.v(TAG,"fBounds2 = "+fBounds[2]+"  fBounds3 = "+fBounds[3]+" fMid="+fMid+" fAutoOffset="+fAutoOffset+" scale="+object.getScale());

Log.v(TAG,"Center = "+object.getCenter()); // Always 0,0,0 if calcCenter() is not called.

// Ground 
ObjectToGround(object, -fAutoOffset);
}


Are you able to show the code in the function calcMinDistance()? I'd like to see how the starting point of the object is calculated.
#163
Support / Re: Inconsistency in collision detection
December 03, 2011, 09:43:02 AM
I'm attempting to use the bounding box to get the magic number but not sure how to calculate it.

// Get mesh
Mesh mesh = object.getMesh();
      
// Get Bounding Box
float[] fBounds = mesh.getBoundingBox();   


The fBounds[2] value is -135f, and the fBounds[3] value is 87f. Object3D.getCenter() is 0,0,0

The magic value is supposed to be -35 (where the lowest polygon touches the terrain). How do I get -35 from -135f and 87f?


// I use this code to calculate and translate the object to the ground
sv = object.getTranslation();
float terrHeight = terrain.calcMinDistance(sv, new SimpleVector(0,1,0));
terrHeight += magicNumber;
sv.set(0, terrHeight, 0);
object.translate(sv);   
#164
Ok no worries, that technique will work fine in my app if I rush the animation to zero before the sequence change.
Thanks.
#165
Support / Re: OutOfMemoryError on ICS
December 01, 2011, 01:00:51 AM
I believe the manufacturer of the phone/tablet can set the max VM size so perhaps that is why it's only 32MB.