Loading src/main/java/com/elphel/imagej/cameras/CLTParameters.java +5 −0 Original line number Diff line number Diff line Loading @@ -424,6 +424,7 @@ public class CLTParameters { public int min_bgnd_tiles = 10; // Minimal number of background tiles to generate background public boolean gltf_emissive = false; // true; // Use emissive textures public boolean gltf_alpha_blend = false; // true; // Use alpha blend (false - opaque) public boolean show_textures = true; // show generated textures public boolean debug_filters = false;// show intermediate results of filtering Loading Loading @@ -1450,6 +1451,7 @@ public class CLTParameters { properties.setProperty(prefix+"min_bgnd_tiles", this.min_bgnd_tiles+""); properties.setProperty(prefix+"gltf_emissive", this.gltf_emissive+""); properties.setProperty(prefix+"gltf_alpha_blend", this.gltf_alpha_blend+""); properties.setProperty(prefix+"show_textures", this.show_textures+""); properties.setProperty(prefix+"debug_filters", this.debug_filters+""); Loading Loading @@ -2354,6 +2356,7 @@ public class CLTParameters { if (properties.getProperty(prefix+"min_bgnd_tiles")!=null) this.min_bgnd_tiles=Integer.parseInt(properties.getProperty(prefix+"min_bgnd_tiles")); if (properties.getProperty(prefix+"gltf_emissive")!=null) this.gltf_emissive=Boolean.parseBoolean(properties.getProperty(prefix+"gltf_emissive")); if (properties.getProperty(prefix+"gltf_alpha_blend")!=null) this.gltf_alpha_blend=Boolean.parseBoolean(properties.getProperty(prefix+"gltf_alpha_blend")); if (properties.getProperty(prefix+"show_textures")!=null) this.show_textures=Boolean.parseBoolean(properties.getProperty(prefix+"show_textures")); if (properties.getProperty(prefix+"debug_filters")!=null) this.debug_filters=Boolean.parseBoolean(properties.getProperty(prefix+"debug_filters")); Loading Loading @@ -3450,6 +3453,7 @@ public class CLTParameters { gd.addMessage ("glTF export"); gd.addCheckbox ("glTF use emissive textures", this.gltf_emissive); gd.addCheckbox ("glTF use alpha blend", this.gltf_alpha_blend); gd.addMessage ("Earlier 3D generation parameters"); gd.addCheckbox ("Show generated textures", this.show_textures); Loading Loading @@ -4492,6 +4496,7 @@ public class CLTParameters { this.min_bgnd_tiles= (int) gd.getNextNumber(); this.gltf_emissive= gd.getNextBoolean(); this.gltf_alpha_blend= gd.getNextBoolean(); this.show_textures= gd.getNextBoolean(); this.debug_filters= gd.getNextBoolean(); Loading src/main/java/com/elphel/imagej/tileprocessor/TexturedModel.java +5 −3 Original line number Diff line number Diff line Loading @@ -1845,6 +1845,7 @@ public class TexturedModel { { final boolean batch_mode = clt_parameters.batch_run; final boolean gltf_emissive = clt_parameters.gltf_emissive; final boolean use_alpha_blend = false; final int ref_index = scenes.length - 1; final QuadCLT ref_scene = scenes[ref_index]; final TileProcessor tp = ref_scene.getTileProcessor(); Loading Loading @@ -2304,6 +2305,7 @@ public class TexturedModel { ref_scene.correctionsParameters.getModelName(ref_scene.getImageName()), // String model_name, tri_meshes, // ArrayList<TriMesh> tri_meshes, gltf_emissive, // boolean gltf_emissive, use_alpha_blend, // boolean use_alpha_blend, 1); } catch (JSONException e) { // TODO Auto-generated catch block Loading src/main/java/com/elphel/imagej/x3d/export/GlTfExport.java +58 −35 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; Loading Loading @@ -91,6 +92,7 @@ public class GlTfExport { String model_name, ArrayList<TriMesh> tri_meshes, boolean gltf_emissive, boolean use_alpha_blend, int debugLevel ) throws IOException, JSONException { boolean invert_faces = true; // false; // true; // false; // true; Loading Loading @@ -172,7 +174,6 @@ public class GlTfExport { } else if (triangles[i][j] > minmax_indx[nmesh][1]) { minmax_indx[nmesh][1] = triangles[i][j]; } } } } Loading Loading @@ -241,7 +242,8 @@ public class GlTfExport { String [] short_names = new String[total_meshes]; for (int nmesh = 0; nmesh < total_meshes; nmesh++) { String tex_uri = tri_meshes.get(nmesh).getImage(); short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-")); // short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-")); short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-"))+"-"+String.format("%03d", nmesh); } JSONObject gltf_json = new JSONObject(); Loading Loading @@ -269,29 +271,43 @@ public class GlTfExport { gltf_scene0.put("name", model_name); gltf_scene0.put("nodes", gltf_scene0_nodes); // Crete scenes // Create scenes JSONArray gltf_scenes = new JSONArray(); gltf_scenes.put(gltf_scene0); gltf_json.put("scenes", gltf_scenes); // Create images HashMap<String,Integer> map_texture_url = new HashMap<String,Integer>(); int [] image_index = new int [total_meshes]; // nmesh first mentioning the url boolean [] is_first_ref = new boolean[total_meshes]; // this nmesh is the first to mention JSONArray gltf_images = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { JSONObject gltf_image = new JSONObject(); gltf_image.put("uri", tri_meshes.get(nmesh).getImage()); String uri = tri_meshes.get(nmesh).getImage(); int sz = map_texture_url.size(); Integer fm = map_texture_url.putIfAbsent(uri,sz); if (fm == null) { // did not yet exist gltf_image.put("uri", uri); gltf_images.put(gltf_image); image_index[nmesh] = sz; is_first_ref[nmesh] = true; } else { image_index[nmesh] = fm; } } gltf_json.put("images", gltf_images); // Create textures JSONArray gltf_textures = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { if (is_first_ref[nmesh]) { JSONObject gltf_texture = new JSONObject(); gltf_texture.put("sampler", 0); gltf_texture.put("source", nmesh); gltf_texture.put("source", image_index[nmesh]); // nmesh); gltf_texture.put("name", short_names[nmesh]+"-tex"); gltf_textures.put(gltf_texture); } } gltf_json.put("textures", gltf_textures); // Create sampler0 Loading Loading @@ -321,18 +337,24 @@ or // Create materials (material references texture, so each mesh object - new material JSONArray gltf_materials = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { if (is_first_ref[nmesh]) { int indx = image_index[nmesh]; JSONObject gltf_material = new JSONObject(); JSONObject gltf_pbrMetallicRoughness = new JSONObject(); JSONObject gltf_baseColorTexture = new JSONObject(); gltf_baseColorTexture.put("index", nmesh); // reference corresponding texture gltf_baseColorTexture.put("index", indx); // nmesh); // reference corresponding texture gltf_pbrMetallicRoughness.put("baseColorTexture", gltf_baseColorTexture); gltf_pbrMetallicRoughness.put("metallicFactor", 0.0); gltf_material.put("pbrMetallicRoughness",gltf_pbrMetallicRoughness); gltf_material.put("name", short_names[nmesh]+"-mat"); if (use_alpha_blend) { gltf_material.put("alphaMode", ALPHAMODE_BLEND); } else { gltf_material.put("alphaMode", ALPHAMODE_OPAQUE); } if (gltf_emissive) { JSONObject gltf_emissiveTexture = new JSONObject(); gltf_emissiveTexture.put("index", nmesh); gltf_emissiveTexture.put("index", indx); // nmesh); gltf_material.put("emissiveTexture", gltf_emissiveTexture); JSONArray gltf_material_emissiveFactor = new JSONArray(); gltf_material_emissiveFactor.put(1.0); Loading @@ -342,6 +364,7 @@ or } gltf_materials.put(gltf_material); } } gltf_json.put("materials", gltf_materials); // create buffer(s) - a single one Loading Loading @@ -461,7 +484,7 @@ or gltf_mesh0_primitive.put("attributes", gltf_mesh0_primitive_attr); gltf_mesh0_primitive.put("indices", 3 * nmesh + 0); gltf_mesh0_primitive.put("mode", MODE_TRIANGLES); gltf_mesh0_primitive.put("material", nmesh); gltf_mesh0_primitive.put("material", image_index[nmesh]); // nmesh); gltf_mesh0_primitives.put(gltf_mesh0_primitive); } gltf_mesh0.put("primitives", gltf_mesh0_primitives); Loading Loading
src/main/java/com/elphel/imagej/cameras/CLTParameters.java +5 −0 Original line number Diff line number Diff line Loading @@ -424,6 +424,7 @@ public class CLTParameters { public int min_bgnd_tiles = 10; // Minimal number of background tiles to generate background public boolean gltf_emissive = false; // true; // Use emissive textures public boolean gltf_alpha_blend = false; // true; // Use alpha blend (false - opaque) public boolean show_textures = true; // show generated textures public boolean debug_filters = false;// show intermediate results of filtering Loading Loading @@ -1450,6 +1451,7 @@ public class CLTParameters { properties.setProperty(prefix+"min_bgnd_tiles", this.min_bgnd_tiles+""); properties.setProperty(prefix+"gltf_emissive", this.gltf_emissive+""); properties.setProperty(prefix+"gltf_alpha_blend", this.gltf_alpha_blend+""); properties.setProperty(prefix+"show_textures", this.show_textures+""); properties.setProperty(prefix+"debug_filters", this.debug_filters+""); Loading Loading @@ -2354,6 +2356,7 @@ public class CLTParameters { if (properties.getProperty(prefix+"min_bgnd_tiles")!=null) this.min_bgnd_tiles=Integer.parseInt(properties.getProperty(prefix+"min_bgnd_tiles")); if (properties.getProperty(prefix+"gltf_emissive")!=null) this.gltf_emissive=Boolean.parseBoolean(properties.getProperty(prefix+"gltf_emissive")); if (properties.getProperty(prefix+"gltf_alpha_blend")!=null) this.gltf_alpha_blend=Boolean.parseBoolean(properties.getProperty(prefix+"gltf_alpha_blend")); if (properties.getProperty(prefix+"show_textures")!=null) this.show_textures=Boolean.parseBoolean(properties.getProperty(prefix+"show_textures")); if (properties.getProperty(prefix+"debug_filters")!=null) this.debug_filters=Boolean.parseBoolean(properties.getProperty(prefix+"debug_filters")); Loading Loading @@ -3450,6 +3453,7 @@ public class CLTParameters { gd.addMessage ("glTF export"); gd.addCheckbox ("glTF use emissive textures", this.gltf_emissive); gd.addCheckbox ("glTF use alpha blend", this.gltf_alpha_blend); gd.addMessage ("Earlier 3D generation parameters"); gd.addCheckbox ("Show generated textures", this.show_textures); Loading Loading @@ -4492,6 +4496,7 @@ public class CLTParameters { this.min_bgnd_tiles= (int) gd.getNextNumber(); this.gltf_emissive= gd.getNextBoolean(); this.gltf_alpha_blend= gd.getNextBoolean(); this.show_textures= gd.getNextBoolean(); this.debug_filters= gd.getNextBoolean(); Loading
src/main/java/com/elphel/imagej/tileprocessor/TexturedModel.java +5 −3 Original line number Diff line number Diff line Loading @@ -1845,6 +1845,7 @@ public class TexturedModel { { final boolean batch_mode = clt_parameters.batch_run; final boolean gltf_emissive = clt_parameters.gltf_emissive; final boolean use_alpha_blend = false; final int ref_index = scenes.length - 1; final QuadCLT ref_scene = scenes[ref_index]; final TileProcessor tp = ref_scene.getTileProcessor(); Loading Loading @@ -2304,6 +2305,7 @@ public class TexturedModel { ref_scene.correctionsParameters.getModelName(ref_scene.getImageName()), // String model_name, tri_meshes, // ArrayList<TriMesh> tri_meshes, gltf_emissive, // boolean gltf_emissive, use_alpha_blend, // boolean use_alpha_blend, 1); } catch (JSONException e) { // TODO Auto-generated catch block Loading
src/main/java/com/elphel/imagej/x3d/export/GlTfExport.java +58 −35 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; Loading Loading @@ -91,6 +92,7 @@ public class GlTfExport { String model_name, ArrayList<TriMesh> tri_meshes, boolean gltf_emissive, boolean use_alpha_blend, int debugLevel ) throws IOException, JSONException { boolean invert_faces = true; // false; // true; // false; // true; Loading Loading @@ -172,7 +174,6 @@ public class GlTfExport { } else if (triangles[i][j] > minmax_indx[nmesh][1]) { minmax_indx[nmesh][1] = triangles[i][j]; } } } } Loading Loading @@ -241,7 +242,8 @@ public class GlTfExport { String [] short_names = new String[total_meshes]; for (int nmesh = 0; nmesh < total_meshes; nmesh++) { String tex_uri = tri_meshes.get(nmesh).getImage(); short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-")); // short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-")); short_names[nmesh] = tex_uri.substring(tex_uri.indexOf("-")+1,tex_uri.lastIndexOf("-"))+"-"+String.format("%03d", nmesh); } JSONObject gltf_json = new JSONObject(); Loading Loading @@ -269,29 +271,43 @@ public class GlTfExport { gltf_scene0.put("name", model_name); gltf_scene0.put("nodes", gltf_scene0_nodes); // Crete scenes // Create scenes JSONArray gltf_scenes = new JSONArray(); gltf_scenes.put(gltf_scene0); gltf_json.put("scenes", gltf_scenes); // Create images HashMap<String,Integer> map_texture_url = new HashMap<String,Integer>(); int [] image_index = new int [total_meshes]; // nmesh first mentioning the url boolean [] is_first_ref = new boolean[total_meshes]; // this nmesh is the first to mention JSONArray gltf_images = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { JSONObject gltf_image = new JSONObject(); gltf_image.put("uri", tri_meshes.get(nmesh).getImage()); String uri = tri_meshes.get(nmesh).getImage(); int sz = map_texture_url.size(); Integer fm = map_texture_url.putIfAbsent(uri,sz); if (fm == null) { // did not yet exist gltf_image.put("uri", uri); gltf_images.put(gltf_image); image_index[nmesh] = sz; is_first_ref[nmesh] = true; } else { image_index[nmesh] = fm; } } gltf_json.put("images", gltf_images); // Create textures JSONArray gltf_textures = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { if (is_first_ref[nmesh]) { JSONObject gltf_texture = new JSONObject(); gltf_texture.put("sampler", 0); gltf_texture.put("source", nmesh); gltf_texture.put("source", image_index[nmesh]); // nmesh); gltf_texture.put("name", short_names[nmesh]+"-tex"); gltf_textures.put(gltf_texture); } } gltf_json.put("textures", gltf_textures); // Create sampler0 Loading Loading @@ -321,18 +337,24 @@ or // Create materials (material references texture, so each mesh object - new material JSONArray gltf_materials = new JSONArray(); for (int nmesh = 0; nmesh < total_meshes; nmesh++) { if (is_first_ref[nmesh]) { int indx = image_index[nmesh]; JSONObject gltf_material = new JSONObject(); JSONObject gltf_pbrMetallicRoughness = new JSONObject(); JSONObject gltf_baseColorTexture = new JSONObject(); gltf_baseColorTexture.put("index", nmesh); // reference corresponding texture gltf_baseColorTexture.put("index", indx); // nmesh); // reference corresponding texture gltf_pbrMetallicRoughness.put("baseColorTexture", gltf_baseColorTexture); gltf_pbrMetallicRoughness.put("metallicFactor", 0.0); gltf_material.put("pbrMetallicRoughness",gltf_pbrMetallicRoughness); gltf_material.put("name", short_names[nmesh]+"-mat"); if (use_alpha_blend) { gltf_material.put("alphaMode", ALPHAMODE_BLEND); } else { gltf_material.put("alphaMode", ALPHAMODE_OPAQUE); } if (gltf_emissive) { JSONObject gltf_emissiveTexture = new JSONObject(); gltf_emissiveTexture.put("index", nmesh); gltf_emissiveTexture.put("index", indx); // nmesh); gltf_material.put("emissiveTexture", gltf_emissiveTexture); JSONArray gltf_material_emissiveFactor = new JSONArray(); gltf_material_emissiveFactor.put(1.0); Loading @@ -342,6 +364,7 @@ or } gltf_materials.put(gltf_material); } } gltf_json.put("materials", gltf_materials); // create buffer(s) - a single one Loading Loading @@ -461,7 +484,7 @@ or gltf_mesh0_primitive.put("attributes", gltf_mesh0_primitive_attr); gltf_mesh0_primitive.put("indices", 3 * nmesh + 0); gltf_mesh0_primitive.put("mode", MODE_TRIANGLES); gltf_mesh0_primitive.put("material", nmesh); gltf_mesh0_primitive.put("material", image_index[nmesh]); // nmesh); gltf_mesh0_primitives.put(gltf_mesh0_primitive); } gltf_mesh0.put("primitives", gltf_mesh0_primitives); Loading