void GameObject::Init( LPDIRECT3DDEVICE9& d3dDevice ) { D3DXMatrixIdentity( &m_Matrix ); InitMesh( d3dDevice ); setBox(); }
HRESULT InitD3D( HWND hWnd ) { // Create the D3D object, which is needed to create the D3DDevice. if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) { MessageBoxA(NULL, "Create D3D9 object failed!", "Error", 0) ; return E_FAIL; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; // use window mode, not full screen d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Create device if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) { MessageBoxA(NULL, "Create D3D9 device failed!", "Error", 0) ; return E_FAIL; } // Disable lighting, since we didn't specify color for vertex g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , FALSE ); InitMesh(); return S_OK; }
std::vector <glm::vec3> Mesh::getVertices(const std::string& data) { IndexedModel model = OBJModel(data).ToIndexedModel(); InitMesh(model); return model.positions; }
// The format of input file should be as follows: // The First Line: amount of vertices (the amount of vertices/points needed to be triangulated) // Other Lines: x y z (the vertices/points coordinates, z should be 0 for 2D) // E.g. // 4 // -1 -1 0 // -1 1 0 // 1 1 0 // 1 -1 0 void Input(const char* pFile, MESH * pMesh) { FILE* fp = fopen(pFile, "r"); if (!fp) { fprintf(stderr,"Error:%s open failed\n", pFile); exit(1); } //int face; int amount; //fscanf( fp, "%d", &face); fscanf( fp, "%d", &amount); if (amount < 3) { fprintf(stderr,"Error:vertex amount should be greater than 2, but it is %d \n",amount); exit(1); } InitMesh(pMesh, amount); REAL x,y,z; for ( int j=3; j<amount+3; ++j) { fscanf( fp, "%lg %lg %lg", &x, &y, &z); ((VERTEX2D *)(pMesh->pVerArr+j))->x = x; ((VERTEX2D *)(pMesh->pVerArr+j))->y = y; } fclose(fp); }
void ModelLoader::InitFromScene(const aiScene* pScene, const std::string& Filename) { //init meshes in scene const aiMesh* paiMesh = pScene->mMeshes[0]; InitMesh(paiMesh); }
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, Material* newMaterial) : m_indexCount(0) , material(newMaterial) { this->vertices = vertices; this->indices = indices; InitMesh(); }
void Mesh::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); // Initialize the meshes in the scene one by one for (unsigned int i = 0; i < m_Entries.size(); i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } }
mesh_t *CreateMesh(void) { mesh_t *mesh; mesh = (mesh_t *)gk_malloc(sizeof(mesh_t), "CreateMesh: mesh"); InitMesh(mesh); return mesh; }
Mesh::Mesh(Vertex* vertices, unsigned int numVertices, unsigned int* indices, unsigned int numIndices) { IndexedModel model; for (unsigned int i = 0; i < numVertices; i++) { model.positions.push_back(*vertices[i].GetPos()); model.texCoords.push_back(*vertices[i].GetTexCoord()); model.normals.push_back(*vertices[i].GetNormal()); } for (unsigned int i = 0; i < numIndices; i++) model.indices.push_back(indices[i]); //*indices[i] da' nuj InitMesh(model); /*/m_drawCount = numVertices; m_drawCount = numIndices; glGenVertexArrays(1, &m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject); std::vector<glm::vec3> positions; std::vector<glm::vec2> texCoords; positions.reserve(numVertices); texCoords.reserve(numVertices); for (int i = 0; i < numVertices; i++) { positions.push_back(*vertices[i].GetPos()); texCoords.push_back(*vertices[i].GetTexCoord()); } glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]); glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(positions[0]), &positions[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[TEXCOORD_VB]); glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(texCoords[0]), &texCoords[0], GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[INDEX_VB]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(indices[0]), &indices[0], GL_STATIC_DRAW); glBindVertexArray(0);*/ }
bool Skeleton::InitFromScene(const aiScene* pScene) { // Initialize the meshes in the scene one by one for (unsigned int i = 0; i < pScene->mNumMeshes; i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(paiMesh, i); } return 0; }
bool BasicMesh::InitFromScene(const aiScene * pScene) { m_Entries.resize(pScene->mNumMeshes); vector<Vertex> vertex_buffer_data; vector<GLuint> index_buffer_data; unsigned int NumVertices = 0; unsigned int NumIndices = 0; // Count the number of vertices and indices for (unsigned int i = 0; i < m_Entries.size(); i++) { m_Entries[i].NumIndices = pScene->mMeshes[i]->mNumFaces * 3; m_Entries[i].BaseVertex = NumVertices; m_Entries[i].BaseIndex = NumIndices; NumVertices += pScene->mMeshes[i]->mNumVertices; NumIndices += m_Entries[i].NumIndices; } vertex_buffer_data.reserve(NumVertices); index_buffer_data.reserve(NumVertices); // Initialize the meshes in the scene one by one for (unsigned int i = 0; i < m_Entries.size(); i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(paiMesh, vertex_buffer_data, index_buffer_data); } // Set the current active buffer glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[0]); // Transfer vertices to OpenGL glBufferData(GL_ARRAY_BUFFER, vertex_buffer_data.size() * sizeof(Vertex), &vertex_buffer_data[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)sizeof(vec3f)); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(vec3f) + sizeof(vec3f))); glEnableVertexAttribArray(3); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(vec3f) + sizeof(vec3f) + sizeof(TexCoord))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_buffer_data.size() * sizeof(GLuint), &index_buffer_data[0], GL_STATIC_DRAW); return true; }
void ZActor::InitFromNPCType(MQUEST_NPC nNPCType, float fTC, int nQL) { m_pNPCInfo = ZGetGameInterface()->GetQuest()->GetNPCInfo(nNPCType); _ASSERT(m_pNPCInfo); InitMesh(m_pNPCInfo->szMeshName, nNPCType); if(m_pNPCInfo->nNPCAttackTypes & NPC_ATTACK_MELEE ) { m_Items.EquipItem(MMCIP_MELEE, m_pNPCInfo->nWeaponItemID); m_Items.SelectWeapon(MMCIP_MELEE); } if(m_pNPCInfo->nNPCAttackTypes & NPC_ATTACK_RANGE ) { m_Items.EquipItem(MMCIP_PRIMARY, m_pNPCInfo->nWeaponItemID); m_Items.SelectWeapon(MMCIP_PRIMARY); } if(m_pNPCInfo->nSkills) { m_pModule_Skills = AddModule<ZModule_Skills>(); m_pModule_Skills->Init(m_pNPCInfo->nSkills,m_pNPCInfo->nSkillIDs); } m_Collision.fRadius = m_pNPCInfo->fCollRadius; m_Collision.fHeight = m_pNPCInfo->fCollHeight; m_fTC = fTC; m_nQL = nQL; m_fSpeed = ZBrain::MakeSpeed(m_pNPCInfo->fSpeed); SetTremblePower(m_pNPCInfo->fTremble); if (m_pVMesh && m_pNPCInfo) { rvector scale; scale.x = m_pNPCInfo->vScale.x; scale.y = m_pNPCInfo->vScale.y; scale.z = m_pNPCInfo->vScale.z; m_pVMesh->SetScale(scale); if (scale.z != 1.0f) { m_Collision.fHeight *= scale.z; } if ((scale.x != 1.0f) || (scale.y != 1.0f)) { float length = max(scale.x, scale.y); m_Collision.fRadius *= length; } } m_pBrain = ZBrain::CreateBrain(nNPCType); m_pBrain->Init(this); _ASSERT(m_pNPCInfo != NULL); }
bool Mesh::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); for (unsigned int i = 0; i < m_Entries.size(); i++){ const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, Filename); }
bool Mesh::InitFromScene(const aiScene* pScene, const std::string& filePath) { m_entries.resize(pScene->mNumMeshes); m_textures.resize(pScene->mNumMaterials); for(unsigned int i = 0; i < m_entries.size(); ++i) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, filePath); }
//--------------------------------------- bool Mesh::InitScene( const aiScene* scene, const char* filename ) { mEntries.resize( scene->mNumMeshes ); mTextures.resize( scene->mNumMaterials ); for ( unsigned i = 0; i < mEntries.size(); ++i ) { const aiMesh* mesh = scene->mMeshes[i]; InitMesh( i, mesh ); } return InitMaterials( scene, filename ); }
bool COpenAssetImporterMesh::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); m_Textures.resize(pScene->mNumMaterials); // Initialize the meshes in the scene one by one for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(i, paiMesh); } return InitMaterials(pScene, Filename); }
bool Mesh::InitFromScene ( const aiScene* pScene, const std::string& filename ) { m_entries.resize ( pScene->mNumMeshes ); m_textures.resize ( pScene->mNumMaterials ); // Инициализируем меши один за другим for ( unsigned int i = 0; i < m_entries.size ( ); i++ ) { const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh ( i, paiMesh ); } return InitMaterials ( pScene, filename ); }
Mesh::Mesh(Gameobject* object, D3DGraphics& gfx) : Component(object), gfx(gfx), tex(NULL), TextureFilePath(NULL) { m_type = CT_DATA; m_pCompIdentifier = CTYPE_MESH; InitMaterial(); InitMesh(); m_pName = new char[5]; m_pName = { "Mesh" }; }
void ViewerMesh::launch(){ glutCreateWindow("Game Mode"); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); } if(! InitMesh()){ fprintf(stderr, "Error: '%s'\n", "error while loading the mesh"); } InitializeGlutCallbacks(); glutMainLoop(); }
void GLMesh::InitNode(const struct aiScene* sc, const struct aiNode* nd, const aiMatrix4x4& mTransformation) { aiMatrix4x4 trans = mTransformation * nd->mTransformation; // draw all meshes assigned to this node for (unsigned int n = 0; n < nd->mNumMeshes; ++n) { const struct aiMesh* mesh = m_pScene->mMeshes[nd->mMeshes[n]]; InitMesh(m_uMeshCount, mesh, trans); m_uMeshCount++; } // draw all children for (unsigned int n = 0; n < nd->mNumChildren; ++n) { InitNode(sc, nd->mChildren[n], trans); } }
Mesh::Mesh(Vertex* vertices, unsigned int numVertices, unsigned int* indices, unsigned int numIndices) { IndexedModel model; for (unsigned int i = 0; i < numVertices; i++) { model.positions.push_back(*vertices[i].GetPos()); model.texCoords.push_back(*vertices[i].GetTexCoord()); model.normals.push_back(*vertices[i].GetNormal()); } for (unsigned int i = 0; i < numIndices; i++) model.indices.push_back(indices[i]); InitMesh(model); }
Maya::Maya(Vertice* vertices, unsigned int numVertices, unsigned int* indices, unsigned int numIndices) { IndexedModel modelo; for(unsigned int i=0; i<numVertices; i++) { modelo.positions.push_back(*vertices[i].getPos()); modelo.texCoords.push_back(*vertices[i].getTexCoord()); modelo.normals.push_back(*vertices[i].getNormal()); } for(unsigned int i=0; i<numIndices; i++) { modelo.indices.push_back(indices[i]); } InitMesh(modelo); }
/** * Load a scene from a supported 3D file format * * @param filename Name of the file (or asset) to load * @param flags (Optional) Set of ASSIMP processing flags * * @return Returns true if the scene has been loaded */ bool LoadMesh(const std::string& filename, int flags = defaultFlags) { #if defined(__ANDROID__) // Meshes are stored inside the apk on Android (compressed) // So they need to be loaded via the asset manager AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING); assert(asset); size_t size = AAsset_getLength(asset); assert(size > 0); void *meshData = malloc(size); AAsset_read(asset, meshData, size); AAsset_close(asset); pScene = Importer.ReadFileFromMemory(meshData, size, flags); free(meshData); #else pScene = Importer.ReadFile(filename.c_str(), flags); #endif if (pScene) { m_Entries.clear(); m_Entries.resize(pScene->mNumMeshes); // Read in all meshes in the scene for (auto i = 0; i < m_Entries.size(); i++) { m_Entries[i].vertexBase = numVertices; numVertices += pScene->mMeshes[i]->mNumVertices; const aiMesh* paiMesh = pScene->mMeshes[i]; InitMesh(&m_Entries[i], paiMesh, pScene); } return true; } else { printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString()); #if defined(__ANDROID__) LOGE("Error parsing '%s': '%s'", filename.c_str(), Importer.GetErrorString()); #endif return false; } }
Mesh::Mesh(VERTICES* vertices, unsigned int numVertex, unsigned int* indices, unsigned int numTriangles) { IndexedModel model; for (unsigned int i = 0; i < numVertex; i++) { model.positions.push_back(*vertices[i].GetPos()); model.uvs.push_back(*vertices[i].GetUV()); model.normals.push_back(*vertices[i].GetNormal()); } for (unsigned int i = 0; i < numTriangles; i++) { model.indices.push_back(indices[i]); } InitMesh(model); }
bool Model::InitFromScene(const aiScene* pScene, const std::string& Filename) { m_Entries.resize(pScene->mNumMeshes); aiColor3D color(0.0f, 0.0f, 0.0f); // Initialize the meshes in the scene one by one for (unsigned int i = 0 ; i < m_Entries.size() ; i++) { aiMesh* paiMesh = pScene->mMeshes[i]; // retrieve the material corresponding to this mesh aiMaterial* pMaterial = pScene->mMaterials[paiMesh->mMaterialIndex]; pMaterial->Get(AI_MATKEY_COLOR_DIFFUSE, color); InitMesh(pScene, i, color); } return true; }
void SceneGame::Config(void) { gameBranch.printBranch(); for (vector<Branch>::iterator branch = gameBranch.childBranches.begin(); branch != gameBranch.childBranches.end(); ++branch) { if (branch->branchName == "Mesh") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; if (tempAttri.name == "Directory") { InitMesh(tempAttri.value); } } } } }
// Sets default values AItem::AItem(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = false; static ConstructorHelpers::FObjectFinder<UTexture2D> IconObj(TEXT("/Game/HUD/DefaultIcons/Item")); Icon = IconObj.Object; Name = "Core Item"; Description = "From the core of Oncoming. You should not have this..."; Weight = 0.0f; MeshOffset = FVector(0); MeshRotation = FRotator(0); static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshObj(TEXT("/Game/Items/Item")); // Get instance of porridge model InitMesh(MeshOffset, MeshObj.Object); SetState(World); }
void Mesh::Load() { Clear(); Assimp::Importer importer; const aiScene* scene = importer.ReadFile(sFilepath.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs); if(scene) { InitMesh(scene, sFilepath); } else { std::cout << "Cannot find " << sFilepath << " " << importer.GetErrorString() << std::endl; //throw std::runtime_error(std::string("Error Parsing: ") + sFilepath + //std::string("\n") + importer.GetErrorString()); } }
static void Init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); InitMaterials(); InitTexture(); InitMesh(); glMatrixMode(GL_MODELVIEW); glTranslatef(0.0, 0.4, -1.8); glScalef(2.0, 2.0, 2.0); glRotatef(-35.0, 1.0, 0.0, 0.0); glRotatef(35.0, 0.0, 0.0, 1.0); }
void SceneCredits::Init(int screenWidth, int screenHeight) { Application::HideMouse(false); // Initialise SceneBase SceneBase::Init(screenWidth, screenHeight); // Init sound sound = irrklang::createIrrKlangDevice(); if (!sound) { std::cout << "Could not start sound engine" << std::endl; } InitMesh(); m_camera = new Camera3(); m_camera->Init(Vector3(0, 0, 10), Vector3(), Vector3(0, 1, 0)); initMenu(); }