www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: Xyvab on April 23, 2010, 08:34:24 pm
-
Hello
I saw that into the res.zip example package there are some files with the ".ser" extension.
How can I create some like them?
Thanks in advance,
Xyvab
_______
I'm not english so I'm sorry for any orthographic error :-\
-
You'll need the desktop version of jPCT for this: http://www.jpct.net/jpct-ae/download/alpha/jpctapi_121a.zip (http://www.jpct.net/jpct-ae/download/alpha/jpctapi_121a.zip)
It contains a DeSerializer class that creates serialized data that jPCT-AE can load at maximum speed.
-
Thanks for the fast answer, man !
Now I have another problem: which code have I to type to work the "serialize" method?
I've looked to the API page on DeSerializer, but I didn't understand a lot ... can you help me?
-
Opps, forgot to document that class...actually it's pretty easy. All you have to do is this:
new DeSerializer().serialize(yourObject3D, someOutputStream, true);
yourObject3D is...your Object3D. Just load it and set it up by assigning textures and calling build() on it. Just like you would do it, if you were about to render it. someOutputStream is most likely a FileOutputStream, reduced can always be true if you serialize for jPCT-AE only.
Textures aren't serialized, but their names are. So if you set up and serialize your object in desktop jPCT with two texture assigned called "hurz" and "gurz", just make sure that your Android version adds textures with the same names "hurz" and "gurz" to the TextureManager prior to loading the serialized object.
-
Thanks again for the fast answer ;D
Now, I wrote this:
new DeSerializer().serialize(Loader.load3DS("C:/file.3ds", 1), new FileOutputStream("C:/file.ser"), true);
but it gives this error:
"The method serialize(Object3D, OutputStream, boolean) in the type DeSerializer is not applicable for the arguments (Object3D[], FileOutputStream, boolean)"
How can I fix it?
P.S.:
I imported these packages:
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.threed.jpct.DeSerializer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
-
The 3ds loader returns an array of Object3Ds, not a single one. There a mergeAll-method in Object3D that you use to combine them or you serialize them as single objects. However, its not the best idea to serialize what comes right from the Loader. Its better to call build() on each object before serializing it because that reduces setup time on Android.
-
Thanks a LOT !!
Now it works !!!
-
hi EgonOlsen
I am not getting you...can you please explain it or show me some code which you are talking about
-
You have to use the desktop version of jPCT to serialize an Object3D. Unfortunatly, there's no tool present ATM that eases this serialization task, so it's up to you to code some small application that does it.
These are the steps to follow:
- load the Object3D in your desktop jPCT application, assign textures and call build() on it.
- serialize it by using the DeSerializer.serialize()-method. Make sure to serialize it in reduced mode
- copy the file created into your Android project's resources
- use the appropriate method in Loader on jPCT-AE to load the serialized file (watch the size...raw resources are limited to 1mb, you can zip them to bypass this is needed)
Note that textures themselves are not part of the file, but their names are. I.e. if you assign textures with the same names to the TextureManager on Android as you do on desktop jPCT before loading the serialized object, jPCT-AE will automagically assign them to your loaded object.
-
got it man thanks
-
Sir I fave got another problem.....and that is how do i add texture into Serialize file
I have done flowing.....whats wrong with this
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.threed.jpct.DeSerializer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import java.awt.Color;
/**
*
* @author sarwar.siddique
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
Object3D grass = null;
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture grass2 = new Texture("C:/Worksapce/SaveMe/res/raw/f15e.jpg");
DeSerializer de;
grass = Loader.load3DS("C:/Worksapce/SaveMe/res/raw/f15.3ds",5)[0];
tm.addTexture("grass2", grass2);
grass.setTexture("grass2");
//grass.setAdditionalColor(Color.yellow);
grass.build();
de = new DeSerializer();
de.serialize(grass, new FileOutputStream("C:/Worksapce/SaveMe/res/raw/sf15.ser"), true);
//.serialize(Loader.load3DS("C:/file.3ds", 1), new FileOutputStream("C:/file.ser"), true);
}
}
Thanks In Advance
-
Nothing is wrong with that at first glance. But you are just showing the serializing code, not how you load it. And you are not telling what the actual problem is. Regarding textures, i can only repeat myself from the post above:
Note that textures themselves are not part of the file, but their names are. I.e. if you assign textures with the same names to the TextureManager on Android as you do on desktop jPCT before loading the serialized object, jPCT-AE will automagically assign them to your loaded object.
-
Sir
I am not rendering the texture over the object..
after serialize I am getting only white object...
And I load the object as you show in your demo code.....
I just want to know how to texture over the object..
thanks in advance
-
Object3D.setTexture(...)...
-
i have downloaded the "jpctapi" but i don't know what i have to open to serialize an object.
so what is the procedure?
how do you use the "jpct api"? with "eclipse jee"? because eclipse don't find a project in "jpctapi"
where do you write this sentence "new DeSerializer().serialize(yourObject3D, someOutputStream, true);"??
thank you
-
It's a jar...exactly like the one that is included in the jPCT-AE zip. You create a plain Java project in Eclipse, add the jpct.jar to the build path, create a new class with a main-method, load your model in the mani-method, call build() on it and use the DeSerializer to write it back to disk. You might want to zip the resulting file afterwards and load it via a ZipInputStream in your Android App.
-
sorry but i don't arrive to realize. Because i am not a good person with eclipse.
so i do " create java project", and i after i have a library "jre system library" and a folder "src".
after i create a class, but what is the "mainmethod"??
could you give more detail to realisation ?
thank you very much
-
Are you serious? You are programming in Java and have no clue about the main-method :o I strongly suggest to do a basic "programming in Java"-tutorial before continuing with anything else...
-
ok, it s great i have create a file ser, thanks for the advice java tutorial
but in my project android i write this it's all??
scene = Loader.loadSerializedObject(res.openRawResource(R.raw.serscene));
i don't write this??
private Object loadModel(InputStream filename, InputStream mtl, float scale) {
Object3D[] model = Loader.load3DS(filename, scale);
because when i load the ser in the android with "the scene = loader.loadserial......."
In the logcat i have this
"08-04 08:57:05.143: INFO/jPCT-AE(454): [ 1312448225150 ] - ERROR: Unsupported version: 2
08-04 08:57:05.174: INFO/jPCT-AE(454): [ 1312448225175 ] - ERROR: Can't deserialize object: [ 1312448225150 ] - ERROR: Unsupported version: 2"
-
Your jPCT-AE seems to be outdated. Try 1.23 or the latest alpha of 1.24 instead.
-
but i have a problem same with the new version
what sould i write ?
if i write only this and i place the ser in the rawx it s good??
private Object loadModel(InputStream filename, InputStream mtl, float scale) {
//Object3D[] model = Loader.load3DS(filename, scale);
scene = Loader.loadSerializedObject(getResources().openRawResource(R.raw.serscene));
// Object3D[] model = Loader.loadOBJ(filename, mtl, scale);
-
If you are using the example projects directly, update the jpct-ae.jar in their lib-directory with the one from the lib-directory that is located directly in the zip. IIRC, i forgot to update those jars in the 1.23 release.
-
yes it's done , i have uploaded the library with the new version alpha. but i have still the same problem
-
Then you did something wrong. The versions since 1.23 support file format version 2. You must be using an old lib. You can check the version number in Config.
-
but some texture are large 1024*1024, there are not problem with this dimension?
scene = Loader.load3DS("C:/workspace/file4/res/raw/scene.3ds", 300)[0];
the "300" and the "0" mean what???
thanks
-
Please...read the docs. It's not my mission to explain everything that i already did in the docs. About the texture size: 1024*1024 is too large for a mobile device. It will work, but it consumes too much memory. 1024*1024*4=4mb per texture plus the uploaded version to the gpu -> 8mb plus mip maps -> ~12mb...
-
i have send a message
but i have another problem when i load my 3ds file without used the serialization, the application is not load in the emulator and in my logcat
i have this
"
08-05 08:20:55.532: INFO/jPCT-AE(426): Object 'Car2_jPCT40' created using 204 polygons and 104 vertices.
08-05 08:20:55.532: INFO/jPCT-AE(426): Processing object from 3DS-file: Car2
08-05 08:20:55.572: INFO/jPCT-AE(426): Object 'Car1_jPCT41' created using 204 polygons and 104 vertices.
08-05 08:20:55.585: INFO/jPCT-AE(426): [ 1312532455586 ] - ERROR: Can't merge null!
08-05 08:20:55.612: WARN/dalvikvm(426): threadid=9: thread exiting with uncaught exception (group=0x40014760)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): FATAL EXCEPTION: GLThread 10
08-05 08:20:55.612: ERROR/AndroidRuntime(426): java.lang.RuntimeException: [ 1312532455586 ] - ERROR: Can't merge null!
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at com.threed.jpct.Logger.log(Logger.java:189)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at com.threed.jpct.Object3D.mergeObjects(Object3D.java:476)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at com.mm.file4$MyRenderer.loadModel(Ovip.java:499)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at com.mm.file4$MyRenderer.onSurfaceChanged(Ovip.java:228)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1422)
08-05 08:20:55.612: ERROR/AndroidRuntime(426): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1184)
"
-
ERROR: Can't merge null!
...just don't merge null.
-
ok, i have resolved the problem with the merge.
but my scene is still blue (like the sky), this is the light??
"
if (master == null) {
world = new World();
world.setAmbientLight(250, 250, 250);
sun = new Light(world);
sun.setIntensity(20, 20, 20);
-
i have loaded to try your file hose_poser.obj (convert in 3ds), and i see only the "hip:2 hip" in the emulator android. (the hip:2 hip is white and the rest is blue)
why? i write this in the application java to create the ser
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.threed.jpct.DeSerializer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
//import java.awt.Color;
public class Main {
public static void main(String[ ] args) throws FileNotFoundException {
Object3D hose_poser = null;
DeSerializer de;
hose_poser = Loader.load3DS("C:/workspace/file/res/raw/hose_poser3ds",20)[0];
hose_poser.build();
de = new DeSerializer();
de.serialize(hose_poser, new FileOutputStream("C:/workspace/file/res/raw/serhose_poser.ser"), true);
}
}
May be it 's in my application android??
should i write in my code android something in rapport with the loading of all the object in ser, because i have writen only this
Hoseposer = Loader.loadSerializedObject(getResources().openRawResource(R.raw.serhose_poser));
-
You haven't read my mail, have you?
-
yes i have read your mail, thanks
sorry but i don't know how i serialize the file, when i delete [ 0 ], i have an error in my line?
-
How about reading the docs? http://www.jpct.net/doc/com/threed/jpct/DeSerializer.html (http://www.jpct.net/doc/com/threed/jpct/DeSerializer.html)
-
public static void main(String[ ] args) throws FileNotFoundException {
Object3D[] sc = null;
DeSerializer de;
sc = Loader.load3DS("C:/workspace/file/res/raw/sc.3ds",20);
//sc.build;
de = new DeSerializer();
de.serializeArray(sc, new FileOutputStream("C:/workspace/file/res/raw/sersc.ser"), true);
}
}
i write this, i have modified the serialize by the serializeArray, but i have still an object which is loaded
i am sorry, but i read and i read your doc deserialize, but i have big problem to understand (in english it's not easy to me so i ask you lots of questions)
so how do i serialize a file (lots of object) please? ? ?
in more when i try to compil my program java with texture to create a file ser
the console says me :
"[ Mon Aug 08 17:23:19 CEST 2011 ] - ERROR: Tried to set an undefined texture as default!"
while i have given the good name associated between the object and the texture
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture textureai= new Texture("C:/workspace/file/res/drawable/ai.jpg");
tm.addTexture("ai", textureai);
scene.setTexture("textureai");
it's correct, is'nt it??
and how do i serialize a file (lots of object) please? ? ? ?
-
Your serialization code is fine. If it doesn't load it correctly, your loading code is wrong. Make sure to use the array-version of the loader-method too.
Wrong:
tm.addTexture("ai", textureai);
scene.setTexture("textureai");
Right:
tm.addTexture("ai", textureai);
scene.setTexture("ai");
-
thank you for the reply by the mail. I listen your advice. But you have said i load the object in the array and i work with but i don't see.
Because in my file .3ds i have 80 objects how do i to load all this object in minimum of line code?
because i don't ssee how do i load the 3ds with all this object same after i have read your doc on the deserialize.
-
load3DS() already loads all objects from the file. serializeArray() serializes all these objects and Loader.loadSerializedObjectArray() loads them all into jPCT-AE. If they still doesn't appear in your app, you are doing something wrong with the loaded objects that i can't possibly guess.
-
so in my jpct (to create the ser)
i have writen this
Object3D[] sce = null;
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture textureai = new Texture("C:/workspace/file/res/drawable/ai.jpg");
DeSerializer de;
sce = Loader.load3DS("C:/workspace/file/res/raw/sce.3ds",20);
tm.addTexture("ai", textureai);
sce.setTexture("ai");
// sce.build();
de = new DeSerializer();
de.serializeArray(sce, new FileOutputStream("C:/workspace/file/res/raw/sersc.ser"), true);
When i have changed the "serialize" by the "serializeArray", eclipse has asked to change "object3d" by "object3d[]" and since i have lots of mistakes
but i have an error on the line
sce.setTexture("ai");
sce.build()
and i writte this in my application android
Scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersc));
and i have the same problem that in my jpct i have changed the
Scee = Loader.loadSerializedObject(getResources().openRawResource(R.raw.sersc));
by
Scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersc));
So eclipse says me that i must to change the objkect 3d in object3[] what create lots of mistakes
example : world.addObject(Scee);
-
Sorry, but the only real advise i can give you is: Learn how to code! You obviously haven't much clue about what you are doing. That's not a problem, everybody has to start somewhere...but 3D graphics doesn't seem to be the right project for a beginner to me.
-
I have changed my code, but now i have "n" file ser (about 30ko each) with "n" the number of object in my 3ds.
It' better than before, but the problem is to load each ser.
i have tried to use the array but there is an error then i use it,
the code in my jpct to create ser is this
for(int i = 0; i < scee.length; i++) {
System.out.println("serializing object: " + i + "/" + scee.length);
scee[i].build();
de.serialize(scee[i], new FileOutputStream("C:/workspace/file/res/raw/serscee"+i+".ser"), true);
}
How do i do to not load each ser one per one, i try , i try to load by array but i don't arrive, there is possibility that you help me same if i am bad in java
because i would like to introduce the "de.serializearray" but it's incompatible with the "scee[ i ]"
and i always have the problem with the texture because like my scee is in "object3D[]", this line of code is specified with error in eclipse, so i have written this
tm.addTexture("ai", textureai);
scee[i].setTexture("ai");
but now in the console after the compilation, there are written to each texture
[ Tue Aug 09 ] - ERROR: A texture with the name 'ai' has been declared twice!
-
Just serialize all objects in one array like you did before. Then load the whole array at once from one file. Then iterator over the array and do everything that you would normally do on one object only on each. Like (pseudo-code):
On the desktop:
Object3D[] objs=Loader.load3DS(....);
for (Object3D obj:objs) {
obj.build();
}
new DeSerializer().serializeArray(objs....);
On Android:
tm.addTexture("ai", textureai);
...
Object3D objs=Loader.loadSerializedObjectArray(....);
world.addObjects(objs);
There's no need serialize each object on its own. There's also no need to assign the textures by using setTexture()...the Loader will do this based on the names (as i've explained multiple times). Just make sure that you've added the textures to the manager BEFORE loading the serialized model.
-
thank you very much ;D ;D ;D ;D ;D ;D ;D ;D
i have loaded the 3ds thantks to file ser. but i have loaded without texture
now the scene load in 1minute, it's great
i am going to try to load with texture now, thank you
-
i don't arrive to load the texture, actually i think to load in my code several texture but the application load only one texture on the all object of the scene.
in my jpct to create the ser i write nothing on the texture, don't you?*
in my application android, (my textures are 256*256 or 512*512) it's not a problem?
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture textureai1 = new Texture(getResources().getDrawable(R.drawable.ai1));
Texture textureai2 = new Texture(getResources().getDrawable(R.drawable.ai2));
tm.addTexture("ai1", textureai1);
tm.addTexture("ai2", textureai2);
Object3D[] scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersce));
world.addObjects(scee);
for(int i = 0; i < scee.length; i++) {
System.out.println("serializing object: " + i + "/" + scee.length);
SimpleVector Sv = new SimpleVector();
Sv.x = 0;
Sv.y = 0;
Sv.z = 0;
scee[i].strip();
scee[i].build();
so i have tried this second code too, because i have said me that the size of texture is too much, but it's more long and sometimes there is a bug (i have to load 32 textures)
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture textureai1 = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.ai1)), 256, 256));
Texture textureai2 = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.ai2)), 256, 256));
textureai1.compress();
textureai2.compress();
tm.addTexture("ai1", textureai1);
tm.addTexture("ai2", textureai2);
Object3D[] scee = Loader.loadSerializedObjectArray(getResources().openRawResource(R.raw.sersce));
world.addObjects(scee);
for(int i = 0; i < scee.length; i++) {
System.out.println("serializing object: " + i + "/" + scee.length);
SimpleVector Sv = new SimpleVector();
Sv.x = 0;
Sv.y = 0;
Sv.z = 0;
scee[i].strip();
scee[i].build();
Do you have a solution??
and another question, if i put color on object in my 3ds ,and i put a spotlight (near camera) in my 3ds or with the application android, will i have the shape effect on the object??
-
I'm not sure what you are tyring to say here...the object has no texture? Or the it has only one texture? Or you don't know how to load 32 textures? It's actually really simple and i tried to explain it multiple times before: The names in the file and the names in the manager have to match exactly. And the textures have to be added to the manager BEFORE loading the mesh. This is needed for deserializing them only, it's not needed for serializing. On the desktop (i.e. where you serialize your object), you can check for all the names that the Android version has to know by calling getNames(); on your instance of the TextureManager. Do these names match your names in the Android code?
Or do you have some setTexture() left in your code from former versions? If so, remove it.
-
actually, on the emulator i have only one texture which is load on all objects. whereas i should have 32 textures loaded on each object with each object a texture different.
and is there shape effect with the jpct if i put a spotlight in my 3ds or in the code android ?
so the second code is not good? i should rather use a texture 512*512
-
I've no idea what you mean with shape effect... ???
-
shadow effect, (sorry i have done a mistake of traduction)
do you have an idea about the texture when you see my code??
because my code correspond at your explications
-
Shading yes, real shadows...no.
-
ok, but do you have an idea for my code because i always have nothing with my texture??
and if i load the texture in my 3ds, do i keep the texture after when i load in my application android without used (the texture manager)?
-
Sorry, but i don't have the slightest idea of what you are trying to say... ???
-
actually, i am going to give you an example to explain my problem
i have three textures :
1.jpg
2.jpg
3.jpg
And i have 3 objects in my scene 3ds when i load on the emulator
on the first object i see 1.jpg
on the second object i see 1.jpg
on the third object i see 1.jpg
whereas i should have when i load
on the first object i should see 1.jpg
on the second object i should see 2.jpg
on the third object i should see 3.jpg
-
I'm not going to repeat myself about how texture assignment works. If your model has the correct textures assigned, you are doing it wrong. It's most likely, that you do an explicit setTexture() either in the serialization code or in the Android code.
-
but if i write this in my application
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Texture textureai1 = new Texture(getResources().getDrawable(R.drawable.ai1));
Texture textureai2 = new Texture(getResources().getDrawable(R.drawable.ai2));
tm.addTexture("ai1", textureai1);
tm.addTexture("ai2", textureai2);
i have loaded nothing texture in my scene, nothing
-
Yes, and that's all fine...but it doesn't say anything about your problem. Without code, logs (at least from the serialization process) or the model, i can't help here. CHECK THE NAMES! ARE THEY REALLY ai1 AND ai2 IN THAT 3DS??
-
but when i looks the console while the compilation of jpct (to create a file ser)
i see that
ai1_jPCT0
ai2_jPCT1
do you use this name may be?
-
These are the names of the objects, not of the textures.
-
and is there a topic who is good to explain how we change between the camera when we click on a part (precise) of the screen?
-
???
-
i have found your code in the topic "How to rotate and move 3D object in world space by 2D mouse coordinaes?"
but how do i add this library in android?
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-
You don't! It's for desktop Java. You have to use the corresponding Android events instead like touch events.
-
so with the touchevents i can slide