Mesh* Mesh::create(std::vector<char> vertexData, size_t vertexCount, std::vector<VertexElement> vertexLayout, PrimitiveType primitiveType) { auto mesh = new Mesh(); mesh->setPrimitiveType(primitiveType); mesh->loadVertices(std::move(vertexData), vertexCount, std::move(vertexLayout)); return mesh; }
AABBMesh::AABBMesh( Qt3DCore::QNode *parent ) : Qt3DRender::QGeometryRenderer( parent ) { setInstanceCount( 1 ); setIndexOffset( 0 ); setFirstInstance( 0 ); setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines ); mLineMeshGeo = new LineMeshGeometry( this ); setGeometry( mLineMeshGeo ); }
//! bool CTestSceneNode::set(ISceneNode* other) { if (!other || this == other || other->getSceneNodeType()!=ESNT_TEST_SCENE_NODE) { return false; } setPrimitiveType( ((ITestSceneNode*)other)->getPrimitiveType() ); setMaterial(other->getMaterial(0)); return true; }
SubImagesGeometry::SubImagesGeometry() : Geometry() , m_normalized(false) , m_w(0) , m_h(0) { setPrimitiveType(Geometry::Triangles); m_attributes << Attribute(TypeFloat, 2) << Attribute(TypeFloat, 2, 2*sizeof(float)) #if U8COLOR << Attribute(TypeUnsignedByte, 4, 4*sizeof(float), true); #else << Attribute(TypeFloat, 4, 4*sizeof(float));
//! constructor CTestSceneNode::CTestSceneNode( core::vector3df size, E_GEOM_PRIMITIVE_TYPE geom_type, ISceneNode* parent, s32 id ) : ITestSceneNode(parent, id), m_PrimitiveMesh(0), m_GeomPrimitiveType(E_GEOM_PRIMITIVE_TYPE_COUNT) { #if MY_DEBUG_MODE setClassName("CTestSceneNode"); #endif setPrimitiveType(geom_type); setScale(size); }
bool GLMesh::setData( const PrimitiveTypes& type, const VertexShaderData* pVertexData, const unsigned int& vertexCount, const unsigned int* pIndexes, const int& indexCount ) { setPrimitiveType(type); m_VertexCount = vertexCount; m_IndexCount = indexCount; glGenBuffers(1, &m_IndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer); //glBufferData() glBufferData(GL_UNIFORM_BUFFER, sizeof(VertexShaderData), NULL, GL_STATIC_COPY); return true; }
Sphere::Sphere( bool fullSphere, byte numSubDiv, float dim ) { setPrimitiveType( PrimitiveType::Triangles ); VertexData position; buildGeometry( fullSphere, numSubDiv, position, dim ); // Build Texture Coordinates. BoundingBox box; for( size_t i = 0; i < position.size(); i++ ) { const Vector3& v = position[i]; box.add(v); } Vector3 center = box.getCenter(); std::vector<Vector3> texCoords; for( size_t i = 0; i < position.size(); i++ ) { const Vector3& vert = position[i]; Vector3 d = vert-center; d.normalize(); // Conveert to spherical coordinates. //float t = d.z / sqrt(d.x*d.x+d.y*d.y+d.z*d.z); //float delta = acos(t); //float phi = atan2(d.y, d.x); //float u = delta / Math::PI; //float v = phi / 2*Math::PI; float u = std::asin(d.x) / PI + 0.5f; float v = std::asin(d.y) / PI + 0.5f; texCoords.push_back( Vector2(u, v) ); } gb->set( VertexAttribute::Position, position ); gb->set( VertexAttribute::TexCoord0, texCoords ); }
UIRenderer::UIRenderer(Ibl::IDevice* device) : Ibl::Mesh (device), _vertexOffset(0), _indexBuffer(nullptr), _currentShader(nullptr), _currentVertexBuffer(nullptr) { setDynamic (true); setPrimitiveType(Ibl::TriangleList); // Setup a Default Material. setMaterial(new Material(device)); // Setup Ringbuffered index buffer. IndexBufferParameters ibResource = IndexBufferParameters(sizeof(uint32_t)*25000, true, true); _indexBuffer = _device->createIndexBuffer(&ibResource); if (!_indexBuffer) { LOG("Failed to create ringed IndexBuffer for UIRenderer") assert(0); } }
Object::Object(InteractiveMarkerServerPtr server, string frame_id, string name) : BoundingBox(server, frame_id, name), show_pregrasp_control_(false), use_material_(false), translated_(false), allow_object_interaction_( true) { setPrimitiveType(srs_interaction_primitives::PrimitiveType::OBJECT); if (ros::param::has(MoveArmToPregraspOnClick_PARAM)) ros::param::get(MoveArmToPregraspOnClick_PARAM, move_arm_to_pregrasp_onclick_); else move_arm_to_pregrasp_onclick_ = false; pregrasp1_.name = "control_grasp_xp"; pregrasp2_.name = "control_grasp_xm"; pregrasp3_.name = "control_grasp_yp"; pregrasp4_.name = "control_grasp_ym"; pregrasp5_.name = "control_grasp_zp"; pregrasp6_.name = "control_grasp_zm"; if (pose_type_ == PoseType::POSE_BASE) { pose_.position.z += scale_.z * 0.5; } }
void CitySceneGenerator::generate(Scene* scene) { auto renderer = scene->renderer(); auto material = std::make_shared<PhongMaterial>(renderer); material->setShader(renderer->shaderManager()->getGlslProgram("phong")); PhongMaterialData materialData = { glm::vec4(0.0f, 0.1f, 0.0f, 1.0f), glm::vec4(0.8f, 0.3f, 0.1f, 1.0f), glm::vec4(0.3f, 0.3f, 0.3f, 1.0f), 5.0f }; material->properties()->setData(materialData); material->properties()->flushData(); auto mesh = std::make_shared<Mesh>(); mesh->setPrimitiveType(PrimitiveType::TriangleList); size_t buildingVerticesCount = sizeof(buildingVertices) / sizeof(*buildingVertices); std::vector<char> vertices(reinterpret_cast<const char*>(buildingVertices), reinterpret_cast<const char*>(buildingVertices) + sizeof(buildingVertices)); std::vector<VertexElement> layout = { VertexElement(3, VertexElementType::Float), VertexElement(3, VertexElementType::Float) }; mesh->loadVertices(vertices, buildingVerticesCount, layout); size_t buildingIndicesCount = sizeof(buildingIndices) / sizeof(*buildingIndices); std::vector<uint32_t> indices(reinterpret_cast<const unsigned*>(buildingIndices), reinterpret_cast<const unsigned*>(buildingIndices) + buildingIndicesCount); mesh->loadIndices(indices); size_t numBuildings = 1000; float citySize = 500.0f; float minBuildingSize = 10.0f; float maxBuildingSize = 60.0f; float minHeightToWidthRatio = 8.0f; float maxHeightToWidthRatio = 16.0f; std::uniform_real_distribution<float> angleDist(0.0f, 360.0f); std::uniform_real_distribution<float> positionDist(-citySize, citySize); std::uniform_real_distribution<float> canonicalDist; std::vector<std::shared_ptr<BaseSceneObject>> buildings; for (size_t i = 0; i < numBuildings; i++) { auto building = std::make_shared<Building>(mesh, material); // set random position glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(positionDist(m_rng), positionDist(m_rng), 0.0f) ); // rotate around z with random angle model = glm::rotate(model, angleDist(m_rng), glm::vec3(0.0f, 0.0f, 1.0f)); glm::vec3 scale; // multiplying uniform distribution will generate beta distribution scale.x = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * (maxBuildingSize - minBuildingSize) + minBuildingSize; scale.y = scale.x; scale.z = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * scale.x * (maxHeightToWidthRatio - minHeightToWidthRatio) + minHeightToWidthRatio; model = glm::scale(model, scale); building->setModelMatrix(model); building->calculateBBox(); buildings.push_back(building); } scene->setStaticGeometry(std::move(buildings)); }
QMeshData::QMeshData(PrimitiveType primitiveType) : d_ptr(new QMeshDataPrivate) { setPrimitiveType(primitiveType); }
bool ScreenOrientedQuad::initialize (const Ctr::Region2f& screenLocation, bool background) { setPrimitiveType (Ctr::TriangleStrip); setPrimitiveCount (2); setVertexCount (4); _screenLocation = screenLocation; uint32_t width = 1; uint32_t height = 1; //create vertex streams and vertex declaration information std::vector<VertexElement> vertexElements; vertexElements.push_back (VertexElement( 0, 0, FLOAT4, METHOD_DEFAULT, POSITION, 0)); vertexElements.push_back (VertexElement( 0, 16, FLOAT2, METHOD_DEFAULT, TEXCOORD, 0)); vertexElements.push_back (VertexElement(0xFF,0, UNUSED,0,0,0)); float lhx = _screenLocation.minExtent.x * width; float lhy = _screenLocation.minExtent.y * height; float screenWidth = _screenLocation.size().x * width; float screenHeight = _screenLocation.size().y * height; float z = 0; float w = 1; if (background) { z = 1; w = 1; } Vector4f vpos[] = {Vector4f(lhx, lhy, z, w), Vector4f(lhx, lhy + screenHeight, z, w), Vector4f(lhx+screenWidth, lhy, z, w), Vector4f(lhx+screenWidth, lhy + screenHeight, z, w) }; Vector2f tpos[] = {Vector2f(0, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(1, 0) }; if (IVertexDeclaration* vertexDeclaration = Ctr::VertexDeclarationMgr::vertexDeclarationMgr()->createVertexDeclaration (&VertexDeclarationParameters(vertexElements))) { setVertexDeclaration (vertexDeclaration); _positionStream = new Ctr::VertexStream (Ctr::POSITION, 0, 4, 4, (float*)vpos); _texCoordStream = new Ctr::VertexStream (Ctr::TEXCOORD, 0, 2, 4, (float*)tpos); addStream (_positionStream); addStream (_texCoordStream); if (create()) { return cache(); } } else { safedelete (vertexDeclaration); return false; } return false; }