{"id":6667,"date":"2022-09-04T13:13:21","date_gmt":"2022-09-04T07:43:21","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/"},"modified":"2022-09-04T13:13:21","modified_gmt":"2022-09-04T07:43:21","slug":"solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/","title":{"rendered":"[Solved] How to get a list the visible vertices and segments of a mesh"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-48784455\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"48784455\" data-parentid=\"48767103\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p><strong>Face culling<\/strong><\/p>\n<p>This works only for single convex strict winding rule mesh without holes!<\/p>\n<p>The idea is that sign of dot product of 2 vectors will tell you if the vectors are opposite or not. So if we have a normal pointing out and view direction their dot should be negative for faces turned towards camera\/viewer.<\/p>\n<p>As you do not want to render just select visible planar faces\/edges you can do this on <strong>CPU<\/strong> side entirely. What you need is to have your mesh in form of planar faces (does not matter if triangles,quads or whatever) so let assume triangles (for more points you just add them to <code>_face<\/code> but for computation still use only <code>v0,v1,v2<\/code>) &#8230; Each face should have the vertexes and normal.<\/p>\n<pre class=\"lang-cpp prettyprint-override\"><code>struct _face\n {\n double v0[3],v1[3],v2[3],n[3];\n };\n\nList&lt;_face&gt; mesh;\n<\/code><\/pre>\n<p>Now the vertexes <code>v0,v1,v2<\/code> you already have. All of them should be ordered in strict winding rule. That means if you look at any face from outside the points should form only <strong>CW<\/strong> (clockwise) loop (or only <strong>CCW<\/strong> (counter-clockwise) loop). To compute normal you simply exploit cross product which returns vector perpendicular to both operands:<\/p>\n<pre><code>n = cross(v1-v0,v2-v1) \/\/ cross product\nn = n \/ |n|            \/\/ optional normalize to unit vector\n<\/code><\/pre>\n<p>If you need the vector math see<\/p>\n<ul>\n<li>Understanding 4&#215;4 homogenous transform matrices<\/li>\n<\/ul>\n<p>On the bottom is how to compute this&#8230; Also the whole answer you will need for the camera direction so read it&#8230;<\/p>\n<p>Now if your mesh has strict winding rule than all the computed normals are pointing out of mesh (or inwards depends on your coordinate system, <strong>CW\/CCW<\/strong> and order of operands in cross product). Let assume they all pointing out (if not just negate normal).<\/p>\n<p>In case you do not have strict winding rule compute avg point of your mesh (sum all vertexes and divide by their count) this will be the center <code>c<\/code> of your object. Now just compute<\/p>\n<pre><code>dot(n,(v0+v1+v2)\/3 - c)\n<\/code><\/pre>\n<p>and if not positive negate the <code>n<\/code>. This will repair your normals (you can also reverse the <code>v0,v1,v2<\/code> to repair the mesh.<\/p>\n<p>Now the camera and mesh usually has its own 4&#215;4 transform matrix. one transfroms from mesh <strong>LCS<\/strong> (local coordinate system) to <strong>GCS<\/strong> (&#8220;world&#8221; global coordinate system) and the other from <strong>GCS<\/strong> to camera <strong>LCS<\/strong> (screen). We do not need projections for this as we do not render &#8230; So what we need to do for each face is:<\/p>\n<ol>\n<li>\n<p>convert <code>n<\/code> to <strong>GCS<\/strong><\/p>\n<\/li>\n<li>\n<p>compute <code>dot(n,camera_view_direction)<\/code><\/p>\n<p>where <code>camera_view_direction<\/code> is <strong>GCS<\/strong> vector pointing in view direction. You can take it from direct camera matrix directly. It is usually the <code>Z<\/code> axis vector (in <strong>OpenGL<\/strong> Perspective view it is <code>-Z<\/code>). Beware camera matrix used for rendering is inverse matrix so if the case either compute inverse first or transpose it as we do not need the offset anyway &#8230;<\/p>\n<\/li>\n<li>\n<p>decide if face visible from the sign of <strong>#2<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>Again all the math is explained in the link above&#8230;<\/p>\n<p>In case you do not have mesh matrix (does not have changing position or orientation) you can assume its matrix is unit one which means <code>GCS = mesh LCS<\/code> so no need for transformations.<\/p>\n<p>In some cases there is no camera and only mesh matrix (I suspect your case) then it is similar you just ignore the camera transforms and use <code>(0,0,-1)<\/code> or <code>(0,0,+1)<\/code> as view direction.<\/p>\n<p>Also see this:<\/p>\n<ul>\n<li>Understanding lighting in OpenGL<\/li>\n<\/ul>\n<p>It should shine some light on the <strong>normals<\/strong> topic.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to get a list the visible vertices and segments of a mesh <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Face culling This works only for single convex strict winding rule mesh without holes! The idea is that sign of dot product of 2 vectors will tell you if the vectors are opposite or not. So if we have a normal pointing out and view direction their dot should be negative for faces turned &#8230; <a title=\"[Solved] How to get a list the visible vertices and segments of a mesh\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\" aria-label=\"More on [Solved] How to get a list the visible vertices and segments of a mesh\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1082,349],"class_list":["post-6667","post","type-post","status-publish","format-standard","hentry","category-solved","tag-opengl","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Face culling This works only for single convex strict winding rule mesh without holes! The idea is that sign of dot product of 2 vectors will tell you if the vectors are opposite or not. So if we have a normal pointing out and view direction their dot should be negative for faces turned ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-04T07:43:21+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How to get a list the visible vertices and segments of a mesh\",\"datePublished\":\"2022-09-04T07:43:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\"},\"wordCount\":554,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"opengl\",\"python\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\",\"name\":\"[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-04T07:43:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How to get a list the visible vertices and segments of a mesh\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb","og_description":"[ad_1] Face culling This works only for single convex strict winding rule mesh without holes! The idea is that sign of dot product of 2 vectors will tell you if the vectors are opposite or not. So if we have a normal pointing out and view direction their dot should be negative for faces turned ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/","og_site_name":"JassWeb","article_published_time":"2022-09-04T07:43:21+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How to get a list the visible vertices and segments of a mesh","datePublished":"2022-09-04T07:43:21+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/"},"wordCount":554,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["opengl","python"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/","name":"[Solved] How to get a list the visible vertices and segments of a mesh - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-04T07:43:21+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-get-a-list-the-visible-vertices-and-segments-of-a-mesh\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How to get a list the visible vertices and segments of a mesh"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=6667"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6667\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=6667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=6667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=6667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}