/*
================
ReadGeoMObject
================
*/
static void ReadGeoMObject( Lexer &lexer, ListEx<aseMesh> &myMeshList ) {
	lexer.ExpectToken("{");
	const char *p;
	const Token *token;
	String name;
	while ( (token = lexer.ReadToken()) != OG_NULL ) {
		p = token->GetString();
		if ( !p || !*p )
			continue;
		if ( String::Icmp( p, "}" ) == 0 ) 
			return;
		if ( String::Icmp( p, "*" ) != 0 ) 
			lexer.Error( Format("expected *, got '$*'") << p );

		if ( lexer.CheckToken( "NODE_NAME" ) )
			name = lexer.ReadString();
		else if ( lexer.CheckToken( "MESH" ) ) {
			aseMesh *inMesh = &myMeshList.Alloc();
			inMesh->name = name;
			ReadMesh( lexer, inMesh );
		}
		else if ( !SkipUnknown(lexer) )
			break;
	}
}
Exemple #2
0
int AseFile::ReadGeomObject()
{
	char temp[255];
	zASE_Object	obj;
	memset( &obj, 0, sizeof( zASE_Object));
	obj.rotmatrix[0].set(1,0,0);
	obj.rotmatrix[1].set(0,1,0);
	obj.rotmatrix[2].set(0,0,1);
	do
	{
		if( !fgets(temp, 255, file) )return 0;
	
		if( EqualString( temp, "*NODE_NAME ") )			{ CopyString( temp, obj.name );	continue; }
		else if( EqualString( temp, "*NODE_TM ") )		{ if(!ReadNode_TM( obj ))return 0;continue; }
		else if( EqualString( temp, "*MESH ") )				
		{ if( !ReadMesh(obj) )return 0; else continue; }
	//	else if( EqualString( temp, "*PROP_MOTIONBLUR ") )			{ continue; }		// 0,1
	//	else if( EqualString( temp, "*PROP_CASTSHADOW ") )			{ continue; }		// 0,1
	//	else if( EqualString( temp, "*PROP_RECVSHADOW ") )			{ continue; }		// 0,1
	//	else if( EqualString( temp, "*WIREFRAME_COLOR ") )			{ continue; }		// 3 x float
		else if( EqualString( temp, "*MATERIAL_REF ") )			{ obj.materialID = atoi(temp); continue; }
		else ReadUnknown( temp);

	}while(!FindBracketClose( temp));		// while temp not contain '}'
	objects.push_back( obj);
	return 1;
}
void XFileLoader::Load(string filename)
{	
	m_nodes.clear();
	m_meshes.clear();
	m_materials.clear();
	m_materialLookup.clear();
	ifstream s;
	s.open(filename);
	if (!s)
		throw "Could not open file!";
	CheckHeader(s);
	int prevSybling = -1;
	while (true)
	{
		XFileToken token = XFileToken::NextToken(s);
		if (token.m_type == XFileToken::Identifier)
		{
			if (token.m_content == "Frame")
				prevSybling = ReadSceneNode(s, prevSybling);
			else if (token.m_content == "Mesh")
				ReadMesh(s);
			else
				SkipDataObject(s);
		}
		else if (token.m_type == XFileToken::LeftBrace)
			SkipDataReference(s);
		else if (token.m_type == XFileToken::None)
			break;
        else
            THROW_EXCEPTION_T("Parsing error", ParsingException);
	}
	s.close();
}
Exemple #4
0
int MREAData::Read(char* fstr)
{
	FILE* fp = NULL;
	fp=fopen(fstr, "r+b");

	// invalidate bounding box
	minBounds.X = FLT_MAX;
	minBounds.Y = FLT_MAX;
	minBounds.Z = FLT_MAX;

	maxBounds.X = FLT_MIN;
	maxBounds.Y = FLT_MIN;
	maxBounds.Z = FLT_MIN;

	m_sectionIndex = 0;

	if (fp)
	{
		fseek(fp, 0, SEEK_SET); //Make sure we're at the beginning of the MREA

		ReadHeader(fp);

		m_materialInfo.ReadMaterialDataMP1_2(fp, m_sectionIndex, m_sectionSizes);

		++m_sectionIndex;

		m_meshes.resize(m_fileHeader.meshCount);

		for (u32 iMesh = 0; iMesh < m_fileHeader.meshCount; ++iMesh)
		{
			m_sectionIndex = ReadMesh(fp, iMesh, m_sectionIndex);
		}

		fclose(fp);

		ReadTextures();

		center.X = 0;//(maxBounds.X + minBounds.X) * 0.5f;
		center.Y = 0;//(maxBounds.Y + minBounds.Y) * 0.5f;
		center.Z = 0;//(maxBounds.Z + minBounds.Z) * 0.5f;

		tex dir;
		dir.X = 0;(maxBounds.X - center.X);
		dir.Y = 0;(maxBounds.Y - center.Y);
		dir.Z = 0;(maxBounds.Z - center.Z);

		float distSq = ((dir.X * dir.X) + (dir.Y * dir.Y) + (dir.Z * dir.Z));
		float dist = sqrtf(distSq);
		float distCu = distSq * dist;

		xCamera = 0;center.X;
		yCamera = 0;center.Y;
		zCamera = 0;center.Z - (dist * 2.0f);
	}

	return m_sectionIndex;
}
Exemple #5
0
Mesh::Mesh(const string& file, int camNum/*=0*/)
{
#ifndef _EXEC_FAST
	printf("%s%s","Reading ",file.c_str());
#endif

	ifstream obj(file.c_str());

	if(!obj.is_open()) { printf("can not read the mesh file!\n"); return;}

	if(file.length() < 4)
		return;

	if(string(file.end() - 4, file.end()) == string(".off"))
		ReadOff(obj,camNum);     
	else if(string(file.end() - 5, file.end()) == string(".mesh"))
		ReadMesh(obj, camNum);
	else if(string(file.end() - 6, file.end()) == string(".dmesh"))
		ReadMesh(obj,camNum);
	else
		return;

	obj.close();

	int verts = int(vertices.size());
	if(verts == 0)
		return;

	for(int i = 0; i < (int)edges.size(); ++i)					//保证所有的顶点都是有效的
	{ 
		if(edges.at(i).vertex<0||edges.at(i).vertex>=verts)
		{
			vertices.clear(); 
			edges.clear(); 
			cout<<"error!"<<i<<endl;
			return;
		}
	}

	computeVertexNormals();
#ifndef _EXEC_FAST
	printf(" success!\n");
#endif
}
	//メッシュの作成
	void GameObject::CreateCustomMesh(){
		//頂点を作成するための配列
		vector<VertexPositionNormalTexture> vertices;
		vector<uint16_t> indices;
		ReadMesh(vertices, indices, m_Materials);
		//頂点バッファの作成(頂点は変更できない)
		VertexUtil::CreateVertexBuffer(m_VertexBuffer, vertices);
		//頂点数の設定
		m_NumVertices = static_cast<UINT>(vertices.size());
		//インデックスバッファの作成
		VertexUtil::CreateIndexBuffer(m_IndexBuffer, indices);
		//インデックス数の設定
		m_NumIndicis = static_cast<UINT>(indices.size());
	}
Exemple #7
0
/*************************************************************************
* Let the game begin
**************************************************************************/
main(int argc, char *argv[])
{
  int i, j, ne, nn, etype, numflag=0;
  idxtype *elmnts, *xadj, *adjncy;
  timer IOTmr, DUALTmr;
  char fileout[256], etypestr[4][5] = {"TRI", "TET", "HEX", "QUAD"};

  if (argc != 2) {
    printf("Usage: %s <meshfile>\n",argv[0]);
    exit(0);
  }

  cleartimer(IOTmr);
  cleartimer(DUALTmr);

  starttimer(IOTmr);
  elmnts = ReadMesh(argv[1], &ne, &nn, &etype);
  stoptimer(IOTmr);

  printf("**********************************************************************\n");
  printf("%s", METISTITLE);
  printf("Mesh Information ----------------------------------------------------\n");
  printf("  Name: %s, #Elements: %d, #Nodes: %d, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]);
  printf("Forming Dual Graph... -----------------------------------------------\n");

  xadj = idxmalloc(ne+1, "main: xadj");
  adjncy = idxmalloc(10*ne, "main: adjncy");

  starttimer(DUALTmr);
  METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, xadj, adjncy);
  stoptimer(DUALTmr);

  printf("  Dual Information: #Vertices: %d, #Edges: %d\n", ne, xadj[ne]/2);

  sprintf(fileout, "%s.dgraph", argv[1]);
  starttimer(IOTmr);
  WriteGraph(fileout, ne, xadj, adjncy);
  stoptimer(IOTmr);


  printf("\nTiming Information --------------------------------------------------\n");
  printf("  I/O:          \t\t %7.3f\n", gettimer(IOTmr));
  printf("  Dual Creation:\t\t %7.3f\n", gettimer(DUALTmr));
  printf("**********************************************************************\n");

  GKfree(&elmnts, &xadj, &adjncy, LTERM);

}
GLvoid NEHE37::InitGL(){
	
	char Line[255];	// Storage For 255 Characters
	float shaderData[32][3];	// Storage For The 96 Shader Values
	FILE *In = NULL;
	
	glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	glClearColor (0.7f, 0.7f, 0.7f, 0.0f);
	glClearDepth (1.0f);
	
	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
	glDepthFunc (GL_LESS);
	
	glShadeModel (GL_SMOOTH);
	glDisable (GL_LINE_SMOOTH);
	glEnable (GL_CULL_FACE);
	glDisable (GL_LIGHTING);
	
	In = fopen (Utils::getAbsoluteDir("NeheGL/model/Shader.txt"), "r");	// Open The Shader File
	
	if(In){
		for (int i = 0; i < 32; i++){
			if (feof (In))
				break;
			fgets (Line, 255, In);
			shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = atof (Line);
		}
		fclose (In);
	}
	else{
		cout<<"Fail to load shader!"<<endl;
	}
	
	glGenTextures (1, &shaderTexture[0]);
	glBindTexture (GL_TEXTURE_1D, shaderTexture[0]);
	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 32, 0, GL_RGB , GL_FLOAT, shaderData);
	lightAngle.X = 0.0f;
	lightAngle.Y = 0.0f;
	lightAngle.Z = 1.0f;
	Normalize (lightAngle);
	
	if(!ReadMesh ()){
		cout<<"Fail to load model!"<<endl;
	}
}
Exemple #9
0
bool ACAMTLoader::LoadFromFile( const CHAR* path, AMT_MODEL* outModel)
{
	// open the file
	mpFile = fopen( path, "rb" );
	if( !mpFile ) return false;

	ReadHeader(outModel);    
	ReadVertices(outModel);  
	ReadFaces(outModel);     
	ReadMesh(outModel);      
	ReadMaterials(outModel);
	ReadJoints(outModel);
	ReadAnimations(outModel);

	return CloseFile( true );
};
int XFileLoader::ReadSceneNode(istream& s, int prevSybling)
{
	int nodeIdx = m_nodes.size();
	m_nodes.push_back(SceneNode());
	if (prevSybling != -1)
		m_nodes[prevSybling].m_nextSybling = nodeIdx;
	XFileToken t = XFileToken::NextToken(s);
	if (t.m_type == XFileToken::Identifier)
	{
		m_nodes[nodeIdx].m_name = move(t.m_content);
		t = XFileToken::NextToken(s);
	}
    if (t.m_type != XFileToken::LeftBrace)
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	int prevChild = -1;
	while (true)
	{
		t = XFileToken::NextToken(s);
		if (t.m_type == XFileToken::Identifier)
		{
			if (t.m_content == "Frame")
			{
				int child = ReadSceneNode(s, prevChild);
				if (prevChild == -1)
					m_nodes[nodeIdx].m_firstChild = child;
				m_nodes[child].m_parent = nodeIdx;
				prevChild = child;
			}
			else if (t.m_content == "Mesh")
				m_nodes[nodeIdx].m_mesh = ReadMesh(s);
			else if (t.m_content == "FrameTransformMatrix")
				m_nodes[nodeIdx].m_localTransform = ReadFaceTransform(s);
			else
				SkipDataObject(s);
		}
		else if (t.m_type == XFileToken::UUID)
			continue;
		else if (t.m_type == XFileToken::LeftBrace)
			SkipDataReference(s);
		else if (t.m_type == XFileToken::RightBrace)
			break;
        else
            THROW_EXCEPTION_T("Parsing error", ParsingException);
	}
	return nodeIdx;
}
Exemple #11
0
void MeshLoaderB3D::ReadNode()
{
	//Joint* joint = new Joint;

	idStr str;
	readString(_file, str);
	PrintTree(str.c_str());

	idVec3 t;
	idVec3 s;
	_file->ReadVec3(t);
	_file->ReadVec3(s);
	idQuat r; 
	_file->ReadFloat(r.x);
	_file->ReadFloat(r.y);
	_file->ReadFloat(r.z);
	_file->ReadFloat(r.w);

	//joint->name = str;
	//joint->position = t;
	//joint->scale = s;
	//joint->rotation = r;

	while( CheckSize() ){
		idStr t = ReadChunk();
		if( t=="MESH" ){
			ReadMesh();
		}else if( t=="BONE" ){
			ReadBone();
		}else if( t=="ANIM" ){
			ReadAnim();
		}else if( t=="KEYS" ){
			ReadKey();
		}else if( t=="NODE" ){
			ReadNode();
			//Joint* child = ReadNode();
			//Sys_Printf("parent %s children %s\n", joint->name.c_str(), child->name.c_str());
			//joint->children.push_back(child);
			//child->parent = joint;
		}
		ExitChunk();
	}
}
Exemple #12
0
void prep_s2warpstereo(OPTIONS *ioptions) {
  _s2w_options = ioptions;
  _s2w_textureready = 0;
  _s2w_warpingactive = 1;
  _s2w_warpstereo_txt = -1;
  _s2w_warpstereo_w = _s2w_warpstereo_h = 0; 
  _s2w_meshfn = NULL;

  _s2w_meshfn = getenv("S2PLOT_MESHFILE");
  if (_s2w_meshfn) {
    if (!ReadMesh(_s2w_meshfn)) {
      _s2w_meshfn = NULL;
    }
  }

  if (!_s2w_meshfn) {
    _s2warn("(internal)", "/S2WPASSV*: no meshfile available");
  }
  _s2debug("(internal)", "/S2WPASSV* device support loaded");

}
Exemple #13
0
static void setup (FileList *f, Element_List **U){
  int i,k;
  Curve *curve;

  ReadParams  (f->rea.fp);

  //option_set("FAMOFF", 1);

  if((i=iparam("NORDER-req"))!=UNSET){
    iparam_set("LQUAD",i);
    iparam_set("MQUAD",i);
  }

  *U = ReadMesh(f->rea.fp, strtok(f->rea.name,"."));       /* Generate the list of elements */
  U[0]->Cat_mem();

  if(option("variable"))  ReadOrderFile   (strtok(f->rea.name,"."),*U);

  if(f->mesh.name) Get_Body(f->mesh.fp);

  return;
}
Exemple #14
0
    aiNode* ReadObject(aiScene* scene)
    {        
        ScopeGuard<aiNode> node(new aiNode());

        std::vector<unsigned long> meshIds;

        int id = std::atoi(xmlReader->getAttributeValue(D3MF::XmlTag::id.c_str()));
        std::string name(xmlReader->getAttributeValue(D3MF::XmlTag::name.c_str()));
        std::string type(xmlReader->getAttributeValue(D3MF::XmlTag::type.c_str()));

        node->mParent = scene->mRootNode;
        node->mName.Set(name);        

        unsigned long meshIdx = meshes.size();

        while(ReadToEndElement(D3MF::XmlTag::object))
        {
            if(xmlReader->getNodeName() == D3MF::XmlTag::mesh)
            {                
                auto mesh = ReadMesh();

                mesh->mName.Set(name);
                meshes.push_back(mesh);
                meshIds.push_back(meshIdx);
                meshIdx++;

            }
        }

        node->mNumMeshes = static_cast<unsigned int>(meshIds.size());

        node->mMeshes = new unsigned int[node->mNumMeshes];

        std::copy(meshIds.begin(), meshIds.end(), node->mMeshes);

        return node.dismiss();

    }
Joint* MeshLoaderB3D::ReadNode()
{
	Joint* joint = new Joint;

	lfStr str = _file->ReadString();
	PrintTree(str.c_str());

	Vec3 t = _file->ReadVec3();
	Vec3 s = _file->ReadVec3();
	Quat r = _file->ReadQuat();

	joint->name = str;
	joint->position = t;
	joint->scale = s;
	joint->rotation = r;

	while( CheckSize() ){
		lfStr t = ReadChunk();
		if( t=="MESH" ){
			ReadMesh();
		}else if( t=="BONE" ){
			ReadBone(joint);
		}else if( t=="ANIM" ){
			ReadAnim();
		}else if( t=="KEYS" ){
			ReadKey(joint);
		}else if( t=="NODE" ){
			Joint* child = ReadNode();
			//Sys_Printf("parent %s children %s\n", joint->name.c_str(), child->name.c_str());
			joint->children.push_back(child);
			child->parent = joint;
		}
		ExitChunk();
	}
	return joint;

}
Exemple #16
0
BOOL Initialize(void)
{
	int i;
	char Line[255];
	float shaderData[32][3];

	FILE *In	= NULL;

	glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glClearColor (0.7f, 0.7f, 0.7f, 0.0f);
	glClearDepth (1.0f);

	glEnable (GL_DEPTH_TEST);
	glDepthFunc (GL_LESS);

	glShadeModel (GL_SMOOTH);
	glDisable (GL_LINE_SMOOTH);

	glEnable (GL_CULL_FACE);

	glDisable (GL_LIGHTING);

	In = fopen ("Data/Shader.txt", "r");

	if (In)
	{
		for (i = 0; i < 32; i++)
		{
			if (feof (In))
				break;

			fgets (Line, 255, In);

			shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = (float)(atof (Line));
		}

		fclose (In);
	}
	else
	{
		printf("Error loading file Shader.txt: Initialize\n");
		return False;
	}
	glGenTextures (1, &shaderTexture[0]);

	glBindTexture (GL_TEXTURE_1D, shaderTexture[0]);

	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 32, 0, GL_RGB , GL_FLOAT, shaderData);

	lightAngle.X = 0.0f;
	lightAngle.Y = 0.0f;
	lightAngle.Z = 1.0f;

	Normalize (&lightAngle);

	return ReadMesh ();
}
Exemple #17
0
/*************************************************************************
* Let the game begin
**************************************************************************/
main(int argc, char *argv[])
{
  int i, j, ne, nn, etype, numflag=0, nparts, edgecut;
  idxtype *elmnts, *epart, *npart;
  timer IOTmr, DUALTmr;
  char etypestr[4][5] = {"TRI", "TET", "HEX", "QUAD"};
  GraphType graph;

  if (argc != 3) {
    printf("Usage: %s <meshfile> <nparts>\n",argv[0]);
    exit(0);
  }

  nparts = atoi(argv[2]);
  if (nparts < 2) {
    printf("nparts must be greater than one.\n");
    exit(0);
  }
   
  cleartimer(IOTmr);
  cleartimer(DUALTmr);

  starttimer(IOTmr);
  elmnts = ReadMesh(argv[1], &ne, &nn, &etype);
  stoptimer(IOTmr);

  epart = idxmalloc(ne, "main: epart");
  npart = idxmalloc(nn, "main: npart");

  printf("**********************************************************************\n");
  printf("%s", METISTITLE);
  printf("Mesh Information ----------------------------------------------------\n");
  printf("  Name: %s, #Elements: %d, #Nodes: %d, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]);
  printf("Partitioning Nodal Graph... -----------------------------------------\n");


  starttimer(DUALTmr);
  METIS_PartMeshNodal(&ne, &nn, elmnts, &etype, &numflag, &nparts, &edgecut, epart, npart);
  stoptimer(DUALTmr);

  printf("  %d-way Edge-Cut: %7d, Balance: %5.2f\n", nparts, edgecut, ComputeElementBalance(ne, nparts, epart));

  starttimer(IOTmr);
  WriteMeshPartition(argv[1], nparts, ne, epart, nn, npart);
  stoptimer(IOTmr);


  printf("\nTiming Information --------------------------------------------------\n");
  printf("  I/O:          \t\t %7.3f\n", gettimer(IOTmr));
  printf("  Partitioning: \t\t %7.3f\n", gettimer(DUALTmr));
  printf("**********************************************************************\n");

/*
  graph.nvtxs = ne;
  graph.xadj = idxmalloc(ne+1, "xadj");
  graph.vwgt = idxsmalloc(ne, 1, "vwgt");
  graph.adjncy = idxmalloc(10*ne, "adjncy");
  graph.adjwgt = idxsmalloc(10*ne, 1, "adjncy");

  METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, graph.xadj, graph.adjncy);

  ComputePartitionInfo(&graph, nparts, epart);

  GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM);
*/

  GKfree(&elmnts, &epart, &npart, LTERM);

}
Exemple #18
0
void TestFunction1(scene& scene1)
{

	AddSphere(scene1, vector3(1.5, -1.5, 0), 0.5, rgbf(0, 0, 1), false);
	//AddSphere(scene1, vector3(1, 1, 0), 0.5, rgbf(0, 1, 1), true);
		
	sphere_object* s1 = new sphere_object(0.5, vector3(1.5, -1, 0));
	s1->natrual_colour = rgbf(0, 0, 0);
	s1->reflective = true;
	s1->I_refl = 1;
	s1->k_spec = 1;	
	s1->ambient_colour = rgbf(0, 0, 0);
	s1->shininess = 100;
	//scene1.add_object(s1);

	sphere_object* s2 = new sphere_object(0.5, vector3(1.5, 1, 0));
	s2->transparent = true;
	s2->transparency = 0.9;
	s2->refindex = 0.9;
	scene1.add_object(s2);

	rgbf red(1, 0, 0);
	rgbf green(0, 1, 0);
	rgbf blue(0, 0, 1);
	rgbf yellow = red + green;
	rgbf magenta = red + blue;
	rgbf cyan = green + blue;


	AddWall(scene1, vector3(3, 0, -0.5), vector3(0, 1, 0), green * 0.7);
	AddWall(scene1, vector3(0, 3, -0.5), vector3(-1, 0, 0), red* 0.7);
	AddWall(scene1, vector3(-3, 0, -0.5), vector3(0, -1, 0), blue* 0.7);
	AddWall(scene1, vector3(0, -3, -0.5), vector3(1, 0, 0), yellow* 0.7);
	

	AddCeiling(scene1, vector3(0, 0, +3.5), magenta * 0.7);
	AddFloor(scene1, vector3(0, 0, -0.5), cyan * 0.7);

	//AddBox(scene1, vector3(1, -0.5, -0.3), 0.2, rgbf(1, 0, 1), true);

	box* box1 = new box(vector3(1, -0.5, 0), vector3(-0.2, -0.2, -0.2), vector3(0.2, 0.2, 0.2));
	box1->natrual_colour = rgbf(0, 0, 0);
	box1->reflective = false;
	box1->transparent = true;
	box1->transparency = 1;
	box1->I_refr = 1;
	box1->refindex = 2;
	scene1.add_object(box1);

	//AddLightBall(scene1, vector3(-0.8, 0, 3), 3, 0.1);

	AddLight(scene1, vector3(-1.5, 1.5, 3));
	//AddLight(scene1, vector3(2, 0, 4));
	//AddLight(scene1, vector3(-5, 3, 2));

	//IcoSphere(scene1, vector3(4, 0, 2));

	torus_object* tor1 = new torus_object(0.1,0.5,vector3(1,0,-0.5));
	tor1->natrual_colour = rgbf(1, 0, 0);	
	//tor1->ambient_colour = rgbf(0, 0, 0.5);
	//scene1.add_object(tor1);

	mesh* m1 = ReadMesh("teapot.obj", vector3(1, -0.25, -0.5));
	m1->natrual_colour = rgbf(0, 0, 0);
	m1->reflective = false;
	m1->transparent = true;
	m1->transparency = 1;
	m1->I_refr = 1;

	//scene1.add_object(m1);
	
	
}
Exemple #19
0
/* A general OpenGL initialization function.  Sets all of the initial parameters. */
bool InitGL(int Width, int Height)
{

  int i;
  char Line[255];                       // Storage For 255 Characters
  float shaderData[32][3];                  // Storate For The 96 Shader Values

  FILE *In  = NULL;                     // File Pointer

  //g_window  = window;
  //g_keys  = keys;

  // Start Of User Initialization
  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);     // Realy Nice perspective calculations

  glClearColor (0.7f, 0.7f, 0.7f, 0.0f);            // Light Grey Background
  glClearDepth (1.0f);                    // Depth Buffer Setup

  glEnable (GL_DEPTH_TEST);                 // Enable Depth Testing
  glDepthFunc (GL_LESS);                    // The Type Of Depth Test To Do

  glShadeModel (GL_SMOOTH);                 // Enables Smooth Color Shading
  glDisable (GL_LINE_SMOOTH);                 // Initially Disable Line Smoothing

  glEnable (GL_CULL_FACE);                  // Enable OpenGL Face Culling

  glDisable (GL_LIGHTING);                  // Disable OpenGL Lighting

  In = fopen ("./Shader.txt", "r");            // Open The Shader File

  if (In) {
    // Loop Though The 32 Greyscale Values
    for (i = 0; i < 32; i++) {

      if (feof (In))
        break;

      fgets (Line, 255, In);
      shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = float(atof(Line));
    }

    cerr << "Shader.txt read" << endl;
    fclose (In);
  } else {
    cerr << "Shader.txt could not be opened" << endl;
    return false;                     // It Went Horribly Horribly Wrong
  }

  glGenTextures (1, &shaderTexture[0]);           // Get A Free Texture ID
  glBindTexture (GL_TEXTURE_1D, shaderTexture[0]);      // Bind This Texture. From Now On It Will Be 1D

  // Don't Let OpenGL Use Bi/Trilinear Filtering!
  glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 32, 0, GL_RGB , GL_FLOAT, shaderData);

  lightAngle.X = 0.0f;                    // Set The X Direction
  lightAngle.Y = 0.0f;                    // Set The Y Direction
  lightAngle.Z = 1.0f;                    // Set The Z Direction

  // Normalize The Light Direction
  Normalize (lightAngle);

  bool readmesh = ReadMesh();
  cerr << "Readmesh: " << readmesh << endl;
  return readmesh;
}
Exemple #20
0
/*
=============
MD5Model::InitMD5ModelWithMesh

	Initializes MD5Model with the mesh at the path.
=============
*/
bool MD5Model::InitMD5ModelWithMesh( const char* path ) {

	if ( !ValidMD5MeshExtension( path ) ) {
		printf( "Not a valid MD5Mesh extension\n" );
		return false;
	}

	char* fileData = FileOperations::ReadFileToCharBuffer( path );

	if ( fileData == NULL ) { //File wasn't opened
		printf( "Mesh at path '%s' could not be opened\n", path );
		return false;
	} else {
		printf( "Beginning load of: %s\n", path );

        modelName       = path;
        unsigned slash  = modelName.find_last_of( "/" ) + 1;
        unsigned dot    = modelName.find_last_of( "." );
        modelName		= modelName.substr( slash, dot - slash );

		char* nextLineToken	= NULL;
		char* currentLine   = strtok_s( fileData, "\n", &nextLineToken );

		while ( currentLine != NULL ) {
			char* nextParam     = NULL;
			char* currentParam  = strtok_s( currentLine, " ", &nextParam );

			if ( STRINGS_ARE_EQUAL( currentParam, "MD5Version" ) ) { //Read the version
				nextParam[2] = '\0'; //Truncate to 2 chars
				 if ( !STRINGS_ARE_EQUAL( nextParam, "10" ) ) {
					printf( "Only MD5Version 10 is supported\n" );
					delete[] fileData;
					return false;                
				 }
			} else if ( STRINGS_ARE_EQUAL( currentParam, "numJoints" ) ) { //Read numjoints
				int numJoints = std::atoi( nextParam );
				joints.resize( numJoints );
				blendSkeleton.joints.resize( numJoints );
                blendSkeleton.jointMatricies.resize( numJoints );                
			} else if ( STRINGS_ARE_EQUAL( currentParam, "numMeshes" ) ) { //Read nummeshes
				int numMeshes = std::atoi( nextParam );
				meshes.reserve( numMeshes );
			} else if ( STRINGS_ARE_EQUAL( currentParam, "joints" ) ) { //Read joints
				if ( joints.size() == 0 ) {
					printf( "numJoints was not specified\n" );
					delete[] fileData;
					return false;    
				}
				nextLineToken = ReadJoints( nextLineToken );
			} else if ( STRINGS_ARE_EQUAL( currentParam, "mesh" ) ) { //Read a mesh
				nextLineToken = ReadMesh( nextLineToken );
			}

			currentLine = strtok_s( NULL, "\n", &nextLineToken );
		}

		GenerateBindPoseMatricies();

		printf( "   MD5Mesh file parsed\n" );
		printf( "      Joint count:\t%i\n", joints.size() );
		printf( "      Mesh count:\t%i\n", meshes.size() );        
		printf( "Successfully Loaded MD5Mesh: %s\n", path );        

	}
    
    delete[] fileData;

	return SetupMatrixTextureBuffer();
}
Exemple #21
0
void ParseMEMD2File(char *pBuffer)
{
	char *buf;
	int a;
	MEHeader *head;
	MEMaterial2 *material;

	bool bWriteOutImage = false;

	buf=pBuffer;
	head=(MEHeader*)pBuffer;

	if(head->ID!=MEMD_ID)
	{
		return;
	}

	if(!(head->Version>=200 && head->Version<300))
	{
		return;
	}

	CalcNormTable();

	MFString_Copy(pModel->name, head->Name);
	MFString_Copy(pModel->author, head->Creator);

	if(head->SequenceCount)
	{
		MESequence2 *pSequences = (MESequence2*)(pBuffer+head->SequenceStart);

		// do some shit for each one
	}

	if(head->MaterialCount)
	{
		buf=pBuffer+head->MaterialStart;
		material=(MEMaterial2*)buf;

		for(a=0; a<head->MaterialCount; a++)
		{
			F3DMaterial &mat = pModel->GetMaterialChunk()->materials.push();

			// material name
//			MFString_Copy(mat.name, material->Name);

			// use texture name instead of material name
			char *pTex = material->TextureFileName;
			pTex += MFString_Length(pTex);

			while(pTex > material->TextureFileName && pTex[-1] != '/' && pTex[-1] != '\\')
			{
				--pTex;
			}

			pTex[MFString_Length(pTex) - 4] = NULL;

			MFString_Copy(mat.name, pTex);

			// material parameters
			mat.specularLevel = material->matPower;
			mat.ambient.x = material->matColours[0].r;
			mat.ambient.y = material->matColours[0].g;
			mat.ambient.z = material->matColours[0].b;
			mat.ambient.w = material->matColours[0].a;

 			buf += 64 + sizeof(v4[4]) + sizeof(float) + sizeof(int);

			if(material->TextureCount)
			{
				buf+=260;

				if(material->ImageLen)
				{
#if 0
					if(bWriteOutImage)
					{
						FILE *pFile = fopen(material->TextureFileName, "wb");
						if(pFile)
						{
							fwrite(material->ImageBuffer, 1, material->ImageLen, pFile);
							fclose(pFile);
						}
					}
#endif

					buf+=material->ImageLen;
				}
			}

			buf+=8;

			material=(MEMaterial2*)buf;
		}

	}

	if(head->FrameCount&&head->MeshCount)
	{
		buf=pBuffer+head->FrameStart;

		for(a=0; a<head->MeshCount; a++)
		{
			ReadMesh(&buf, head->FrameCount, 1.0f, 0);
		}
	}

	return;
}
Exemple #22
0
bool L3DS::Read3DS()
{
    LChunk mainchunk;
    LChunk edit;
    edit.id = EDIT3DS;
    mainchunk = ReadChunk();
    if (mainchunk.id != MAIN3DS)
    {
        fprintf(stderr, "L3DS::Read3DS - wrong file format");
        return false;
    }
    if (!FindChunk(edit, mainchunk))
        return false;
    LChunk obj;
    LChunk ml;

    GotoChunk(edit);
    obj.id = MAT_ENTRY;
    while (FindChunk(obj, edit))
    {
        ReadMaterial(obj);
        SkipChunk(obj);
    }
    GotoChunk(edit);

    obj.id = EDIT_OBJECT;
    {
        while (FindChunk(obj, edit))
        {
            ReadASCIIZ(m_objName, 99);
            ml = ReadChunk();
            if (ml.id == OBJ_TRIMESH)
                ReadMesh(ml);
            else
            if (ml.id == OBJ_LIGHT)
                ReadLight(ml);
            else
            if (ml.id == OBJ_CAMERA)
                ReadCamera(ml);
            SkipChunk(obj);
        }
    }

    // read the keyframer data here to find out correct object orientation

    LChunk keyframer;
    keyframer.id = KFDATA;

    LChunk objtrack;
    objtrack.id = OBJECT_NODE_TAG;

    GotoChunk(mainchunk);
    if (FindChunk(keyframer, mainchunk))
    {   // keyframer chunk is present
        GotoChunk(keyframer);
        while (FindChunk(objtrack, keyframer))
        {
            ReadKeyframeData(objtrack);
            SkipChunk(objtrack);
        }
    }

    for (uint i=0; i<m_meshes.size(); i++)
        m_meshes[i].Optimize(m_optLevel);
    m_pos = 0;
    strcpy(m_objName, "");
    return true;
}
Exemple #23
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  idxtype i, j, ne, nn, etype, mtype, numflag=0, nparts, edgecut;
  idxtype *elmnts, *epart, *npart, *metype, *weights;
  double IOTmr, DUALTmr;
  char etypestr[5][5] = {"TRI", "TET", "HEX", "QUAD", "LINE"};
  GraphType graph;

  if (argc != 3) {
    mprintf("Usage: %s <meshfile> <nparts>\n",argv[0]);
    exit(0);
  }



  nparts = atoi(argv[2]);
  if (nparts < 2) {
    mprintf("nparts must be greater than one.\n");
    exit(0);
  }
   
  gk_clearcputimer(IOTmr);
  gk_clearcputimer(DUALTmr);
 
  mtype=MeshType(argv[1]);
  ne=MixedElements(argv[1]);
  metype = idxmalloc(ne, "main: metype");
  weights = idxmalloc(ne, "main: weights");

  gk_startcputimer(IOTmr);
 
  if(mtype==1)
       elmnts = ReadMesh(argv[1], &ne, &nn, &etype);
  else if(mtype==3)
       elmnts = ReadMeshWgt(argv[1], &ne, &nn, &etype, weights);
  else if(mtype==0)
       elmnts = ReadMixedMesh(argv[1], &ne, &nn, metype);
  else
       elmnts = ReadMixedMeshWgt(argv[1], &ne, &nn, metype, weights);

  gk_stopcputimer(IOTmr);

  epart = idxmalloc(ne, "main: epart");
  npart = idxmalloc(nn, "main: npart");

  mprintf("**********************************************************************\n");
  mprintf("%s", METISTITLE);
  mprintf("Mesh Information ----------------------------------------------------\n");
  if (mtype==1)
  mprintf("  Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]);
  else
  mprintf("  Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, "Mixed");
  mprintf("Partitioning Nodal Graph... -----------------------------------------\n");


  gk_startcputimer(DUALTmr);
  
  if (mtype==1 || mtype==3)
  METIS_PartMeshNodal(&ne, &nn, elmnts, &etype, &numflag, &nparts, &edgecut, epart, npart);
  else 
  METIS_PartMixedMeshNodal(&ne, &nn, elmnts, metype, &numflag, &nparts, &edgecut, epart, npart);
  
  gk_stopcputimer(DUALTmr);

  mprintf("  %D-way Edge-Cut: %7D, Balance: %5.2f\n", nparts, edgecut, ComputeElementBalance(ne, nparts, epart));

  gk_startcputimer(IOTmr);
  WriteMeshPartition(argv[1], nparts, ne, epart, nn, npart);
  gk_stopcputimer(IOTmr);


  mprintf("\nTiming Information --------------------------------------------------\n");
  mprintf("  I/O:          \t\t %7.3f\n", gk_getcputimer(IOTmr));
  mprintf("  Partitioning: \t\t %7.3f\n", gk_getcputimer(DUALTmr));
  mprintf("**********************************************************************\n");

/*
  graph.nvtxs = ne;
  graph.xadj = idxmalloc(ne+1, "xadj");
  graph.vwgt = idxsmalloc(ne, 1, "vwgt");
  graph.adjncy = idxmalloc(10*ne, "adjncy");
  graph.adjwgt = idxsmalloc(10*ne, 1, "adjncy");

  METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, graph.xadj, graph.adjncy);

  ComputePartitionInfo(&graph, nparts, epart);

  gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM);
*/

  gk_free((void **)&elmnts, &epart, &npart, &metype, &weights,  LTERM);

}