void FBXHandle::Update() { for(int i=0; i<m_fbx->getMeshCount(); ++i) { // get the current mesh FBXMeshNode *mesh = m_fbx->getMeshByIndex(i); // if you move an object around within your scene // children nodes are not updated until this function is called. mesh->updateGlobalTransform(); } }
Shadow::Shadow(char* string,FBXFile::UNIT_SCALE a_Scale){ m_file = new FBXFile(); m_file->load( string,a_Scale,true,true ); // how manu meshes and materials are stored within the fbx file unsigned int meshCount = m_file->getMeshCount(); unsigned int matCount = m_file->getMaterialCount(); // loop through each mesh for(int i=0; i<meshCount; ++i) { // get the current mesh FBXMeshNode *pMesh = m_file->getMeshByIndex(i); // genorate our OGL_FBXRenderData for storing the meshes VBO, IBO and VAO // and assign it to the meshes m_userData pointer so that we can retrive // it again within the render function OGL_FBXRenderData *ro = new OGL_FBXRenderData(); pMesh->m_userData = ro; // OPENGL: genorate the VBO, IBO and VAO glGenBuffers(1, &ro->VBO); glGenBuffers(1, &ro->IBO); glGenVertexArrays(1, &ro->VAO); // OPENGL: Bind VAO, and then bind the VBO and IBO to the VAO glBindVertexArray(ro->VAO); glBindBuffer(GL_ARRAY_BUFFER, ro->VBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ro->IBO); // Send the vertex data to the VBO glBufferData(GL_ARRAY_BUFFER, pMesh->m_vertices.size() * sizeof(FBXVertex), pMesh->m_vertices.data(), GL_STATIC_DRAW); // send the index data to the IBO glBufferData(GL_ELEMENT_ARRAY_BUFFER, pMesh->m_indices.size() * sizeof(unsigned int), pMesh->m_indices.data(), GL_STATIC_DRAW); //Here we push everything! just need to setup in the shaders // enable the attribute locations that will be used on our shaders glEnableVertexAttribArray(0); //Pos glEnableVertexAttribArray(2); //norm glEnableVertexAttribArray(7); //tex // tell our shaders where the information within our buffers lie glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(FBXVertex), ((char *)0) + FBXVertex::PositionOffset); glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(FBXVertex), ((char *)0) + FBXVertex::NormalOffset); glVertexAttribPointer(7, 2, GL_FLOAT, GL_FALSE, sizeof(FBXVertex), ((char *)0) + FBXVertex::TexCoord1Offset); // finally, where done describing our mesh to the shader // we can describe the next mesh glBindVertexArray(0); pMesh->updateGlobalTransform(); } // Loop through each material and load the texture for(unsigned int i = 0; i<matCount; ++i) { // get the current material being loaded FBXMaterial *pMaterial = m_file->getMaterialByIndex(i); // each material can optionally have many different textures that can be used to describe how the object should be rendered. // Look at the FBXMaterial structure. // the following textures can be assigned to a material within the 3D modeling programs // we can optionally support loading these in... // - DiffuseTexture, // - AmbientTexture, // - GlowTexture, // - SpecularTexture, // - GlossTexture, // - NormalTexture, // - AlphaTexture, // - DisplacementTexture for(unsigned int j = 0; j<FBXMaterial::TextureTypes_Count; ++j) { // find the path to the texture to be loaded std::string path = m_file->getPath(); // append the filename of the texture path += pMaterial->textureFilenames[j]; // load the texture using SOIL pMaterial->textureIDs[j] = SOIL_load_OGL_texture(path.c_str(), 4, 0, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_INVERT_Y); // lets just print what is loaded to the console... if (pMaterial->textureIDs[j] != 0){ printf("Loading texture : %s - ID: %i\n", path.c_str(), pMaterial->textureIDs[j]); } } } //resolution of the texture to put our shadow map in m_shadowSize = 1024; // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. glGenFramebuffers(1, &m_shadowFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_shadowFramebuffer); glGenTextures(1,&m_shadowTexture); glBindTexture(GL_TEXTURE_2D,m_shadowTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,m_shadowSize, m_shadowSize,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_shadowTexture, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); // Always check that our framebuffer is ok if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { printf("depth buffer not created"); } else { printf("Success! created depth buffer\n"); } // return to back-buffer rendering glBindFramebuffer(GL_FRAMEBUFFER, 0); }