Shape Shape::createShape( ShapeType type, float size /* = 1.0f */, float texturing /* = 2.0f */, int resolution /* = 16 */, float width /* = 0.0f */, float height /* = 0.0f */, float depth /* = 0.0f */) { this->setSize(size); this->setResolution(resolution); switch (type) { case SPHERE: this->setVertices(createSphere(size, resolution, true)); break; case PYRAMID: this->setVertices(createPyramid(size, texturing)); break; case TETRAHEDRON: this->setVertices(createTetrahedron(size, texturing)); break; case CUBOID: this->setVertices(createCuboid(size, width, height, depth, texturing)); break; default: break; } this->setMesh(Mesh(this->m_vertices, this->m_vertices.size())); return *(this); }
//----------------------------------------------------------------------- Resource* MeshManager::createImpl(const String& name, ResourceHandle handle, const String& group, bool isManual, ManualResourceLoader* loader, const NameValuePairList* createParams) { // no use for createParams here return OGRE_NEW Mesh(this, name, handle, group, isManual, loader); }
/** @brief Update memory using the Transfer object */ void TRMTransportAnalysis::UpdateMemory(){ Mesh()->LoadSolution(fX); TPZBuildMultiphysicsMesh::TransferFromMultiPhysics(fmeshvec, Mesh()); // Volumetric update if (fSimulationData->IsTwoPhaseQ()) { fTransfer->s_To_Transport_Memory(fmeshvec[0], Mesh(),0); } // Volumetric update if (fSimulationData->IsThreePhaseQ()) { fTransfer->s_To_Transport_Memory(fmeshvec[0], Mesh(),0); fTransfer->s_To_Transport_Memory(fmeshvec[1], Mesh(),1); } }
// ------------------------------------ GeomAttr::GeomAttr() : // ------------------------------------ Attribute(EATTR_GEOM), m_shape(GEOM_SQUARE), m_bound(Box(Vector2(-0.5, -0.5), Vector2(1, 1))) { m_mesh = Mesh(m_bound); }
// ------------------------------------ GeomAttr::GeomAttr(GEOM g) : // ------------------------------------ Attribute(EATTR_GEOM), m_shape(g) { switch(g) { case GEOM_SQUARE: m_bound = Box(Vector2(-0.5, -0.5), Vector2(1, 1)); m_mesh = Mesh(m_bound); break; case GEOM_TRIANGLE: m_bound = Box(Vector2(-0.5, -0.5), Vector2(1, 1)); m_mesh = Mesh(m_bound); break; } }
// ------------------------------------ GeomAttr::GeomAttr(Box b) : // ------------------------------------ Attribute(EATTR_GEOM), m_shape(GEOM_SQUARE) { m_bound = b; m_mesh = Mesh(b); }
bool loadMeshIntoMeshGroup(MeshGroup* meshgroup, const char* filename, const FMatrix3x3& transformation, SettingsBaseVirtual* object_parent_settings) { TimeKeeper load_timer; const char* ext = strrchr(filename, '.'); if (ext && (strcmp(ext, ".stl") == 0 || strcmp(ext, ".STL") == 0)) { Mesh mesh = object_parent_settings ? Mesh(object_parent_settings) : Mesh(meshgroup); //If we have object_parent_settings, use them as parent settings. Otherwise, just use meshgroup. if(loadMeshSTL(&mesh,filename,transformation)) //Load it! If successful... { meshgroup->meshes.push_back(mesh); log("loading '%s' took %.3f seconds\n",filename,load_timer.restart()); return true; } } return false; }
Scene Scene::load(const std::string &filename, const json11::Json &settings) { std::ifstream is(filename); std::stringstream ss; ss << is.rdbuf(); std::string err; Json jsonRoot = Json::parse(ss.str(), err); if (jsonRoot.is_null()) { throw Exception("Failed to load scene from '%s' (error: %s)", filename, err); } _resolver = filesystem::resolver(); _resolver.prepend(filesystem::path(filename).parent_path()); Scene scene; // Patch settings auto settingsValues = jsonRoot["settings"].object_items(); for (auto kv : settings.object_items()) { settingsValues[kv.first] = kv.second; } scene.settings = Properties(json11::Json(settingsValues)); // Parse scene objects Json jsonScene = jsonRoot["scene"]; if (jsonScene.is_object()) { auto jsonCamera = jsonScene["camera"]; if (jsonCamera.is_object()) { Properties props(jsonCamera); scene.camera = Camera(jsonCamera); } auto jsonWorld = jsonScene["world"]; if (jsonWorld.is_object()) { Properties props(jsonWorld); scene.world = World(jsonWorld); } for (auto jsonBox : jsonScene["boxes"].array_items()) { scene.boxes.emplace_back(Box(Properties(jsonBox))); } for (auto jsonSphere : jsonScene["spheres"].array_items()) { scene.spheres.emplace_back(Sphere(Properties(jsonSphere))); } for (auto jsonMesh : jsonScene["meshes"].array_items()) { scene.meshes.emplace_back(Mesh(Properties(jsonMesh))); } for (auto jsonCameraKeyframe : jsonScene["cameraKeyframes"].array_items()) { scene.cameraKeyframes.emplace_back(Camera(Properties(jsonCameraKeyframe))); } // Set default camera if (!jsonCamera.is_object()) { Vector3f center = scene.world.bounds.center(); scene.camera.position += center; scene.camera.target += center; } } return scene; }
Mesh Model::processMesh(aiMesh * mesh, const aiScene * scene) { std::vector<Vertex> vertices; std::vector<GLuint> indices; std::vector<Texture> textures; // process vertices 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.texCoords.x = mesh->mTextureCoords[0][i].x; vertex.texCoords.y = mesh->mTextureCoords[0][i].y; } else { vertex.texCoords = glm::vec2(0.0f, 0.0f); } vertices.push_back(vertex); } // process indices for (GLuint i = 0; i < mesh->mNumFaces; i++) { aiFace face = mesh->mFaces[i]; for (GLuint j = 0; j < face.mNumIndices; j++) { indices.push_back(face.mIndices[j]); } } // process material if (mesh->mMaterialIndex >= 0) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; std::vector<Texture> diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse"); textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); std::vector<Texture> specularMaps = this->loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular"); textures.insert(textures.end(), specularMaps.begin(), specularMaps.end()); } return Mesh(vertices, indices, textures); }
void TestGame::Init(const Window& window) { Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Material skin("humanFace", Texture("human.jpg"), 0.0f, 0, Texture("human_normal_inv.jpg")); //Material skin("humanFace", Texture("human.jpg"), 0.08f, 8, Texture("human_normal_inv.jpg")); IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f)) ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(7,0,7))) ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1)))); AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f))); AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f))); AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity(Vector3f(0, 0, 25))) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity()) ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook(window.GetCenter())) ->AddComponent(new FreeMove(10.0f))))); AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); }
Size2F SpriteTemplate::Measure(const FileId& data, const Size2F& limitSize /*= Size2F::Zero*/) const { auto obj= RenderingObjectFactory::Instance().CreateFromTexture(data); if (obj.IsValid()) { return obj.Mesh()->Size().To2D(); } return limitSize; }
Model Model::ConvertAssimpToDarknec(Model model, aiScene* scene) { model.numMeshes_ = scene->mNumMeshes; for (unsigned int mesh = 0; mesh < scene->mNumMeshes; mesh++) { Mesh messh = Mesh(); int vertCount = scene->mMeshes[mesh]->mNumVertices; int normCount = scene->mMeshes[mesh]->mNumVertices; int indiCount = scene->mMeshes[mesh]->mNumFaces * 3; //All imported models must be comprised of tris. int uvCount = scene->mMeshes[mesh]->mNumVertices; messh.numIndices_ = indiCount; messh.numNormals_ = normCount * 3; messh.numVertices_ = vertCount * 3; messh.numUVs_ = uvCount * 2; messh.hasNormals_ = scene->mMeshes[mesh]->HasNormals(); messh.hasUVS_ = scene->mMeshes[mesh]->HasTextureCoords(0); for (unsigned int face = 0; face < scene->mMeshes[mesh]->mNumFaces; face++) { aiFace facce = scene->mMeshes[mesh]->mFaces[face]; messh.indices_.push_back(facce.mIndices[0]); messh.indices_.push_back(facce.mIndices[1]); messh.indices_.push_back(facce.mIndices[2]); } for (int vertex = 0; vertex < vertCount; vertex++) { aiVector3D vector = scene->mMeshes[mesh]->mVertices[vertex]; messh.vertices_.push_back(vector.x); messh.vertices_.push_back(vector.y); messh.vertices_.push_back(vector.z); } if (messh.hasNormals_) { for (int normal = 0; normal < normCount; normal++) { aiVector3D vector = scene->mMeshes[mesh]->mNormals[normal]; messh.normals_.push_back(vector.x); messh.normals_.push_back(vector.y); messh.normals_.push_back(vector.z); } } if (messh.hasUVS_) { for (int uv = 0; uv < uvCount; uv++) { aiVector3D vector = scene->mMeshes[mesh]->mTextureCoords[0][uv]; messh.UVs_.push_back(vector.x); messh.UVs_.push_back(1- vector.y); } } model.meshes_.push_back(messh); } return model; }
Mesh Generate::line(const vector<VectorF> &linePointsIn, TextureDescriptor texture, Color color, float lineWidth) { if(linePointsIn.size() < 2) // if less than 2 points then we can't have a line { return Mesh(new Mesh_t()); } vector<VectorF> linePoints; linePoints.reserve(linePointsIn.size()); linePoints.push_back(linePointsIn[0]); for(size_t i = 1; i < linePointsIn.size(); i++) { if(absSquared(linePointsIn[i] - linePoints.back()) >= eps * eps) // remove duplicates linePoints.push_back(linePointsIn[i]); } if(linePoints.size() < 2) // if less than 2 points then we can't have a line { return Mesh(new Mesh_t()); } vector<Edge> edges; edges.reserve(linePoints.size()); float distance = 0; edges.push_back(makeStartEdge(linePoints[0], linePoints[1], distance, lineWidth)); distance += abs(linePoints[1] - linePoints[0]); for(size_t i = 2; i < linePoints.size(); i++) { edges.push_back(makeMiddleEdge(linePoints[i - 2], linePoints[i - 1], linePoints[i], distance, lineWidth)); distance += abs(linePoints[i - 1] - linePoints[i]); } edges.push_back(makeEndEdge(linePoints[linePoints.size() - 2], linePoints[linePoints.size() - 1], distance, lineWidth)); Mesh retval = nullptr; for(size_t i = 1; i < edges.size(); i++) { TextureDescriptor currentTexture = texture.subTexture(edges[i - 1].distance / distance, edges[i].distance / distance, 0, 1); Mesh mesh = Generate::quadrilateral(currentTexture, edges[i - 1].p2, color, edges[i].p2, color, edges[i].p1, color, edges[i - 1].p1, color); if(retval == nullptr) retval = mesh; else retval->add(mesh); } return retval; }
void TestDetector::detectMovingObject() { InternalMessage("Model","Model::TestDetector::detectMovingObject entering") ; /*! We create a ship with a detector and a second object to detect. */ std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestDetector::detectMovingObject")) ; model->init() ; Kernel::Object* system = model->createObject() ; Kernel::Object* ship = system->createObject() ; ship->addTrait(new Positioned()) ; ship->addTrait(new Oriented()) ; ship->addTrait(new Mobile()) ; ship->addTrait(new Solid(Mesh("test_ship.mesh"))) ; ship->addTrait(new Massive(Mass::Kilogram(1000))) ; ship->addTrait(new Computer()) ; ship->addTrait(new Detector()) ; Detector::connect(ship,ship) ; Kernel::Object* ship2 = system->createObject() ; ship2->addTrait(new Positioned(Position::Meter(0,0,500))) ; ship2->addTrait(new Massive(Mass::Kilogram(1000))) ; ship2->addTrait(new Oriented()) ; ship2->addTrait(new Mobile()) ; ship2->addTrait(new Solid(Mesh("test_ship.mesh"))) ; // the second ship has been detected. std::set<Kernel::Object*> detected(ship->getTrait<Computer>()->getDetectedObjects()) ; CPPUNIT_ASSERT(!detected.empty()) ; CPPUNIT_ASSERT(detected.find(ship2) != detected.end()) ; ship2->getTrait<Positioned>()->setPosition(Position::Meter(0,100,0)) ; // the second ship has been detected. detected = ship->getTrait<Computer>()->getDetectedObjects() ; CPPUNIT_ASSERT(!detected.empty()) ; CPPUNIT_ASSERT(detected.find(ship2) != detected.end()) ; InternalMessage("Model","Model::TestDetector::detectMovingObject leaving") ; }
void MeshBuilder::apply(Mesh& mesh) const { if (!mesh.is_initialized()) { mesh = Mesh(vertex_decl, index_type, DRAW_TRIANGLES); } else { COLD_DEBUG_ASSERT(mesh.get_vertex_declaration() == vertex_decl); COLD_DEBUG_ASSERT(mesh.get_index_type() == index_type); } mesh.set_vertices(vertices.get_pointer(), vertices.get_count()); mesh.set_indices(indices.get_pointer(), indices.get_count()); }
RenderingEngine::RenderingEngine(const Window& window) : m_plane(Mesh("plane.obj")), m_window(&window), m_tempTarget(window.GetWidth(), window.GetHeight(), 0, GL_TEXTURE_2D, GL_NEAREST, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0), m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8), m_defaultShader("forward-ambient"), m_shadowMapShader("shadowMapGenerator"), m_nullFilter("filter-null"), m_gausBlurFilter("filter-gausBlur7x1"), m_fxaaFilter("filter-fxaa"), m_altCameraTransform(Vector3f(0,0,0), Quaternion(Vector3f(0,1,0),ToRadians(180.0f))), m_altCamera(Matrix4f().InitIdentity(), &m_altCameraTransform) { SetSamplerSlot("diffuse", 0); SetSamplerSlot("normalMap", 1); SetSamplerSlot("dispMap", 2); SetSamplerSlot("shadowMap", 3); SetSamplerSlot("roughMap", 4); SetSamplerSlot("filterTexture", 0); SetVector3f("ambient", Vector3f(0.2f, 0.2f, 0.2f)); SetFloat("fxaaSpanMax", 8.0f); SetFloat("fxaaReduceMin", 1.0f/128.0f); SetFloat("fxaaReduceMul", 1.0f/8.0f); SetFloat("fxaaAspectDistortion", 150.0f); SetTexture("displayTexture", Texture(m_window->GetWidth(), m_window->GetHeight(), 0, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, true, GL_COLOR_ATTACHMENT0)); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glFrontFace(GL_CW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); //glEnable(GL_DEPTH_CLAMP); //glEnable(GL_MULTISAMPLE); //glEnable(GL_FRAMEBUFFER_SRGB); //m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8); m_planeTransform.SetScale(1.0f); m_planeTransform.Rotate(Quaternion(Vector3f(1,0,0), ToRadians(90.0f))); m_planeTransform.Rotate(Quaternion(Vector3f(0,0,1), ToRadians(180.0f))); for(int i = 0; i < NUM_SHADOW_MAPS; i++) { int shadowMapSize = 1 << (i + 1); m_shadowMaps[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0); m_shadowMapTempTargets[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0); } m_lightMatrix = Matrix4f().InitScale(Vector3f(0,0,0)); }
Sprite* NodeFactory::CreateSpriteFromAtlasRegion(StringRef regionName, const FileIdRef& atlasFileId, TextureAtlasFileFormat fileFormat /*= TextureAtlasFileFormat::Spine*/, uint atlasPageCount /*= 1*/) { auto renderingObject = RenderingObjectFactory::Instance().CreateFromTextureAtlasRegion(regionName, atlasFileId, fileFormat, atlasPageCount); RETURN_NULL_IF_NULL(renderingObject); Sprite* sprite = new Sprite(); sprite->SetRenderingObject(renderingObject); sprite->SetSize(renderingObject.Mesh()->Size()); sprite->Initialize(); return sprite; }
Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) { vector<Vertex> vertices; vector<GLuint> indices; vector<Texture> textures; // Process vertex positions, normals and texture coordinates for(GLuint i = 0; i < mesh->mNumVertices; i++) { Vertex vertex; glm::vec3 vector; vector.x = mesh->mVertices[i].x; vector.y = mesh->mVertices[i].z; vector.z = mesh->mVertices[i].y; //printVec("vertex ", vector); vertex.position = vector; vector.x = mesh->mNormals[i].x; vector.y = mesh->mNormals[i].z; vector.z = mesh->mNormals[i].y; vertex.normal = vector; // Does the mesh contain texture coordinates? if(mesh->mTextureCoords[0]) { glm::vec2 vec; vec.x = mesh->mTextureCoords[0][i].x; vec.y = mesh->mTextureCoords[0][i].y; vertex.textureCoords = vec; } else vertex.textureCoords = glm::vec2(0.0f, 0.0f); vertices.push_back(vertex); } // Process indices for(GLuint i = 0; i < mesh->mNumFaces; i++) { aiFace face = mesh->mFaces[i]; for(GLuint j = 0; j < face.mNumIndices; j++) indices.push_back(face.mIndices[j]); } // Process material if(mesh->mMaterialIndex >= 0) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; vector<Texture> diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse"); textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); vector<Texture> specularMaps = this->loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular"); textures.insert(textures.end(), specularMaps.begin(), specularMaps.end()); } return Mesh(vertices, indices, textures); }
Mesh Model::ProcessMesh(aiMesh* mesh, const aiScene* scene) { // Data to fill std::vector<MeshVertex> vertices; std::vector<uint> indices; std::vector<MeshTexture> textures; if (mesh->mMaterialIndex >= 0) { aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex]; if (textype.empty()) textype = determineTextureType(scene, mat); } // Walk through each of the mesh's vertices for (uint i = 0; i < mesh->mNumVertices; i++) { MeshVertex vertex; vertex.x = mesh->mVertices[i].x; vertex.y = mesh->mVertices[i].y; vertex.z = mesh->mVertices[i].z; vertex.normal = vec3(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z); if (mesh->mTextureCoords[0]) { vertex.texcoord.x = (float)mesh->mTextureCoords[0][i].x; vertex.texcoord.y = (float)mesh->mTextureCoords[0][i].y; } vertices.push_back(vertex); } for(uint i = 0; i < mesh->mNumFaces; i++) { aiFace face = mesh->mFaces[i]; for (uint j = 0; j < face.mNumIndices; j++) indices.push_back(face.mIndices[j]); } if (mesh->mMaterialIndex >= 0) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; std::vector<MeshTexture> diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene); textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); } return Mesh(vertices, indices, textures); }
SceneNode::SceneNode(glm::vec3 dispxyzIN, float rotyIN, glm::vec3 scalexyzIN, ShapeGen::ShapeType shapeTypeIn, int matIndIN, bool inheritsColorIN) { dispxyz = dispxyzIN; roty = rotyIN; scalexyz = scalexyzIN; shapeType = shapeTypeIn; matInd = matIndIN; inheritsColor = inheritsColorIN; meshContents = Mesh(); }
void Mesh::loadMesh(const std::string & modelName, std::vector<Mesh> & meshData, aiNode * node, const aiScene * scene) { for (unsigned i = 0; i < node->mNumMeshes; i++) { auto mesh = scene->mMeshes[node->mMeshes[i]]; meshData.emplace_back(Mesh(modelName, mesh, scene)); } for (unsigned i = 0; i < node->mNumChildren; i++) { loadMesh(modelName, meshData, node->mChildren[i], scene); } }
eae6320::Graphics::GameObject::GameObject(char* const i_path_mesh, char* const i_path_material) { m_mesh = Mesh(i_path_mesh); m_material = Material(i_path_material); m_position = Math::cVector(); m_orientation = Math::cQuaternion(); m_velocity = Math::cVector(0, 0, 0); m_collider.sExtends = Math::cVector(0, 0, 0); m_alpha = 1.0; }
//---------------------------------------------------------------------------- bool ObjLoader::GetMaterialAndMesh (const vector<string>& tokens) { if (tokens[0] == "usemtl") { if (tokens.size() == 1) { assert(false); mCode = EC_TOO_FEW_TOKENS; return false; } if (tokens.size() > 2) { assert(false); mCode = EC_TOO_MANY_TOKENS; return false; } int i; for (i = 0; i < (int)mMaterials.size(); ++i) { if (tokens[1] == mMaterials[i].Name) { break; } } if (i == (int)mMaterials.size()) { assert(false); mCode = EC_FAILED_TO_FIND_MATERIAL; return false; } mCurrentMtl = i; Group& group = mGroups[mCurrentGroup]; for (i = 0; i < (int)group.Meshes.size(); ++i) { if (group.Meshes[i].MtlIndex == mCurrentMtl) { break; } } if (i == (int)group.Meshes.size()) { // Mesh with this material does not yet exist. group.Meshes.push_back(Mesh()); group.Meshes.back().MtlIndex = mCurrentMtl; } mCurrentMesh = i; return true; } return false; }
int MeshManager::MeshFactory( GameObject* gameObject, string meshAsset, string matAsset ) { Mesh M = Mesh( __keyToIndex.size(), gameObject, meshAsset, matAsset ); __meshes.push_back( M ); int key = __keyToIndex.size(); __keyToIndex[ key ] = __meshes.size() - 1; return key; }
Sprite* NodeFactory::CreateQuadSprite(const FileIdRef& textureName, const Rect2F& textureRect/*=Rect2F::Zero*/) { auto renderingObject = RenderingObjectFactory::Instance().CreateFromTexture(textureName, textureRect); RETURN_NULL_IF_NULL(renderingObject); Sprite* sprite = new Sprite(); sprite->SetRenderingObject(renderingObject); sprite->SetSize(renderingObject.Mesh()->Size()); sprite->Initialize(); return sprite; }
GLWidget::GLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent) { backgroundColor = QColor::fromRgb(235.0, 235.0, 235.0); position = QVector3D(0.0, 0.0, -20.0); boundingBoxesVisible = false; xRot = 0; yRot = 0; zRot = 0; Mesh mesh = Mesh(); mesh.readObjFile("C:/Users/Sebastian/Desktop/capsule.obj"); mesh.calculateBoundingBox(); mesh.translation = QVector3D(2, 0, -2); meshes.append(mesh); mesh = Mesh(); mesh.readObjFile("C:/Users/Sebastian/Desktop/cube.obj"); mesh.calculateBoundingBox(); mesh.translation = QVector3D(10, 0, 10); meshes.append(mesh); mesh = Mesh(); mesh.readObjFile("C:/Users/Sebastian/Desktop/armchair.obj"); mesh.calculateBoundingBox(); mesh.translation = QVector3D(-15, 0, 15); meshes.append(mesh); mesh = Mesh(); mesh.readObjFile("C:/Users/Sebastian/Desktop/armchair.obj"); mesh.calculateBoundingBox(); mesh.translation = QVector3D(-15, 0, 20); meshes.append(mesh); mesh = Mesh(); mesh.readObjFile("C:/Users/Sebastian/Desktop/armchair.obj"); mesh.calculateBoundingBox(); mesh.translation = QVector3D(-20, 0, 20); meshes.append(mesh); }
void TPZMultiphysicsElement::CreateInterfaces() { //nao verifica-se caso o elemento de contorno //eh maior em tamanho que o interface associado //caso AdjustBoundaryElement nao for aplicado //a malha eh criada consistentemente TPZGeoEl *ref = Reference(); int nsides = ref->NSides(); int InterfaceDimension = Mesh()->Dimension() - 1; int side; nsides--;//last face for(side=nsides;side>=0;side--) { if(ref->SideDimension(side) != InterfaceDimension) continue; TPZCompElSide thisside(this,side); if(this->ExistsInterface(side)) { // cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n"; continue; } TPZStack<TPZCompElSide> highlist; thisside.HigherLevelElementList(highlist,0,1); //a interface se cria uma vez so quando existem ambos //elementos esquerdo e direito (compu tacionais) if(!highlist.NElements()) { this->CreateInterface(side);//s�tem iguais ou grande => pode criar a interface } else { int64_t ns = highlist.NElements(); int64_t is; for(is=0; is<ns; is++) {//existem pequenos ligados ao lado atual const int higheldim = highlist[is].Reference().Dimension(); if(higheldim != InterfaceDimension) continue; // TPZCompElDisc *del = dynamic_cast<TPZCompElDisc *> (highlist[is].Element()); // if(!del) continue; TPZCompEl *del = highlist[is].Element(); if(!del) continue; TPZCompElSide delside( del, highlist[is].Side() ); TPZMultiphysicsElement * delSp = dynamic_cast<TPZMultiphysicsElement *>(del); if (!delSp){ PZError << "\nERROR AT " << __PRETTY_FUNCTION__ << " - CASE NOT AVAILABLE\n"; return; } if ( delSp->ExistsInterface(highlist[is].Side()) ) { // cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n"; } else { delSp->CreateInterface(highlist[is].Side()); } } } } }
Sprite* NodeFactory::CreateSpriteFromAtlasRegion(TextureAtlasRegion* region) { auto renderingObject = RenderingObjectFactory::Instance().CreateFromTextureAtlasRegion(region); RETURN_NULL_IF_NULL(renderingObject); Sprite* sprite = new Sprite(); sprite->SetRenderingObject(renderingObject); sprite->SetSize(renderingObject.Mesh()->Size()); sprite->Initialize(); return sprite; }
void RawSceneLoader::load(Scene& r , const std::string fileName) { Vector3f positions[] = { Vector3f(-0.5f, -0.5f, 0.5f), // left front Vector3f(-0.5f, -0.5f, -0.5f), // left rear Vector3f( 0.5f, -0.5f, 0.5f), // right front Vector3f( 0.5f, -0.5f, -0.5f), // right rear Vector3f( 0.0f, 0.5f, 0.0f), // peak }; Vector3f colors[] = { Vector3f(0.0f, 0.0f, 1.0f), Vector3f(0.0f, 0.0f, 1.0f), Vector3f(0.0f, 1.0f, 0.0f), Vector3f(1.0f, 1.0f, 0.0f), Vector3f(1.0f, 0.0f, 0.0f), }; unsigned int indices[] = { 1, 3, 0, 0, 3, 2, 1, 0, 4, 3, 1, 4, 2, 3, 4, 0, 2, 4 }; Vector3f normals[sizeof(positions) / sizeof(Vector3f)]; CalcNormals(indices, sizeof(indices) / sizeof(unsigned int), positions,sizeof(positions) / sizeof(Vector3f), normals); Vector2f tex[] = { Vector2f(0.0f, 0.0f), Vector2f(1.0f, 0.0f), Vector2f(1.0f, 0.0f), Vector2f(0.0f, 0.0f), Vector2f(0.5f, 1.0f), }; Vector3f lightColor = Vector3f(1.0f, 1.0f, 1.0f); float ambientLightIntensity = 0.1f; float diffuseLightIntensity = 0.3f; float specularIntensity = 1.0f; float specularPower = 32.0f; Vector3f direction = Vector3f(0.0,0.0f,1.0f); r.meshes.push_back(Mesh(5, positions, colors, tex, normals, 6, indices)); r.lights.push_back(Light(lightColor,ambientLightIntensity,diffuseLightIntensity,direction)); r.textures.push_back(Texture()); // load texture from file r.materials.push_back(Material(specularIntensity, specularPower)); }
void Enco3D::Rendering::Mesh::renderErrorMesh(Rendering::Shader *shader, Core::Transform *transform, const Component::Camera *camera, Rendering::RenderingEngine *renderingEngine) { static bool initializedMeshAndMaterial = false; static Mesh errorMesh; static Material errorMaterial; if (!initializedMeshAndMaterial) { initializedMeshAndMaterial = true; Vertex vertices[8] = { Vertex(-1, -1, 0).setTexCoord(1, 1, 0).setNormal(0, 0, +1), Vertex(+1, -1, 0).setTexCoord(0, 1, 0).setNormal(0, 0, +1), Vertex(+1, +1, 0).setTexCoord(0, 0, 0).setNormal(0, 0, +1), Vertex(-1, +1, 0).setTexCoord(1, 0, 0).setNormal(0, 0, +1), Vertex(+1, -1, 0).setTexCoord(1, 1, 0).setNormal(0, 0, -1), Vertex(-1, -1, 0).setTexCoord(0, 1, 0).setNormal(0, 0, -1), Vertex(-1, +1, 0).setTexCoord(0, 0, 0).setNormal(0, 0, -1), Vertex(+1, +1, 0).setTexCoord(1, 0, 0).setNormal(0, 0, -1), }; unsigned int indices[12] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, }; errorMesh = Mesh(vertices, 8, indices, 12); errorMaterial.addTexture2D("diffuseTexture", new Texture2D("texture/error.png", TextureFilter::Linear)); errorMaterial.addVector3f("diffuseColor", Core::Color3Template::White); errorMaterial.addFloat("specularIntensity", 0.0f); errorMaterial.addFloat("specularExponent", 1.0f); } Core::Transform billboardTransform; billboardTransform.setTranslation(transform->getTranslation()); billboardTransform.setScaling(transform->getScaling()); billboardTransform.setBillboardEnabled(true); billboardTransform.setBillboardCamera((Component::Camera*)camera); billboardTransform.update(); shader->bind(); shader->updateUniforms(&billboardTransform, camera, renderingEngine, errorMaterial); errorMesh.render(); }