Exemplo n.º 1
0
void Model::mesh_create_all(Scene &scene, const aiNode &node, const BoneForAssimpBone &boneForAssimpBone)
{
  mesh_create(scene, node, boneForAssimpBone);
  for (unsigned int i = 0; i < node.mNumChildren; i++) {
    mesh_create_all(scene, *node.mChildren[i], boneForAssimpBone);
  }
}
Exemplo n.º 2
0
void create_random_meshes(const char *filename,int num_meshes)
{
    hid_t fid,mid;
    herr_t status = output_file_create(filename,&fid);
    char mesh_name[64];
    telem_t elem;
    int seed = 0x123456;
    int m;

    if ( status != DANU_SUCCESS ) {
	printf("FAILED TO CREATE DUMMY TEST FILE\n");
	fail_exit_now();
    }

    for(m=1; m <= num_meshes; m++) {
        elem = generate_random_bound_int(LINE_ELEM,HEX_ELEM,&seed);
	sprintf(mesh_name,"Mesh %02d",m);
	status = mesh_create(fid,mesh_name,UNSTRUCTURED_MESH,elem,&mid);
	if ( status != DANU_SUCCESS ) {
	    printf("FAILED TO CREATE DUMMY MESH\n");
	    fail_exit_now();
	}
	danu_group_close(mid);
    }

    output_file_close(&fid);
}
Exemplo n.º 3
0
RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) {
	
	DVector<Vector3> vertices;
	DVector<Vector3> normals;
	
	for(int i = 1; i <= p_lats; i++) {
		double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats);
		double z0  = Math::sin(lat0);
		double zr0 =  Math::cos(lat0);
	
		double lat1 = Math_PI * (-0.5 + (double) i / p_lats);
		double z1 = Math::sin(lat1);
		double zr1 = Math::cos(lat1);
	
		for(int j = p_lons; j >= 1; j--) {
		
			double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons;
			double x0 = Math::cos(lng0);
			double y0 = Math::sin(lng0);
			
			double lng1 = 2 * Math_PI * (double) (j) / p_lons;
			double x1 = Math::cos(lng1);					
			double y1 = Math::sin(lng1);
			
			
			Vector3 v[4]={
				Vector3(x1 * zr0, z0, y1 *zr0),
				Vector3(x1 * zr1, z1, y1 *zr1),
				Vector3(x0 * zr1, z1, y0 *zr1),
				Vector3(x0 * zr0, z0, y0 *zr0)
			};
			
#define ADD_POINT(m_idx)\
	normals.push_back(v[m_idx]);	\
	vertices.push_back(v[m_idx]*p_radius);\
	
			ADD_POINT(0);
			ADD_POINT(1);
			ADD_POINT(2);
			
			ADD_POINT(2);
			ADD_POINT(3);
			ADD_POINT(0);
		}
	}

	RID mesh = mesh_create();
	Array d;
	d.resize(VS::ARRAY_MAX);

	d[ARRAY_VERTEX]=vertices;
	d[ARRAY_NORMAL]=normals;

	mesh_add_surface(mesh,PRIMITIVE_TRIANGLES,d);

	return mesh;
}
Exemplo n.º 4
0
int 
main(int argc, char** argv) {
   
   cairo_surface_t *sfc;
   cairo_t *ctx;
   
   int x, y;
   struct timespec ts = {0, 500000000};
   
   int running;

   x = y = 0;
   sfc = cairo_create_x11_surface(&x, &y);
   ctx = cairo_create(sfc);
   cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE);

   mesh_t* m = mesh_create(x, y);

   for (running = 1; running;) {

      cairo_push_group(ctx);
      
         cairo_set_source_rgb(ctx, 0.1, 0.1, 0.1);
         cairo_paint(ctx);
         
         mesh_draw(ctx, m);

      cairo_pop_group_to_source(ctx);
      cairo_paint(ctx);

      cairo_surface_flush(sfc);

      int event=0;
      switch (event=cairo_check_event(sfc, 0)) {
         case 0xff53:   // right cursor
            break;

         case 0xff51:   // left cursor
            break;

         case 0xff1b:   // Esc
         case -1:       // left mouse button
            running = 0;
            break;
      }

      nanosleep(&ts, NULL);
   }

   mesh_free(m);

   cairo_destroy(ctx);
   cairo_close_x11_surface(sfc);

   return 0;
}
Exemplo n.º 5
0
bool
mesh_resize_capacity(Mesh_data *data, const size_t size_hint)
{
  assert(data);
  assert(size_hint > data->size); // Will slice data

  // Create new data.
  Mesh_data new_data;
  const bool created_new = mesh_create(&new_data, size_hint);

  // Failed to resize.
  if(!created_new)
  {
    mesh_destroy(&new_data);
    return false;
  }

  // Copy over data
  {
    memcpy(new_data.keys, data->keys, sizeof(uint32_t) * data->size);
    memcpy(new_data.field_name, data->field_name, sizeof(char) * data->size * 32);
    memcpy(new_data.field_mesh, data->field_mesh, sizeof(Graphics_api::Mesh) * data->size * 1);
    memcpy(new_data.field_aabb, data->field_aabb, sizeof(math::aabb) * data->size * 1);
  }

  // Swap ptrs
  {
    uint32_t *old_keys = data->keys;
    data->keys = new_data.keys;
    new_data.keys = old_keys;

    char *old_name = data->field_name;
    data->field_name = new_data.field_name;
    new_data.field_name = old_name;

    Graphics_api::Mesh *old_mesh = data->field_mesh;
    data->field_mesh = new_data.field_mesh;
    new_data.field_mesh = old_mesh;

    math::aabb *old_aabb = data->field_aabb;
    data->field_aabb = new_data.field_aabb;
    new_data.field_aabb = old_aabb;
  }

  // Set the Capacity
  {
    size_t *capacity = const_cast<size_t*>(&data->capacity);
    *capacity = new_data.capacity;
  }

  // Destroy new data
  mesh_destroy(&new_data);

  return true;
}
Exemplo n.º 6
0
struct mesh *obj_read(const char *file)
{
	FILE *f;
	char line[512];
	const char *str;
	struct mesh *mesh;
	int has_normals = 0;

	if (!(f = fopen(file, "r")))
		return NULL;

	mesh = mesh_create();
	while (!feof(f)) {
		if (!fgets(line, sizeof(line), f))
			break;

		str = line;
		if (strncmp(str, "v ", 2) == 0) {
			/* Vertex command */
			vector v;

			sscanf(str, "v %f %f %f", v, v + 1, v + 2);
			mesh_add_vertex(mesh, v);
		} else if (strncmp(str, "vn ", 3) == 0) {
			/* Normal command */
			vector n;

			sscanf(str, "vn %f %f %f", n, n + 1, n + 2);
			mesh_add_normal(mesh, n);
		} else if (strncmp(str, "f ", 2) == 0) {
			/* Face command */
			int vi, ti, ni;

			mesh_begin_face(mesh);
			str = skip_space(++str); /* Skip 'f ' */
			while (*str) {
				vi = ti = ni = 0;
				if (sscanf(str, "%d/%d/%d", &vi, &ti, &ni) == 3)
					has_normals = 1;
				mesh_add_index(mesh, vi - 1, ni - 1);
				str = skip_non_space(str);
				str = skip_space(str);
			}
			mesh_end_face(mesh);
		}
	}

	fclose(f);

	if (!has_normals)
		mesh_compute_normals(mesh);

	return mesh;
}
Exemplo n.º 7
0
Text *Node::text_create(Font *font, Scene &scene)
{
  Assets &assets = scene.assets_get();
  std::unique_ptr<Text> text(new Text());
  Text *text_ptr = text.get();
  text_ptr->font_set(font);
  text_set(text_ptr);

  if (!mesh_get())
    mesh_create(scene);

  assets.text_add(std::move(text));
  return text_ptr;
}
Exemplo n.º 8
0
END_TEST

START_TEST (test_unstruct_mesh_create)
{
    const char test_file[] = FILENAME;
    hid_t  fid,mid;
    herr_t status = output_file_create(test_file,&fid);
    char mesh_name[64];
    telem_t elem;



    fail_unless ( H5_ISA_VALID_ID(fid),
                  "Failed to create output file. Invalid H5 ID");

    if ( H5_ISA_VALID_ID(fid) ) {

	elem = -2;
	sprintf(mesh_name,"Failed Mesh");
	status = mesh_create(fid,mesh_name,UNSTRUCTURED_MESH,elem,&mid);
	fail_unless( status != DANU_SUCCESS,
		     "Failed to flag bad elem type");

	/* Create mesh for each element type */
	for(elem=LINE_ELEM; elem <= HEX_ELEM; elem++) {
	    sprintf(mesh_name,"%s elemtype=%d",MESHNAME, elem);
	    status = mesh_create(fid,mesh_name,UNSTRUCTURED_MESH,elem,&mid);
            fail_unless( status == DANU_SUCCESS,
	                 "Failed to create 2D unstructured mesh");
	}

	output_file_close(&fid);
	danu_file_delete(test_file);

    }

}
Exemplo n.º 9
0
struct mesh *luaL_checkmesh(lua_State *L, int index)
{
	struct mesh *m;

	luaL_argcheck(L, lua_ismesh(L, index), index, "not a mesh");
	m = mesh_create();
	lua_getfield(L, -1, "vertices");
	mesh_addluaverts(m, L, -1);
	lua_pop(L, 1);
	lua_getfield(L, -1, "faces");
	mesh_addluafaces(m, L, -1);
	lua_pop(L, 1);

	return m;
}
Exemplo n.º 10
0
int load_level(const char *filename)
{
	struct mesh *m;
	const char *err;
	int ret;

	DEBUG(1, "game: load_level(\"%s\")\n", filename);
	ret = luaL_dofile(L1, filename);
	if (ret)
	{
		err = lua_tostring(L1, -1);
		ERROR("error while loading level: %s", err);
		lua_pop(L1, 1);
		return 1;
	}
	lua_getfield(L1, -1, "vertices");
	if (!lua_istable(L1, -1))
	{
		ERROR("expected `vertices' field in Lua level data table");
		lua_pop(L1, 2);
		return 1;
	}
	clear_level();
	m = mesh_create();
	mesh_addluaverts(m, L1, -1);
	lua_pop(L1, 1);
	lua_getfield(L1, -1, "faces");
	if (!lua_istable(L1, -1))
	{
		mesh_destroy(m);
		ERROR("expected `faces' field in Lua level data table");
		return 1;
	}
	mesh_addluafaces(m, L1, -1);
	lua_pop(L1, 1);
	lua_setglobal(L1, "level");
	level = model_create(m);
	/* m is no longer needed. */
	mesh_destroy(m);
	gfx_prepmodel(level);
	gfx->set_level(level);

	return 0;
}
Exemplo n.º 11
0
struct model *model_create(const struct mesh *data)
{
	struct model *m;

	m = CALLOC1(struct model);
	if (data)
	{
		DEBUG(3, "model_create(%p) = %p\n", data, m);
		DEBUG(2, "Created new model\n");
		m->ngroups = 1;
		m->groups = mesh_create();
		mesh_copy(m->groups, data);
		m->offsets = CALLOC1(vector);
	}
	else
	{
		DEBUG(3, "model_create(NULL) = %p\n", m);
		DEBUG(2, "Created new empty model\n");
	}

	return m;
}
Exemplo n.º 12
0
object_t *
object_get_fs_quad(void)
{
	vbuf_fmt_t format = 0;
	mesh_t *mesh;
	object_t *object;
	float verts[] = {
		-1.0, -1.0, 0.0, 1.0,
		1.0, -1.0, 0.0, 1.0,
		1.0, 1.0, 0.0, 1.0,
		-1.0, 1.0, 0.0, 1.0,
	};
	uint16_t elems[] = { 0, 1, 2, 3 };

	vbuf_fmt_add(&format, "position", 4, GL_FLOAT);

	mesh = mesh_create(4, verts, 4, elems, format, GL_TRIANGLE_FAN);
	object = object_create(NULL);
	object_set_mesh(object, mesh);
	mesh_ungrab(mesh);

	return object;
}
Exemplo n.º 13
0
/** setup fresh libworker struct */
static struct libworker*
libworker_setup(struct ub_ctx* ctx, int is_bg, struct ub_event_base* eb)
{
	unsigned int seed;
	struct libworker* w = (struct libworker*)calloc(1, sizeof(*w));
	struct config_file* cfg = ctx->env->cfg;
	int* ports;
	int numports;
	if(!w) return NULL;
	w->is_bg = is_bg;
	w->ctx = ctx;
	w->env = (struct module_env*)malloc(sizeof(*w->env));
	if(!w->env) {
		free(w);
		return NULL;
	}
	*w->env = *ctx->env;
	w->env->alloc = context_obtain_alloc(ctx, !w->is_bg || w->is_bg_thread);
	if(!w->env->alloc) {
		libworker_delete(w);
		return NULL;
	}
	w->thread_num = w->env->alloc->thread_num;
	alloc_set_id_cleanup(w->env->alloc, &libworker_alloc_cleanup, w);
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_lock(&ctx->cfglock);
	}
	w->env->scratch = regional_create_custom(cfg->msg_buffer_size);
	w->env->scratch_buffer = sldns_buffer_new(cfg->msg_buffer_size);
	w->env->fwds = forwards_create();
	if(w->env->fwds && !forwards_apply_cfg(w->env->fwds, cfg)) { 
		forwards_delete(w->env->fwds);
		w->env->fwds = NULL;
	}
	w->env->hints = hints_create();
	if(w->env->hints && !hints_apply_cfg(w->env->hints, cfg)) { 
		hints_delete(w->env->hints);
		w->env->hints = NULL;
	}
	if(cfg->ssl_upstream) {
		w->sslctx = connect_sslctx_create(NULL, NULL,
			cfg->tls_cert_bundle);
		if(!w->sslctx) {
			/* to make the setup fail after unlock */
			hints_delete(w->env->hints);
			w->env->hints = NULL;
		}
	}
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_unlock(&ctx->cfglock);
	}
	if(!w->env->scratch || !w->env->scratch_buffer || !w->env->fwds ||
		!w->env->hints) {
		libworker_delete(w);
		return NULL;
	}
	w->env->worker = (struct worker*)w;
	w->env->probe_timer = NULL;
	seed = (unsigned int)time(NULL) ^ (unsigned int)getpid() ^
		(((unsigned int)w->thread_num)<<17);
	seed ^= (unsigned int)w->env->alloc->next_id;
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_lock(&ctx->cfglock);
	}
	if(!(w->env->rnd = ub_initstate(seed, ctx->seed_rnd))) {
		if(!w->is_bg || w->is_bg_thread) {
			lock_basic_unlock(&ctx->cfglock);
		}
		seed = 0;
		libworker_delete(w);
		return NULL;
	}
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_unlock(&ctx->cfglock);
	}
	if(1) {
		/* primitive lockout for threading: if it overwrites another
		 * thread it is like wiping the cache (which is likely empty
		 * at the start) */
		/* note we are holding the ctx lock in normal threaded
		 * cases so that is solved properly, it is only for many ctx
		 * in different threads that this may clash */
		static int done_raninit = 0;
		if(!done_raninit) {
			done_raninit = 1;
			hash_set_raninit((uint32_t)ub_random(w->env->rnd));
		}
	}
	seed = 0;

	if(eb)
		w->base = comm_base_create_event(eb);
	else	w->base = comm_base_create(0);
	if(!w->base) {
		libworker_delete(w);
		return NULL;
	}
	w->env->worker_base = w->base;
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_lock(&ctx->cfglock);
	}
	numports = cfg_condense_ports(cfg, &ports);
	if(numports == 0) {
		int locked = !w->is_bg || w->is_bg_thread;
		libworker_delete(w);
		if(locked) {
			lock_basic_unlock(&ctx->cfglock);
		}
		return NULL;
	}
	w->back = outside_network_create(w->base, cfg->msg_buffer_size,
		(size_t)cfg->outgoing_num_ports, cfg->out_ifs,
		cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6, 
		cfg->do_tcp?cfg->outgoing_num_tcp:0,
		w->env->infra_cache, w->env->rnd, cfg->use_caps_bits_for_id,
		ports, numports, cfg->unwanted_threshold,
		cfg->outgoing_tcp_mss, &libworker_alloc_cleanup, w,
		cfg->do_udp || cfg->udp_upstream_without_downstream, w->sslctx,
		cfg->delay_close, NULL);
	w->env->outnet = w->back;
	if(!w->is_bg || w->is_bg_thread) {
		lock_basic_unlock(&ctx->cfglock);
	}
	free(ports);
	if(!w->back) {
		libworker_delete(w);
		return NULL;
	}
	w->env->mesh = mesh_create(&ctx->mods, w->env);
	if(!w->env->mesh) {
		libworker_delete(w);
		return NULL;
	}
	w->env->send_query = &libworker_send_query;
	w->env->detach_subs = &mesh_detach_subs;
	w->env->attach_sub = &mesh_attach_sub;
	w->env->add_sub = &mesh_add_sub;
	w->env->kill_sub = &mesh_state_delete;
	w->env->detect_cycle = &mesh_detect_cycle;
	comm_base_timept(w->base, &w->env->now, &w->env->now_tv);
	return w;
}
Exemplo n.º 14
0
RID VisualServer::_make_test_cube() {

	DVector<Vector3> vertices;
	DVector<Vector3> normals;
	DVector<float> tangents;	
	DVector<Vector3> uvs;
							
	int vtx_idx=0;
#define ADD_VTX(m_idx);\
	vertices.push_back( face_points[m_idx] );\
	normals.push_back( normal_points[m_idx] );\
	tangents.push_back( normal_points[m_idx][1] );\
	tangents.push_back( normal_points[m_idx][2] );\
	tangents.push_back( normal_points[m_idx][0] );\
	tangents.push_back( 1.0 );\
	uvs.push_back( Vector3(uv_points[m_idx*2+0],uv_points[m_idx*2+1],0) );\
	vtx_idx++;\

	for (int i=0;i<6;i++) {

	
		Vector3 face_points[4];
		Vector3 normal_points[4];
		float uv_points[8]={0,0,0,1,1,1,1,0};
	
		for (int j=0;j<4;j++) {
		
			float v[3];
			v[0]=1.0;
			v[1]=1-2*((j>>1)&1);
			v[2]=v[1]*(1-2*(j&1));
		
			for (int k=0;k<3;k++) {
			
				if (i<3)
					face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
				else
					face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
			}
			normal_points[j]=Vector3();
			normal_points[j][i%3]=(i>=3?-1:1);
		}

	//tri 1
		ADD_VTX(0);
		ADD_VTX(1);
		ADD_VTX(2);
	//tri 2
		ADD_VTX(2);
		ADD_VTX(3);
		ADD_VTX(0);

	}

	RID test_cube = mesh_create();

	Array d;
	d.resize(VS::ARRAY_MAX);
	d[VisualServer::ARRAY_NORMAL]= normals ;
	d[VisualServer::ARRAY_TANGENT]= tangents ;
	d[VisualServer::ARRAY_TEX_UV]= uvs ;
	d[VisualServer::ARRAY_VERTEX]= vertices ;

	DVector<int> indices;
	indices.resize(vertices.size());
	for(int i=0;i<vertices.size();i++)
		indices.set(i,i);
	d[VisualServer::ARRAY_INDEX]=indices;

	mesh_add_surface( test_cube, PRIMITIVE_TRIANGLES,d );
	

	RID material = fixed_material_create();
	//material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
	fixed_material_set_texture( material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
	fixed_material_set_param( material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
	fixed_material_set_param( material, FIXED_MATERIAL_PARAM_EMISSION, Vector3(0.2,0.2,0.2) );

	fixed_material_set_param( material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
	fixed_material_set_param( material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );

	mesh_surface_set_material(test_cube, 0, material );
	
	return test_cube;
}
Exemplo n.º 15
0
int main(int argc, char ** argv)
{
    int num_errs = 0;

    hid_t fid, mid;

    char root_file[] = FILE;
    char meshname[] = MESH_NAME1;
    tmesh_t mesh_type = UNSTRUCTURED_MESH;
    telem_t elem_type = HEX_ELEM;
    int elem_order    = HEX_ELEM_ORDER;

    double *coordinates[DIM];

    int exists;
    int nmesh;
    char **meshnames;
    int i,*size;



    if ( DANU_RETURN_FAIL(output_file_create(root_file,&fid)) ) {
        DANU_ERROR_MESS("Failed to create the output file");
        num_errs++;
        goto EXIT_NOW;
    }


    /* Create a mesh */
    if ( DANU_RETURN_FAIL(mesh_create(fid,meshname,DIM,mesh_type,elem_type)) ) {
        DANU_ERROR_MESS("Failed to create the mesh group");
        num_errs++;
        goto EXIT_NOW;
    }

    /* Query the existence of the mesh */
    if ( DANU_RETURN_FAIL(mesh_exists(fid,meshname,&exists) ) ) {
        DANU_ERROR_MESS("Failed to query mesh");
        num_errs++;
        goto EXIT_NOW;
    }

    if ( exists ) {
        printf("Mesh existence query successful\n");
    }

    /* Query a mesh that does not exist */
    if ( DANU_RETURN_FAIL(mesh_exists(fid,"DUHMesh",&exists) ) ) {
        DANU_ERROR_MESS("Failed to query fake mesh");
        num_errs++;
        goto EXIT_NOW;
    }

    if ( ! exists ) {
        printf("Query of fake mesh passed\n");
    }

    /* Create another mesh */
    sprintf(meshname,MESH_NAME2);
    mesh_type = STRUCTURED_MESH;
    elem_type = HEX_ELEM;
    if ( DANU_RETURN_FAIL(mesh_create(fid,meshname,DIM,mesh_type,elem_type)) ) {
        DANU_ERROR_MESS("Failed to create the second mesh group");
        num_errs++;
        goto EXIT_NOW;
    }

    /* Count the number of meshes */
    if ( DANU_RETURN_FAIL(mesh_count(fid,&nmesh) ) ) {
        DANU_ERROR_MESS("Failed to count meshes");
        num_errs++;
        goto EXIT_NOW;
    }


    printf("Found %d meshes in %s\n", nmesh, root_file);

    /* Now get the names */
    meshnames = DANU_MALLOC(char *, nmesh);
    size      = DANU_MALLOC(int,nmesh);
    for(i=0;i<nmesh;i++) {
        size[i] = 64;
        meshnames[i] = DANU_MALLOC(char, size[i]);
    }

    if ( DANU_RETURN_FAIL(mesh_list(fid,nmesh,size,meshnames) ) ) {
        DANU_ERROR_MESS("Failed to get mesh list");
        num_errs++;
        goto EXIT_NOW;
    }

    DANU_FREE(size);
    for(i=0;i<nmesh;i++) {
        printf("\t-->%s\n",meshnames[i]);
        DANU_FREE(meshnames[i]);
    }
    DANU_FREE(meshnames);
       

    danu_file_close(fid);

    goto EXIT_NOW;


EXIT_NOW:
    printf("Found %d errors\n",num_errs);
    return num_errs;

}