예제 #1
0
파일: CMoon.cpp 프로젝트: RaoMiao/freestyle
void CMoon::ParseBlock( const CVarBlockParser::_VariableBlock *pBlock_ )
{
	if( pBlock_==NULL ) { return; }

	pBlock_->GetBool( "Active", m_bActive );
	
	if( pBlock_->GetString( "MeshFile", m_strMeshName ) )
	{
		HGRPOBJ hMesh = DGraphicAcquireSMD( SFullName( DCtrlGrp()->GroupEnvironment, m_strMeshName ), DGraphicStore::StaticMesh );
		if( !hMesh.IsValid() )
		{
			hMesh = DGraphicAcquireSMD( m_strMeshName, DGraphicStore::StaticMesh );
		}
		LoadMesh( hMesh );
	}
	if( pBlock_->GetVector( "Translation", m_vTranslation ) )
	{
		SMatrix mat;
		mat.SetTranslation( m_vTranslation );
		Transform( mat );
	}
	bool bMoonFace;
	if( pBlock_->GetBool( "MoonFace", bMoonFace ) )
	{
		SetMoonFace( bMoonFace );
	}
	SColor Color;
	if( pBlock_->GetColor( "Color", Color ) )
	{
		SetColor( Color );
	}
	pBlock_->GetRealNumber( "FillRate", m_fFillRate );
	pBlock_->GetRealNumber( "RisingRate", m_fRisingRate );
	pBlock_->GetRealNumber( "Pitch", m_fPitch );
}
예제 #2
0
파일: Mesh.cpp 프로젝트: kaisama/Phase-1
void CreateSprite(Mesh *sprite, vec2 size, vec3 pos, Texture *texture, Color *colors, int colorCount)
{
	//Square vertices 
	Vertex vertices[] =
	{
		Vertex(Position(pos.x			, pos.y			  , pos.z), colorCount == 1 ? *colors : colors[0], TexCoords(1, 1)),		//TOP RIGHT
		Vertex(Position(pos.x			, pos.y + (size.y), pos.z), colorCount == 1 ? *colors : colors[1], TexCoords(1, 0)),		//BOTTOM RIGHT
		Vertex(Position(pos.x + (size.x), pos.y + (size.y), pos.z), colorCount == 1 ? *colors : colors[2], TexCoords(0, 0)),		//BOTTOM LEFT
		Vertex(Position(pos.x + (size.x), pos.y			  , pos.z), colorCount == 1 ? *colors : colors[3], TexCoords(0, 1)),		//TOP LEFT
	};


	//Order of vertices that will be drawn
	unsigned int indices[] =
	{
		0,
		1,
		3,
		1,
		2,
		3,
	};

	LoadMesh(&sprite->Buffers, &sprite->Data, vertices, sizeof(vertices) / sizeof(Vertex), indices, sizeof(indices) / sizeof(unsigned int));
	sprite->MeshTexture = *texture;
}
BOOL cXMeshParser::ParseObject(                             \
                       IDirectXFileData *pDataObj,            \
                       IDirectXFileData *pParentDataObj,      \
                       DWORD Depth,                           \
                       void **Data, BOOL Reference)
{ 
  const GUID *Type = GetObjectGUID(pDataObj);

  // Make sure template being parsed is a mesh (non-referenced)
  if(*Type == TID_D3DRMMesh && Reference == FALSE) {

    // Load the mesh data
    D3DXMESHCONTAINER_EX *Mesh = NULL;
    LoadMesh(&Mesh, g_pD3DDevice, pDataObj);

    // Assign a name if none already
    if(Mesh && !Mesh->Name)
      Mesh->Name = strdup("NoNameMesh");

    // Link mesh into head of list
    if(Mesh)
      Mesh->pNextMeshContainer = m_RootMesh;
    m_RootMesh = Mesh; Mesh = NULL;
  }

  return ParseChildObjects(pDataObj, Depth, Data, Reference);
}    
예제 #4
0
bool XFileUtils::LoadMeshContainer(
	ID3DXFileData* pFileData, 
	IDirect3DDevice9* pDevice, 
	GMeshContainer** pNewMeshContainer)
{
	_XCheckType(pFileData, "Mesh", false);

	GMeshContainer* pMeshContainer = new GMeshContainer();

	char name[128] = { 0 };
	SIZE_T nameSize = 128;
	pFileData->GetName(name, &nameSize);
	pMeshContainer->Name = name;

	if (!LoadMesh(
		pFileData, 
		pDevice,
		&pMeshContainer->pMesh,
		&pMeshContainer->pMaterials,
		&pMeshContainer->NumMaterials, 
		&pMeshContainer->pSkinInfo))
		return false;

	*pNewMeshContainer = pMeshContainer;
	return true;
}
BOOL DoInit(HWND hWnd)
{
  // Initialize Direct3D
  InitD3D(&g_pD3D, &g_pD3DDevice, hWnd);

  // Load a skeletal mesh
  LoadMesh(&g_Mesh, &g_Frame, g_pD3DDevice, "..\\Data\\tiny.x", "..\\Data\\");

  // Get the bounding radius of the object
  g_MeshRadius = 0.0f;
  D3DXMESHCONTAINER_EX *pMesh = g_Mesh;
  while(pMesh) {

    // Lock the vertex buffer, get its radius, and unlock buffer
    if(pMesh->MeshData.pMesh) {
      D3DXVECTOR3 *pVertices, vecCenter;
      float Radius;
      pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pVertices);
      D3DXComputeBoundingSphere(pVertices, 
                                pMesh->MeshData.pMesh->GetNumVertices(),
                                D3DXGetFVFVertexSize(pMesh->MeshData.pMesh->GetFVF()),
                                &vecCenter, &Radius);
      pMesh->MeshData.pMesh->UnlockVertexBuffer();

      // Update radius
      if(Radius > g_MeshRadius)
        g_MeshRadius = Radius;
    }

    // Go to next mesh
    pMesh = (D3DXMESHCONTAINER_EX*)pMesh->pNextMeshContainer;
  }

  return TRUE;
}
예제 #6
0
void Mesh::LoadOgreXML(const char* name_material, const char* name_mesh)
{
	std::fstream file(name_material, std::ios::in);
	std::string line;
	char name[1000];
	if(file.is_open())
	{
		Material mat,empty_mat;

		while(std::getline(file, line))
		{
			if(sscanf(line.c_str(),"material %s",name )==1){materials.push_back(mat);mat=empty_mat;mat.name=name;}
			sscanf(line.c_str()," ambient %f %f %f",&mat.ambient.x,&mat.ambient.y,&mat.ambient.z );
			sscanf(line.c_str()," diffuse %f %f %f",&mat.diffuse.x,&mat.diffuse.y,&mat.diffuse.z );
			sscanf(line.c_str()," specular %f %f %f",&mat.specular.x,&mat.specular.y,&mat.specular.z );
			sscanf(line.c_str()," emissive %f %f %f",&mat.emissive.x,&mat.emissive.y,&mat.emissive.z );
			if(sscanf(line.c_str()," texture %s",name )==1)
			{
				Texture *texture=&mat.diffuse_map; bool bump=0;
				if(strcmp(name,"_unit")==0)continue;
				if(strcmp(name,"_bump")==0)
				{
					bump=1;
					sscanf(line.c_str()," texture_bump %s",name );
					texture=&mat.bump_map;
				}
				if(strcmp(name,"_ambient")==0)
				{
					sscanf(line.c_str()," texture_ambient %s",name );
					texture=&mat.ambient_map;
				}
				std::string prename;
				std::string tempname(name_material);
				std::size_t pos = tempname.rfind("/");
				if(pos == std::string::npos)
					pos = tempname.rfind("\\");

				if(pos != std::string::npos)
					prename = tempname.substr(0, pos+1);
				texture->filename = prename + std::string(name);
				// texture->gl_handle = loadBMP_custom(texture->filename.c_str());
				texture->gl_handle = loadImage(texture->filename.c_str());
			}
			if(sscanf(line.c_str()," env_map %s",name )==1)
			{
				// To do
			}
		}
		materials.push_back(mat);
		//PrintMaterials();
	}
	else
	{
		std::cerr << "Can't read material" << name_material << std::endl;
		return;
	}

	file.close();
	LoadMesh(name_mesh);
}
예제 #7
0
bool ModelResourceExtraData::LoadModel(char* pRawBuffer, unsigned int rawSize, std::string modelFilepath)
{
	m_pModelData = BE_NEW ModelClass;

	LoadMesh(&m_pModelData, reinterpret_cast<byte*>(pRawBuffer));

	return true;
}
예제 #8
0
void initOpenGl()
{
   glewInit();

   glEnable(GL_DEPTH_TEST);

   reload_shader();

   //mesh and texture for pass 1
   mesh_data = LoadMesh(mesh_name);
   texture_id = LoadTexture(texture_name.c_str());

   //mesh for pass 2 (full screen quadrilateral)
   glGenVertexArrays(1, &quad_vao);
   glBindVertexArray(quad_vao);

   float vertices[] = {1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, -1.0f, 0.0f};

   //create vertex buffers for vertex coords
   glGenBuffers(1, &quad_vbo);
   glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
   glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
   int pos_loc = glGetAttribLocation(shader_program, "pos_attrib");
   if(pos_loc >= 0)
   {
      glEnableVertexAttribArray(pos_loc);
	   glVertexAttribPointer(pos_loc, 3, GL_FLOAT, false, 0, 0);
   }

   //create texture to render pass 1 into
   const int w = glutGet(GLUT_WINDOW_WIDTH);
   const int h = glutGet(GLUT_WINDOW_HEIGHT);
   glGenTextures(1, &fbo_texture);
   glBindTexture(GL_TEXTURE_2D, fbo_texture);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
   glBindTexture(GL_TEXTURE_2D, 0);   

   //Create renderbuffer for depth.
   glGenRenderbuffers(1, &rbo_id);
   glBindRenderbuffer(GL_RENDERBUFFER, rbo_id);
   glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, w, h);

   //Create the framebuffer object
   glGenFramebuffers(1, &fbo_id);
   glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo_texture, 0);
   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_id); // attach depth renderbuffer

   check_framebuffer_status();

   glBindFramebuffer(GL_FRAMEBUFFER, 0);

}
예제 #9
0
//////////////////////////////////////////////////////////////////////////
// 
//	Function: 		ReloadMeshes
//
//	Last Modified:	03/09/2007
//
//	Purpose:		Reloads all the xfiles, based on the mesh vector 
//
//////////////////////////////////////////////////////////////////////////
void CMeshManager::ReloadMeshes()
{
	//time to load these textures back it memory
	for(int i = 0; i < (int)m_vMeshes.size(); i++)
		LoadMesh(m_vMeshes[i]->szFileName, &m_vMeshes[i]->d3dMesh,  m_vMeshes[i]->bUnique);

	int temp = 0;

}
예제 #10
0
void BgLoader::ContinueLoading(bool waiting)
{  
    // Limit even while waiting - we want some frames.
    size_t i = 0;
    size_t count = 0;
    while(count < 10)
    {
        // True if at least one mesh finished load.
        bool finished = false;

        // Delete from delete queue (fairly expensive, so limited per update).
        if(!deleteQueue.IsEmpty())
        {
            CleanMesh(deleteQueue[0]);
            deleteQueue.DeleteIndexFast(0);
        }

        // Check if we need to reset i
        if (i == loadingMeshes.GetSize())
            i = 0;

        // Check already loading meshes.
        for(; i<(loadingMeshes.GetSize() < 20 ? loadingMeshes.GetSize() : 20); ++i)
        {
            if(LoadMesh(loadingMeshes[i]))
            {
                finished = true;
                finalisableMeshes.Push(loadingMeshes[i]);
                loadingMeshes.DeleteIndex(i);
            }
        }

        // Finalise loaded meshes (expensive, so limited per update).
        if(!finalisableMeshes.IsEmpty())
        {
            if(finished)
                engine->SyncEngineListsNow(tloader);

            FinishMeshLoad(finalisableMeshes[0]);
            finalisableMeshes.DeleteIndexFast(0);
        }

        // Load meshgens.
        for(size_t j=0; j<loadingMeshGen.GetSize(); ++j)
        {
            if(LoadMeshGen(loadingMeshGen[j]))
            {
                loadingMeshGen.DeleteIndex(j);
            }
        }

        ++count;
        if(!waiting || GetLoadingCount() == 0)
            break;
    }
}
예제 #11
0
	void Model_IO::LoadMeshes(std::vector<Mesh>& meshes, BinaryReader& reader, const achar* path)
	{
		auto mcount = reader.Get<int32_t>();
		meshes.resize(mcount);
		
		for (auto i = 0; i < mcount; i++)
		{
			LoadMesh(meshes[i], reader, path);
		}
	}
예제 #12
0
    void setup() {
        LoadMesh();
        LoadEffect();
        glEnable(GL_DEPTH_TEST);

        const float x = 0.6f;
        const float y = x * m_frameBufferHeight / m_frameBufferWidth;
        const float zNear = 0.1, zFar = 100;
        m_camera.setDimensions(x, y);
        m_camera.setClippingPlanes(zNear, zFar);
    }
예제 #13
0
EntHaste::EntHaste(EngineExport *EE) : Entity(EE)
{
	ClassName = "light";

	SetAABB(Vector3f(-20, -20, -20), Vector3f(20, 20, 30));
	LoadMesh(String("basehaste/models/items/silencer/silencer.obj"));
	EE->AttachToWorld(this);

	float_time = 0;

//	Link();
}
예제 #14
0
void LoadGraphics(){
	GLuint programID = LoadShaders("shaders/StandardShading.vertexshader", "shaders/StandardShading.fragmentshader");
	g_program.createProgram(programID, 1);

	g_text.initText2D("textures/WhiteFont.tga");

	LoadMesh("mesh/g5.obj", JUST_VERTICES);
	LoadTexture(1, "textures/WhiteFont.tga", 0);

	createArc();
	
}
예제 #15
0
void SceneBase::InitMeshes()
{
	const string MESH_FILE_PATH = "SONs//Meshes.son";

	StopWatch initTimer;
	initTimer.startTimer();

	std::cout << "Loading " << MESH_FILE_PATH << "... ";

	meshList = LoadMesh(MESH_FILE_PATH, texList, matList);

	std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
}
BOOL DoInit(HWND hWnd)
{
    // Initialize Direct3D
    InitD3D(&g_pD3D, &g_pD3DDevice, hWnd);

    // Load the robot mesh
    LoadMesh(&g_RobotMesh, g_pD3DDevice, "..\\Data\\robot.x", "..\\Data\\");

    // Load the ground mesh
    LoadMesh(&g_GroundMesh, g_pD3DDevice, "..\\Data\\ground.x", "..\\Data\\");

    // Create the backdrop
    sBackdropVertex BackdropVerts[4] = {
        {   0.0f,   0.0, 1.0, 1.0f, 0.0f, 0.0f },
        { 640.0f,   0.0, 1.0, 1.0f, 1.0f, 0.0f },
        {   0.0f, 480.0, 1.0, 1.0f, 0.0f, 1.0f },
        { 640.0f, 480.0, 1.0, 1.0f, 1.0f, 1.0f }
    };
    g_pD3DDevice->CreateVertexBuffer(sizeof(BackdropVerts), D3DUSAGE_WRITEONLY, BACKDROPFVF, D3DPOOL_DEFAULT, &g_BackdropVB, NULL);
    char *Ptr;
    g_BackdropVB->Lock(0,0, (void**)&Ptr, 0);
    memcpy(Ptr, BackdropVerts, sizeof(BackdropVerts));
    g_BackdropVB->Unlock();
    D3DXCreateTextureFromFile(g_pD3DDevice, "..\\Data\\Backdrop.bmp", &g_BackdropTexture);

    // Setup a directional light
    D3DLIGHT9 Light;
    ZeroMemory(&Light, sizeof(D3DLIGHT9));
    Light.Type = D3DLIGHT_DIRECTIONAL;
    Light.Diffuse.r = Light.Diffuse.g = Light.Diffuse.b = Light.Diffuse.a = 1.0f;
    Light.Direction = D3DXVECTOR3(0.0f, -0.5f, 0.5f);
    g_pD3DDevice->SetLight(0, &Light);
    g_pD3DDevice->LightEnable(0, TRUE);

    // Load the route to use
    g_Route.Load("..\\Data\\Route.x");

    return TRUE;
}
예제 #17
0
Geometry* SceneLoader::LoadGeometry(QDomElement element)
{
  Geometry* geom = GeometryPool::Get()->GetGeometry(_geometryName, _geometryIdx);
  if (geom)
    {
      return geom;
    }

  if (element.nodeName() != QString ("geometry"))
    {
      printf ("ceXMLDataLoader::LoadGeometry: Illegal data format: '%s' != 'geometry'\n", element.nodeName().toStdString().c_str()); fflush (stdout);
      return 0;
    }

  geom = new Geometry ();

  QDomElement staticElement = element.firstChildElement("staticmesh");
  if (!staticElement.isNull())
    {
      ceMesh* mesh = LoadMesh (staticElement);
      if (!mesh)
        {
          geom->Release();
          return 0;
        }
      iStaticMesh* staticMesh = _engine->GetDevice()->CreateStaticMesh();
      staticMesh->SetMesh(mesh);
      geom->SetMesh(staticMesh);
      geom->SetMetaMesh(MT_Static,
      staticElement.firstChildElement("mesh").attribute("filename"));
    }

  MaterialManager* matMgr = Session::Get()->GetMaterialManager();

  QDomElement materialElement = element.firstChildElement("material");
  Material* mat = 0;
  if (!materialElement.isNull())
    {
      mat = matMgr->GetMaterial(materialElement.text());
    }

  if (!mat)
    {
      mat = matMgr->GetDefaultMaterial();
    }
  geom->SetMetaMaterial(mat);

  GeometryPool::Get()->Set(_geometryName, _geometryIdx, geom);
  return geom;

}
BOOL DoInit(HWND hWnd)
{
  // Initialize Direct3D
  InitD3D(&g_pD3D, &g_pD3DDevice, hWnd);

  // Load the base mesh
  LoadMesh(&g_BaseMesh, g_pD3DDevice, "..\\Data\\Base.x", "..\\Data\\");

  // Load the collection of meshes used for demo
  LoadMesh(&g_MorphMeshes, NULL, g_pD3DDevice, "..\\Data\\Dummy.x", "..\\Data\\", MORPHFVF);

  // Load the morphing animation set and map animations to meshes
  g_MorphAnim.Load("..\\Data\\dummy.x");
  g_MorphAnim.Map(g_MorphMeshes);

  // Load the vertex shader
  LoadVertexShader(&g_VS, g_pD3DDevice, "Morph.vsh", g_MorphMeshDecl, &g_Decl);

  // Create the backdrop
  sBackdropVertex BackdropVerts[4] = {
    {   0.0f,   0.0, 1.0, 1.0f, 0.0f, 0.0f },
    { 640.0f,   0.0, 1.0, 1.0f, 1.0f, 0.0f },
    {   0.0f, 480.0, 1.0, 1.0f, 0.0f, 1.0f },
    { 640.0f, 480.0, 1.0, 1.0f, 1.0f, 1.0f }
  };
  g_pD3DDevice->CreateVertexBuffer(sizeof(BackdropVerts), D3DUSAGE_WRITEONLY, BACKDROPFVF, D3DPOOL_DEFAULT, &g_BackdropVB, NULL);
  char *Ptr;
  g_BackdropVB->Lock(0,0, (void**)&Ptr, 0);
  memcpy(Ptr, BackdropVerts, sizeof(BackdropVerts));
  g_BackdropVB->Unlock();
  D3DXCreateTextureFromFile(g_pD3DDevice, "..\\Data\\Backdrop.bmp", &g_BackdropTexture);

  // Play the song
  PlaySound("..\\Data\\dance.wav", NULL,  SND_ASYNC | SND_LOOP);

  return TRUE;
}
예제 #19
0
    //-----------------------------------------------------------------------------
    //  CreateDefaultObjects
    //  Creates the default objects
    //-----------------------------------------------------------------------------
    void CRenderer::CreateDefaultObjects( void )
    {
        // Texture
        m_nDefaultTexture = LoadTexture2D( "Assets/Textures/DefaultTexture.png" );
        
        // Default mesh
        m_nDefaultMesh = CreateMesh();

        // debug sphere
        m_nSphereMesh = LoadMesh( "Assets/meshes/sphere.mesh" );

        // debug box
        m_nDebugBox = CreateDynamicBox();
        
        //////////////////////////////////////////
        //  Load Shaders
        LoadShaders();

        // a vertex shader for drawing lines        
        VPosColor pLineVertices[] =
        {
            { RVector3(  0.0f,  0.0f,  0.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) },
            { RVector3(  1.0f,  1.0f,  1.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) },
        };
        m_pLineBuffer = m_pDevice->CreateVertexBuffer( sizeof( pLineVertices ), pLineVertices );

        // Set the defaults
        SetVertexShader( eVS3DPosNorTexStd );
        SetPixelShader( ePS3DStd );
        SetSamplerState( eSamplerLinear );
        m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_TRIANGLELIST );


        static float Vtx[] = 
        { 
            -1.0f, -1.0f, 
            -1.0f,  1.0f, 
             1.0f,  1.0f, 
             1.0f, -1.0f, 
        };
        static uint16 Idx[] = 
        { 
            0, 1, 2, 
            0, 2, 3,
        };

        m_pFSRectVB = m_pDevice->CreateVertexBuffer( sizeof( Vtx ), Vtx );
        m_pFSRectIB = m_pDevice->CreateIndexBuffer ( sizeof( Idx ), Idx );
    }
T* ResourceManager::LoadResource(std::string filepath)
{
	T* ret;
	// Checks if the resource we're looking for
	if (ret = dynamic_cast<T*>(CheckResourceCollection(filepath)))
	{		
		dynamic_cast<Resource*>(ret)->IncreaseReferenceCount();
		return ret;
	}

	// Checks the file extension to see if the file is of correct type
	uint index = (uint)filepath.find_last_of('.');
	std::string ext = filepath.substr(index, filepath.length() - 1);

	// If the given extension is not a valid key...
	if (typemap.find(ext) == typemap.end())
	{
#ifdef DEBUG
		Debug::LogError("[ResourceManager] File extension is invalid.");
#endif
		return 0;
	}

	// Call the appropriate loading function
	if (typemap[ext] == "Texture2D")
	{
		ret = dynamic_cast<T*>(LoadTexture2D(filepath));
	}
	else if (typemap[ext] == "Mesh")
	{
		ret = dynamic_cast<T*>(LoadMesh(filepath));
	}
	else
	{
#ifdef DEBUG
		Debug::LogError("[ResourceManager] Resource type not initialized in typemap");
#endif
		return 0;
	}

#ifdef DEBUG
	if (!ret)
	{
		Debug::LogError("[ResourceManager] File could not be loaded.");
	}
#endif
	return ret;
}
void KinectSkeletonRigger::LoadRig(const std::string& f) {
	if(f=="") return;
	ifstream ifs(f.c_str());
	string s_; 
	ifs >> m_meshfile;
	LoadMesh(m_meshfile);
	if(m_m.vertices.size() == 0) {
		cerr << "can't load mesh"<<endl; return;
	}
	ifs >> m_skeletonfile;
	LoadSkeletonFromText(m_skeletonfile);
	if(m_skel.get() == NULL || m_skel->fGraph().verts.size() == 0) {
		cerr << "can't load skeleton"<<endl; return;
	}
	int embedding_size,tmp;
	ifs >> embedding_size;
	m_po.embedding.resize(embedding_size);
	for (int i=0; i<embedding_size; i++) {
		ifs >> tmp >> m_po.embedding[i][0] >> m_po.embedding[i][1] >> m_po.embedding[i][2] >> tmp;
	}
	int attachment_size;
	ifs >> attachment_size;
	if(m_po.attachment == NULL) m_po.attachment = new Attachment;
	my_weights.resize(attachment_size);
	for (int i=0; i<attachment_size; i++) {
		//		my_weights[i].resize(embedding_size-1);
		for (int v=0; v<embedding_size-1; v++) {
			ifs >> my_weights[i][v];
		}
		//		cout << my_weights[i];
	}
	
	for (int v_idx = 0; v_idx < m_skel->fGraph().verts.size(); v_idx++) 
	{
		int prev_idx = m_skel->fPrev()[v_idx];
		string joint_name = m_skel->jointIdxToName[v_idx];
		string prev_joint_name = m_skel->jointIdxToName[prev_idx];
		if (joint_name == "shoulders") {
			prev_joint_name = "back";
			prev_idx = m_skel->getJointForName("back");
		}
		EigV3f skel_offset = m_skel->jointV[joint_name] - m_skel->jointV[prev_joint_name];
		EigV3f embed_offest = Pinoc2EigV3f(m_po.embedding[v_idx]) - Pinoc2EigV3f(m_po.embedding[prev_idx]);
		embedding_scale[joint_name] = embed_offest.norm() / skel_offset.norm(); // / ;
		
		cout << "embedding_scale " << joint_name << ": " << embedding_scale[joint_name] << endl;		
	}
}
예제 #22
0
void RBTerrain::Load(const char *name)
{
	RUDE_REPORT("Loading terrain %s\n", name);
	
	LoadMesh(name);
	LoadPhysicsMesh(0.0f);
	
	LoadMaterials();
	
	RudePhysicsMesh *obj = (RudePhysicsMesh *) GetPhysicsObject();
	btRigidBody *rb = obj->GetRigidBody();

	rb->setFriction(50.0f);
	rb->setRestitution(0.99f);
	rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
	
	obj->SetNotifyOnContact(true);
	obj->SetContactCallback(RBTerrainContactCallback);
	

	LoadNodes();
	
	m_holeTexture = RudeTextureManager::GetInstance()->LoadTextureFromPNGFile("hole");
	RUDE_ASSERT(m_holeTexture, "Could not load hole texture");
	
	
	btDiscreteDynamicsWorld *world = RudePhysics::GetInstance()->GetWorld();
	
	
	btVector3 p0 = m_hole;
	p0.setY(m_hole.y() - 1000);
	btVector3 p1 = m_hole;
	p1.setY(m_hole.y() + 1000);
	
	btCollisionWorld::ClosestRayResultCallback cb(p0, p1);
	
	world->rayTest(p0, p1, cb);
	
	RUDE_ASSERT(cb.hasHit(), "Could not position hole.. is it over terrain? (%f %f %f)", m_hole.x(), m_hole.y(), m_hole.z());
	
	RUDE_REPORT("  Hole %f %f %f -> %f %f %f\n", m_hole.x(), m_hole.y(), m_hole.z(), cb.m_hitPointWorld.x(), cb.m_hitPointWorld.y(), cb.m_hitPointWorld.z());
	
	m_hole = cb.m_hitPointWorld;
	
	m_decorator.Load(name);
}
예제 #23
0
    PMDDataDx9( const std::string &_file_name ) :
      Node(&PMDNoBoneManagerDx9::Instance()),
      m_FilePass(_file_name)
    {
        if(_file_name.empty()) return;

        PMDLoader::DATA *data = PMDLoader::Load(_file_name);
        if(!data) return;

        LoadMesh(data);
        LoadMaterial(data);
        delete[] data->vertex;
        delete[] data->face_vert_index;
        delete[] data->bone;
        delete[] data->material;
        delete data;
    };
예제 #24
0
파일: mesh.cpp 프로젝트: diegofu/raytracer
void mesh::Init(const char* obj_file)
{
	float default_value[3] = {1,1,1};

	vList.push_back(Vec3(default_value));	// ¦]¬° 
	nList.push_back(Vec3(default_value));	// 
	tList.push_back(Vec3(default_value));

	// 
	mat[0].Ka[0] = 0.0; mat[0].Ka[1] = 0.0; mat[0].Ka[2] = 0.0; mat[0].Ka[3] = 1.0; 
	mat[0].Kd[0] = 1.0; mat[0].Kd[1] = 1.0; mat[0].Kd[2] = 1.0; mat[0].Kd[3] = 1.0; 
	mat[0].Ks[0] = 0.8; mat[0].Ks[1] = 0.8; mat[0].Ks[2] = 0.8; mat[0].Ks[3] = 1.0;
	mat[0].Ns = 32;
	matTotal++;

	LoadMesh(string(obj_file));		// 
}
예제 #25
0
void mesh::Init(const char* obj_file)
{
	float default_value[3] = {1,1,1};

	vList.push_back(Vec3(default_value));	// 因為 *.obj 的 index 是從 1 開始
	nList.push_back(Vec3(default_value));	// 所以要先 push 一個 default value 到 vList[0],nList[0],tList[0]
	tList.push_back(Vec3(default_value));

	// 定義 default meterial: mat[0]
	mat[0].Ka[0] = 0.0; mat[0].Ka[1] = 0.0; mat[0].Ka[2] = 0.0; mat[0].Ka[3] = 1.0;
	mat[0].Kd[0] = 1.0; mat[0].Kd[1] = 1.0; mat[0].Kd[2] = 1.0; mat[0].Kd[3] = 1.0;
	mat[0].Ks[0] = 0.8; mat[0].Ks[1] = 0.8; mat[0].Ks[2] = 0.8; mat[0].Ks[3] = 1.0;
	mat[0].Ns = 32;
	matTotal++;

	LoadMesh(string(obj_file));		// 讀入 .obj 檔 (可處理 Material)
}
예제 #26
0
//-------------------------------------
// Bullet()
//-------------------------------------
Bullet::Bullet(
	const OBJECT_PARAMETER_DESC &parameter)
{
	// 弾実体生成
	parameter_ = parameter;
	mesh_ = NULL;
	material_buffer_ = NULL;
	shader_ = nullptr;
	shader_ = ShaderManager::Get("resource/shader/bullet.hlsl");
	texture_ = NULL;
	LoadMesh("resource/model/x/ball.x");
	SetTexture("resource/texture/game/bullet.png");

	// 使用フラグOFF
	collision_ = nullptr;
	use_ = false;
}
예제 #27
0
  void Ngx_Mesh :: DoArchive (ngstd::Archive & archive)
  {

    if (archive.Output())
      {
        stringstream str;
        SaveMesh (str);
        string st = str.str();
        archive & st;
      }
    else
      {
        string st;
        archive & st;
        stringstream str(st);
        LoadMesh (str);
      }
  }
예제 #28
0
	void FbxParser::LoadNode(GameObjectPtr node, FbxNode * fbxNode)
	{
		GameObject::Ptr childNode = GameObject::Create(fbxNode->GetName());

		ApplyLocalTransform(childNode, fbxNode);
		childNode->SetParent(node, false);

		FbxNodeAttribute* fbxNodeAttr = fbxNode->GetNodeAttribute();

		if (fbxNodeAttr != nullptr)
		{
			auto attrType = fbxNodeAttr->GetAttributeType();
			if (attrType == FbxNodeAttribute::eMesh)
			{
				LoadMesh(childNode, fbxNode);
			}
		}
	}
예제 #29
0
bool BgLoader::LoadMeshGen(MeshGen* meshgen)
{
    bool ready = true;
    for(size_t i=0; i<meshgen->meshfacts.GetSize(); i++)
    {
        if(!meshgen->mftchecked[i])
        {
            meshgen->mftchecked[i] = LoadMeshFact(meshgen->meshfacts[i]);
            ready &= meshgen->mftchecked[i];
        }
    }

    if(!ready)
      return false;

    for(size_t i=0; i<meshgen->materials.GetSize(); i++)
    {
        if(!meshgen->matchecked[i])
        {
            meshgen->matchecked[i] = LoadMaterial(meshgen->materials[i]);
            ready &= meshgen->matchecked[i];
        }
    }

    if(!ready || !LoadMesh(meshgen->object))
      return false;

    if(ready && !meshgen->status)
    {
        meshgen->status = tloader->LoadNode(vfs->GetCwd(), meshgen->data, 0, meshgen->sector->object);
        return false;
    }

    if(meshgen->status && meshgen->status->IsFinished())
    {
      meshgen->loading = false;
      return true;
    }

    return false;
}
예제 #30
0
	void FbxUtil::LoadNode(const SceneNode::Ptr &ntNode, FbxNode* fbxNode)
	{
		SceneNode::Ptr childNode = SceneNode::Create(fbxNode->GetName());

		// copy transforms.
		FbxQuaternion fbxQ;
		fbxQ.ComposeSphericalXYZ(fbxNode->LclRotation.Get());
		FbxDouble3 fbxT = fbxNode->LclTranslation.Get();
		FbxDouble3 fbxS = fbxNode->LclScaling.Get();

		Vector4 furyT((float)fbxT.mData[0] * m_ScaleFactor, (float)fbxT.mData[1] * m_ScaleFactor, (float)fbxT.mData[2] * m_ScaleFactor, 1.0f);
		Vector4 furyS((float)fbxS.mData[0] * m_ScaleFactor, (float)fbxS.mData[1] * m_ScaleFactor, (float)fbxS.mData[2] * m_ScaleFactor, 1.0f);
		Quaternion furyR((float)fbxQ.mData[0], (float)fbxQ.mData[1], (float)fbxQ.mData[2], (float)fbxQ.mData[3]);

		childNode->SetLocalPosition(furyT);
		childNode->SetLocalRoattion(furyR);
		childNode->SetLocalScale(furyS);

		// add to scene graph
		ntNode->AddChild(childNode);

		// read Components
		FbxNodeAttribute* fbxNodeAttr = fbxNode->GetNodeAttribute();
		if (fbxNodeAttr != NULL)
		{
			FbxNodeAttribute::EType fbxNodeAttrType = fbxNodeAttr->GetAttributeType();
			if (fbxNodeAttrType == FbxNodeAttribute::eMesh)
			{
				LoadMesh(childNode, fbxNode);
			}
			else if (fbxNodeAttrType == FbxNodeAttribute::eLight)
			{
				LoadLight(childNode, fbxNode);
			}
		}

		// read child nodes.
		for (int i = 0; i < fbxNode->GetChildCount(); i++)
			LoadNode(ntNode, fbxNode->GetChild(i));
	}