Ejemplo n.º 1
0
ArchiveEntryFile::~ArchiveEntryFile()
{
    DENG2_GUARD(this);

    DENG2_FOR_AUDIENCE2(Deletion, i) i->fileBeingDeleted(*this);
    audienceForDeletion().clear();
    
    deindex();
}
Ejemplo n.º 2
0
void SurfaceTool::generate_tangents() {

	ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_TEX_UV));
	ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_NORMAL));

	bool indexed = index_array.size() > 0;
	if (indexed)
		deindex();

	SMikkTSpaceInterface mkif;
	mkif.m_getNormal = mikktGetNormal;
	mkif.m_getNumFaces = mikktGetNumFaces;
	mkif.m_getNumVerticesOfFace = mikktGetNumVerticesOfFace;
	mkif.m_getPosition = mikktGetPosition;
	mkif.m_getTexCoord = mikktGetTexCoord;
	mkif.m_setTSpace = mikktSetTSpaceDefault;
	mkif.m_setTSpaceBasic = NULL;

	SMikkTSpaceContext msc;
	msc.m_pInterface = &mkif;

	Vector<List<Vertex>::Element *> vtx;
	vtx.resize(vertex_array.size());
	int idx = 0;
	for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) {
		vtx.write[idx++] = E;
		E->get().binormal = Vector3();
		E->get().tangent = Vector3();
	}
	msc.m_pUserData = &vtx;

	bool res = genTangSpaceDefault(&msc);

	ERR_FAIL_COND(!res);
	format |= Mesh::ARRAY_FORMAT_TANGENT;

	if (indexed) {
		index();
	}
}
Ejemplo n.º 3
0
Archivo: models.c Proyecto: yui0/catgl
// create a cube model that looks like a wavefront model, 
MODEL_T cube_wavefront()
{
	static const float qv[] = {
		-0.5f, -0.5f,  0.5f,
		-0.5f, -0.5f, -0.5f,
		 0.5f, -0.5f, -0.5f,
		 0.5f, -0.5f,  0.5f,
		-0.5f,  0.5f,  0.5f,
		 0.5f,  0.5f,  0.5f,
		 0.5f,  0.5f, -0.5f,
		-0.5f,  0.5f, -0.5f,
	};

	static const float qn[] = {
		 0.0f, -1.0f, -0.0f,
		 0.0f,  1.0f, -0.0f,
		 0.0f,  0.0f,  1.0f,
		 1.0f,  0.0f, -0.0f,
		 0.0f,  0.0f, -1.0f,
		-1.0f,  0.0f, -0.0f,
	};

	static const float qt[] = {
		1.0f, 0.0f,
		1.0f, 1.0f,
		0.0f, 1.0f,
		0.0f, 0.0f,
	};
   
	static const unsigned short qf[] = {
		1,1,1, 2,2,1, 3,3,1,
		3,3,1, 4,4,1, 1,1,1,
		5,4,2, 6,1,2, 7,2,2,
		7,2,2, 8,3,2, 5,4,2,
		1,4,3, 4,1,3, 6,2,3,
		6,2,3, 5,3,3, 1,4,3,
		4,4,4, 3,1,4, 7,2,4,
		7,2,4, 6,3,4, 4,4,4,
		3,4,5, 2,1,5, 8,2,5,
		8,2,5, 7,3,5, 3,4,5,
		2,4,6, 1,1,6, 5,2,6,
		5,2,6, 8,3,6, 2,4,6,
	};
	WAVEFRONT_MODEL_T *model = malloc(sizeof *model);
	if (model) {
		WAVEFRONT_MATERIAL_T *mat = model->material;
		float *temp;
		const int offset = 0;
		memset(model, 0, sizeof *model);

		temp = allocbuffer(3*MAX_VERTICES*sizeof *temp);
		//mat->numverts = countof(qf)/3;
		mat->numverts = sizeof(qf)/sizeof(short)/3;
		// vertex, texture, normal
		deindex(temp, qv, qf+3*offset+0, 3, mat->numverts);
		create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_VERTEX, 3 * mat->numverts * sizeof *qv, temp); // 3

		deindex(temp, qt, qf+3*offset+1, 2, mat->numverts);
		create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_TEXTURE, 2 * mat->numverts * sizeof *qt, temp); // 2

		deindex(temp, qn, qf+3*offset+2, 3, mat->numverts);
		create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_NORMAL, 3 * mat->numverts * sizeof *qn, temp); // 3

		freebuffer(temp);
		model->num_materials = 1;
	}
	return (MODEL_T)model;
}
Ejemplo n.º 4
0
Archivo: models.c Proyecto: yui0/catgl
MODEL_T load_wavefront(const char *modelname, const char *texturename)
{
   WAVEFRONT_MODEL_T *model;
   float *temp, *qv, *qt, *qn;
   unsigned short *qf;
   int i;
   int numverts = 0, offset = 0;
   struct wavefront_model_loading_s *m;
   int s=-1;
   char modelname_obj[128];
   model = malloc(sizeof *model);
   if (!model || !modelname) return NULL;
   memset (model, 0, sizeof *model);
   model->texture = 0; //load_texture(texturename);
   m = allocbuffer(sizeof *m + 
      sizeof(float)*(3+2+3)*MAX_VERTICES +    // 3 vertices + 2 textures + 3 normals
      sizeof(unsigned short)*3*MAX_VERTICES); //each face has 9 vertices
   if (!m) return 0;

   if (strlen(modelname) + 5 <= sizeof modelname_obj) {
      strcpy(modelname_obj, modelname);
      strcat(modelname_obj, ".dat");
      s = load_wavefront_dat(modelname_obj, model, m);
   }
   if (s==0) {}
   else if (strncmp(modelname + strlen(modelname) - 4, ".obj", 4) == 0) {
      #ifdef DUMP_OBJ_DAT
      int size;
      FILE *fp;
      #endif
      s = load_wavefront_obj(modelname, model, m);
      #ifdef DUMP_OBJ_DAT
      strcpy(modelname_obj, modelname);
      strcat(modelname_obj, ".dat");
      size = sizeof *m + 
         sizeof(float)*(3*m->numv+2*m->numt+3*m->numn) +  // 3 vertices + 2 textures + 3 normals
         sizeof(unsigned short)*3*m->numf;                //each face has 9 vertices
      fp = host_file_open(modelname_obj, "w");
      fwrite(m, 1, size, fp);
      fclose(fp);
      #endif
   } else if (strncmp(modelname + strlen(modelname) - 4, ".dat", 4) == 0) {
      s = load_wavefront_dat(modelname, model, m);
   }
   if (s != 0) return 0;

   qv = (float *)(m->data);
   qt = (float *)(m->data + m->numv);
   qn = (float *)(m->data + m->numv + m->numt);
   qf = (unsigned short *)(m->data + m->numv + m->numt + m->numn);

   numverts = m->numf/3;
   vc_assert(numverts <= MAX_VERTICES);

   temp = allocbuffer(3*numverts*sizeof *temp);
   for (i=0; i<m->num_materials; i++) {
      WAVEFRONT_MATERIAL_T *mat = model->material + i;
      mat->numverts = i < m->num_materials-1 ? m->material_index[i+1]-m->material_index[i] : numverts - m->material_index[i];
      // vertex, texture, normal
      deindex(temp, qv, qf+3*offset+0, 3, mat->numverts);
      create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_VERTEX, 3 * mat->numverts * sizeof *qv, temp); // 3
   
      deindex(temp, qt, qf+3*offset+1, 2, mat->numverts);
      create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_TEXTURE, 2 * mat->numverts * sizeof *qt, temp); // 2
   
      deindex(temp, qn, qf+3*offset+2, 3, mat->numverts);
      create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_NORMAL, 3 * mat->numverts * sizeof *qn, temp); // 3
      offset += mat->numverts;
      mat->texture = model->texture;
   }
   model->num_materials = m->num_materials;
   vc_assert(offset == numverts);
   freebuffer(temp);
   freebuffer(m);
   return (MODEL_T)model;
}
Ejemplo n.º 5
0
ArchiveFolder::~ArchiveFolder()
{
    DENG2_FOR_AUDIENCE2(Deletion, i) i->fileBeingDeleted(*this);
    audienceForDeletion().clear();
    deindex();
}
Ejemplo n.º 6
0
void SurfaceTool::generate_normals(bool p_flip) {

	ERR_FAIL_COND(primitive != Mesh::PRIMITIVE_TRIANGLES);

	bool was_indexed = index_array.size();

	deindex();

	HashMap<Vertex, Vector3, VertexHasher> vertex_hash;

	int count = 0;
	bool smooth = false;
	if (smooth_groups.has(0))
		smooth = smooth_groups[0];

	List<Vertex>::Element *B = vertex_array.front();
	for (List<Vertex>::Element *E = B; E;) {

		List<Vertex>::Element *v[3];
		v[0] = E;
		v[1] = v[0]->next();
		ERR_FAIL_COND(!v[1]);
		v[2] = v[1]->next();
		ERR_FAIL_COND(!v[2]);
		E = v[2]->next();

		Vector3 normal;
		if (!p_flip)
			normal = Plane(v[0]->get().vertex, v[1]->get().vertex, v[2]->get().vertex).normal;
		else
			normal = Plane(v[2]->get().vertex, v[1]->get().vertex, v[0]->get().vertex).normal;

		if (smooth) {

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

				Vector3 *lv = vertex_hash.getptr(v[i]->get());
				if (!lv) {
					vertex_hash.set(v[i]->get(), normal);
				} else {
					(*lv) += normal;
				}
			}
		} else {

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

				v[i]->get().normal = normal;
			}
		}
		count += 3;

		if (smooth_groups.has(count) || !E) {

			if (vertex_hash.size()) {

				while (B != E) {

					Vector3 *lv = vertex_hash.getptr(B->get());
					if (lv) {
						B->get().normal = lv->normalized();
					}

					B = B->next();
				}

			} else {
				B = E;
			}

			vertex_hash.clear();
			if (E) {
				smooth = smooth_groups[count];
			}
		}
	}

	format |= Mesh::ARRAY_FORMAT_NORMAL;

	if (was_indexed) {
		index();
		smooth_groups.clear();
	}
}