Recent Posts

Pages: 1 ... 8 9 [10]
91
Support / Re: Transparency lost after deserialization
« Last post by Promyclon on August 21, 2017, 12:52:35 pm »
When I load object florm .obj, the attributes are taken from .mtl, assigned to objects by material names when the parser finds o or g lines. The material name is 'forgotten' but material's attributes are kept in object. When serializing some of them, like texture names are exported but some are not. If the object is not bound to a material anymore, how can I retrieve it's attributes?

The point is, I have a nice looking model in .obj & .mtl and I want it look nicely when I load it, faster, from a serialized form. And I cannot rewrite code whenever I change a model. For now I have retrieved from .mtl transparency data like that:

Code: [Select]
Map<String, Float> transMap = new TreeMap<>(); // <MaterialName, d attribute>
transMap.put("glass", 0.34f);
transMap.put("windscreen", 0.44f);
transMap.put("lights", 0.52f);

Only because I split earlier all objects to face groups by material, adding material to group names (because transparency is assigned by object an I had multimaterial objects) I could strip the object name from the original name and _jPCTnn suffix and reassign transparency after importing serialized model.

Code: [Select]
for (Object3D element : elements) {
  String elementMaterial = extractMaterialName(element.getName());
  Float transparency = transMap.get(elementMaterial);
  if (null != transparency) element.setTransparency((int) (100f * transparency)); // is this formula correct?
}

This, however, is an workaround that I cannot use in production because each model would need some implementation.

Of course, I can add all needed material attributes to object names (is there a limitation on object length?) but if we went to binary serialization to avoid text parsing overhead, it's not the direction we'd like to go.
92
Support / Re: Transparency lost after deserialization
« Last post by EgonOlsen on August 21, 2017, 11:59:21 am »
No, that information isn't a part of the serialized data. The idea of the serialized format is to handle the actual data the defines the object, not the attributes of an object.
93
Support / Transparency lost after deserialization
« Last post by Promyclon on August 21, 2017, 10:52:25 am »
Hi,

I used the DeSerializer to speed-up loading of the model I had in OBJ:

Code: [Select]
class SerializeEngine {
private Object3D[] objects;
private String sourceModelFileName;
private String sourceMaterialFileName;

SerializeEngine(final String obj, final String mtl) {
sourceModelFileName = obj;
sourceMaterialFileName = mtl;
}

int loadObj() throws IOException {
try (InputStream modelFile = new FileInputStream(sourceModelFileName);
InputStream materialsFile = new FileInputStream(sourceMaterialFileName)) {
objects = Loader.loadOBJ(modelFile, materialsFile, 1.0f);
for (Object3D o : objects)
o.build();
}
return objects.length;
}

String serialize() throws FileNotFoundException, IOException {
if (null == objects) throw new NullPointerException("Object not loaded");
if (0 == objects.length) throw new IndexOutOfBoundsException("Object is empty");
int l = sourceModelFileName.lastIndexOf('.');
String destModelFileName = ((l <= 0) ? sourceModelFileName : sourceModelFileName.substring(0, l)) + ".j3d";
try (OutputStream dest = new FileOutputStream(destModelFileName)) {
(new DeSerializer()).serializeArray(objects, dest, true);
}
return destModelFileName;
}
}

Then, instead of slow loading from .obj:

Code: [Select]
elements = Loader.loadOBJ(modelStream, materialStream, 1.0f);
I loaded the model in Android from a serialized form:

Code: [Select]
elements = Loader.loadSerializedObjectArray(modelStream);
and got the model loaded in application in jus about one second. The dispalyed model looked fine except for transparent elements. They lost their transparency. Did I do something wrong or the transparency isn't written to/read from the serialized form? I was looking at the jPCT-AE DeSerializer's code and couldn't find any code related with transparency but It's hard to believe this information is just lost.
94
Support / Re: Problem loading textures from ZIP - BitmapHelper closes file
« Last post by EgonOlsen on August 21, 2017, 09:56:05 am »
I see your point, but I don't consider this to be a bug. Either way, it's nothing that can be changed now without breaking a lot of existing code. I'll look into it and maybe add a constructor variant that doesn't close the stream.
95
Support / Problem loading textures from ZIP - BitmapHelper closes file
« Last post by Promyclon on August 21, 2017, 09:09:12 am »
Hi

I'm using jPCT-AE. To load set of bitmaps I made a ZIP fie in raw resource folder. I'ts convenient and more space-efficient to load many textures from a ZipInputStream. When I change the model, i.e. in another flavor of the app it will still work event if I'll have completely different set of textures but the file will have the same name. Unfortunately, whenever I call the first new Texture(InputStream is) iterating through ZipEntries in ZipInputStream, the stream is being closed by the BitmapHelper that decodes the image data. In my opinion this is a bug.  Java's BitmapFactory.decodeStream doesnt't do that. Closing of the stream should be the responsibility of the caller, who opens the stream.

To workaround I found the following solution that works as long as I us textures in .png (and whatever else the BitmapFactory recognizes):

Code: [Select]
private void loadTexturesFromZip(final int resId) {
        ZipEntry txMetadata;
        TextureManager txMan = TextureManager.getInstance();
        try {
            // try-with-resources closes the file automatically when leaving its scope:
            try (ZipInputStream zipTx = new ZipInputStream(res.openRawResource(resId))) {
                while (null != (txMetadata = zipTx.getNextEntry())) {
                    String txName = txMetadata.getName();
                    if (!txMan.containsTexture(txName)) {
                        Log.d(getClass().getSimpleName(), "Loading tx: " + txName);
                        Bitmap tx = BitmapFactory.decodeStream(zipTx);
                        if (null == tx) {
                            Log.e(getClass().getSimpleName(), "failed, bitmap is null");
                        } else {
                            txMan.addTexture(txName, new Texture(tx));
                        }
                    }
                }
            }
        } catch (Exception e) {
            Log.e(getClass().getCanonicalName(), "Texture loading failed: " + e.toString());
        }
    }
96
Support / Re: how to lazyload
« Last post by EgonOlsen on August 20, 2017, 10:20:41 pm »
No, if you load it...it will be loaded. However, it will be uploaded to the GPU when the first render request for it happens (if you don't preload it).
97
Support / Re: how to lazyload
« Last post by MichaelJPCT on August 20, 2017, 07:50:36 pm »
i think of another question:
is a Texture fully loaded from storage when Texture is constructed or when Texture is added to TextureManager? or it's not fully loaded from storage until it's requested for render?
i mean , when a Texture is constructed, it can be just a description of the image , but without loading the actual image texels.
98
Bones / SkeletonDebugger Auto-Scale Feature?
« Last post by AGP on August 18, 2017, 10:19:15 pm »
I've been stuck for weeks on what has to be the last stages of my file format. I load the whole thing into bones without a problem, but animating it is something else altogether. When I try to use the SkeletonDebugger, I get an "ERROR: Invalid scale!" message. When I animate it, the center of the object doesn't change but it disappears entirely. No further errors as the animation runs, but no visible object, even with culling set to false.

I can't figure this error out (especially since I can reimport the object back into 3ds max and succesfully play its animations). Would it be possible to add some logic such that SkeletonHelper would automatically rescale this invalid scale?
99
Bones / Re: My Format
« Last post by AGP on August 17, 2017, 06:41:11 pm »
I think that it's still being maintained, but I'm not sure. The user base is almost gone, per a thread I read on their board. But we have no way of using it anymore.
100
Bones / Re: My Format
« Last post by raft on August 17, 2017, 12:00:21 pm »
so, does that mean that Ogre3d is also kind of dead?
Pages: 1 ... 8 9 [10]