Knowing that objects always have a texture was all I needed. Just adding environment to the second channel should does the job. Thank you!
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 MenuTexture(InputStream is, boolean useAlpha, boolean closeStream)
private void loadTexture(InputStream is, Bitmap img, boolean alpha, boolean closeStream) {
this.isLoaded = false;
Logger.log("Loading Texture...", 2);
try {
Bitmap image = img;
boolean recycleMe = false;
if(img == null) {
image = BitmapHelper.loadImage(is); // closeStream defaults to true there :(
recycleMe = true;
}
Quote08-22 06:26:29.204 4388-4411/gov.nasa.iss E/jPCT-AE: [ 1503383189204 ] - ERROR: Can't deserialize object: float[] array expected (410)!So, something went wrong and I have now only programatically generated surface in my scene.
Map<String, Float> transMap = new TreeMap<>(); // <MaterialName, d attribute>
transMap.put("glass", 0.34f);
transMap.put("windscreen", 0.44f);
transMap.put("lights", 0.52f);
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?
}
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;
}
}
elements = Loader.loadOBJ(modelStream, materialStream, 1.0f);
elements = Loader.loadSerializedObjectArray(modelStream);
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());
}
}
Page created in 0.017 seconds with 11 queries.