Пример #1
0
Mesh* TriPatchObject::GetRenderMesh(TimeValue t, INode *inode, View& view, BOOL& needDelete) {
	UpdatePatchMesh(t);
	TessApprox tess = patch.GetProdTess();
	if (tess.type == TESS_SET) {
		needDelete = FALSE;
		patch.InvalidateMesh(); // force this...
		// temporarlily set the view tess to prod tess
		TessApprox tempTess = patch.GetViewTess();
		patch.SetViewTess(tess);
		PrepareMesh(t);
		patch.SetViewTess(tempTess);
		return &patch.GetMesh();
	} else {
		Mesh *nmesh = new Mesh/*(mesh)*/;
		Matrix3 otm = inode->GetObjectTM(t);

		Box3 bbox;
		GetDeformBBox(t, bbox);
		tess.merge *= Length(bbox.Width())/1000.0f;
		TessApprox disp = patch.GetDispTess();
		disp.merge *= Length(bbox.Width())/1000.0f;

		GetGTessFunction();
		(*psGTessFunc)(&patch, BEZIER_PATCH, &otm, nmesh, &tess, &disp, &view, inode->GetMtl(), FALSE, FALSE);
		if (tess.merge > 0.0f && patch.GetProdTessWeld())
			WeldMesh(nmesh, tess.merge);
		needDelete = TRUE;
		return nmesh;
	}
}
Пример #2
0
int csMeshList::Add (iMeshWrapper *obj)
{
  PrepareMesh (obj);
  const char* name = obj->QueryObject ()->GetName ();
  CS::Threading::ScopedWriteLock lock(meshLock);
  if (name)
    meshes_hash.Put (name, obj);
  obj->QueryObject ()->AddNameChangeListener (listener);
  return (int)list.Push (obj);
}
Пример #3
0
void csMeshList::AddBatch (csRef<iMeshLoaderIterator> itr)
{
  CS::Threading::ScopedWriteLock lock(meshLock);
  while(itr->HasNext())
  {
    iMeshWrapper* obj = itr->Next();
    PrepareMesh (obj);
    const char* name = obj->QueryObject ()->GetName ();
    if (name)
      meshes_hash.Put (name, obj);
    obj->QueryObject ()->AddNameChangeListener (listener);
    list.Push (obj);
  }
}
Пример #4
0
Object* TriPatchObject::ConvertToType(TimeValue t, Class_ID obtype) {
	if(obtype == patchObjectClassID || obtype == defObjectClassID || obtype == mapObjectClassID) {
		PatchObject *ob;
		UpdatePatchMesh(t);
		ob = new PatchObject();	
		ob->patch = patch;
		ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t));
		ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t));
		return ob;
		}

	if(obtype == triObjectClassID) {
		TriObject *ob = CreateNewTriObject();
		PrepareMesh(t);
		ob->GetMesh() = patch.GetMesh();
		ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t));
		ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t));
		return ob;
		}
#ifndef NO_NURBS
	if (obtype==EDITABLE_SURF_CLASS_ID) {
		PatchObject *pob;
		UpdatePatchMesh(t);
		pob = new PatchObject();	
		pob->patch = patch;
		Object *ob = BuildEMObjectFromPatchObject(pob);
		delete pob;
		ob->SetChannelValidity(TOPO_CHAN_NUM, ObjectValidity(t));
		ob->SetChannelValidity(GEOM_CHAN_NUM, ObjectValidity(t));
		return ob;
		}
#endif
	if (Object::CanConvertToType (obtype)) return Object::ConvertToType (t, obtype);

	if (CanConvertPatchObject (obtype)) {
		PatchObject *ob;
		UpdatePatchMesh(t);
		ob = new PatchObject();	
		ob->patch = patch;
		ob->SetChannelValidity(TOPO_CHAN_NUM,ObjectValidity(t));
		ob->SetChannelValidity(GEOM_CHAN_NUM,ObjectValidity(t));
		Object *ret = ob->ConvertToType (t, obtype);
		ob->DeleteThis ();
		return ret;
		}
	return NULL;
	}
Пример #5
0
int TriPatchObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags) {
	Matrix3 tm;
	GraphicsWindow *gw = vpt->getGW();
	gw->setTransform(inode->GetObjectTM(t));
	UpdatePatchMesh(t);
	if(!(gw->getRndMode() & GW_BOX_MODE)) {
		PrepareMesh(t);
		Mesh& mesh = patch.GetMesh();
		if(mesh.getNumVerts()) {
			mesh.render( gw, inode->Mtls(),
				(flags&USE_DAMAGE_RECT) ? &vpt->GetDammageRect() : NULL, 
				COMP_ALL | (inode->Selected()?COMP_OBJSELECTED:0), inode->NumMtls());	
			}
		}
	patch.render( gw, inode->Mtls(),
		(flags&USE_DAMAGE_RECT) ? &vpt->GetDammageRect() : NULL, 
		COMP_ALL | (inode->Selected()?COMP_OBJSELECTED:0), inode->NumMtls());	
	return(0);
	}
Пример #6
0
void Draw_model(struct md5_model_t md5file, struct md5_joint_t *skeleton)
{
	int i = 0;
	glColor3f (1.0f, 1.0f, 1.0f);

	glEnableClientState (GL_VERTEX_ARRAY);
	glEnableClientState (GL_NORMAL_ARRAY);
	glEnableClientState (GL_TEXTURE_COORD_ARRAY);
	
//	glRotatef (-90.f, 1.0f, .0f, .0f);

	for (i = 0; i < md5file.num_meshes; ++i)
	{
		PrepareMesh (&md5file.meshes[i], skeleton);

		glVertexPointer (3, GL_FLOAT, 0, vertexArray);
		glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
		glNormalPointer(GL_FLOAT, 0, normals);
	
		glDrawElements (GL_TRIANGLES, md5file.meshes[i].num_tris * 3,
						GL_UNSIGNED_INT, vertexIndices);

/*		glBegin(GL_LINES);
		for(int j = 0; j < md5file.meshes[i].num_tris*3; ++j)
		{
			vec3_t *v = &vertexArray[vertexIndices[j]];
			vec3_t *n = &normals[vertexIndices[j]];
			glTexCoord1f(0); glVertex3f((*v)[0], (*v)[1], (*v)[2]);
			glTexCoord1f(1); glVertex3f((*v)[0]+(*n)[0], (*v)[1]+(*n)[1], (*v)[2]+(*n)[2]);
		}
		glEnd();
*/	}

	glDisableClientState (GL_TEXTURE_COORD_ARRAY);
	glDisableClientState (GL_NORMAL_ARRAY);
	glDisableClientState (GL_VERTEX_ARRAY);
}
Пример #7
0
ObjectHandle TriPatchObject::CreateTriObjRep(TimeValue t) {
	TriObject *tri = CreateNewTriObject();
	PrepareMesh(t);	// Turn it into a mesh
	tri->GetMesh() = patch.GetMesh();	// Place it into the TriObject
	return(ObjectHandle(tri));
	}
Пример #8
0
// From GeomObject
int TriPatchObject::IntersectRay(TimeValue t, Ray& r, float& at, Point3& norm) {
	PrepareMesh(t);	// Turn it into a mesh
	return patch.IntersectRay(r, at, norm);
	}
Пример #9
0
void md5_render(md5_model_t md5)
{
	const struct md5_mesh *mesh = md5->mesh;
	vector_t org, rot;
	unsigned int i;

	if ( !AllocVertexArrays(mesh) )
		return;

	v_copy(org, md5->ent.origin);
	v_copy(rot, md5->ent.angles);

	if (md5->anim) {
		/* TODO: interpolate motion */
		Animate(md5);
	}

	glTranslatef(org[X], org[Y], org[Z]);
	glRotatef(rot[X] - 90, 1, 0, 0);
	glRotatef(rot[Y], 0, 1, 0);
	glRotatef(rot[Z], 0, 0, 1);

	glCullFace(GL_FRONT);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	//glEnableClientState(GL_VERTEX_ATTRIB_ARRAY);
	//glEnableVertexAttribArray();
	glEnableClientState(GL_NORMAL_ARRAY);

	glUseProgram(prog);

	glUniform1iARB(u_Texture,0);
	glUniform1iARB(u_normalTexture,1);

	/* Draw each mesh of the model */
	for (i = 0; i < mesh->num_meshes; ++i) {
		PrepareMesh(&mesh->meshes[i], md5->skeleton);
		glActiveTextureARB(GL_TEXTURE0);
		tex_bind(mesh->meshes[i].skin);
		glActiveTextureARB(GL_TEXTURE1);
		tex_bind(mesh->meshes[i].normalmap);
		glActiveTextureARB(GL_TEXTURE0);

		glVertexPointer(3, GL_FLOAT, 0, vertexArray);
		glNormalPointer(GL_FLOAT, 0, normalArray);
		glTexCoordPointer(2, GL_FLOAT, 0, texArray);
//		glVertexAttribPointerARB(tangent_attrib, 3, GL_FLOAT, GL_FALSE, 0, tangentArray);

		glDrawElements(GL_TRIANGLES, mesh->meshes[i].num_tris * 3,
				GL_UNSIGNED_INT, vertexIndices);
	}

	glUseProgram(0);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#if 0
	/* Draw skeleton */
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_CULL_FACE);
	DrawSkeleton(skeleton, md5file.num_joints);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_TEXTURE_2D);
#endif
	glCullFace(GL_BACK);
}