GeometryBufferPtr Gizmo::generateLines() { static const float OriginOffset = 0.01f; // Create a new VBO and upload triangle data GeometryBufferPtr gb = AllocateThis(GeometryBuffer); // Vertex position data std::vector< Vector3 > pos; // X axis pos.push_back( Vector3::Zero ); pos.push_back( Vector3::UnitX / 2.0f ); // Y axis pos.push_back( Vector3::UnitY*OriginOffset ); pos.push_back( Vector3::UnitY / 2.0f ); // Z axis pos.push_back( Vector3::Zero ); pos.push_back( Vector3::UnitZ / 2.0f ); // Vertex color data std::vector< Vector3 > colors; generateLinesColors(colors); // Vertex buffer setup gb->set( VertexAttribute::Position, pos ); gb->set( VertexAttribute::Color, colors ); return gb; }
void Model::doSkinning(const GeometryBufferPtr& gb) { VertexElement* elemPosition = gb->declarations.find(VertexAttribute::Position); if( !elemPosition ) return; // Can only handle buffers with 3 components and float. if(elemPosition->components != 3 || elemPosition->type != VertexDataType::Float) return; #if 0 uint32 numVertices = gb->getNumVertices(); if( mesh->position.size() != numVertices ) { LogDebug("Skinned mesh and its buffer have different vertices"); return; } for(size_t i = 0; i < meshPositions.size(); ++i) { int32 boneIndex = (int32) mesh->boneIndices[i]; Vector3* pos = (Vector3*) gb->getAttribute(VertexAttribute::Position, i); *pos = bones[boneIndex] * meshPositions[i]; } #endif gb->forceRebuild(); }
GeometryBufferPtr GizmoRotate::generateCircles() { // Vertex data std::vector< Vector3 > pos; std::vector< Vector3 > colors; Matrix4x3 transform; // X axis std::vector< Vector3 > posX; generateCircle(posX, SLICES); generateColors(colors, X); transform = Matrix4x3::createScale( Vector3(0.4f) ); TransformVertices(pos, posX, transform); // Y axis std::vector< Vector3 > posY; generateCircle(posY, SLICES); generateColors(colors, Y); transform = Matrix4x3::createScale( Vector3(0.4f) ); transform = transform*Matrix4x3::createRotation( EulerAngles(0, 90, 0) ); TransformVertices(pos, posY, transform); // Z axis std::vector< Vector3 > posZ; generateCircle(posZ, SLICES); generateColors(colors, Z); transform = Matrix4x3::createScale( Vector3(0.4f) ); transform = transform*Matrix4x3::createRotation( EulerAngles(90, 0, 0) ); TransformVertices(pos, posZ, transform); // Translate it a bit. transform = Matrix4x3::createTranslation( Vector3::UnitY * 0.5f ); for( uint i = 0; i < pos.size(); i++ ) { Vector3& v = pos[i]; v = transform*v; } // Vertex buffer setup GeometryBufferPtr gb = AllocateHeap(GeometryBuffer); assert( pos.size() == colors.size() ); gb->set( VertexAttribute::Position, pos ); gb->set( VertexAttribute::Color, colors ); return gb; }
DebugDrawer::DebugDrawer() : lines(nullptr) , triangles(nullptr) { Allocator* alloc = AllocatorGetThis(); MaterialHandle debug = MaterialCreate(alloc, "Debug"); Material* mat = debug.Resolve(); mat->setBackfaceCulling(false); mat->setBlending(BlendSource::SourceAlpha, BlendDestination::InverseSourceAlpha); mat->setDepthCompare( DepthCompare::LessOrEqual ); mat->setDepthOffset(Vector2(-1.0f, 1.0f)); //mat->setDepthRange( Vector2(0.1f, 0.9f) ); //mat->setDepthWrite(false); // Lines GeometryBuffer* linesVB = AllocateThis(GeometryBuffer); linesVB->setBufferAccess(BufferAccess::Write); linesVB->setBufferUsage(BufferUsage::Dynamic); SetupDebugVertexFormat(linesVB); lines = RenderBatchCreate(alloc); lines->setGeometryBuffer(linesVB); lines->setPrimitiveType(PrimitiveType::Lines); lines->setMaterial(debug); lines->setRenderLayer(RenderLayer::PostTransparency); renderables.push_back(lines.get()); // Triangles GeometryBufferPtr trianglesVB = AllocateThis(GeometryBuffer); trianglesVB->setBufferAccess(BufferAccess::Write); trianglesVB->setBufferUsage(BufferUsage::Dynamic); SetupDebugVertexFormat(trianglesVB.get()); triangles = RenderBatchCreate(alloc); triangles->setGeometryBuffer(trianglesVB); triangles->setPrimitiveType(PrimitiveType::Triangles); triangles->setMaterial(debug); triangles->setRenderLayer(RenderLayer::PostTransparency); renderables.push_back(triangles.get()); // Quads GeometryBufferPtr quadsVB = AllocateThis(GeometryBuffer); quadsVB->setBufferAccess(BufferAccess::Write); quadsVB->setBufferUsage(BufferUsage::Dynamic); SetupDebugVertexFormat(quadsVB.get()); quads = RenderBatchCreate(alloc); quads->setGeometryBuffer(quadsVB); quads->setPrimitiveType(PrimitiveType::Quads); quads->setMaterial(debug); quads->setRenderLayer(RenderLayer::PostTransparency); renderables.push_back(quads.get()); reset(); }