Skip to content

Commit

Permalink
1. gltf default value
Browse files Browse the repository at this point in the history
2. pbr config
  • Loading branch information
nicos-fan committed Jul 17, 2021
1 parent 8b90519 commit 2d1fe22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ fn convert_osgb(src: &str, dest: &str, config: &str) {
let mut center_y = 0f64;
let mut max_lvl = None;
let mut trans_region = None;
let mut pbr_texture = false;

// try parse metadata.xml
let metadata_file = dir.join("metadata.xml");
Expand Down Expand Up @@ -359,12 +360,16 @@ fn convert_osgb(src: &str, dest: &str, config: &str) {
if let Some(lvl) = v["max_lvl"].as_i64() {
max_lvl = Some(lvl as i32);
}
if let Some(pbr) = v["pbr"].as_bool() {
pbr_texture = pbr;
}
} else if config.len() > 0 {
error!("config error --> {}", config);
}
let tick = time::SystemTime::now();
if let Err(e) =
osgb::osgb_batch_convert(&dir, &dir_dest, max_lvl, center_x, center_y, trans_region)
if let Err(e) = osgb::osgb_batch_convert(
&dir, &dir_dest, max_lvl,
center_x, center_y, trans_region, pbr_texture)
{
error!("{}", e);
return;
Expand Down
3 changes: 3 additions & 0 deletions src/osgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
x: f64,
y: f64,
max_lvl: i32,
pbr_texture: bool
) -> *mut libc::c_void;

#[allow(dead_code)]
Expand Down Expand Up @@ -112,6 +113,7 @@ pub fn osgb_batch_convert(
center_x: f64,
center_y: f64,
region_offset: Option<f64>,
pbr_texture: bool,
) -> Result<(), Box<dyn Error>> {
use std::fs::File;
use std::io::prelude::*;
Expand Down Expand Up @@ -171,6 +173,7 @@ pub fn osgb_batch_convert(
rad_x,
rad_y,
max_lvl,
pbr_texture,
);
if out_ptr.is_null() {
error!("failed: {}", info.in_dir);
Expand Down
8 changes: 6 additions & 2 deletions src/osgb23dtile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using namespace std;
#undef min
#endif // max

static bool b_pbr_texture = false;

template<class T>
void put_val(std::vector<unsigned char>& buf, T val) {
buf.insert(buf.end(), (unsigned char*)&val, (unsigned char*)&val + sizeof(T));
Expand Down Expand Up @@ -834,7 +836,7 @@ bool osgb2glb_buf(std::string path, std::string& glb_buff, MeshInfo& mesh_info)
model.samplers = { sample };
}
/// --------------
if(0)
if(b_pbr_texture)
{
for (int i = 0 ; i < infoVisitor.texture_array.size(); i++)
{
Expand Down Expand Up @@ -1128,7 +1130,8 @@ encode_tile_json(osg_tree& tree, double x, double y)
*/
extern "C" void*
osgb23dtile_path(const char* in_path, const char* out_path,
double *box, int* len, double x, double y,int max_lvl)
double *box, int* len, double x, double y,
int max_lvl, bool pbr_texture)
{
std::string path = osg_string(in_path);
osg_tree root = get_all_tree(path);
Expand All @@ -1137,6 +1140,7 @@ osgb23dtile_path(const char* in_path, const char* out_path,
LOG_E( "open file [%s] fail!", in_path);
return NULL;
}
b_pbr_texture = pbr_texture;
do_tile_job(root, out_path, max_lvl);
// 返回 json 和 最大bbox
extend_tile_box(root);
Expand Down
11 changes: 8 additions & 3 deletions src/tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,10 @@ struct Accessor {
return 0;
}

Accessor() { bufferView = -1; }
Accessor() {
bufferView = -1;
byteOffset = 0;
}
};

struct PerspectiveCamera {
Expand Down Expand Up @@ -3529,8 +3532,10 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) {
}

primitive["attributes"] = attributes;
SerializeNumberProperty<int>("indices", gltfPrimitive.indices, primitive);
SerializeNumberProperty<int>("material", gltfPrimitive.material, primitive);
if (gltfPrimitive.indices > -1)
SerializeNumberProperty<int>("indices", gltfPrimitive.indices, primitive);
if (gltfPrimitive.material > -1)
SerializeNumberProperty<int>("material", gltfPrimitive.material, primitive);
SerializeNumberProperty<int>("mode", gltfPrimitive.mode, primitive);

// Morph targets
Expand Down

0 comments on commit 2d1fe22

Please sign in to comment.