void setup_font() { if ( (cur_font != font_in->get()) || (cur_render_type !=render_type->get()) || (cur_glyph_size != glyph_size->get()) ) { vsx::file *fp; if ((fp = engine_state->filesystem->f_open(font_in->get().c_str())) == NULL) { printf("font not found: %s\n",cur_font.c_str()); return; } cur_font = font_in->get(); cur_render_type = render_type->get(); cur_glyph_size = glyph_size->get(); if (ftfont) { delete ftfont; ftfont = 0; } if (ftfont2) { delete ftfont2; ftfont2 = 0; } unsigned long size = engine_state->filesystem->f_get_size(fp); char* fdata = (char*)malloc(size); unsigned long bread = engine_state->filesystem->f_read((void*)fdata, size, fp); if (bread == size) { switch (cur_render_type) { case 0: ftfont = new FTGLTextureFont((unsigned char*)fdata, size); break; case 1: ftfont = new FTGLPolygonFont((unsigned char*)fdata, size); ftfont2 = new FTGLOutlineFont((unsigned char*)fdata, size); break; } ftfont->FaceSize((unsigned int)round(cur_glyph_size)); ftfont->CharMap(ft_encoding_unicode); if (ftfont2) { ftfont2->FaceSize((unsigned int)round(cur_glyph_size)); ftfont2->CharMap(ft_encoding_unicode); } loading_done = true; } engine_state->filesystem->f_close(fp); } }
void log(vsx_string<>message, int level) { #if PLATFORM_FAMILY == PLATFORM_FAMILY_UNIX openlog ("vsx_engine", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); syslog(LOG_ERR,"%d: %s", level, message.c_str()); #else vsx_printf(L"VSX_LOG: %hs\n", message.c_str() ); /* if (log_level < level) return; printf("%s\n",message.c_str()); FILE* fpo = 0; if (first) { fpo = fopen((log_dir+"vsx_engine.debug.log").c_str(),"w"); first = 0; } else fpo = fopen((log_dir+"vsx_engine.debug.log").c_str(),"a"); if (!fpo) return; fprintf(fpo, "%s\n", message.c_str() ); fclose(fpo);*/ #endif }
void vsx_window_object_inspector::load_file(vsx_string filename) { //cout << "trying to load " << filename << endl; filename = vsx_get_data_path()+filename; #ifdef VSXU_DEBUG printf("filename: %s\n", filename.c_str()); #endif std::vector<vsx_string> parts; vsx_string deli = "."; explode(filename, deli, parts); if (filename_loaded != filename) { if (parts[parts.size()-1] == "jpg") { view_type = 1; // image viewer texture_loaded = false; #ifndef VSXU_PLAYER texture.texture_info.size_y = 0; // if (texture.valid) texture.unload(); texture.init_opengl_texture(); texture.load_jpeg(filename,false); //float screenaspect = screen_x/screen_y; //printf("%f, %f\n",texture.texture_info.size_x,texture.texture_info.size_y); #endif filename_loaded = filename; } else if (parts[parts.size()-1] == "png") { //printf("png"); //texture.unload(); view_type = 1; // image viewer texture_loaded = false; #ifndef VSXU_PLAYER texture.texture_info.size_y = 0; // if (texture.valid) texture.unload(); texture.load_png(filename,false); //float screenaspect = screen_x/screen_y; //printf("%f, %f\n",texture.texture_info.size_x,texture.texture_info.size_y); #endif filename_loaded = filename; //vsx_vector aa; //aa.x = 0.4/screenaspect*(texture.size_x/texture.size_y); //aa.y = 0.4; //aa.z = 0; //resize_to(aa); //move(1-0.4/screenaspect*(texture.size_x/texture.size_y),1,0); //resize_to(vsx_vector(0.1,0.1,0)); //move(0.9,1,0); } } }
void log_a(vsx_string message, int level) { if (log_level < level) return; FILE* fpo = 0; if (a_first) { fpo = fopen((log_dir+"vsxu_artiste.debug.log").c_str(),"w"); a_first = 0; } else fpo = fopen((log_dir+"vsxu_artiste.debug.log").c_str(),"a"); if (!fpo) return; fprintf(fpo, "%s\n", message.c_str() ); fclose(fpo); }
void vsx_engine_param::set_string_index(vsx_string data, int index) { if (alias) { alias_owner->set_string_index(data,index); return; } ++module->param_updates; ++module_param->updates; switch (module_param->type) { case VSX_MODULE_PARAM_ID_INT: { ((vsx_module_param_int*)module_param)->set_internal(atoi(data.c_str())); return; } case VSX_MODULE_PARAM_ID_FLOAT: { ((vsx_module_param_float*)module_param)->set_internal((float)atof(data.c_str())); return; } case VSX_MODULE_PARAM_ID_DOUBLE: { ((vsx_module_param_double*)module_param)->set_internal(atof(data.c_str())); return; } case VSX_MODULE_PARAM_ID_FLOAT3: { ((vsx_module_param_float3*)module_param)->set_internal((float)atof(data.c_str()),index); return; } case VSX_MODULE_PARAM_ID_FLOAT4: { ((vsx_module_param_float4*)module_param)->set_internal((float)atof(data.c_str()),index); return; } case VSX_MODULE_PARAM_ID_QUATERNION: { ((vsx_module_param_quaternion*)module_param)->set_internal((float)atof(data.c_str()),index); return; } case VSX_MODULE_PARAM_ID_STRING: { ((vsx_module_param_string*)module_param)->check_free(); ((vsx_module_param_string*)module_param)->param_data[0] = data; return; } case VSX_MODULE_PARAM_ID_RESOURCE: { ((vsx_module_param_resource*)module_param)->check_free(); data = str_replace("//", "/", data); ((vsx_module_param_resource*)module_param)->param_data[0] = data; return; } case VSX_MODULE_PARAM_ID_SEQUENCE: { ((vsx_module_param_sequence*)module_param)->param_data[index].set_string(data); return; } case VSX_MODULE_PARAM_ID_FLOAT_ARRAY: { clean_up_module_param(module_param); if (!((vsx_module_param_float_array*)module_param)->valid) { // data in our param is most likely pointing at invalid memory. vsx_float_array nn; nn.data = new vsx_array<float>; ((vsx_module_param_float_array*)module_param)->param_data[0] = nn; } vsx_string deli = ";"; vsx_avector<vsx_string> parts; explode(data,deli,parts); ((vsx_module_param_float_array*)module_param)->param_data[0].data->clear(); for (unsigned long i = 0; i < parts.size(); ++i) { (*((vsx_module_param_float_array*)module_param)->param_data[0].data).push_back(vsx_string_helper::s2f(parts[i])); } ((vsx_module_param_float_array*)module_param)->valid = true; return; } } }
void run() { if (filename->get() != current_filename) { if (!verify_filesuffix(filename->get(),"obj")) { filename->set(current_filename); message = "module||ERROR! This is not a OBJ mesh file!"; return; } else message = "module||ok"; current_filename = filename->get(); vsxf_handle *fp; //printf("a\n"); if ((fp = engine->filesystem->f_open(current_filename.c_str(), "r")) == NULL) { return; } char buf[65535]; vsx_string line; vsx_array<vsx_vector> vertices; //vertices.set_allocation_increment(15000); vsx_array<vsx_vector> normals; //normals.set_allocation_increment(15000); vsx_array<vsx_tex_coord> texcoords; //texcoords.set_allocation_increment(15000); //mesh->data->vertex_tex_coords.reset_used(); mesh->data->clear(); //mesh->data->vertices.set_allocation_increment(15000); //mesh->data->vertex_normals.set_allocation_increment(15000); //mesh->data->vertex_tex_coords.set_allocation_increment(15000); //mesh->data->faces.set_allocation_increment(15000); int face_cur = 0; //printf("b\n"); bool found_normals = false; bool found_texcoords = false; if (preserve_uv_coords->get()) { mesh->data->vertices.reset_used(); mesh->data->vertex_tex_coords.reset_used(); mesh->data->vertex_normals.reset_used(); mesh->data->faces.reset_used(); while (engine->filesystem->f_gets(buf,65535,fp)) { line = buf; if (line[line.size()-1] == 0x0A) line.pop_back(); if (line[line.size()-1] == 0x0D) line.pop_back(); //printf("reading line: %s\n",line.c_str()); //printf("c\n"); if (line.size()) { vsx_avector<vsx_string> parts; vsx_string deli = " "; explode(line, deli, parts); if (parts[0] == "v") { //printf("v\n"); //mesh->data->vertices.push_back(vsx_vector(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); vertices.push_back(vsx_vector(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); } else if (parts[0] == "vt") { //printf("vt\n"); vsx_tex_coord a; a.s = (s2f(parts[1])); a.t = (s2f(parts[2])); //printf("%f :: %f\n",a.s,a.t); texcoords.push_back(a); //vsx_vector__(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); found_texcoords = true; } else if (parts[0] == "vn") { //printf("vn\n"); //printf("normal\n"); normals.push_back(vsx_vector(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); found_normals = true; //mesh->data->vertex_normals.push_back(vsx_vector__(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); } else if (parts[0] == "f") { //printf("f1\n"); //printf("face\n"); //if (parts.size() == 4) { //printf("num texcoords %d\n",texcoords.size()); vsx_face ff; // vsx_avector<vsx_string> parts2; vsx_string deli2 = "/"; /* explode(parts[1], deli2, parts2); ff.c = s2i(parts2[0])-1; mesh->data->vertex_normals[ff.c] = normals[s2i(parts2[1])-1]; mesh->data->vertex_tex_coords[ff.c] = texcoords[s2i(parts2[1])-1]; explode(parts[2], deli2, parts2); ff.b = s2i(parts2[0])-1; mesh->data->vertex_normals[ff.b] = normals[s2i(parts2[1])-1]; mesh->data->vertex_tex_coords[ff.b] = texcoords[s2i(parts2[1])-1]; explode(parts[3], deli2, parts2); ff.a = s2i(parts2[0])-1; mesh->data->vertex_normals[ff.a] = normals[s2i(parts2[1])-1]; mesh->data->vertex_tex_coords[ff.a] = texcoords[s2i(parts2[1])-1];*/ vsx_avector<vsx_string> parts2; explode(parts[1], deli2, parts2); vsx_avector<vsx_string> parts3; explode(parts[2], deli2, parts3); vsx_avector<vsx_string> parts4; explode(parts[3], deli2, parts4); ff.c = face_cur; //s2i(parts2[0])-1; ff.b = face_cur+1; //s2i(parts3[0])-1; ff.a = face_cur+2; //s2i(parts4[0])-1; //printf("f2\n"); //printf("reading line: %s\n",line.c_str()); int id; id = s2i(parts2[0])-1; if (id < 0) id=0; mesh->data->vertices[ff.a] = vertices[id]; id = s2i(parts3[0])-1; if (id < 0) id=0; mesh->data->vertices[ff.b] = vertices[id]; id = s2i(parts4[0])-1; if (id < 0) id=0; mesh->data->vertices[ff.c] = vertices[id]; if (found_texcoords && found_normals) { if (parts2[1] != "") { mesh->data->vertex_tex_coords[ff.a] = texcoords[s2i(parts2[1])-1]; mesh->data->vertex_tex_coords[ff.b] = texcoords[s2i(parts3[1])-1]; mesh->data->vertex_tex_coords[ff.c] = texcoords[s2i(parts4[1])-1]; } if (parts2[2] != "") { mesh->data->vertex_normals[ff.a] = normals[s2i(parts2[2])-1]; mesh->data->vertex_normals[ff.b] = normals[s2i(parts3[2])-1]; mesh->data->vertex_normals[ff.c] = normals[s2i(parts4[2])-1]; } } else if (found_normals) { if (parts2[2] != "") { mesh->data->vertex_normals[ff.a] = normals[s2i(parts2[2])-1]; mesh->data->vertex_normals[ff.b] = normals[s2i(parts3[2])-1]; mesh->data->vertex_normals[ff.c] = normals[s2i(parts4[2])-1]; } } else if (found_texcoords) { if (parts2[1] != "") { mesh->data->vertex_tex_coords[ff.a] = texcoords[s2i(parts2[1])-1]; mesh->data->vertex_tex_coords[ff.b] = texcoords[s2i(parts3[1])-1]; mesh->data->vertex_tex_coords[ff.c] = texcoords[s2i(parts4[1])-1]; } } //printf("%d ",s2i(parts2[1])); //printf("%d ",s2i(parts3[1])); //printf("%d\n",s2i(parts4[1])); //printf("f3\n"); /*printf("ida: %d\n",s2i(parts2[1])); printf("orig coords: %f %f\n",texcoords[s2i(parts2[1])-1].s,texcoords[s2i(parts2[1])-1].t); printf("texcoord s: %f %f\n",mesh->data->vertex_tex_coords[ff.a].s,mesh->data->vertex_tex_coords[ff.a].t); printf("idb: %d\n",s2i(parts3[1])); printf("orig coords: %f %f\n",texcoords[s2i(parts3[1])-1].s,texcoords[s2i(parts3[1])-1].t); printf("texcoord s: %f %f\n",mesh->data->vertex_tex_coords[ff.a].s,mesh->data->vertex_tex_coords[ff.a].t); printf("idc: %d\n",s2i(parts4[1])); printf("orig coords: %f %f\n",texcoords[s2i(parts4[1])-1].s,texcoords[s2i(parts4[1])-1].t); printf("texcoord s: %f %f\n",mesh->data->vertex_tex_coords[ff.a].s,mesh->data->vertex_tex_coords[ff.a].t); */ face_cur += 3; mesh->data->faces.push_back(ff); //printf("f4\n"); //} } } } } else { while (engine->filesystem->f_gets(buf,65535,fp)) { line = buf; if (line[line.size()-1] == 0x0A) line.pop_back(); if (line[line.size()-1] == 0x0D) line.pop_back(); if (line.size()) { vsx_avector<vsx_string> parts; vsx_string deli = " "; explode(line, deli, parts); if (parts[0] == "v") { mesh->data->vertices.push_back(vsx_vector(s2f(parts[1]),s2f(parts[2]),s2f(parts[3]))); } else if (parts[0] == "f") { vsx_face ff; vsx_string deli2 = "/"; vsx_avector<vsx_string> parts2; explode(parts[1], deli2, parts2); vsx_avector<vsx_string> parts3; explode(parts[2], deli2, parts3); vsx_avector<vsx_string> parts4; explode(parts[3], deli2, parts4); ff.c = s2i(parts2[0])-1; ff.b = s2i(parts3[0])-1; ff.a = s2i(parts4[0])-1; //printf("face %d %d %d %d\n", mesh->data->faces.size(), ff.a, ff.b, ff.c); mesh->data->faces.push_back(ff); } } } } engine->filesystem->f_close(fp); loading_done = true; mesh->timestamp = (int)(engine->real_vtime*1000.0f); #ifdef VSXU_DEBUG //printf("mesh timestamp: %d\n", (int)mesh->timestamp); #endif } result->set_p(mesh); }
void run() { if (filename->get() != current_filename) { if (!verify_filesuffix(filename->get(),"vxm")) { filename->set(current_filename); message = "module||ERROR! This is not a OBJ mesh file!"; return; } else message = "module||ok"; current_filename = filename->get(); vsxf_handle *fp; //printf("a\n"); if ((fp = engine->filesystem->f_open(current_filename.c_str(), "r")) == NULL) return; char tag[4]; engine->filesystem->f_read((void*)&tag,sizeof(char) * 4,fp); vsx_string line; line = tag; //printf("vxm line read: %s\n",line.c_str()); if (line == "vxm") { //printf("found vxm file\n"); size_t vert_size; engine->filesystem->f_read((void*)&vert_size,sizeof(size_t) * 1,fp); if (vert_size) { //printf("vertex bytes: %d\n",vert_size); void* vert_p = malloc(vert_size); engine->filesystem->f_read(vert_p,vert_size,fp); mesh->data->vertices.set_data((vsx_vector*)vert_p,vert_size / sizeof(vsx_vector)); } size_t normals_size; engine->filesystem->f_read((void*)&normals_size,sizeof(size_t) * 1,fp); if (normals_size) { //printf("normals bytes: %d\n",normals_size); void* norm_p = malloc( normals_size); engine->filesystem->f_read(norm_p,normals_size,fp); mesh->data->vertex_normals.set_data((vsx_vector*)norm_p,normals_size / sizeof(vsx_vector)); } size_t tex_coords_size; engine->filesystem->f_read((void*)&tex_coords_size,sizeof(size_t) * 1,fp); if (tex_coords_size) { //printf("texcoord count: %d\n",tex_coords_size); void* texcoords_p = malloc(tex_coords_size); engine->filesystem->f_read(texcoords_p,tex_coords_size,fp); mesh->data->vertex_tex_coords.set_data((vsx_tex_coord*)texcoords_p,tex_coords_size / sizeof(vsx_tex_coord)); } size_t faces_size; engine->filesystem->f_read((void*)&faces_size,sizeof(size_t) * 1,fp); if (faces_size) { //printf("face count: %d\n",faces_size); void* faces_p = malloc(faces_size); engine->filesystem->f_read(faces_p,faces_size,fp); mesh->data->faces.set_data((vsx_face*)faces_p,faces_size / sizeof(vsx_face)); } } engine->filesystem->f_close(fp); loading_done = true; mesh->timestamp++; } //result->set_p(mesh); // mesh->data->vertices[0] = vsx_vector__(0,0,0); // mesh->data->vertex_colors[0] = vsx_color__(center_color->get(0),center_color->get(1),center_color->get(2),center_color->get(3)); //balls.Update(engine->real_dtime); // a += 0.02; //balls.Render(); // if (first_run || n_rays != (int)num_rays->get()) { // mesh->data->vertex_tex_coords[0] = vsx_vector__(0,0,0); // mesh->data->vertices.reset_used(); // mesh->data->faces.reset_used(); //printf("generating random points\n"); /* for (int i = 1; i < (int)num_rays->get(); ++i) { mesh->data->vertices[i*2].x = (rand()%10000)*0.0001-0.5; mesh->data->vertices[i*2].y = (rand()%10000)*0.0001-0.5; mesh->data->vertices[i*2].z = (rand()%10000)*0.0001-0.5; mesh->data->vertex_colors[i*2] = vsx_color__(0,0,0,0); mesh->data->vertex_tex_coords[i*2] = vsx_vector__(0,1,0); mesh->data->vertices[i*2+1].x = (rand()%10000)*0.0001-0.5; mesh->data->vertices[i*2+1].y = (rand()%10000)*0.0001-0.5; mesh->data->vertices[i*2+1].z = (rand()%10000)*0.0001-0.5; mesh->data->vertex_colors[i*2+1] = vsx_color__(0,0,0,0); mesh->data->vertex_tex_coords[i*2+1] = vsx_vector__(1,0,0); mesh->data->faces[i-1].a = 0; mesh->data->faces[i-1].b = i*2; mesh->data->faces[i-1].c = i*2+1; n_rays = (int)num_rays->get(); } first_run = false; } */ /*mesh->data->vertices = balls.vertices; mesh->data->vertex_normals = balls.vertex_normals; mesh->data->vertex_tex_coords = balls.vertex_tex_coords; mesh->data->faces = balls.faces; result->set_p(mesh);*/ /*else { if (num_points->get() < mesh->data->vertices.size()) { mesh->data->vertices.reset_used((int)num_points->get()); } else if (num_points->get() > mesh->data->vertices.size()) { for (int i = mesh->data->vertices.size(); i < (int)num_points->get(); ++i) { mesh->data->vertices[i].x = (rand()%10000)*0.0001*scaling->get(0); mesh->data->vertices[i].y = (rand()%10000)*0.0001*scaling->get(1); mesh->data->vertices[i].z = (rand()%10000)*0.0001*scaling->get(2); } } } printf("randMesh done %d\n",mesh->data->vertices.size());*/ // } }