void SetupMeshAction::act() { // Create the mesh object and tell it to build itself if (_current_task == "setup_mesh") { _mesh = _factory.create<MooseMesh>(_type, "mesh", _moose_object_pars); if (isParamValid("displacements")) _displaced_mesh = _factory.create<MooseMesh>(_type, "displaced_mesh", _moose_object_pars); } else if (_current_task == "init_mesh") { _mesh->init(); if (isParamValid("displacements")) { // Initialize the displaced mesh _displaced_mesh->init(); std::vector<std::string> displacements = getParam<std::vector<std::string>>("displacements"); if (displacements.size() < _displaced_mesh->dimension()) mooseError( "Number of displacements must be greater than or equal to the dimension of the mesh!"); } setupMesh(_mesh.get()); if (_displaced_mesh) setupMesh(_displaced_mesh.get()); } }
void SphereMesh::setGlobe(int in_segments, int in_sections) { type = GLOBE; segments = in_segments; sections = in_sections; setupMesh(); }
const Patch* PatchCache::get(const AssetAtlas::Entry* entry, const uint32_t bitmapWidth, const uint32_t bitmapHeight, const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch) { const PatchDescription description(bitmapWidth, bitmapHeight, pixelWidth, pixelHeight, patch); const Patch* mesh = mCache.get(description); if (!mesh) { Patch* newMesh = new Patch(); TextureVertex* vertices; if (entry) { // An atlas entry has a UV mapper vertices = newMesh->createMesh(bitmapWidth, bitmapHeight, pixelWidth, pixelHeight, entry->uvMapper, patch); } else { vertices = newMesh->createMesh(bitmapWidth, bitmapHeight, pixelWidth, pixelHeight, patch); } if (vertices) { setupMesh(newMesh, vertices); } #if DEBUG_PATCHES if (g_HWUI_debug_patches) dumpFreeBlocks("Adding patch"); #endif mCache.put(description, newMesh); return newMesh; } return mesh; }
OFX_ASSIMP_BEGIN_NAMESPACE Mesh::Mesh(Scene* scene, aiMesh* assimp_mesh) { material = &scene->resource->materials[assimp_mesh->mMaterialIndex]; setupMesh(scene, assimp_mesh); setupSkin(scene, assimp_mesh); }
void Mesh::setData(const std::vector<Vertex>& vertices, const std::vector<GLuint>& indices) { mVertices = vertices; mIndices = indices; setupMesh(); }
void ForwardRenderTechnique::render() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); if(!m_scene) { return; } glUseProgram(m_shader->getProgramId()); const auto &renderMap = m_scene->getRenderMap(); const auto &lightList = m_scene->getLightList(); int i = 0; for(const auto &l : lightList) { m_shader->setLight(i++, l); } m_shader->setNumLights(lightList.size()); for(auto it : renderMap) { if(it.first) { if(!setupMaterial(m_shader, it.first)) { m_logManager->logErr("Failed to setup material"); continue; } } for(auto o : it.second) { m_shader->setMVP(m_viewCamera->getVP()*o->getWorldMat()); if(!setupMesh(m_shader, o->getMesh())) { m_logManager->logErr("Failed to setup mesh"); continue; } drawCall(o->getMesh()->getNumVerts()); } } }
GLRenderer::GLRenderer(void) { GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set the clear Display state to the black color; the windows will use this setting during the whole execution program = std::unique_ptr<GLProgram>(new GLProgram()); program->run(); program->transformObjIndex = glGetUniformLocation(program->getID(),"gObjectTransform"); program->transformCamIndex = glGetUniformLocation(program->getID(),"gCamera"); program->lightColorIndex = glGetUniformLocation(program->getID(), "light.lightColor"); program->ambientIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityAmbient"); program->diffuseIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityDiffuse"); program->directionIndex = glGetUniformLocation(program->getID(), "light.direction"); program->eyeIndex = glGetUniformLocation(program->getID(), "eyeWorldSpace"); program->specularIntensityIndex = glGetUniformLocation(program->getID(), "specularIntensity"); program->specularPowerIndex = glGetUniformLocation(program->getID(), "specularPower"); _root = std::unique_ptr<Node>(new Node); /* Setup the scene */ RawSceneLoader loader; Scene scene; loader.load(scene); setupMesh(scene.meshes[0],1); setupTexture(scene.textures[0],1); setupLight(scene.lights[0], 1); setupMaterial(scene.materials[0],1); }
void menu(int value) { switch (value) { case M_2ND_ORDER_GRID: grid = &grid2x2[0][0][0]; uSize = 2; vSize = 2; setupMesh(); break; case M_4TH_ORDER_GRID: grid = &grid4x4[0][0][0]; uSize = 4; vSize = 4; setupMesh(); break; case M_INCREASE_GRID: gridSize += 2; setupMesh(); break; case M_DECREASE_GRID: gridSize -= 2; if (gridSize < 2) { gridSize = 2; } setupMesh(); break; case M_TOGGLE_ANTIALIASING: if (antialiasing) { antialiasing = 0; glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); } else { antialiasing = 1; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); } break; case M_QUIT: exit(0); break; } glutPostRedisplay(); }
bool Mesh::loadFromFile(const std::string& path) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_CalcTangentSpace); if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) { std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl; return false; } const aiMesh* mesh = scene->mMeshes[0]; for (GLuint i = 0; i < mesh->mNumVertices; ++i) { Vertex vertex; vertex.position.x = mesh->mVertices[i].x; vertex.position.y = mesh->mVertices[i].y; vertex.position.z = mesh->mVertices[i].z; vertex.normal.x = mesh->mNormals[i].x; vertex.normal.y = mesh->mNormals[i].y; vertex.normal.z = mesh->mNormals[i].z; if (mesh->mTextureCoords[0]) { vertex.texCoord.x = mesh->mTextureCoords[0][i].x; vertex.texCoord.y = mesh->mTextureCoords[0][i].y; } //else // vertex.texCoord = glm::vec2(0.0f, 0.0f); vertex.tangent.x = mesh->mTangents[i].x; vertex.tangent.y = mesh->mTangents[i].y; vertex.tangent.z = mesh->mTangents[i].z; vertex.biTangent.x = mesh->mBitangents[i].x; vertex.biTangent.y = mesh->mBitangents[i].y; vertex.biTangent.z = mesh->mBitangents[i].z; append(vertex); } for (GLuint i = 0; i < mesh->mNumFaces; ++i) { aiFace face = mesh->mFaces[i]; for (GLuint j = 0; j < face.mNumIndices; ++j) append(face.mIndices[j]); } setupMesh(); return true; }
/* Constructors & Destructor */ Mesh::Mesh(const std::vector<Vertex>& vertices, const std::vector<GLuint>& indices, const std::vector<Texture>& textures): m_vertices(vertices), m_indices(indices), m_textures(textures), m_VAO(), m_VBO(), m_EBO() { // Now that we have all the required data, set the vertex buffers and its attribute pointers setupMesh(); }
//-------------------------------------------------------------- void ofxOcean::setup(){ width = 1000; height = 1000; resolution = 100; gridSize = width / resolution; setupMesh(width,height,gridSize); }
kart::kart() : Model(){ color = glm::vec3(1.0, 0.1, 0.2); position = glm::vec4(0.0, 0.0, 0.0, 1.0); maxSpeed = 10.0f; acceleration = 0.03f; speed = 0.0f; isAccelarating = false; getModel(); setupMesh(); camera = new Camera(); camera->cameraPos = glm::vec3(position.x, position.y + 1, position.z + 3.0); }
//------------------------------------------------------------------------- void OgreHead::setUp(const String& name) { // Create visual presence SceneManager* sm = World::getSingleton().getSceneManager(); mEntity = sm->createEntity(name, "OgreHead.mesh"); mSceneNode = sm->getRootSceneNode()->createChildSceneNode(name); mSceneNode->attachObject(mEntity); // Add reverse reference mEntity->setUserObject(this); //Setup mesh setupMesh(); }
// allows water to process /// This should be called once per frame. /// \param elapsed The elapsed time in seconds since the last time process /// was called. void Water::process(float elapsed) { // increment texture coordinates m_texturePos += elapsed * textureVelocity; // wrap the texture coordinates around 0; m_texturePos.x = fmod(m_texturePos.x, 1.0f); m_texturePos.y = fmod(m_texturePos.y, 1.0f); // recreate a new mesh with the correct texture coordinates setupMesh(); return; }
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<GLuint> indices, std::vector<std::shared_ptr<Texture2D>> textures, std::vector<VertexBoneData> boneData, std::vector<glm::mat4> boneOffsets): vertices(vertices), indices(indices), textures(textures), boneOffsets(boneOffsets), processBones(false) { if(boneData.size() > 0 ) { processBones = true; boneBuffer = std::unique_ptr<VertexBuffer>(new VertexBuffer()); boneBuffer->setData(boneData); } setupMesh(); }
void EnMesh::initialize() { _mesh = setupMesh(); getTransformationNode()->setName( getInstanceName() ); // is dynamic shadows enabled in the configuration? yaf3d::Configuration::get()->getSettingValue( YAF3D_GS_SHADOW_ENABLE, _cgfShadow ); // is dynamic shadow for this mesh desired? _shadowEnable = ( _throwShadow || _receiveShadow ) && _cgfShadow; if ( _mesh.valid() ) addToTransformationNode( _mesh.get() ); // the node is added and removed by notification callback! yaf3d::EntityManager::get()->removeFromScene( this ); // register entity in order to get menu notifications yaf3d::EntityManager::get()->registerNotification( this, true ); }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("editgrid"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutMotionFunc(motion); glutCreateMenu(menu); glutAddMenuEntry("2nd order grid", M_2ND_ORDER_GRID); glutAddMenuEntry("4nd order grid", M_4TH_ORDER_GRID); glutAddMenuEntry("Increase grid sizing by 2", M_INCREASE_GRID); glutAddMenuEntry("Decrease grid sizing by 2", M_DECREASE_GRID); glutAddMenuEntry("Toggle antialiasing", M_TOGGLE_ANTIALIASING); glutAddMenuEntry("Quit", M_QUIT); glutAttachMenu(GLUT_RIGHT_BUTTON); glSelectBuffer(sizeof(selectBuffer), selectBuffer); setupMesh(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
//-------------------------------------------------------------- void ofxOcean::updateMesh(float W, float H, int res){ if (width != W || height != H || resolution != res) { width = W; height = H; resolution = res; gridSize = W / res; setupMesh(W, H, gridSize); } }
Mesh::Mesh(std::vector<Vertex> & vertices, std::vector<unsigned int> & indices, std::vector<Texture> & textures) : _vertices(vertices), _indices(indices), _textures(textures) { setupMesh(); }
void Mesh::setData(const std::vector<Vertex>& vertices) { mVertices = vertices; setupMesh(); }
void SetupMeshAction::act() { // Create the mesh object and tell it to build itself if (_current_task == "setup_mesh") { // switch non-file meshes to be a file-mesh if using a pre-split mesh configuration. if (_app.parameters().get<bool>("use_split")) { auto split_file = _app.parameters().get<std::string>("split_file"); // Get the split_file extension, if there is one, and use that to decide // between .cpr and .cpa std::string split_file_ext; auto pos = split_file.rfind("."); if (pos != std::string::npos) split_file_ext = split_file.substr(pos + 1, std::string::npos); // If split_file already has the .cpr or .cpa extension, we go with // that, otherwise we strip off the extension and append ".cpr". if (split_file != "" && split_file_ext != "cpr" && split_file_ext != "cpa") split_file = MooseUtils::stripExtension(split_file) + ".cpr"; if (_type != "FileMesh") { if (split_file == "") { if (_app.processor_id() == 0) mooseError( "Cannot use split mesh for a non-file mesh without specifying --split-file on " "command line"); MOOSE_ABORT; } _type = "FileMesh"; auto new_pars = validParams<FileMesh>(); new_pars.set<MeshFileName>("file") = split_file; new_pars.set<MooseApp *>("_moose_app") = _moose_object_pars.get<MooseApp *>("_moose_app"); new_pars.set<MooseEnum>("parallel_type") = "distributed"; _moose_object_pars = new_pars; } else { _moose_object_pars.set<MooseEnum>("parallel_type") = "distributed"; if (split_file != "") _moose_object_pars.set<MeshFileName>("file") = split_file; else _moose_object_pars.set<MeshFileName>("file") = MooseUtils::stripExtension(_moose_object_pars.get<MeshFileName>("file")) + ".cpr"; } } _mesh = _factory.create<MooseMesh>(_type, "mesh", _moose_object_pars); if (isParamValid("displacements")) _displaced_mesh = _factory.create<MooseMesh>(_type, "displaced_mesh", _moose_object_pars); } else if (_current_task == "init_mesh") { _mesh->init(); if (isParamValid("displacements")) { // Initialize the displaced mesh _displaced_mesh->init(); std::vector<std::string> displacements = getParam<std::vector<std::string>>("displacements"); if (displacements.size() < _displaced_mesh->dimension()) mooseError( "Number of displacements must be greater than or equal to the dimension of the mesh!"); } setupMesh(_mesh.get()); if (_displaced_mesh) setupMesh(_displaced_mesh.get()); } }
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<GLuint> indices) :mVertices(vertices), mIndices(indices) { setupMesh(); }
//-------------------------------------------------------------- void ofxOcean::setup(){ ofApp *app = (ofApp *)ofxGetAppPtr(); // app->transformer.cam.reset(); // // app->transformer.cam.lookAt(ofVec3f(0.151753, 0.923233, -0.353005)); // app->transformer.cam.setPosition(ofVec3f(-600.906, -3368.04, 538.046)); // // turn on smooth lighting // smoothLighting = true; ofSetSmoothLighting(true); // Point lights emit light in all directions // // set the diffuse color, color reflected from the light source // // specular color, the highlight/shininess color // pointLight.setPointLight(); // Directional Lights emit light based on their orientation, regardless of their position // directionalLight.setDirectional(); // set the direction of the light // set it pointing from left to right -> // // shininess is a value between 0 - 128, 128 being the most shiny // material.setShininess(shininess); // the light highlight of the material // material.setColors(matDiffuseColor, matAmbientColor, matSpecularColor, matEmissiveColor); width = 1000; height = 1000; resolution = 100; gridSize = width / resolution; setupMesh(width,height,gridSize); gui.setup("panel",Globals::hostName + OCEAN_SETTINGS_FILE); // most of the time you don't need a name but don't forget to call setup gui.add(filled.set("bFill", true)); gui.add(useLights.set("Use lights", true)); gui.add(smoothLighting.set("Smooth Lighting", false)); gui.add(usePointLight.set("usePointLight", false)); gui.add(useDirLight.set("useDirLight", true)); gui.add(useMaterial.set("useMaterial", true)); meshParams.setName("Ocean mesh"); meshParams.add(meshColor.set("meshColor", ofFloatColor(1, 0.72449, 1, 1),ofFloatColor(0,0,0,0),ofColor::white)); meshParams.add(meshSize.set("size", 10, 10,100)); meshParams.add(meshResolution.set("resolution", 2, 1,10)); meshParams.add(noiseAmp.set("noiseAmp", 2, 0,50)); meshParams.add(noiseSpeed.set("noiseSpeed", 2, 0,50)); meshParams.add(noiseHeight.set("noiseHeight", 2, 0,500)); meshParams.add(waveAmp.set("waveAmp", 0,0,PI)); meshParams.add(waveSpeed.set("waveSpeed", 0,0,10)); meshParams.add(waveHeight.set("waveHeight", 0,0,500)); meshParams.add(waveDirection.set("waveDirection", ofVec3f(0),ofVec3f(-1),ofVec3f(1))); meshParams.add(waveAmp2.set("waveAmp2", 0,0,PI)); meshParams.add(waveSpeed2.set("waveSpeed2", 0,0,10)); meshParams.add(waveHeight2.set("waveHeight2", 0,0,500)); meshParams.add(waveDirection2.set("waveDirection2", ofVec3f(0),ofVec3f(-1),ofVec3f(1))); gui.add(meshParams); lightParams.setName("Lights"); lightParams.add(dirLightOrientation.set("Orientation (x,z,y angles)", ofVec3f(180, -42.2449, 117.551), ofVec3f(-180), ofVec3f(180))); lightParams.add(diffuseColor.set("diffuseColor", ofFloatColor(1, 1, 1, 1),ofFloatColor(0,0,0,0),ofColor::white)); lightParams.add(specularColor.set("specularColor", ofFloatColor(1, 1, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); lightParams.add(ambientColor.set("ambientColor", ofFloatColor(0, 0.00510204, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); gui.add(lightParams); materialParams.setName("Material"); materialParams.add(shininess.set("shininess", 128, 0, 128)); materialParams.add(matDiffuseColor.set("matDiffuseColor", ofFloatColor(0, 0.204082, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); materialParams.add(matSpecularColor.set("matSpecularColor", ofFloatColor(1, 1, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); materialParams.add(matEmissiveColor.set("matEmissiveColor", ofFloatColor(0, 0.540816, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); materialParams.add(matAmbientColor.set("matAmbientColor", ofFloatColor(0, 0.55102, 1, 1), ofFloatColor(0,0,0,0),ofColor::white)); gui.add(materialParams); bShowGui = false; }
void EnMesh::handleNotification( const yaf3d::EntityNotification& notification ) { // handle notifications, add and remove the transformation node to / from scenegraph on menu entring / leaving switch( notification.getId() ) { case YAF3D_NOTIFY_MENU_ENTER: { if ( _enable ) { if ( _usedInMenu ) { addToSceneGraph(); } else { removeFromSceneGraph(); } } } break; case YAF3D_NOTIFY_MENU_LEAVE: { if ( _enable ) { if ( _usedInMenu ) { removeFromSceneGraph(); } else { addToSceneGraph(); } } } break; //! Note: by default the level manager re-adds persistent entity transformation nodes to its entity group while unloading a level. // thus we have to remove shadow nodes from that entity group on unloading a level; addToSceneGraph() does this job. case YAF3D_NOTIFY_ENTITY_TRANSNODE_CHANGED: { if ( _usedInMenu ) { // this method really removes the node from all its parents yaf3d::EntityManager::get()->removeFromScene( this ); // now add it to scene graph again addToSceneGraph(); } } break; case YAF3D_NOTIFY_ENTITY_ATTRIBUTE_CHANGED: { // re-setup mesh if ( _mesh.valid() ) removeFromTransformationNode( _mesh.get() ); _mesh = setupMesh(); if ( _mesh.valid() && _enable ) addToTransformationNode( _mesh.get() ); // if the attribute changes then we enable rendering regardless of current state // this method really removes the node from all its parents yaf3d::EntityManager::get()->removeFromScene( this ); // now add it to scene graph again addToSceneGraph(); } break; case YAF3D_NOTIFY_UNLOAD_LEVEL: if ( !_usedInMenu ) removeFromSceneGraph(); break; // if used in menu then this entity is persisten, so we have to trigger its deletion on shutdown case YAF3D_NOTIFY_SHUTDOWN: { removeFromTransformationNode( _mesh.get() ); if ( _usedInMenu ) yaf3d::EntityManager::get()->deleteEntity( this ); } break; default: ; } }